Calculating "Time"

Calculating "Time"

Postby Jeff Barnes » Thu Dec 04, 2008 1:29 pm

Hi,

In my app I extract data from a medical device (oximeter).
The data is collected overnight and it is possible for the device to turn itself off is there is no valid data for a period of time. The patient usually turns the unit on again a some point during the night.

In the device, when it is switched on, it creates a new file.

Data is collected and stored in the device memory every 4 seconds.

I need to merge these files but also need to show the missing time.

Basically I need to add a blank record every 4 seconds.

In the dbf files, I have a char field for "time".

The problem I am facing is that I can not think of how to add this "missing" time and have it stop adding when it gets within the 4 seconds of the next file.

Since data is collected every 4 seconds I can't just do something like:
(since the data is every 4 seconds, the two might not match)

If Last_Rec_In_File1>Time = First_Rec_In_File2->Time
**stop adding files
Endif




Anyone have an idea for me? :oops:
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby HunterEC » Thu Dec 04, 2008 1:57 pm

Jeff:

It will be much easier if you store time as a numeric field. You can get the time as a number with the SECONDS() function. I have a similar app and finally in the last major revision changed the time field from a character string to a numeric one. 8)

If (Last_Rec_In_File1>Time - First_Rec_In_File2->Time) < 4
**stop adding files
Endif

Assuming time is a numeric field stored with the SECONDS() function. Bear in mind that you should check also that the time field belongs to the same day (date).

If Last_Rec_In_File1>Date == First_Rec_In_File2->Date
If (Last_Rec_In_File1>Time - First_Rec_In_File2->Time) < 4
**stop adding files
Endif
Else
// Assuming dates are entered in ascending order.
// We have to calculate seconds elapsed from last day's time until
// midnight and add the seconds elapsed from 2nd time reading.
If ((86399 - First_Rec_In_File2>Time) + Last_Rec_In_File1>Time) < 4
** stop adding records.
Endif
Endif

You an also combine both If with an OR operator. :D

Example:

First Record Last Record
12/04/2008 82800 (11:00:00PM) 12/04/2008 82803 (11:00:03PM)
12/03/2008 86397 (11:59:57AM) 12/04/2008 00002 (12:00:02AM)

On the first one you don't add any records, on the second one you have to add (5 seconds elapsed).

I hope this helps !
Last edited by HunterEC on Thu Dec 04, 2008 2:23 pm, edited 1 time in total.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Postby Jeff Barnes » Thu Dec 04, 2008 2:05 pm

Either way, I still run into the same problem. I can always convert the field to a numeric one in my code. In my app this time field is used in many places where it is actually easier to have it as a text field.

If the gaps in the time were in the same day I do not have a problem as I can do something like:

If Last_Rec_Time1 >= First_Rec_Time2
**Stop adding blank records
Else
**Append blank records with adjusted time
Endif

The adjusted time just adds 4 seconds each time. Thus giving me what I need. But when the time jumps over midnight my above code will not work.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby HunterEC » Thu Dec 04, 2008 3:01 pm

Jeff:

Please check my previous post. I was revising it when you posted your response. Thank you. :D
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Postby Jeff Barnes » Thu Dec 04, 2008 3:07 pm

Ahh. I think I now understand what you are saying.

I will play with this idea tonight when I get home and see what I can do.

Thanks for the idea. I think this will help.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby HunterEC » Thu Dec 04, 2008 7:23 pm

If I can be of further assistance don't hesitate in dropping a note. Thank you.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Postby sambomb » Fri Dec 05, 2008 12:55 pm

You have 21600 intervals of 4 seconds, you can fill a DBF like that:
Code: Select all  Expand view
Static procedure NewDay(dDate)

Local nSec

Default dDate := Date()

For nSec := 1 to 21600
   DbAppend()
   Replace Time with tString(nSec*4)
   Replace Day with dDate
   Replace Value with "Empty"
end

Return Nil


And you just replace in the DBF after start the program, testing only if is necessary to run the NewDay() before.

Hope it can help you [;)]
Email: SamirSSabreu@gmail.com
xHarbour 1.2.3 + Fwhh 20.2
User avatar
sambomb
 
Posts: 388
Joined: Mon Oct 13, 2008 11:26 am
Location: Itaocara - RJ - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 107 guests