Discussion:
A Date and Time challenge!
Jim Wagner
2016-08-02 00:01:00 UTC
Permalink
Greetings NUG -

I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.

I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).

The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.

Suggestions are solicited!

Cheers and many thanks…

Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home



_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xoj
donJ
2016-08-02 01:11:57 UTC
Permalink
Hi Jim,
maybe I don't understand, but couldn't you just round the starting time
up to the next hour? (Ceil (0722 / 100) ) * 100

Don
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug
vaughnsc .
2016-08-02 01:15:14 UTC
Permalink
Rounding up to the 'natural' datetime is easy enough if using a date object.

How to iterate/move to that sample depends on your setup: array/recordset
etc. You may not have a sample exactly at that rounded time.

Multiplying analysis interval by sample interval will tell you how many n
samples to skip from that point forward.
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly
long intervals relative to the sample rate (typically sample rate of 10X
per second for a day). These 1 day files can start at any time of day (from
00:00:00 to 23:59:59). The starting time is encoded at the beginning of
each file (in a meta-data header). There are precision time stamps through
the data.
I have an analysis algorithm that I would like to run at multiple points
through the data set. The intervals between analyses can be set from 0.5
hour through 24 hours, in steps that are integer divisors of 24 hours (0.5
hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by
the program user. I would like those analysis points to be executed at
“natural” clock times (that is, if the user chooses 1 hour, and the file
begins at 0722 hours, it will start at 0800 and every hour, on the hour,
there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the
starting time and the user selected interval? I’ve been flailing around on
this for a while and nothing I’ve tried feels very good - lots and lots and
lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help:
Keith DeLong
2016-08-02 01:18:22 UTC
Permalink
Hi Jim,
The solution is pretty straight forward - assuming I understand your requirements correctly.

1. Calculate SecondsUntilNextHour when the user selects the sample frequency or at program launch.

There’s lot of ways to do this - a really simple way is to instantiate two date objects: d1 and d2.
Set d2.Second = 0, d2.Minnute = 0 and d2.Hour = d2.hour + 1
SecondsUntilNextHour = d2.TotalSeconds - d1.TotalSeconds

2. Set a timer with a single run at that time that will execute your data collection. Timer.Period = SecondsUntilNextHour * 1000

3. Since the exact execution time is not guaranteed with a timer (it more or less runs on the idle event loop), you’ll want to recalculate the SecondsUntilNextHour to determine the next period based on the selected sample frequency. Reset the time for a single run each time will auto correct potential small drifts off your natural time with each run.

HTH,

Keith DeLong
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lis
V S Cordero
2016-08-02 01:30:49 UTC
Permalink
I cobbled up the analysis start time as a date.extension in a module.
Its worth noting you can set up a Date in the Constructor as shown, it saves a call to the system time.
Something similar can be used to round down the sample timestamps to the nearest minute.
Function RoundUpHour(extends d as date) As date
dim result as new date(d.Year,d.Month,d.Day,d.Hour)
if d.minute>0 Then result.TotalSeconds=result.TotalSeconds+3600
Return result
End Function
Cheers,

Vaughn
Hi Jim,
The solution is pretty straight forward - assuming I understand your requirements correctly.
1. Calculate SecondsUntilNextHour when the user selects the sample frequency or at program launch.
There’s lot of ways to do this - a really simple way is to instantiate two date objects: d1 and d2.
Set d2.Second = 0, d2.Minnute = 0 and d2.Hour = d2.hour + 1
SecondsUntilNextHour = d2.TotalSeconds - d1.TotalSeconds
2. Set a timer with a single run at that time that will execute your data collection. Timer.Period = SecondsUntilNextHour * 1000
3. Since the exact execution time is not guaranteed with a timer (it more or less runs on the idle event loop), you’ll want to recalculate the SecondsUntilNextHour to determine the next period based on the selected sample frequency. Reset the time for a single run each time will auto correct potential small drifts off your natural time with each run.
HTH,
Keith DeLong
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug
Jim Wagner
2016-08-02 04:20:00 UTC
Permalink
Thanks, everyone.

Part of the challenge is knowing when the first valid time point is. For example, if the start time is 0725 and the interval is 0.5 hour, the start time will be 0730. But, if the interval is 1 for, it will be 0800. And , if 2 hour, it will also be 0800. If 3 hour, it will be 0900, If 4 hour, it will be 0800. If 6 hour, it will be 1200. If 8 hour, it will be 1600. If 12 hour, it will be 1200. And, if 24 hour, it will be 0000 hours. This is where my huge chain of if-then tests came from. I was hoping to find a more direct algorithm for finding when that first valid hour is, given a file start and an interval between operations.

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
I cobbled up the analysis start time as a date.extension in a module.
Its worth noting you can set up a Date in the Constructor as shown, it saves a call to the system time.
Something similar can be used to round down the sample timestamps to the nearest minute.
Function RoundUpHour(extends d as date) As date
dim result as new date(d.Year,d.Month,d.Day,d.Hour)
if d.minute>0 Then result.TotalSeconds=result.TotalSeconds+3600
Return result
End Function
Cheers,
Vaughn
Hi Jim,
The solution is pretty straight forward - assuming I understand your requirements correctly.
1. Calculate SecondsUntilNextHour when the user selects the sample frequency or at program launch.
There’s lot of ways to do this - a really simple way is to instantiate two date objects: d1 and d2.
Set d2.Second = 0, d2.Minnute = 0 and d2.Hour = d2.hour + 1
SecondsUntilNextHour = d2.TotalSeconds - d1.TotalSeconds
2. Set a timer with a single run at that time that will execute your data collection. Timer.Period = SecondsUntilNextHour * 1000
3. Since the exact execution time is not guaranteed with a timer (it more or less runs on the idle event loop), you’ll want to recalculate the SecondsUntilNextHour to determine the next period based on the selected sample frequency. Reset the time for a single run each time will auto correct potential small drifts off your natural time with each run.
HTH,
Keith DeLong
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nu
V S Cordero
2016-08-02 05:41:26 UTC
Permalink
This passes your 7:25AM test case. Im just a bit too numb to walk through it at this hour :) Add salt to taste. Wut?

Function StartTime(d as date, intervalMinutes as integer) As date
dim result as new date(d.Year,d.Month,d.Day)
dim intervalsToAdd as Integer=ceil((d.hour*60+d.minute)/intervalMinutes)
result.TotalSeconds=result.TotalSeconds+(intervalsToAdd*intervalMinutes*60)
return result
End Function


Hope this sheds some light

Vaughn
Post by Jim Wagner
Thanks, everyone.
Part of the challenge is knowing when the first valid time point is. For example, if the start time is 0725 and the interval is 0.5 hour, the start time will be 0730. But, if the interval is 1 for, it will be 0800. And , if 2 hour, it will also be 0800. If 3 hour, it will be 0900, If 4 hour, it will be 0800. If 6 hour, it will be 1200. If 8 hour, it will be 1600. If 12 hour, it will be 1200. And, if 24 hour, it will be 0000 hours. This is where my huge chain of if-then tests came from. I was hoping to find a more direct algorithm for finding when that first valid hour is, given a file start and an interval between operations.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
I cobbled up the analysis start time as a date.extension in a module.
Its worth noting you can set up a Date in the Constructor as shown, it saves a call to the system time.
Something similar can be used to round down the sample timestamps to the nearest minute.
Function RoundUpHour(extends d as date) As date
dim result as new date(d.Year,d.Month,d.Day,d.Hour)
if d.minute>0 Then result.TotalSeconds=result.TotalSeconds+3600
Return result
End Function
Cheers,
Vaughn
Hi Jim,
The solution is pretty straight forward - assuming I understand your requirements correctly.
1. Calculate SecondsUntilNextHour when the user selects the sample frequency or at program launch.
There’s lot of ways to do this - a really simple way is to instantiate two date objects: d1 and d2.
Set d2.Second = 0, d2.Minnute = 0 and d2.Hour = d2.hour + 1
SecondsUntilNextHour = d2.TotalSeconds - d1.TotalSeconds
2. Set a timer with a single run at that time that will execute your data collection. Timer.Period = SecondsUntilNextHour * 1000
3. Since the exact execution time is not guaranteed with a timer (it more or less runs on the idle event loop), you’ll want to recalculate the SecondsUntilNextHour to determine the next period based on the selected sample frequency. Reset the time for a single run each time will auto correct potential small drifts off your natural time with each run.
HTH,
Keith DeLong
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-lea
Jim Wagner
2016-08-02 07:22:25 UTC
Permalink
Thanks, Vaughn -

Late here also. Will run through it in detail in the morning.

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
This passes your 7:25AM test case. Im just a bit too numb to walk through it at this hour :) Add salt to taste. Wut?
Function StartTime(d as date, intervalMinutes as integer) As date
dim result as new date(d.Year,d.Month,d.Day)
dim intervalsToAdd as Integer=ceil((d.hour*60+d.minute)/intervalMinutes)
result.TotalSeconds=result.TotalSeconds+(intervalsToAdd*intervalMinutes*60)
return result
End Function
Hope this sheds some light
Vaughn
Post by Jim Wagner
Thanks, everyone.
Part of the challenge is knowing when the first valid time point is. For example, if the start time is 0725 and the interval is 0.5 hour, the start time will be 0730. But, if the interval is 1 for, it will be 0800. And , if 2 hour, it will also be 0800. If 3 hour, it will be 0900, If 4 hour, it will be 0800. If 6 hour, it will be 1200. If 8 hour, it will be 1600. If 12 hour, it will be 1200. And, if 24 hour, it will be 0000 hours. This is where my huge chain of if-then tests came from. I was hoping to find a more direct algorithm for finding when that first valid hour is, given a file start and an interval between operations.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
I cobbled up the analysis start time as a date.extension in a module.
Its worth noting you can set up a Date in the Constructor as shown, it saves a call to the system time.
Something similar can be used to round down the sample timestamps to the nearest minute.
Function RoundUpHour(extends d as date) As date
dim result as new date(d.Year,d.Month,d.Day,d.Hour)
if d.minute>0 Then result.TotalSeconds=result.TotalSeconds+3600
Return result
End Function
Cheers,
Vaughn
Hi Jim,
The solution is pretty straight forward - assuming I understand your requirements correctly.
1. Calculate SecondsUntilNextHour when the user selects the sample frequency or at program launch.
There’s lot of ways to do this - a really simple way is to instantiate two date objects: d1 and d2.
Set d2.Second = 0, d2.Minnute = 0 and d2.Hour = d2.hour + 1
SecondsUntilNextHour = d2.TotalSeconds - d1.TotalSeconds
2. Set a timer with a single run at that time that will execute your data collection. Timer.Period = SecondsUntilNextHour * 1000
3. Since the exact execution time is not guaranteed with a timer (it more or less runs on the idle event loop), you’ll want to recalculate the SecondsUntilNextHour to determine the next period based on the selected sample frequency. Reset the time for a single run each time will auto correct potential small drifts off your natural time with each run.
HTH,
Keith DeLong
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug
V S Cordero
2016-08-02 20:54:22 UTC
Permalink
Full circle:

