@@ -10,62 +10,53 @@ import JSON.Serializations: CommonSerialization, StandardSerialization
10
10
JSON. show_json (io:: JSONContext , serialization:: CommonSerialization , uuid:: UUID ) = print (io. io, " \" $uuid \" " )
11
11
12
12
13
+ # # Utility functions for ZonedDateTime
14
+
15
+ # Regex parser that converts clauses like ":59.82-" to well formatted ":59.820-"
16
+ function _fixSubseconds (a)
17
+ length (a) == 4 && return a[1 : 3 ]* " .000" * a[4 ]
18
+ frac = a[5 : length (a)- 1 ]
19
+ frac = length (frac) > 3 ? frac[1 : 3 ] : frac* ' 0' ^ (3 - length (frac))
20
+ return a[1 : 4 ]* frac* a[length (a)]
21
+ end
22
+
23
+ function getStandardZDTString (stringTimestamp:: String )
24
+ # This is finding :59Z or :59.82-05:00 and fixing it to always have 3 subsecond digits.
25
+ # Temporary fix until TimeZones.jl gets an upstream fix.
26
+ return replace (stringTimestamp, r" :\d\d (\.\d +)?(Z|z|\+ |-)" => _fixSubseconds)
27
+ end
28
+
29
+ # Corrects any `::ZonedDateTime` fields of T in corresponding `interm::Dict` as `dateformat"yyyy-mm-ddTHH:MM:SS.ssszzz"`
30
+ function standardizeZDTStrings! (T, interm:: Dict )
31
+ for (name, typ) in zip (fieldnames (T), T. types)
32
+ if typ <: ZonedDateTime
33
+ namestr = string (name)
34
+ interm[namestr] = getStandardZDTString (interm[namestr])
35
+ end
36
+ end
37
+ nothing
38
+ end
39
+
13
40
# #==============================================================================
14
41
# # Variable Packing and unpacking
15
42
# #==============================================================================
16
43
function packVariable (dfg:: G , v:: DFGVariable ):: Dict{String, Any} where G <: AbstractDFG
17
44
props = Dict {String, Any} ()
18
45
props[" label" ] = string (v. label)
19
- props[" timestamp" ] = Dates. format (v. timestamp, " yyyy-mm-ddTHH:MM:SS.ssszzz" )# string(v.timestamp)
46
+ props[" timestamp" ] = Dates. format (v. timestamp, " yyyy-mm-ddTHH:MM:SS.ssszzz" )
20
47
props[" nstime" ] = string (v. nstime. value)
21
48
props[" tags" ] = JSON2. write (v. tags)
22
49
props[" ppeDict" ] = JSON2. write (v. ppeDict)
23
50
props[" solverDataDict" ] = JSON2. write (Dict (keys (v. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (v. solverDataDict))))
24
51
props[" smallData" ] = JSON2. write (v. smallData)
25
52
props[" solvable" ] = v. solvable
26
53
props[" softtype" ] = string (typeof (getSofttype (v)))
27
- # props["bigData"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> JSON2.write(bde), values(v.dataDict))))
28
- # props["bigDataElemType"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> typeof(bde), values(v.dataDict))))
29
54
props[" dataEntry" ] = JSON2. write (Dict (keys (v. dataDict) .=> map (bde -> JSON. json (bde), values (v. dataDict))))
30
55
31
56
props[" dataEntryType" ] = JSON2. write (Dict (keys (v. dataDict) .=> map (bde -> typeof (bde), values (v. dataDict))))
32
57
return props
33
58
end
34
59
35
- # Corrects any `::ZonedDateTime` fields of T in corresponding `interm::Dict` as `dateformat"yyyy-mm-ddTHH:MM:SS.ssszzz"`
36
- function standardizeZDTString! (T, interm:: Dict )
37
- @debug " About to look through types of" T
38
- for (name, typ) in zip (fieldnames (T), T. types)
39
- # @debug "name=$name"
40
- # @debug "typ=$typ"
41
- if typ <: ZonedDateTime
42
- # Make sure that the timestamp is correctly formatted with subseconds
43
- namestr = string (name)
44
- @debug " must ensure SS.ssszzz on $name :: $typ -- $(interm[namestr]) "
45
- # # FIXME copy #588, but doesnt work: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/582#issuecomment-671884668
46
- # # E.g.: interm[namestr] = replace(interm[namestr], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3") = "2020-08-11T04:05:59.82-04:00"
47
- # @show interm[namestr] = replace(interm[namestr], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3")
48
- # @debug "after SS.ssszzz -- $(interm[namestr])"
49
- # # DROP piece below once this cleaner copy #588 is working
50
- supersec, subsec = split (interm[namestr], ' .' )
51
- sss, zzz = split (subsec, ' -' )
52
- # @debug "split time elements are $sss-$zzz"
53
- # make sure milliseconds portion is precisely 3 characters long
54
- if length (sss) < 3
55
- # pad with zeros at the end
56
- while length (sss) < 3
57
- sss *= " 0"
58
- end
59
- newtimessszzz = supersec* " ." * sss* " -" * zzz
60
- @debug " new time string: $newtimessszzz "
61
- # reassembled ZonedDateTime is put back in the dict
62
- interm[namestr] = newtimessszzz
63
- end
64
- end
65
- end
66
- nothing
67
- end
68
-
69
60
function unpackVariable (dfg:: G ,
70
61
packedProps:: Dict{String, Any} ;
71
62
unpackPPEs:: Bool = true ,
@@ -74,7 +65,7 @@ function unpackVariable(dfg::G,
74
65
@debug " Unpacking variable:\r\n $packedProps "
75
66
label = Symbol (packedProps[" label" ])
76
67
# Make sure that the timestamp is correctly formatted with subseconds
77
- packedProps[" timestamp" ] = replace (packedProps[" timestamp" ], r" :( \d )( \d )(Z|z| \+ |-) " => s " : \1\2 .000 \3 " )
68
+ packedProps[" timestamp" ] = getStandardZDTString (packedProps[" timestamp" ])
78
69
# Parse it
79
70
timestamp = ZonedDateTime (packedProps[" timestamp" ])
80
71
nstime = Nanosecond (get (packedProps, " nstime" , 0 ))
@@ -119,11 +110,9 @@ function unpackVariable(dfg::G,
119
110
end
120
111
121
112
for (k,bdeInter) in dataIntermed
122
- # @debug "label=$label"
123
- # @debug "bdeInter=$bdeInter"
124
113
interm = JSON. parse (bdeInter)
125
114
objType = getfield (DistributedFactorGraphs, dataElemTypes[k])
126
- standardizeZDTString ! (objType, interm)
115
+ standardizeZDTStrings ! (objType, interm)
127
116
fullVal = Unmarshal. unmarshal (objType, interm)
128
117
variable. dataDict[k] = fullVal
129
118
end
@@ -180,7 +169,7 @@ function packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: Abstract
180
169
# Construct the properties to save
181
170
props = Dict {String, Any} ()
182
171
props[" label" ] = string (f. label)
183
- props[" timestamp" ] = Dates. format (f. timestamp, " yyyy-mm-ddTHH:MM:SS.ssszzz" )# string(f.timestamp)
172
+ props[" timestamp" ] = Dates. format (f. timestamp, " yyyy-mm-ddTHH:MM:SS.ssszzz" )
184
173
props[" nstime" ] = string (f. nstime. value)
185
174
props[" tags" ] = JSON2. write (f. tags)
186
175
# Pack the node data
218
207
function unpackFactor (dfg:: G , packedProps:: Dict{String, Any} ):: DFGFactor where G <: AbstractDFG
219
208
label = packedProps[" label" ]
220
209
# Make sure that the timestamp is correctly formatted with subseconds
221
- packedProps[" timestamp" ] = replace (packedProps[" timestamp" ], r" :( \d )( \d )(Z|z| \+ |-) " => s " : \1\2 .000 \3 " )
210
+ packedProps[" timestamp" ] = getStandardZDTString (packedProps[" timestamp" ])
222
211
# Parse it
223
212
timestamp = ZonedDateTime (packedProps[" timestamp" ])
224
213
nstime = Nanosecond (get (packedProps, " nstime" , 0 ))
0 commit comments