FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour I'm stuck - "Time" issue
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
I'm stuck - "Time" issue
Posted: Tue Jan 12, 2010 09:03 PM
Hi,

I will try to explain this as best I can...

I have a device connect to a patient that records data every 4 seconds.
The idea is the the patient wears the device all night.

Sometimes the patient will either turn off or disconnect the device to go to the bathroom.
Or it falls off during sleep and at some point they wake up and reconnect it.
When this happens, a new file will get created in the device.

Here is my problem ... I need this to be a continuous file (including the time the device was off/disconnected).

Let's say the patient only did this once ... leaving me with 2 files.
I have no problem if it happens in the same day as I simply add a new entry and just leave it blank every 4 seconds.
I do this using this basic idea:

Code (fw): Select all Collapse
   Local cTime1:="22:15:00"  //time the device was disconnected
   Local cTime2:="23:30:45"  //time the device was reconnected

   do while cTime1 < cTime2
       APPEND BLANK
       cTime1 := GetNewTime( cTime1, 4 )
       DataFile->Time := cTime1
   enddo
 


STATIC FUNCTION GetNewTime( cTimeStart, nSec )
    LOCAL nHour, nMin
    nSec = ( VAL( LEFT( cTimeStart, 2 ) ) * 3600 + VAL( SUBSTR( cTimeStart, 4, 2 ) ) * 60 + VAL( RIGHT( cTimeStart, 2 ) ) + nSec ) % 86400
    nHour = INT( nSec / 3600 )
    nSec -= nHour * 3600
    nMin = INT( nSec / 60 )
    nSec -= nMin * 60
    cTimeStart := STRZERO( nHour, 2 ) + ":" + STRZERO( nMin, 2 ) + ":" + STRZERO( nSec, 2 )
RETURN cTimeStart



I run into a problem if the disconnect is over 2 different days.
cTime1:="23:45:00" and cTime2:="01:30:00"

In this situation, cTime1 will always be less than cTime2.

Any ideas are welcome :-)
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Tue Jan 12, 2010 11:15 PM

First, why create a new database when the device is reconnected? Wouldn't it solve the problem if the same database was used? If you need all the data for one day or the last 24 hours or whatever, you could just export the data to a new dbf.

Are you recording the date with the time? I would, and that would also solve your problem.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 04:17 AM

Dear Mr.Jeff,

As Mr.James suggested, why don't you use DateTime()

Regards
Anser

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 01:47 PM

i think my description was a but off...

The device creates "files" in its memory. When I say "connected" I mean the patient is connected to the device. My software only comes into play later via a memory dump (serial data) to the computer.

Every time the unit is powered off or the patient is not connected to the device for a period of time (which causes it to power off) it creates a new "file" in memory.

In my software, it displays a list of these "files" and allows the user to select one to work with.
When the power off situation happens my users would like to be able to "merge" these files into one "file". Since this is a medical device connected to a patient, I need to show the entire time in the report (even disconnects) so I can't simply do an "append". I need actual entries for the missing time.

As far as date/time info goes... all I get from the device is the Start Time/Date of the "file". I know the device stores a data point every 4 seconds so I add in all the times.
All I want to do is add the ability to merge these "files" with the missing times (gap between two files). I don't want to rewrite the entire module as it is more complicated than this basic description I am giving here.

I only have this problem if there is a disconnect over midnight.

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 02:35 PM

Jeff,
show us please a few records and a few files, so that we can think of some ideas.
It's not too clear
Marco

Marco Boschi
info@marcoboschi.it
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 03:35 PM
Here are two samples of what I am working with:

http://www.can-soft.net/temp/D1.dbf
http://www.can-soft.net/temp/D2.dbf
http://www.can-soft.net/temp/D3.dbf

D1.dbf would be the first file in the set and D2.dbf is the file after the device has been turned off then back on.
I manually created D3.dbf just to have a file that was over the midnight time span.

Note: the dbf structure is used for other parts of the program so there are many fields that are not used for this test.
The fields I am working with are TIME, DATE (from record 1 only) and WALKMARK (.t. if valid data point)
Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 04:05 PM

Jeff,
can’t you compare the last timestamp of db1 with the first timestamp of db2 and then calculate the difference and then add as many entries offlinetime in sec. / 5 sec. as necessary.
Best regards,
Otto

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 04:18 PM

Hi Otto,

That is what I am doing when they are both in the same day.
(see example above)

I run into a problem when one file ends at say 23:30 on Dec 2 and the next starts at 1:30 on Dec 3

I know there is a simple way to do this ... I am just over-thinking it.

I think this is one of those situations where I am best to walk away from it for a while ... then the easy solution just poops out :-)

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 04:31 PM

Jeff,
I think you have to convert your timestamp into seconds.
Best regards,
Otto

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 06:22 PM

Thanks everyone.

I've got it working now. I ended up using some IF/ELSE statements to sort out the data.

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: I'm stuck - &quot;Time&quot; issue
Posted: Wed Jan 13, 2010 06:57 PM
Jeff,

I see you already have it working but the functions below may still be useful or useful to someone else. Using these functions the new time is:

cNewTime := stot( ttos( cNewTime ) + 4 )

This also handles passing midnight.

When thinking about it, here are some senarios you have to deal with.

1) Date1 and date2 are the same.
2) Date1 < Date2 by one or more days
3) The 4 second interval may be less than 4 seconds when the calculated values for offline times approach the new online time.

Regards,
James


Code (fw): Select all Collapse
// Time To Seconds
// Converts time string to numeric seconds
FUNCTION TTOS( cTime )
RETURN VAL( SUBSTR( cTime, 1, 2 )) * 3600  + ;
       VAL( SUBSTR( cTime, 4, 2 )) * 60    + ;
       VAL( SUBSTR( cTime, 7, 2 ))
       

// Seconds To Time
// Converts numeric seconds to time string.
// Handles passing midnight
FUNCTION STOT( nSeconds )
   IF nSeconds > 86400
      nSeconds = MOD( nSeconds, 86400 )
   ENDIF
RETURN STRZERO( INT( MOD( nSeconds / 3600, 24 )), 2, 0 ) + ':' + ;
       STRZERO( INT( MOD( nSeconds /   60, 60 )), 2, 0 ) + ':' + ;
       STRZERO( INT( MOD( nSeconds       , 60 )), 2, 0 )
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion