2626def deserialize (buffer ):
2727 offset = 0
2828 samples = []
29+ # read header (uint8)
30+ version = np .frombuffer (buffer , dtype = np .uint8 , count = 1 , offset = offset )
31+ if version [0 ] != 1 :
32+ raise ValueError ('Invalid version %d' % version [0 ])
33+ offset += 1
34+
35+ userId = buffer [offset :offset + 36 ].decode ('utf-8' )
36+ offset += 36
37+ placeId = buffer [offset :offset + 36 ].decode ('utf-8' )
38+ offset += 36
39+ screenId = buffer [offset :offset + 36 ].decode ('utf-8' )
40+ offset += 36
41+ # read samples
2942 while offset < len (buffer ):
30- sample = {}
43+ sample = {
44+ 'userId' : userId ,
45+ 'placeId' : placeId ,
46+ 'screenId' : screenId ,
47+ }
3148
3249 # Read time (uint32)
3350 time_data = np .frombuffer (buffer , dtype = '>I' , count = 1 , offset = offset )
@@ -54,22 +71,10 @@ def deserialize(buffer):
5471 sample ['goal' ] = goal = np .frombuffer (buffer , dtype = '>f4' , count = 2 , offset = offset )
5572 offset += 4 * 2
5673
57- # Read userId (36 bytes as string)
58- sample ['userId' ] = buffer [offset :offset + 36 ].decode ('utf-8' )
59- offset += 36
60-
61- # Read placeId (36 bytes as string)
62- sample ['placeId' ] = buffer [offset :offset + 36 ].decode ('utf-8' )
63- offset += 36
64-
65- # Read screenId (int32)
66- sample ['screenId' ] = buffer [offset :offset + 36 ].decode ('utf-8' )
67- offset += 36
68-
69- if (- 2 < sample ['goal' ]).all () and (sample ['goal' ] < 2 ).all ():
74+ if (- 2 < goal ).all () and (goal < 2 ).all ():
7075 samples .append (sample )
7176 else :
72- print ('Invalid goal:' , sample [ ' goal' ] )
77+ print ('Invalid goal:' , goal )
7378 continue
7479
7580 # Transpose them to the make columnwise
0 commit comments