Output CSV, too. Allow selecting a day.

This commit is contained in:
Birth Markus 2017-03-09 17:07:36 +01:00
parent 324426b261
commit ae240dd76c
2 changed files with 32 additions and 11 deletions

View File

@ -147,7 +147,7 @@ class MosDb():
self.db_insert_or_replace("moslufs", {"objId": obj_id, "lufs": lufs, "lra": lra, "ldiff": ldiff})
self.commit()
def get_today_oa(self):
def get_daily_oa(self, delta = "-0 days"):
"""Finds today's OA Material with LUFS values
"""
self.c.execute(
@ -162,7 +162,9 @@ class MosDb():
WHERE mo.isDeleted=0 \
AND ms.mosServer LIKE \"StudioA%\" \
AND mg.objGroup=\"OA Material\" \
AND po.created >= strftime('%s', date('now', 'start of day'))"
AND po.created >= strftime('%s', 'now', '" + delta + "', 'start of day', 'utc') \
AND po.created < strftime('%s', 'now', '" + delta + "', '+1 day', 'start of day', 'utc') \
ORDER BY po.created ASC"
)
result = []
for row in self.c.fetchall():

View File

@ -7,7 +7,8 @@ import MosDb
db = MosDb.MosDb()
items = db.get_today_oa()
items = db.get_daily_oa()
#items = db.get_daily_oa("-1 day")
db.finish()
longest_name = 9
@ -25,20 +26,27 @@ output_text = ("{:19} | {:" + str(longest_name) + "} | {:" + str(longest_author)
"Autor",
"LUFS",
"LRA",
"±LU"
"LDIFF"
)
output_text += ("{:-<19} | {:-<" + str(longest_name) + "} | {:-<" + str(longest_author) + "} | {:->5} | {:->5} | {:->5}\n").format("", "", "", "", "", "")
# Output CSV, use BOM because Excel is ignorant
output_csv = "\ufeff"
output_csv += "objId,planningId,created,name,createdBy,lufs,lra,ludiff\n"
for i in items:
print(repr(i))
lu = i["lu"]
if lu is None:
lu = "-"
lra = i["lra"]
if lra is None:
lu = "n/a"
lra = "-"
ldiff = i["ldiff"]
if ldiff is None:
ldiff = "-"
elif lu == -99.0:
lu = "-∞"
lra = "-"
ldiff = "-"
else:
lu = "{:>5.1f}".format(lu)
lra = "{:>5.1f}".format(i["lra"])
ldiff = "{:>5.1f}".format(i["ldiff"])
output_text += ("{} | {:" + str(longest_name) + "} | {:" + str(longest_author) + "} | {:>5} | {:>5} | {:>5}\n").format(
i["created"],
i["name"],
@ -47,5 +55,16 @@ for i in items:
lra,
ldiff
)
output_csv += ("{},{},{},\"{}\",\"{}\",{},{},{}").format(
i["objId"],
i["planningId"],
i["created"],
i["name"],
i["createdBy"],
i["lu"],
i["lra"],
i["ldiff"]
) + "\n"
print(output_text)
print(output_csv)