Just wanted to point out that since ‘intervalMinutes’ takes integers, this would be a stellar opportunity to define and use an ENUM as the second argument, e.g. Interval.SemiHourly=30 etc. to reject ‘bad’ values.

Vaughn
Post by Jim Wagner
Thanks, Vaughn -
Late here also. Will run through it in detail in the morning.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
This passes your 7:25AM test case. Im just a bit too numb to walk through it at this hour :) Add salt to taste. Wut?
Function StartTime(d as date, intervalMinutes as integer) As date
dim result as new date(d.Year,d.Month,d.Day)
dim intervalsToAdd as Integer=ceil((d.hour*60+d.minute)/intervalMinutes)
result.TotalSeconds=result.TotalSeconds+(intervalsToAdd*intervalMinutes*60)
return result
End Function
Hope this sheds some light
Vaughn
Post by Jim Wagner
Thanks, everyone.
Part of the challenge is knowing when the first valid time point is. For example, if the start time is 0725 and the interval is 0.5 hour, the start time will be 0730. But, if the interval is 1 for, it will be 0800. And , if 2 hour, it will also be 0800. If 3 hour, it will be 0900, If 4 hour, it will be 0800. If 6 hour, it will be 1200. If 8 hour, it will be 1600. If 12 hour, it will be 1200. And, if 24 hour, it will be 0000 hours. This is where my huge chain of if-then tests came from. I was hoping to find a more direct algorithm for finding when that first valid hour is, given a file start and an interval between operations.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
I cobbled up the analysis start time as a date.extension in a module.
Its worth noting you can set up a Date in the Constructor as shown, it saves a call to the system time.
Something similar can be used to round down the sample timestamps to the nearest minute.
Function RoundUpHour(extends d as date) As date
dim result as new date(d.Year,d.Month,d.Day,d.Hour)
if d.minute>0 Then result.TotalSeconds=result.TotalSeconds+3600
Return result
End Function
Cheers,
Vaughn
Hi Jim,
The solution is pretty straight forward - assuming I understand your requirements correctly.
1. Calculate SecondsUntilNextHour when the user selects the sample frequency or at program launch.
There’s lot of ways to do this - a really simple way is to instantiate two date objects: d1 and d2.
Set d2.Second = 0, d2.Minnute = 0 and d2.Hour = d2.hour + 1
SecondsUntilNextHour = d2.TotalSeconds - d1.TotalSeconds
2. Set a timer with a single run at that time that will execute your data collection. Timer.Period = SecondsUntilNextHour * 1000
3. Since the exact execution time is not guaranteed with a timer (it more or less runs on the idle event loop), you’ll want to recalculate the SecondsUntilNextHour to determine the next period based on the selected sample frequency. Reset the time for a single run each time will auto correct potential small drifts off your natural time with each run.
HTH,
Keith DeLong
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <listhe
Jim Wagner
2016-08-02 21:12:29 UTC
Permalink
Good point. That value will come from a popup menu so that constrains what that value can be.

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
Just wanted to point out that since ‘intervalMinutes’ takes integers, this would be a stellar opportunity to define and use an ENUM as the second argument, e.g. Interval.SemiHourly=30 etc. to reject ‘bad’ values.
Vaughn
Post by Jim Wagner
Thanks, Vaughn -
Late here also. Will run through it in detail in the morning.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
This passes your 7:25AM test case. Im just a bit too numb to walk through it at this hour :) Add salt to taste. Wut?
Function StartTime(d as date, intervalMinutes as integer) As date
dim result as new date(d.Year,d.Month,d.Day)
dim intervalsToAdd as Integer=ceil((d.hour*60+d.minute)/intervalMinutes)
result.TotalSeconds=result.TotalSeconds+(intervalsToAdd*intervalMinutes*60)
return result
End Function
Hope this sheds some light
Vaughn
Post by Jim Wagner
Thanks, everyone.
Part of the challenge is knowing when the first valid time point is. For example, if the start time is 0725 and the interval is 0.5 hour, the start time will be 0730. But, if the interval is 1 for, it will be 0800. And , if 2 hour, it will also be 0800. If 3 hour, it will be 0900, If 4 hour, it will be 0800. If 6 hour, it will be 1200. If 8 hour, it will be 1600. If 12 hour, it will be 1200. And, if 24 hour, it will be 0000 hours. This is where my huge chain of if-then tests came from. I was hoping to find a more direct algorithm for finding when that first valid hour is, given a file start and an interval between operations.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by V S Cordero
I cobbled up the analysis start time as a date.extension in a module.
Its worth noting you can set up a Date in the Constructor as shown, it saves a call to the system time.
Something similar can be used to round down the sample timestamps to the nearest minute.
Function RoundUpHour(extends d as date) As date
dim result as new date(d.Year,d.Month,d.Day,d.Hour)
if d.minute>0 Then result.TotalSeconds=result.TotalSeconds+3600
Return result
End Function
Cheers,
Vaughn
Hi Jim,
The solution is pretty straight forward - assuming I understand your requirements correctly.
1. Calculate SecondsUntilNextHour when the user selects the sample frequency or at program launch.
There’s lot of ways to do this - a really simple way is to instantiate two date objects: d1 and d2.
Set d2.Second = 0, d2.Minnute = 0 and d2.Hour = d2.hour + 1
SecondsUntilNextHour = d2.TotalSeconds - d1.TotalSeconds
2. Set a timer with a single run at that time that will execute your data collection. Timer.Period = SecondsUntilNextHour * 1000
3. Since the exact execution time is not guaranteed with a timer (it more or less runs on the idle event loop), you’ll want to recalculate the SecondsUntilNextHour to determine the next period based on the selected sample frequency. Reset the time for a single run each time will auto correct potential small drifts off your natural time with each run.
HTH,
Keith DeLong
Post by Jim Wagner
Greetings NUG -
I am working on an application that deals with sampled data over fairly long intervals relative to the sample rate (typically sample rate of 10X per second for a day). These 1 day files can start at any time of day (from 00:00:00 to 23:59:59). The starting time is encoded at the beginning of each file (in a meta-data header). There are precision time stamps through the data.
I have an analysis algorithm that I would like to run at multiple points through the data set. The intervals between analyses can be set from 0.5 hour through 24 hours, in steps that are integer divisors of 24 hours (0.5 hour, 1 hour, 2 hour, 3 hour, 4 hour, 6 hour, 8 hour, 12 hour, 24 hour) by the program user. I would like those analysis points to be executed at “natural” clock times (that is, if the user chooses 1 hour, and the file begins at 0722 hours, it will start at 0800 and every hour, on the hour, there-after until the end of the file).
The question: how do I find those “on the mark”execution times given the starting time and the user selected interval? I’ve been flailing around on this for a while and nothing I’ve tried feels very good - lots and lots and lots of “if-tests”.
Suggestions are solicited!
Cheers and many thanks…
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@l

Loading...