mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Complete rework of time descriptors, A New Hope
This commit is contained in:
parent
935691dd58
commit
c9c53aa592
@ -5,6 +5,7 @@ from malojatime import *
|
|||||||
from urihandler import compose_querystring, internal_to_uri, uri_to_internal
|
from urihandler import compose_querystring, internal_to_uri, uri_to_internal
|
||||||
import urllib
|
import urllib
|
||||||
import datetime
|
import datetime
|
||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
#def getpictures(ls,result,tracks=False):
|
#def getpictures(ls,result,tracks=False):
|
||||||
@ -602,6 +603,12 @@ def module_filterselection(keys,time=True,delimit=False):
|
|||||||
html += "<span class='stat_selector' style='opacity:0.5;'>Long Trailing</span>"
|
html += "<span class='stat_selector' style='opacity:0.5;'>Long Trailing</span>"
|
||||||
else:
|
else:
|
||||||
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"3"}) + "'><span class='stat_selector'>Long Trailing</span></a>"
|
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"3"}) + "'><span class='stat_selector'>Long Trailing</span></a>"
|
||||||
|
html += " | "
|
||||||
|
|
||||||
|
if delimitkeys.get("trail") == math.inf:
|
||||||
|
html += "<span class='stat_selector' style='opacity:0.5;'>Cumulative</span>"
|
||||||
|
else:
|
||||||
|
html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"cumulative":"yes"}) + "'><span class='stat_selector'>Cumulative</span></a>"
|
||||||
|
|
||||||
html += "</div>"
|
html += "</div>"
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from calendar import monthrange
|
from calendar import monthrange
|
||||||
from os.path import commonprefix
|
from os.path import commonprefix
|
||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
FIRST_SCROBBLE = int(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp())
|
FIRST_SCROBBLE = int(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp())
|
||||||
@ -173,6 +174,7 @@ class MTime(MRangeDescriptor):
|
|||||||
|
|
||||||
# next range of equal length (not exactly same amount of days, but same precision level)
|
# next range of equal length (not exactly same amount of days, but same precision level)
|
||||||
def next(self,step=1):
|
def next(self,step=1):
|
||||||
|
if abs(step) == math.inf: return None
|
||||||
if self.precision == 1:
|
if self.precision == 1:
|
||||||
return MTime(self.year + step)
|
return MTime(self.year + step)
|
||||||
elif self.precision == 2:
|
elif self.precision == 2:
|
||||||
@ -252,6 +254,7 @@ class MTimeWeek(MRangeDescriptor):
|
|||||||
return int(datetime.datetime.combine(day,datetime.time(tzinfo=datetime.timezone.utc)).timestamp() - 1)
|
return int(datetime.datetime.combine(day,datetime.time(tzinfo=datetime.timezone.utc)).timestamp() - 1)
|
||||||
|
|
||||||
def next(self,step=1):
|
def next(self,step=1):
|
||||||
|
if abs(step) == math.inf: return None
|
||||||
try:
|
try:
|
||||||
return MTimeWeek(self.year,self.week + step)
|
return MTimeWeek(self.year,self.week + step)
|
||||||
except:
|
except:
|
||||||
@ -265,7 +268,8 @@ class MRange(MRangeDescriptor):
|
|||||||
since,to = time_pad(since,to)
|
since,to = time_pad(since,to)
|
||||||
self.since = since
|
self.since = since
|
||||||
self.to = to
|
self.to = to
|
||||||
|
if isinstance(self.since,MRange): self.since = self.since.start()
|
||||||
|
if isinstance(self.to,MRange): self.to = self.to.end()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.since) + " - " + str(self.to)
|
return str(self.since) + " - " + str(self.to)
|
||||||
@ -319,6 +323,7 @@ class MRange(MRangeDescriptor):
|
|||||||
else: return self.to.last_stamp()
|
else: return self.to.last_stamp()
|
||||||
|
|
||||||
def next(self,step=1):
|
def next(self,step=1):
|
||||||
|
if abs(step) == math.inf: return None
|
||||||
# hop from the start element by one until we reach the end element
|
# hop from the start element by one until we reach the end element
|
||||||
diff = 1
|
diff = 1
|
||||||
nxt = self.since
|
nxt = self.since
|
||||||
@ -512,7 +517,8 @@ def delimit_desc(step="month",stepn=1,trail=1):
|
|||||||
if stepn is not 1: txt += _num(stepn) + "-"
|
if stepn is not 1: txt += _num(stepn) + "-"
|
||||||
txt += {"year":"Yearly","month":"Monthly","week":"Weekly","day":"Daily"}[step.lower()]
|
txt += {"year":"Yearly","month":"Monthly","week":"Weekly","day":"Daily"}[step.lower()]
|
||||||
#if trail is not 1: txt += " " + _num(trail) + "-Trailing"
|
#if trail is not 1: txt += " " + _num(trail) + "-Trailing"
|
||||||
if trail is not 1: txt += " Trailing" #we don't need all the info in the title
|
if trail is math.inf: txt += " Cumulative"
|
||||||
|
elif trail is not 1: txt += " Trailing" #we don't need all the info in the title
|
||||||
|
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
@ -547,19 +553,17 @@ def ranges(since=None,to=None,within=None,timerange=None,step="month",stepn=1,tr
|
|||||||
(firstincluded,lastincluded) = time_stamps(since=since,to=to,within=within,range=timerange)
|
(firstincluded,lastincluded) = time_stamps(since=since,to=to,within=within,range=timerange)
|
||||||
|
|
||||||
d_start = from_timestamp(firstincluded,step)
|
d_start = from_timestamp(firstincluded,step)
|
||||||
d_start = d_start.next(stepn)
|
d_start = d_start.next(stepn-1) #last part of first included range
|
||||||
d_start = d_start.next(stepn*trail*-1)
|
|
||||||
first_range = MRange(d_start,d_start.next(stepn*trail-1))
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
current = d_start
|
current_end = d_start
|
||||||
while current.first_stamp() <= lastincluded and (max_ is None or i < max_):
|
while current_end.first_stamp() <= lastincluded and (max_ is None or i < max_):
|
||||||
current_end = current.next(stepn*trail-1)
|
current_start = current_end.next((stepn*trail-1)*-1)
|
||||||
if current == current_end:
|
if current_start == current_end:
|
||||||
yield current
|
yield current_start
|
||||||
else:
|
else:
|
||||||
yield MRange(current,current_end)
|
yield MRange(current_start,current_end)
|
||||||
current = current.next(stepn)
|
current_end = current_end.next(stepn)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import urllib
|
import urllib
|
||||||
from bottle import FormsDict
|
from bottle import FormsDict
|
||||||
from malojatime import time_fix, time_str, get_range_object
|
from malojatime import time_fix, time_str, get_range_object
|
||||||
|
import math
|
||||||
|
|
||||||
# necessary because urllib.parse.urlencode doesnt handle multidicts
|
# necessary because urllib.parse.urlencode doesnt handle multidicts
|
||||||
def compose_querystring(*dicts,exclude=[]):
|
def compose_querystring(*dicts,exclude=[]):
|
||||||
@ -91,7 +91,6 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False):
|
|||||||
elif "within" in keys: within = keys.get("within")
|
elif "within" in keys: within = keys.get("within")
|
||||||
elif "during" in keys: within = keys.get("during")
|
elif "during" in keys: within = keys.get("during")
|
||||||
resultkeys2["timerange"] = get_range_object(since=since,to=to,within=within)
|
resultkeys2["timerange"] = get_range_object(since=since,to=to,within=within)
|
||||||
print(resultkeys2["timerange"].desc())
|
|
||||||
|
|
||||||
#3
|
#3
|
||||||
resultkeys3 = {"step":"month","stepn":1,"trail":1}
|
resultkeys3 = {"step":"month","stepn":1,"trail":1}
|
||||||
@ -99,6 +98,7 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False):
|
|||||||
if "stepn" in keys: resultkeys3["stepn"] = keys["stepn"] #overwrite if explicitly given
|
if "stepn" in keys: resultkeys3["stepn"] = keys["stepn"] #overwrite if explicitly given
|
||||||
if "stepn" in resultkeys3: resultkeys3["stepn"] = int(resultkeys3["stepn"]) #in both cases, convert it here
|
if "stepn" in resultkeys3: resultkeys3["stepn"] = int(resultkeys3["stepn"]) #in both cases, convert it here
|
||||||
if "trail" in keys: resultkeys3["trail"] = int(keys["trail"])
|
if "trail" in keys: resultkeys3["trail"] = int(keys["trail"])
|
||||||
|
if "cumulative" in keys: resultkeys3["trail"] = math.inf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -140,6 +140,9 @@ def internal_to_uri(keys):
|
|||||||
if "stepn" in keys:
|
if "stepn" in keys:
|
||||||
urikeys.append("stepn",str(keys["stepn"]))
|
urikeys.append("stepn",str(keys["stepn"]))
|
||||||
if "trail" in keys:
|
if "trail" in keys:
|
||||||
|
if keys["trail"] == math.inf:
|
||||||
|
urikeys.append("cumulative","yes")
|
||||||
|
else:
|
||||||
urikeys.append("trail",str(keys["trail"]))
|
urikeys.append("trail",str(keys["trail"]))
|
||||||
|
|
||||||
# stuff
|
# stuff
|
||||||
|
Loading…
Reference in New Issue
Block a user