Dynamic structure

I need calculate a how hours of job have a personal from a sequential list of ID + TIMESTAMP (cvs). I need know what dynamic structure is the most efficient for this. Thank’s. Apologies for traslation

What is most efficient depends on access patterns and the number of items you need to handle.

I usually start by writing what is most clear and easy to understand and work with.

For example, in https://play.golang.org/p/fBDy5d5-hv I used a map[string]time.Duration because I wanted an easy way to add job hours to an id and did not care in which order the jobs were later listed.

If I found the program was running too long, I would profile it to find out what parts are slow and then improve those.

1 Like

Thank’s nathankerr. My record list is sequential id+timestamp. I need descompose the format id+timestamp into Id+start+stop. There are cases of start or end records without their counterpart. Record only start or stop for an ID in determinated date. Always sequentially.

Could you provide some sample data that covers all the cases?

This is an example.
Thank’s

ID TIMESTAMP
37 42736.00564162570
17 42736.00711895730
14 42736.03072278890
64 42736.03499420700
40 42736.08125681970
19 42736.08720280260
59 42736.09831293960
17 42736.11073484240
98 42736.11188691400
8 42736.12711812150
44 42736.13515285610
52 42736.14079403100
38 42736.14628215710
61 42736.16012103180
74 42736.16263917280
98 42736.16626200620
73 42736.16627330630
87 42736.17180555940
35 42736.17460540100
30 42736.18314764970
78 42736.19214913930
35 42736.19428995320
49 42736.21040584360
34 42736.22650447890
31 42736.23887257920
35 42736.24684449840
35 42736.25197605200
1 42736.26774022790
44 42736.27661999410
39 42736.28717925310
45 42736.29963756900
86 42736.31139315210
69 42736.31512441190
66 42736.32560860600
66 42736.33782070880
46 42736.34528976290
44 42736.34757738580
90 42736.35900666630
59 42736.37381840330
11 42736.39582486290
40 42736.40265593970
63 42736.42328251070
16 42736.42504789550
73 42736.43227988290
45 42736.43371830230
27 42736.43779266290
100 42736.43803211490
52 42736.46270913210
18 42736.46702386620
13 42736.46979713630
26 42736.46984699760
91 42736.47359215940
52 42736.50702441200
16 42736.51215907240
99 42736.51576961870
50 42736.52193344820
75 42736.53240727180
89 42736.53278070830
83 42736.53560719340
63 42736.55507134290
76 42736.55643497990
11 42736.56461712850
41 42736.58305668980
9 42736.58809800790
46 42736.59022394520
42 42736.60412476200
99 42736.60435434800
83 42736.60592908210
61 42736.60631811330
34 42736.62813021890
7 42736.62831322880
36 42736.64858356680
34 42736.66129507100
42 42736.66486939670
67 42736.67727199120
55 42736.68546944670
37 42736.70150527330
55 42736.70399355010
73 42736.70538492500
89 42736.72102908290
56 42736.72338871900
7 42736.72356158400
39 42736.72772495150
12 42736.73080649120
37 42736.75933655650
8 42736.77624558030
32 42736.77845177290
7 42736.78360514380
18 42736.79045459100
46 42736.79409153390
82 42736.84672858030
95 42736.84691826500
94 42736.85823901460
74 42736.86169977510
44 42736.87021313480
66 42736.87314263750
51 42736.88309863320
88 42736.88499391970
62 42736.88840066110
7 42736.89269164430
17 42736.90071724600
72 42736.91010273030
17 42736.91143879480
93 42736.91217908800
30 42736.91935569660
8 42736.92633466590
52 42736.93415083600
34 42736.95346229700
78 42736.95880732950
5 42736.95982773750
50 42736.96011440080
84 42736.96333547590
21 42736.97146645860
7 42736.98603905980
57 42736.99065204430
97 42736.99228635540
91 42737.00297905730
70 42737.02814198750
91 42737.03721395890
70 42737.06912145640
38 42737.07786505240
7 42737.09832625630
7 42737.10871357950
75 42737.11033386420
6 42737.11483564210
1 42737.11486245030
10 42737.14184232080
71 42737.14787355070
82 42737.15259837710
86 42737.15308453000
30 42737.16193830550
24 42737.17494287840
31 42737.19059901230
64 42737.20211094670
82 42737.21086089560
49 42737.22400084390
56 42737.22844545620
56 42737.23440736010
18 42737.24901446730
37 42737.25036636010
95 42737.26204661830
20 42737.26236438440
94 42737.26268038820
19 42737.26475727290
69 42737.27001365340
95 42737.27060250280
37 42737.27227665430
49 42737.27285773220
42 42737.28400942860
1 42737.28716223180
78 42737.29983935530
35 42737.30152561550
26 42737.30780497930
40 42737.31420072230
94 42737.33401535420
7 42737.33964063340
72 42737.35407790420
66 42737.35511519910
12 42737.37222463110
9 42737.38674276420
60 42737.38716691000
85 42737.38797457940
79 42737.38921542600
59 42737.40230534000
9 42737.41456947710
26 42737.44213728600
79 42737.45376786650
92 42737.45915852180
46 42737.46326166440
95 42737.46503573760
46 42737.47289496160
66 42737.47387247380
23 42737.47554298610
44 42737.47865797760
68 42737.48423642240
40 42737.50813939320
33 42737.51864519010
100 42737.52419170350
4 42737.52894004320
94 42737.53070544980
100 42737.53403602510
17 42737.53635470520
55 42737.53699660350
73 42737.55653181220
36 42737.56174438240
40 42737.56762323950
36 42737.57312580520
74 42737.57853033760
28 42737.59177208360
91 42737.62361701950
33 42737.62593871370
59 42737.62723563450
25 42737.62754512250
65 42737.64106704330
39 42737.65708520140
13 42737.66527597220
84 42737.67104116710
16 42737.69278244720
14 42737.69348684630
71 42737.69825659360
40 42737.70451044050
63 42737.72932868390
100 42737.73086566840
50 42737.73139029180
57 42737.73210203710
92 42737.74726164930
100 42737.76062822620
75 42737.76111768040
25 42737.77669936060
80 42737.78430086380
60 42737.78804862920
31 42737.78922104760
42 42737.79098221550
37 42737.79703606650
77 42737.81383669810
62 42737.82917447140
65 42737.83937602450
67 42737.84375445060
18 42737.86627193180
63 42737.87049375580
61 42737.87144826780
80 42737.87908357760
75 42737.88111236970
81 42737.89339157300
69 42737.89512955160
36 42737.89885851790
42 42737.90048665280
64 42737.93643016430
33 42737.94110771590
96 42737.94296953960
66 42737.94718815090
68 42737.94986848590
77 42737.95825687900
61 42737.97737028390
11 42737.97807332700
20 42737.98463417170
17 42737.98956166610
43 42738.00160109540
94 42738.00214245410
82 42738.01353366840
7 42738.03080938440
86 42738.03764960780
43 42738.06202717420
80 42738.06723570430
16 42738.07591544290
17 42738.08366313280
28 42738.08512921310
7 42738.08584673190
17 42738.09746090780
23 42738.11199270510
90 42738.12214180650
26 42738.12650270360
26 42738.13068956540
38 42738.13522588760
6 42738.13533270630
73 42738.14576013430
65 42738.15599400740
50 42738.16902867520
72 42738.16911128360
9 42738.19605151410
70 42738.21883850790
67 42738.23036551120
71 42738.23061783410
76 42738.24927224220
48 42738.28189431210
2 42738.28254470690
26 42738.28300153880
43 42738.28507664590
47 42738.28741919520
15 42738.28829237820
54 42738.29066931030
9 42738.29168781610
26 42738.29948426500
7 42738.32089840090
90 42738.32490074340
13 42738.32769466300
79 42738.32819651470
17 42738.32856694710
8 42738.34090141410
91 42738.35060833650
19 42738.36668063040
58 42738.36932980090
31 42738.37049269730
67 42738.37347068390
8 42738.37888897940
9 42738.39083188840
47 42738.39572609100
71 42738.39993484340
63 42738.40773102630
46 42738.41402276820
8 42738.41679923410
34 42738.42815997330
52 42738.43045477210
30 42738.43527875910
66 42738.44517827990
32 42738.45408703180
92 42738.45706356720
70 42738.46189241980
53 42738.46876763940
60 42738.47863379380
43 42738.48249666390
58 42738.48325694450
83 42738.48988272230
79 42738.49592067640
49 42738.50381279120
74 42738.50731374040
99 42738.50884840720
46 42738.52947112780

