Helpers to bootstrap daily archives based on task_mtime

This commit is contained in:
Ivan A. Melnikov 2022-03-31 16:22:09 +04:00
parent 92b514f6f1
commit 153130a18f

29
port_stats/daily_tasks.py Normal file
View File

@ -0,0 +1,29 @@
import datetime
EPOCH = datetime.datetime(1970, 1, 1)
DAY = datetime.timedelta(days=1)
SECOND = datetime.timedelta(seconds=1)
def publish_time(ts):
dt = datetime.datetime.utcfromtimestamp(ts)
publish = dt.replace(hour=23, minute=50, second=0, microsecond=0)
pt = (publish - EPOCH).total_seconds()
if pt < ts:
pt = (publish + DAY - EPOCH).total_seconds()
return pt
def dayly(tasks, repo):
seq = sorted((t['task_mtime'], t['taskid']) for t in tasks
if t['repo'] == repo and t['state'] == 'DONE')
pt = publish_time(seq[0][0])
result = []
prev = 0
for t in seq:
if t[0] > pt:
result.append(prev)
pt = publish_time(t[0])
prev = t[1]
return result