How do I convert timespan to OAdate? - zedgraph

I am using Zedgraph and for x-axis, they require us to convert to OADate. I am plotting live stock chart and I want to show the last 60sec.
So I use zedGraphControl1.GraphPane.XAxis.Scale.Max and zedGraphControl1.GraphPane.XAxis.Scale.Min. For the Max value, I will set it to the latest time while for the Min value I plan to set to the latest time minus 60 secs (variable). I will store the 60sec in the type timespan. But the problem is that timespan does not have the function toOADate.

Implement your own method!
all you need to know is
1 day = 24 hours
1 hour = 60 minutes
1 minute = 60 seconds
1 second = 1000 milliseconds
Example: let's say i have time t= 456722622 msec
struct TimeDetailed
{
public int millisec;
public int seconds;
public int minutes;
public int hours;
public int days;
};
static TimeDetailed tConverted;
int t = 456722622;
public void function(int a)
{
int d,h,m,s;
d=h=m=s=0;
while(a >= 86400000) // milliseconds per day
{
a -= 86400000;
d++;
}
while(a >= 3600000) // milliseconds per hour
{
a -= 3600000;
h++;
}
while(a >= 60000) // milliseconds per minute
{
a -= 60000;
m++;
}
while(a >= 1000) // milliseconds per second
{
a -= 1000;
s++;
}
tConverted.days = d;
tConverted.hours = h;
tConverted.minutes = m;
tConverted.seconds = s;
tConverted.millisec = a;
}
function(t);
the output is:
tConverted.days = 5
tConverted.hours = 6
tConverted.minutes = 52
tConverted.seconds = 2
tConverted.millisec = 622
Though I didn't test this code but you can similarly make one

Related

how to write unit test cases in jasmine for this code?

private getTotalMinutesBetweenStartAndEnd(startTime: string, endTime: string): number {
// get each time's hour and min values
let [startHrs, startMins] = this.getHoursAndMinsFromTime(startTime);
let [endHrs, endMins] = this.getHoursAndMinsFromTime(endTime);
// time arithmetic (subtraction)
if (endMins < startMins) {
endHrs -= 1;
endMins += 60;
}
let mins = endMins - startMins;
let hrs = endHrs - startHrs;
// this handles scenarios where the startTime > endTime
if (hrs < 0) {
hrs += 24;
}
return hrs * 60 + mins;
}

Is there an issue with trying to pass a constant or variable to a rem() method in kotlin?

Is there an issue with trying to pass a constant or variable to a rem() method in kotlin?
object TimeCalc {
private const val SECONDS: Int = 1000
private const val MINUTES: Int = SECONDS * 60
private const val HOURS: Int = MINUTES * 60
private const val DAYS: Int = HOURS * 24
fun timeDiff(sTime: Long, eTime: Long){
Log.i("Test", "sec $SECONDS: min $MINUTES : hrs $HOURS : days $DAYS")
var startTime = sTime
var endTime = eTime
var mDiff: Int
var mHours: Int
var mMinutes: Int
var mSeconds:Int
var mMilliS: Int
Log.i("Test", "$startTime - $endTime")
mDiff = (endTime - startTime).toInt()
Log.i("Test", "Diff = $mDiff")
**mHours = mDiff.rem(DAYS)**
Log.i("Test", "Hours = $mHours")
Log.i("Test", "${mHours}")
}
}
Result
I/Test: sec 1000: min 60000 : hrs 3600000 : days 86400000
I/Test: 1545062123189 - 1545062217296
I/Test: Diff = 94107
I/Test: Hours = 94107
I/Test: 94107

MpAndroidChart CandleStick Showing a range with dual seekbar?

