mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Complete rework of time descriptors, The Return
This commit is contained in:
parent
a36f0c4ab9
commit
935691dd58
@ -382,9 +382,8 @@ def get_pulse_external():
|
|||||||
|
|
||||||
def get_pulse(**keys):
|
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 = []
|
results = []
|
||||||
|
|
||||||
for rng in rngs:
|
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"]}))
|
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})
|
results.append({"range":rng,"scrobbles":res})
|
||||||
|
@ -63,11 +63,15 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,earlystop=F
|
|||||||
|
|
||||||
def module_pulse(max_=None,**kwargs):
|
def module_pulse(max_=None,**kwargs):
|
||||||
|
|
||||||
|
from doreah.timing import clock, clockp
|
||||||
|
|
||||||
kwargs_filter = pickKeys(kwargs,"artist","track","associated")
|
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)
|
ranges = database.get_pulse(**kwargs_time,**kwargs_filter)
|
||||||
|
|
||||||
|
|
||||||
if max_ is not None: ranges = ranges[:max_]
|
if max_ is not None: ranges = ranges[:max_]
|
||||||
|
|
||||||
# if time range not explicitly specified, only show from first appearance
|
# if time range not explicitly specified, only show from first appearance
|
||||||
@ -536,7 +540,7 @@ def module_filterselection(keys,time=True,delimit=False):
|
|||||||
html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"year"}) + "'><span class='stat_selector'>This Year</span></a>"
|
html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"year"}) + "'><span class='stat_selector'>This Year</span></a>"
|
||||||
html += " | "
|
html += " | "
|
||||||
|
|
||||||
if timekeys == {}:
|
if timekeys.get("timerange") is None or timekeys.get("timerange").unlimited():
|
||||||
html += "<span class='stat_selector' style='opacity:0.5;'>All Time</span>"
|
html += "<span class='stat_selector' style='opacity:0.5;'>All Time</span>"
|
||||||
else:
|
else:
|
||||||
html += "<a href='?" + compose_querystring(unchangedkeys) + "'><span class='stat_selector'>All Time</span></a>"
|
html += "<a href='?" + compose_querystring(unchangedkeys) + "'><span class='stat_selector'>All Time</span></a>"
|
||||||
|
@ -77,6 +77,9 @@ class MRangeDescriptor:
|
|||||||
def uri(self):
|
def uri(self):
|
||||||
return "&".join(k + "=" + self.urikeys[k] for k in self.urikeys)
|
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)
|
# a range that is exactly a gregorian calendar unit (year, month or day)
|
||||||
class MTime(MRangeDescriptor):
|
class MTime(MRangeDescriptor):
|
||||||
@ -263,6 +266,7 @@ class MRange(MRangeDescriptor):
|
|||||||
self.since = since
|
self.since = since
|
||||||
self.to = to
|
self.to = to
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.since) + " - " + str(self.to)
|
return str(self.since) + " - " + str(self.to)
|
||||||
def fromstr(self):
|
def fromstr(self):
|
||||||
@ -270,6 +274,8 @@ class MRange(MRangeDescriptor):
|
|||||||
def tostr(self):
|
def tostr(self):
|
||||||
return str(self.to)
|
return str(self.to)
|
||||||
|
|
||||||
|
def unlimited(self):
|
||||||
|
return (self.since is None and self.to is None)
|
||||||
|
|
||||||
def urikeys(self):
|
def urikeys(self):
|
||||||
keys = {}
|
keys = {}
|
||||||
@ -535,6 +541,7 @@ def from_timestamp(stamp,unit):
|
|||||||
if unit == "year": return year_from_timestamp(stamp)
|
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):
|
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)
|
(firstincluded,lastincluded) = time_stamps(since=since,to=to,within=within,range=timerange)
|
||||||
|
@ -21,7 +21,7 @@ def instructions(keys):
|
|||||||
newdate = tod - d
|
newdate = tod - d
|
||||||
weekstart = [newdate.year,newdate.month,newdate.day]
|
weekstart = [newdate.year,newdate.month,newdate.day]
|
||||||
|
|
||||||
#clock()
|
clock()
|
||||||
|
|
||||||
# artists
|
# artists
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ def instructions(keys):
|
|||||||
topartists_month = module_artistcharts_tiles(since="month")
|
topartists_month = module_artistcharts_tiles(since="month")
|
||||||
topartists_week = module_artistcharts_tiles(since=weekstart)
|
topartists_week = module_artistcharts_tiles(since=weekstart)
|
||||||
|
|
||||||
#clockp("Artists")
|
clockp("Artists")
|
||||||
|
|
||||||
# tracks
|
# tracks
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ def instructions(keys):
|
|||||||
toptracks_week = module_trackcharts_tiles(since=weekstart)
|
toptracks_week = module_trackcharts_tiles(since=weekstart)
|
||||||
|
|
||||||
|
|
||||||
#clockp("Tracks")
|
clockp("Tracks")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ def instructions(keys):
|
|||||||
# scrobbles
|
# scrobbles
|
||||||
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True)
|
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True)
|
||||||
|
|
||||||
#clockp("Scrobbles")
|
clockp("Scrobbles")
|
||||||
|
|
||||||
# stats
|
# stats
|
||||||
|
|
||||||
@ -69,29 +69,22 @@ def instructions(keys):
|
|||||||
amount_total = database.get_scrobbles_num()
|
amount_total = database.get_scrobbles_num()
|
||||||
scrobbles_total = "<a href='/scrobbles'>" + str(amount_total) + "</a>"
|
scrobbles_total = "<a href='/scrobbles'>" + str(amount_total) + "</a>"
|
||||||
|
|
||||||
#clockp("Amounts")
|
clockp("Amounts")
|
||||||
|
|
||||||
# pulse
|
# pulse
|
||||||
dt = datetime.utcnow()
|
from malojatime import today,thisweek,thismonth,thisyear
|
||||||
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]
|
|
||||||
|
|
||||||
html_pulse_days = module_pulse(max_=7,since=first_day,step="day",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=first_week,step="week",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=first_month,step="month",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=first_year,step="year",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_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_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)
|
#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 = [{"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 = []
|
pushresources = []
|
||||||
|
Loading…
Reference in New Issue
Block a user