how to set the Shinobicharts column width fixed in Android? - android

I am facing a strange issue with ShinobiCharts[Android] column width for the below scenarios:
XAxis : Date <br>
YAxis : Double
Input 1: DataAdapter= {[00:00,0.0], [02:00,360] , [24:00,0.0] }
Output : below output#1 screenshot shows expected column width wit bar.
Input 2: DataAdapter={[00,0.0], [15:150.0], [24:00,0.0]}
Output : screenshot 2 shows a bar with more length of column which does not fit inside that bounds.
Input 3: DataAdapter={[00,0.0], [23:00,360.0] , [24:00,0.0]}
Output : screenshot 3 shows even bigger and bigger and column width.
If adapter all has 3 entries for that day, then every column width showed like screenshot 1.
Question is: I just wanted to know what am i missing here, and what api should I use to restrict this column width to shown only inside that bounds where it fits?
Please help me.
private Series createSeries(#NonNull final DataAdapter<Date, Integer> dataAdapter, #NonNull final String title, final int color) {
final ColumnSeries series = new ColumnSeries();
series.setDataAdapter(dataAdapter);
series.setShownInLegend(true);
series.setTitle(title);
series.setSelectionMode(Series.SelectionMode.POINT_MULTIPLE);
ColumnSeriesStyle style = series.getStyle();
style.setAreaColor(color);
style.setAreaColorGradient(color);
style.setLineColor(color);
series.setStackId(1);
return series;
}

Here is the solution to my own question.
Problem:
shinoby-version: shinobicharts-android-premium-1.7.2-0.jar
from the below link , got to know that shinobycharts does not have api to control the width of the column (vertical bar) (scroll down and see (rippling posted this 22 January 2016)) its backlog item .
[shinobicontrols.com/forum/shinobicontrols/2013/4/how-are-the-widths-of-columns-set]
as per the attached screenshots, if there is no entry point for the first partition midnight 12- to early morning 4 [12-4] or [00-04] per a day on X-axis, the width of the column is uncontrollable.
Solution:
As a workaround or a proper fix, I just added a dummy entry in the first partition if there is no actual data. and the final adapter looks like below.
If actual data presents for the 1st partition i.e [12-4] in screenshot. no need to add dummy here:
earlier: DataAdapter= {[00:00,0.0],[02:00,360],[24:00,0.0] }
now: DataAdapter= {[00:00,0.0],[02:00,360],[24:00,0.0] }
//no change as it was earlier.
if not:
earlier: DataAdapter={[00,0.0], [15:150.0], [24:00,0.0]}
now: DataAdapter= {[00:00,0.0],[02:00,0],[15:150.0],[24:00,0.0] }
end entry [02:00, 0] is the dummy entry here. and does not mess up the output as the VALUE is set to Zero here.
Output:#
Without entry in the first partition 12-4
With entry in the first partition 12-4

I am glad that you were able to resolve your issue.
As you have seen, the data itself can have a significant impact on the width at which the columns are drawn.
When the chart calculates the width at which to draw the column, amongst other things it looks at the distance between each data value for the relevant axis. It will choose the shortest distance between two data point values and base it’s column width calculation on this. This approach usually results in evenly spaced columns with a consistent width, except when the data point values have a varied frequency. For example if most of your data points have an x value 9 hours from it’s adjacent ones, but then one pair of x values are only 2 hours apart, you may experience this type of issue. Furthermore, a DateTime axis, when used with a column or bar chart can also result in varying column or bar widths because date frequencies are often varied. For example, for monthly data, some months have 31 days whereas some have 30, 28 or 29.
In the future we may look to provide additional api methods to allow manual setting of column width. I cannot of course give any firm indication of when such api will be available. In the meantime if you still experience issues with your column chart, please do get in touch by contacting info#shinobicontrols.com. In this instance please do include a code sample where possible, to help us to get up to speed with your issue quickly.
Thanks and kind regards,
Kai
Disclaimer: I work for Shinobicontrols.

Related

OpenCV Android - Calculate the average of a column of Mat

