Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stackoverflow count warm/cold by 5 minute interval
import datetime
with open("myfile.csv") as f:
window_from = None
window_to = None
warm = cold = 0
for line in f:
milliseconds, topics = line.split(",")
if milliseconds == 'milliseconds':
continue
seconds = float(milliseconds) / 1000
t1Convert = datetime.datetime.fromtimestamp(seconds)
if window_from is None:
window_from = t1Convert
window_to = t1Convert + datetime.timedelta(minutes=5)
if t1Convert > window_to:
print("{} - {}: {} warm, {} cold".format(window_from, window_to, warm, cold))
window_from += datetime.timedelta(minutes=5)
window_to += datetime.timedelta(minutes=5)
warm = cold = 0
if topics == "today is warm":
warm += 1
elif topics == "today is cold":
cold += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.