I am using a dual seekbar to select the min and max range.
It works when taking the max range down, but when pulling the min range up it fails.
The range seekbar OnRangeSekkbarChangedListener:
RangeSeekBar.OnRangeSeekBarChangeListener<Integer> skListener = new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
#Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
int max = bar.getSelectedMaxValue().intValue();
int min = bar.getSelectedMinValue().intValue();
mChart.resetTracking();
//Hold of actual drawing lists
List<CandleEntry> y = new ArrayList<CandleEntry>();
List<String> x = new ArrayList<String>();
for (int i = min; i < max ; i++){
//get candle entry from
CandleEntry current = yVals.get(i);
String currentDate = xVals.get(i);
y.add(current);
x.add(currentDate);
}
//Show less of the chart and invalidate
CandleDataSet mSet = new CandleDataSet(y, "Price");
mSet.setDecreasingColor(getResources().getColor(R.color.black));
mSet.setIncreasingPaintStyle(Paint.Style.FILL);
mSet.setIncreasingColor(getResources().getColor(R.color.accent));
mSet.setDecreasingPaintStyle(Paint.Style.FILL);
mSet.setShadowColor(getResources().getColor(R.color.black));
mCandledata = new CandleData(x, mSet);
//Don't show value text
mCandledata.setDrawValues(false);
mChart.setData(mCandledata);
mChart.invalidate();
}
};
rangeSeekBar.setOnRangeSeekBarChangeListener(skListener);
Results Sceenshots:
Initial Load:
Max Range pulled to near beginning:
Min Range pulled to near end:
You need to change the xIndex of the candle Entries. The first candle needs to have an xIndex of 0
int xIndex = 0;
for (int i = min; i < max ; i++){
//get candle entry from
CandleEntry current = yVals.get(i);
String currentDate = xVals.get(i);
//set the xIndex value
x.setXIndex(xIndex);
y.add(current);
x.add(currentDate);
xIndex++;
}

How to print out the digits of an integer of any length?

This program is works as long as the divide variable is of the same base 10 power as the variable num, in this case the number is 12345 so divide needs to be 10000. While this works for 5 digit numbers, anything with more or less than 5 digits will not have their individual digits printed out. How do I configure divide to have be of the same base 10 power as num automatically?
public class lab5testing
{
public static void main (String args[])
{
int num = 12345, digit = 0, divide = 10000;
if (num != 0)
{
while(num != 0 )
{
digit = ((num/divide)%10);
System.out.println(digit);
divide /= 10;
if (divide == 0)
{
num = 0;
}
}
}
else
{
System.out.println(num);
}
}
}
Maybe you should try with this :
int length = (int)(Math.log10(num)+1);
and then :
int divide = Math.pow(10,lengh);

How do i create a calculated measure that will filter data by days overdue

I have a field in my fact table called days overdue. I would like to create a set that will do the following: If the days due is between 0 - 29, then 0 - 29 days overdue, if between 30 and 59 days old, then '30 - 59 days overdue. How would i create this?
We need to know what kind of array you're using, or linked list, or my favorite for these things, a vector, etc.
If you were using a vector, you would create your own class to be used as a datatype with things like:
Class MyData
{
String name;
int daysPastDue; // how you want to factor this is up to you,
// i suggest looking into Java.util.date or Java.util.calendar
public MyData
{
name = "";
daysPastDue = 0;
}
}
Class DoWork
{
public void myWork() // excuse the indent, forgot to put in the class name
{
vector <MyData> input;
MyData 0To29 [] = new MyData[input.size()];
MyData 33To59 [] = new MyData[input.size()];
MyData item = new MyData();
int 0To29count = 0;
int 30To59count = 0;
for (i = 0; i <= list.size(); i++)
{
item = input.elementAt(i)
if (item.daysPastDue <= 29)
{
0To29[0To29Count] = input;
0To29Count ++;
}
elseif (item.daysPastDue >= 30 && item.daysPastDue <= 59)
{
30To59[30To59Count] = input;
30To59Count ++;
}
}
}
}
then you have your 2 arrays and can output them as you wish. however i would recommend starting at daysPastDue = 100000 and decrement it and check the number through the vector until you have all the items in the vector listed. That way they're all in order from the most past due, to the least and you get the output of exactly how long they've been past due.