Thanks for supplying some data.

What format is the timestamp in?

How can you tell if a record is start or stop?

I take the first record of day as start. The format is extracted from excel or acces. The device provide in this format.

What device? Are there instructions on how to interpret the time format?

The device is an clock register. Time format is, integer part is date and decimal part is time record. Reviews other registration format offered by the device.

1 Like

It doesn’t seem obvious from this what constitutes a start or a stop. For example, for ID 37,

jb@unu:~ $ grep \^37 foo
37	42736.00564162570
37	42736.70150527330
37	42736.75933655650
37	42737.25036636010
37	42737.27227665430
37	42737.79703606650

this could be interpreted as

// timer is not running
37	42736.00564162570 (start)
37	42736.70150527330 (stop)
37	42736.75933655650 (start)
37	42737.25036636010 (stop)
37	42737.27227665430 (start)
37	42737.79703606650 (stop)
// timer is not running

where the first record of day 42736 is a start and the first record of day 42737 is a stop. Or the opposite

// timer is running
37	42736.00564162570 (stop)
37	42736.70150527330 (start)
37	42736.75933655650 (stop)
37	42737.25036636010 (start)
37	42737.27227665430 (stop)
37	42737.79703606650 (start)
// timer is running

In either case, once you decide to handle this it looks like a

type event struct {
    id    int
    start time.Time
    stop  time.Time
}

var events []event

might be one possible structure, after you decide how to interpret the log. While processing the log you may want something like a var currentRecord map[int]event that keeps track of the current event record for each ID. If there is an entry for a given ID you’ve seen a “start” and the next line is a “stop” - fill in the stop time, archive the record and remove it from the map. If there is nothing in the map, assume a “start” and fill it out appropriately.

Good luck. :slight_smile:

2 Likes

Thank’s Jakob!.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.