63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
def get_report(items):
|
|
"""Returns plaintext and csv data for given items.
|
|
*items* is the result of MosDb.get_daily_oa()
|
|
"""
|
|
longest_name = 9
|
|
longest_author = 5
|
|
for i in items:
|
|
if len(i["name"]) > longest_name:
|
|
longest_name = len(i["name"])
|
|
if len(i["createdBy"]) > longest_author:
|
|
longest_author = len(i["createdBy"])
|
|
|
|
# Output table
|
|
output_text = ("{:19} | {:" + str(longest_name) + "} | {:" + str(longest_author) + "} | {:>5} | {:>5} | {:>5}\n").format(
|
|
"Datum",
|
|
"OnAir-MAZ",
|
|
"Autor",
|
|
"LUFS",
|
|
"LRA",
|
|
"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:
|
|
lu = i["lu"]
|
|
if lu is None:
|
|
lu = "n/a"
|
|
lra = "-"
|
|
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"],
|
|
i["createdBy"],
|
|
lu,
|
|
lra,
|
|
ldiff
|
|
)
|
|
output_csv += ("{},{},{},\"{}\",\"{}\",{},{},{}").format(
|
|
i["objId"],
|
|
i["planningId"],
|
|
i["created"],
|
|
i["name"],
|
|
i["createdBy"],
|
|
i["lu"],
|
|
i["lra"],
|
|
i["ldiff"]
|
|
) + "\n"
|
|
return (output_text, output_csv)
|
|
|