Created
December 30, 2017 07:56
-
-
Save philippkeller/b56683ac7db03ac5e7670b21f0d5dae4 to your computer and use it in GitHub Desktop.
Stackoverflow count warm/cold by 5 minute interval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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