Commit b3520e3e authored by Robert Ricci's avatar Robert Ricci

Fix the function that decides which ones to keep

parent 6e8276d1
......@@ -29,7 +29,8 @@ def candidates(l, n):
# keep all
return l, []
else:
indices = list(map(lambda x: int(x/len(l)), range(n)))
indices = list(map(lambda x: int(x * len(l) / n), range(n)))
#print("Keep {} of {}: {}".format(n,len(l),indices))
# I'm sure there's a more pythonic way to do this
keep = []
discard = []
......@@ -48,8 +49,8 @@ class Calendar:
self.month_target = 30
self.year_target = 4
times = list(map(lambda x: datetime.utcfromtimestamp(float(x)), sorted(snapshots.keys())))
now = datetime.utcnow()
times = list(map(lambda x: datetime.fromtimestamp(float(x)), sorted(snapshots.keys())))
now = datetime.now()
self.today_by_hour = partition([x for x in times if x.date() == now.date()], lambda x: x.hour)
self.this_month_by_day = partition([x for x in times if x.year == now.year and x.month == now.month and x.day < now.day], lambda x: x.day)
......@@ -75,17 +76,21 @@ class Calendar:
k,r = all_candidates(self.today_by_hour, self.hour_target)
keep.extend(k)
remove.extend(r)
#print("### Hourly: Keep {}, Remove {}, K: {}".format(len(k),len(r),k))
k,r = all_candidates(self.this_month_by_day, self.day_target)
keep.extend(k)
remove.extend(r)
#print("### Daily: Keep {}, Remove {}, K: {}".format(len(k),len(r),k))
k,r = all_candidates(self.this_year_by_month, self.month_target)
keep.extend(k)
remove.extend(r)
#print("### Monthly Keep {}, Remove {}".format(len(k),len(r)))
k,r = all_candidates(self.previous_years_by_year, self.year_target)
keep.extend(k)
remove.extend(r)
#print("### Yearly: Keep {}, Remove {}".format(len(k),len(r)))
return keep, remove
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment