B4J Question Start & End Times

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I have been stuck on this for a few days and can't seem to work out what I am doing wrong.

There could be 500+ events (strings) in a list, some will contain a start time and some strings will contain the end time. Think of it as a clock in/out.

I am trying to store this in a SQLite database.

The strings are formatted like the following:
1CLD13640011101808030015170049

1CLD - ignore
1364 - event
001 - user
1 - area (there are 8 areas)
10 - Hour
18 - Minute
08 - Month
03 - Day
001 - eventID
5 - day of week
17 - year
0049 - ignore

I need to work out the start and end times.

if the event from above is 1173 then it means clock on
if the event from above is 1174 then it means clock off

However..
If the event before the event 1173 is event 1239, or event 1239 is after 1173 then I need to put the light_mode in my SQLite database as 50.

If there is no event 1239 before or after event 1173, then it needs to put the light_mode as 100.

If the event is 1174 then it means that it has finished. (event 1239 doesn't need to be before or after 1174 event)

Each event has an area it belongs to. Area's 1 - 8.

In my code below, I am processing all the area 1 start events and then doing area 2 events etc.
Then when that is done it's then processing all the finish events. This way all the start times are in the database already.

There can be multiple area start and finish events but if the event starts then it must finish before it can start again.

Based on my code it seems to only do some of the events for some reason.

Based on my screenshot below, this is what the database ends up looking like.

EventId 9 and below are all missing the finishing times.

But something I noticed, eventid 7 the finish time is before the event start time.

I have been stuck on this for a few days and can't work out what I am doing wrong. I most likely overlooked this and missed something obvious.

I have attached the project I am using and hoping someone can help me out.

upload_2017-8-3_16-48-16.png
 

Attachments

  • TestApp.zip
    7.1 KB · Views: 139

Daestrum

Expert
Licensed User
Longtime User
After trying your code and making a few debug changes, I can see that the finish events are being added to the start events in the database, even when the user id is different. This is probably incorrect.
Maybe try
a, extract to a list for each area (assuming each area could have a user 1)
b, extract from (a) to a list for each user
Then use your logic of prev/next record event id's
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I removed the following code from the CheckForStart sub:

B4X:
If CurrentEventNum = "1173" And NEvent = "1239" Then
                    ' 50
                    AddEvent(CurrentArea,CurrentDayOfWeek & " " & CurrentDay & "-" & CurrentMonth & " " & CurrentHour & ":" & CurrentMinutes,CurrentEventNumberData,"50","")
                End If

If CurrentEventNum = "1173" And NEvent <> "1239" Then
                    ' 100
                    AddEvent(CurrentArea,CurrentDayOfWeek & " " & CurrentDay & "-" & CurrentMonth & " " & CurrentHour & ":" & CurrentMinutes,CurrentEventNumberData,"100","")
                End If

Then in the UpdateFinish sub, I had:


B4X:
If RS.GetString("finish") = "" And RS.GetString("eventid") = area Then

and I changed it to:
B4X:
If RS.GetString("finish") = "" And RS.GetString("area") = area Then

Seems to so far work, except that it doesn't check the next event. The user isn't that important for the finish time only the start time.
 
Upvote 0
Top