Skip to content

Commit

Permalink
fix: use UTC for plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Feb 8, 2024
1 parent ffc2904 commit 268aff7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/DIRAC/Core/Utilities/Graphs/BarGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def draw(self):
start_plot = 0
end_plot = 0
if "starttime" in self.prefs and "endtime" in self.prefs:
start_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["endtime"])))
start_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["endtime"])))

nKeys = self.gdata.getNumberOfKeys()
tmp_b = []
Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/Core/Utilities/Graphs/CurveGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def draw(self):
start_plot = 0
end_plot = 0
if "starttime" in self.prefs and "endtime" in self.prefs:
start_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["endtime"])))
start_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["endtime"])))

labels = self.gdata.getLabels()
labels.reverse()
Expand Down
4 changes: 3 additions & 1 deletion src/DIRAC/Core/Utilities/Graphs/GraphData.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def makeNumKeys(self):
self.all_num_keys.append(next)
next += 1
elif self.key_type == "time":
self.all_num_keys = [date2num(datetime.datetime.fromtimestamp(to_timestamp(key))) for key in self.all_keys]
self.all_num_keys = [
date2num(datetime.datetime.utcfromtimestamp(to_timestamp(key))) for key in self.all_keys
]
elif self.key_type == "numeric":
self.all_num_keys = [float(key) for key in self.all_keys]

Expand Down
10 changes: 5 additions & 5 deletions src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def convert_to_datetime(dstring):
else:
results = eval(str(dstring), {"__builtins__": None, "time": time, "math": math}, {})
if isinstance(results, (int, float)):
results = datetime.datetime.fromtimestamp(int(results))
results = datetime.datetime.utcfromtimestamp(int(results))
elif isinstance(results, datetime.datetime):
pass
else:
Expand All @@ -81,7 +81,7 @@ def convert_to_datetime(dstring):
try:
t = time.strptime(dstring, dateformat)
timestamp = calendar.timegm(t) # -time.timezone
results = datetime.datetime.fromtimestamp(timestamp)
results = datetime.datetime.utcfromtimestamp(timestamp)
break
except Exception:
pass
Expand All @@ -90,7 +90,7 @@ def convert_to_datetime(dstring):
dstring = dstring.split(".", 1)[0]
t = time.strptime(dstring, dateformat)
timestamp = time.mktime(t) # -time.timezone
results = datetime.datetime.fromtimestamp(timestamp)
results = datetime.datetime.utcfromtimestamp(timestamp)
except Exception:
raise ValueError(
"Unable to create time from string!\nExpecting "
Expand All @@ -108,8 +108,8 @@ def to_timestamp(val):
pass

val = convert_to_datetime(val)
# return calendar.timegm( val.timetuple() )
return time.mktime(val.timetuple())
return calendar.timegm(val.timetuple())
# return time.mktime(val.timetuple())


# If the graph has more than `hour_switch` minutes, we print
Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/Core/Utilities/Graphs/LineGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def draw(self):
start_plot = 0
end_plot = 0
if "starttime" in self.prefs and "endtime" in self.prefs:
start_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["endtime"])))
start_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["endtime"])))

self.polygons = []
seq_b = [(self.gdata.max_num_key, 0.0), (self.gdata.min_num_key, 0.0)]
Expand Down
4 changes: 2 additions & 2 deletions src/DIRAC/Core/Utilities/Graphs/QualityMapGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def draw(self):
start_plot = 0
end_plot = 0
if "starttime" in self.prefs and "endtime" in self.prefs:
start_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.fromtimestamp(to_timestamp(self.prefs["endtime"])))
start_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["starttime"])))
end_plot = date2num(datetime.datetime.utcfromtimestamp(to_timestamp(self.prefs["endtime"])))

labels = self.gdata.getLabels()
nKeys = self.gdata.getNumberOfKeys()
Expand Down

0 comments on commit 268aff7

Please sign in to comment.