diff --git a/database.py b/database.py index 7184748..4eac8dd 100644 --- a/database.py +++ b/database.py @@ -382,9 +382,8 @@ def get_pulse_external(): def get_pulse(**keys): - rngs = ranges(**{k:keys[k] for k in keys if k in ["timerange","step","stepn","trail"]}) + rngs = ranges(**{k:keys[k] for k in keys if k in ["since","to","within","timerange","step","stepn","trail"]}) results = [] - for rng in rngs: res = len(db_query(timerange=rng,**{k:keys[k] for k in keys if k in ["artists","artist","track","title","associated"]})) results.append({"range":rng,"scrobbles":res}) diff --git a/htmlmodules.py b/htmlmodules.py index 0dfe999..51af4bc 100644 --- a/htmlmodules.py +++ b/htmlmodules.py @@ -63,11 +63,15 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,earlystop=F def module_pulse(max_=None,**kwargs): + from doreah.timing import clock, clockp + kwargs_filter = pickKeys(kwargs,"artist","track","associated") - kwargs_time = pickKeys(kwargs,"timerange","step","stepn","trail") + kwargs_time = pickKeys(kwargs,"since","to","within","timerange","step","stepn","trail") + ranges = database.get_pulse(**kwargs_time,**kwargs_filter) + if max_ is not None: ranges = ranges[:max_] # if time range not explicitly specified, only show from first appearance @@ -536,7 +540,7 @@ def module_filterselection(keys,time=True,delimit=False): html += "This Year" html += " | " - if timekeys == {}: + if timekeys.get("timerange") is None or timekeys.get("timerange").unlimited(): html += "All Time" else: html += "All Time" diff --git a/malojatime.py b/malojatime.py index 22dc3d3..b9300a6 100644 --- a/malojatime.py +++ b/malojatime.py @@ -77,6 +77,9 @@ class MRangeDescriptor: def uri(self): return "&".join(k + "=" + self.urikeys[k] for k in self.urikeys) + def unlimited(self): + return False + # a range that is exactly a gregorian calendar unit (year, month or day) class MTime(MRangeDescriptor): @@ -263,6 +266,7 @@ class MRange(MRangeDescriptor): self.since = since self.to = to + def __str__(self): return str(self.since) + " - " + str(self.to) def fromstr(self): @@ -270,6 +274,8 @@ class MRange(MRangeDescriptor): def tostr(self): return str(self.to) + def unlimited(self): + return (self.since is None and self.to is None) def urikeys(self): keys = {} @@ -535,6 +541,7 @@ def from_timestamp(stamp,unit): if unit == "year": return year_from_timestamp(stamp) +# since, to and within can accept old notations or objects. timerange can only be a new object. def ranges(since=None,to=None,within=None,timerange=None,step="month",stepn=1,trail=1,max_=None): (firstincluded,lastincluded) = time_stamps(since=since,to=to,within=within,range=timerange) diff --git a/website/start.py b/website/start.py index 7c00310..22e9659 100644 --- a/website/start.py +++ b/website/start.py @@ -21,7 +21,7 @@ def instructions(keys): newdate = tod - d weekstart = [newdate.year,newdate.month,newdate.day] - #clock() + clock() # artists @@ -30,7 +30,7 @@ def instructions(keys): topartists_month = module_artistcharts_tiles(since="month") topartists_week = module_artistcharts_tiles(since=weekstart) - #clockp("Artists") + clockp("Artists") # tracks @@ -40,7 +40,7 @@ def instructions(keys): toptracks_week = module_trackcharts_tiles(since=weekstart) - #clockp("Tracks") + clockp("Tracks") @@ -48,7 +48,7 @@ def instructions(keys): # scrobbles html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True) - #clockp("Scrobbles") + clockp("Scrobbles") # stats @@ -69,29 +69,22 @@ def instructions(keys): amount_total = database.get_scrobbles_num() scrobbles_total = "" + str(amount_total) + "" - #clockp("Amounts") + clockp("Amounts") # pulse - dt = datetime.utcnow() - first_month = [dt.year-1,dt.month+1] - dt_firstweek = dt - timedelta(11*7) - timedelta((tod.weekday() + 1) % 7) - first_week = [dt_firstweek.year,dt_firstweek.month,dt_firstweek.day] - dt_firstday = dt - timedelta(6) - first_day = [dt_firstday.year,dt_firstday.month,dt_firstday.day] - first_year = [dt.year - 9] - if first_month[1] > 12: first_month = [first_month[0]+1,first_month[1]-12] + from malojatime import today,thisweek,thismonth,thisyear - html_pulse_days = module_pulse(max_=7,since=first_day,step="day",trail=1) - html_pulse_weeks = module_pulse(max_=12,since=first_week,step="week",trail=1) - html_pulse_months = module_pulse(max_=12,since=first_month,step="month",trail=1) - html_pulse_years = module_pulse(max_=10,since=first_year,step="year",trail=1) + html_pulse_days = module_pulse(max_=7,since=today().next(-6),step="day",trail=1) + html_pulse_weeks = module_pulse(max_=12,since=thisweek().next(-11),step="week",trail=1) + html_pulse_months = module_pulse(max_=12,since=thismonth().next(-11),step="month",trail=1) + html_pulse_years = module_pulse(max_=10,since=thisyear().next(-9),step="year",trail=1) #html_pulse_week = module_pulse(max_=7,since=weekstart,step="day",trail=1) #html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1) #html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1) - #clockp("Pulse") + clockp("Pulse") #pushresources = [{"file":img,"type":"image"} for img in artistimages + trackimages] #can't push scrobble images as we don't get them from the module function, need to think about that pushresources = []