What I'm trying is to calculate the average of a column using openCV in android.
The initial idea was to copy each column to a temp matrix, then use Core.mean() to get the average value.
But the problem is :
To use Mat.put(), it is expected to have a row, column and a Array[] data and Core.Mean() returns a scalar, so I can't do something like:
myMat.put(row,1,Core.Mean(myTempColumn)).
So how this operation can be done?
I'm wondering that I'll need to get each element from myMat using get and then sum. But the problem is get returns also a Array[] data (that I think is the RGB value), and to sum it, will be necessary another for structure (which I don't think it is the easiest way).
Thank you in advance.
Ok solve it:
Core.reduce(imageMat,averageMat,0,Core.REDUCE_AVG);
Where:
0 means that the matrix is reduced to a single row. 1 means that the matrix is reduced to a single column.
Core.REDUCE_AVG - does the average

Count until zero

I am beginner and trying to write some calculations with App Inventor 2.
I am trying to write a code to calculate Net present value.
The formula of NPV = - investment + CF/(1+i)power up by years of investment, which means if years of investment are > 1 the second part of formula will repeat until it reached the number of years.
I successfully code the formula for one year that works correct, but have problem with the "repeating" the second part powered by number of years.
I tried to declare years as variable to use it as powering number but think something is wrong with it.
In my opinion I need to split the powering number somewhere to memory and then increase it by 1 until the required number. However have no clue how to do it.
Can anyone help?
Screenshot of the blocks
Following the calculation from the NPB Calculator,
this is converted into blocks the following
Note: for a better clarity and to avoid such long calculation blocks as in your screenshot, I used External Inputs instead of Inline Inputs, which is the default. You can switch that from the context menu after doing a right mouse click onto one of the calculation blocks.
EDIT: screenshot updated for changing cashflows using a list.See also
How to work with Lists by Saj and
How to work with Lists and Lists of lists (pdf) by appinventor.org

How to store a gps coordinates in mysql, and then retrieve it without time lag?

I have completed a phonegap app which pools gps cordinate data every 10 sec to the server. now according to the calculations 8 hours of tracking it will store around 8*60*6=2880 records per user. my current requirement is limited to use of 20 user. (basically it tracks a users rout travelled)
There are two parts to the question:
what is the best way to store the data and retrieve it as fast as possible.
is it possible to display 2880 coordinates at a time on google maps API v3 ? if not, what is the best way to display the rout traveled?
I am having good results with 90 or so points, for one of my demos, but the enormous 2880 records per user per 8 hours is what worries me.
Thanks
EDIT 1
Although this is an old question , I recently worked on a project where I displayed about 10K points on the map, I hope my observations would help the future visitors:
The google maps as if now do not have a hard limit on the number of points you can display on the client side.
The number of points you can display on the client side is entirely dependent on the client side `Hardware` , bigger the number of points using a jpeg or gif marker , slower will be the renders , when moving around or zooming in and out
To have huge number of pointers on the map with a minimal performance hit, precomputing the number of points needed to be rendered before and after pan or zoom occurs will help a lot.
So here is a possible solution:
First of all, you need to find out how many points Google Maps API can handle and still show the line. I think this will just take some testing or researching. Anyways once you find your magical number of points to display to plot your path then take that number and multiply it by 2/3.
For instance if a good path needs have say 90 points then calculate 90*2/3
The reason for 2/3 is that the following loop will return a max number of points that is averagely equal to 3/2 times the variable we use so using. 60 would give us on average 90 plots. There is a case where the most returned plots would be (2 * (magical number of points)) - 1 for instance say we want on average of 90 points then we could in some rare cases have (2*(90*2/3))-1 = 119 points You will just have to do some testing after implementation to make sure that your magical number of points works good for maps with 2/3 of the magical number of points and 2 * magical number of points -1. I hope this isn't too confusing... I tried to explain as best I can.
The rest of this is going to be sudo code. You will have to adapt it for whatever language you connect to MySQL with:
//get the total number of rows returned
var total_rows = mysql->num_rows;
//calculate max to be 2/3 times your magic number for max plots, i.e. 90
var max_plots = 90*2/3;
//define empty plots array to fill with coordinates
var plots = array();
//check if total_rows is less than max_plots then:
if(total_rows > max_plots){
//find the quotient of the the divident total_rows and the divisor max_plots rounded down to the nearest whole int
var quotient = floor(total_rows/max_plots);
//define variable i to use in loop
var i = 1;
//loop through returned rows
while(row = mysql->fetch_row()){
//return only rows that are the first, last, or are dividable by the quotient evenly; Note: if your language supports it, use the Modulus operator like (i % quotient) == 0 for the last or statement.
if(i == 1 || 1 == total_rows || (i - (i * (floor(i/quotient)))) == 0){
//set plots to use on map
plots[] = array(
'lat' => row['lat'],
'lon' => row['lon'],
);
}
//increment counting variable
i++;
}
// else if total_rows less than or equal to max_plots retrieve all plots
} else {
while(row = mysql->fetch_row()){
plots[] = array(
'lat' => row['lat'],
'lon' => row['lon'],
);
}
}
This may not be the best way as it still requires to retrieve all of the rows from the database, but it does solve how to only print a selected maximum amount evenly spaced on the Google map.
Note: Be sure that your query orders the rows by an auto incrementing key or some other way so that the plots will be in order that they were entered into the database.
The most detailed maps would be a map with (2 * magic_plot_number) - 1 and your least details map would contain magic_plot_number or if lower, the number of total_plots. That being said an 8 hour tracking would plot a path with points every 7 minutes and 51 seconds totaling 61 points over 8 hours using the magic plot number of 90. The more plots the closer number of points will be to 2/3 * the magic plot number
I hope this helps you with this situation.

Android - Do I need to sort a collection for min and max?

I came here (SO) a few days ago to research how to get the min and max from a collection in Android and found a solution to the effect of the following (sorry haven't got a link to the actual answer I used):
Max = (TextView)findViewById(R.id.Max);
Collections.sort(list);
Max.setText(String.format("%.2f", Collections.max(list)));
My question is do I actually need to sort the list before pulling the min/max value? I have tried running the code without sorting the list and it seems to work OK. I am just worried because the answer I used definitely sorted the list first so I assume there must be a reason, I just don't know what it is!
In addition #BobbyDigital's answer who corectly points out the th method iterates over the complete list, I would just like to mention that the result of using the max function might depend on the type of the list elements. If you see the doc , it says that
Returns the maximum element of the given collection, according to the natural ordering of its elements.
If you see Why does Collections.max() not return actual max value for a Collection of String? question, the person used a list of Strings. On extracting max using the abve number he did not get the max number as it was returning the value that's the largest lexicographically. So, just to mention his code:
ArrayList<String> dirNo = new ArrayList<String>();
dirNo.add("1");
dirNo.add("2");
dirNo.add("3");
dirNo.add("4");
dirNo.add("5");
dirNo.add("6");
dirNo.add("7");
dirNo.add("8");
dirNo.add("9");
dirNo.add("10");
dirNo.add("11");
System.out.println("max : " + Integer.parseInt(Collections.max(dirNo))
+ "");
The above code gave 9 as the answer. So be careful while using it. You mgiht want to convert everything to Integer etc based on your needs.
P.S: The example is from the question mentioned and the answer is inspired from this answer by NPE on same question.
No it doesn't have to be sorted. The method iterates over the entire collection.
See the Java docs for the method!

how to randomly select different numbers of prize objects in a lottery system, android / java

making an android app to do a lottery prize system.
I want to randomly select winners of prizes. but each of the prizes are in different amounts. they are currently stored in a database as three columns, first is index id, auto incremented, the second is the name of the prize, and third is the number of each of these prizes.
for example the most expensive prize is a car and there will be only one of them. but the next cheaper prize will be a small 50 cc scooter, about 10 of them. and the list goes down to to a pencil and pen set where there are 800 winners for this prize.
so the chance of winning the pencil and pen set is much higher than the other prizes.
i am trying to get the idea on what is the best way to code this. i understand that random number generator and even a better one that more evenly distributes true random numbers.
what i am not clear on is the best way to go about this with the different frequency for each of the prizes.
can someone point me in the right direction for this?
Compute the sum of "number of each of these prizes".
Pick a random number between 1 and this sum.
Then order the prizes according some criteria and associate a range to each price (the only car will have the range [1;1]).
Ensure the ranges don't overlap each other. The size of each range must be equal to amount of available prices.
Find the range holding your random number and that's it.
Easiest and least error prone way => put all the prizes in an array. Each prize should be put as many times as there are prizes of the given type. Then generate a random number up to the size of the array and see what is the prize at the given index.
Note that this only considers the case when you know the given user will win a prize. Maybe you should first give a way bigger chance for the user not to win anything for instance say you have 4000 total prizes and you want a user to win a prize with 1/40 chance. So generate a random number up to 40*4000 = 160000 and if the number is not less than 4000 the user wins nothing, otherwise he wins the prize at the index corresponding to the generated value.
Random rand = new Random();
int pickedNumber = rand.nextInt(100);
if(pickednumber>99)
{
pen or pencil
}
else
{
car
}
I'm giving you example and you must me add more condition for scooter or any thing which you want to add on lottery.

Categories

Resources