def __render_json_canvasjs_history_days(self, request, upr): """ handle request and return json data formated for canvasjs graphlibrary show one account balance for each day that has at least one transaction """ if not upr.path == b'/canvasjsaccounthistoryindays.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" qryaccts = query["account"] frs = ledger.registerFromRunningSum( ledger.filterRunningSum(running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts) ) limit = int(query["limit"][0]) if "limit" in query else 1000 returndict=defaultdict(list) for tdate, account_currency_sum in itail(frs, limit): tdate_ms = int(datetime.datetime.strptime(tdate,ledger.dateformat_hledger_csvexport_).timestamp()*1000) for acc, currdict in account_currency_sum.items(): if not acc in qryaccts: continue for currency, amt in currdict.items(): datasetname = "%s in %s" % (amt.currency,acc) returndict[datasetname].append( {"x":tdate_ms, "y":round(amt.quantity,2), "currency":currency} ) if amt.totalprice and amt.totalprice.currency != amt.currency: returndict["%s in %s" % (amt.totalprice.currency,acc)].append( {"x":tdate_ms, "y":round(amt.totalprice.quantity,2), "currency":amt.totalprice.currency} ) return json.dumps(returndict).encode("utf-8")
def __render_json_canvasjs_history(self, request, upr): """ handle request and return json data formated for canvasjs graphlibrary return all transactions with balance on that day """ if not upr.path == b'/canvasjsaccounthistory.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" qryaccts = query["account"] maxlinelength = int(query["maxlinelength"][0]) if "maxlinelength" in query else 60 frs = ledger.filterRunningSum(running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts) limit = int(query["limit"][0]) if "limit" in query else 1000 returndict=defaultdict(list) for t, account_currency_sum, assrt in itail(frs, limit): tdate_ms = int(datetime.datetime.strptime(t.date,ledger.dateformat_hledger_csvexport_).timestamp()*1000) for acc, currdict in account_currency_sum.items(): if not acc in qryaccts: continue tstr = "\n".join([line[:maxlinelength] for line in str(t).split("\n")]) for currency, amt in currdict.items(): datasetname = "%s in %s" % (amt.currency,acc) returndict[datasetname].append( {"x":tdate_ms, "y":round(amt.quantity,2), "currency":currency, "transaction":tstr} ) if amt.totalprice and amt.totalprice.currency != amt.currency: returndict["%s in %s" % (amt.totalprice.currency,acc)].append( {"x":tdate_ms, "y":round(amt.totalprice.quantity,2), "currency":amt.totalprice.currency, "transaction":tstr} ) return json.dumps(returndict).encode("utf-8")
def __render_json_journal(self, request, upr): """ handle request and return json data formated for visjs graphlibrary return all transaction, no running sum """ if not upr.path == b'/accountjournal.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" self.groupid_next = 0 groupid = defaultdict(self.__getnextgroupid) qryaccts = query["account"] frs = ledger.filterRunningSum(running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts) limit = int(query["limit"][0]) if "limit" in query else 60 returnlist=[] for t, account_currency_sum, assrt in itail(frs, limit): posting_accounts = [p.account for p in t.postings] for p in t.postings: if not any([p.account.startswith(acc) for acc in qryaccts]): continue if p.amount.quantity == 0 or len(p.amount.currency) == 0: continue returnlist.append({"x":t.date, "y":round(p.amount.quantity,2), "label": {"content": "<%s] %s" %(p.amount,t.name), "className":"hoverlabel"} , "group": groupid["%s in %s" % (p.amount.currency,p.account)]}) #, "label":{"content":str(amt)} if p.amount.totalprice and p.amount.totalprice.currency != p.amount.currency: returnlist.append({"x":t.date, "y":round(p.amount.totalprice.quantity,2), "group": groupid["%s in %s" % (p.amount.totalprice.currency,p.account)]}) #, "label":str(amt.totalprice) grouplist = [{"id":gid, "content":gname} for (gname, gid) in groupid.items()] return json.dumps({"dataset":returnlist,"groupset":grouplist}).encode("utf-8")
def __render_json_history(self, request, upr): if not upr.path == b'/accounthistory.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" self.groupid_next = 0 groupid = defaultdict(self.__getnextgroupid) qryaccts = query["account"] frs = ledger.registerFromRunningSum( ledger.filterRunningSum(running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts) ) limit = int(query["limit"][0]) if "limit" in query else 60 returnlist=[] for tdate, account_currency_sum in itail(frs, limit): for acc, currdict in account_currency_sum.items(): if not acc in qryaccts: continue for currency, amt in currdict.items(): returnlist.append({"x":tdate, "y":round(amt.quantity,2), "group": groupid["%s in %s" % (amt.currency,acc)]}) #, "label":{"content":str(amt)} if amt.totalprice and amt.totalprice.currency != amt.currency: returnlist.append({"x":tdate, "y":amt.totalprice.quantity, "group": groupid["%s in %s" % (amt.totalprice.currency,acc)]}) #, "label":str(amt.totalprice) grouplist = [{"id":gid, "content":gname} for (gname, gid) in groupid.items()] return json.dumps({"dataset":returnlist,"groupset":grouplist}).encode("utf-8")
def __render_json_journal(self, request, upr): """ handle request and return json data formated for visjs graphlibrary return all transaction, no running sum """ if not upr.path == b'/accountjournal.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" self.groupid_next = 0 groupid = defaultdict(self.__getnextgroupid) qryaccts = query["account"] frs = ledger.filterRunningSum( running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts) limit = int(query["limit"][0]) if "limit" in query else 60 returnlist = [] for t, account_currency_sum, assrt in itail(frs, limit): posting_accounts = [p.account for p in t.postings] for p in t.postings: if not any([p.account.startswith(acc) for acc in qryaccts]): continue if p.amount.quantity == 0 or len(p.amount.currency) == 0: continue returnlist.append({ "x": t.date, "y": round(p.amount.quantity, 2), "label": { "content": "<%s] %s" % (p.amount, t.name), "className": "hoverlabel" }, "group": groupid["%s in %s" % (p.amount.currency, p.account)] }) #, "label":{"content":str(amt)} if p.amount.totalprice and p.amount.totalprice.currency != p.amount.currency: returnlist.append({ "x": t.date, "y": round(p.amount.totalprice.quantity, 2), "group": groupid["%s in %s" % (p.amount.totalprice.currency, p.account)] }) #, "label":str(amt.totalprice) grouplist = [{ "id": gid, "content": gname } for (gname, gid) in groupid.items()] return json.dumps({ "dataset": returnlist, "groupset": grouplist }).encode("utf-8")
def __render_json_canvasjs_history(self, request, upr): """ handle request and return json data formated for canvasjs graphlibrary return all transactions with balance on that day """ if not upr.path == b'/canvasjsaccounthistory.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" qryaccts = query["account"] maxlinelength = int( query["maxlinelength"][0]) if "maxlinelength" in query else 60 frs = ledger.filterRunningSum( running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts) limit = int(query["limit"][0]) if "limit" in query else 1000 returndict = defaultdict(list) for t, account_currency_sum, assrt in itail(frs, limit): tdate_ms = int( datetime.datetime.strptime( t.date, ledger.dateformat_hledger_csvexport_).timestamp() * 1000) for acc, currdict in account_currency_sum.items(): if not acc in qryaccts: continue tstr = "\n".join( [line[:maxlinelength] for line in str(t).split("\n")]) for currency, amt in currdict.items(): datasetname = "%s in %s" % (amt.currency, acc) returndict[datasetname].append({ "x": tdate_ms, "y": round(amt.quantity, 2), "currency": currency, "transaction": tstr }) if amt.totalprice and amt.totalprice.currency != amt.currency: returndict["%s in %s" % (amt.totalprice.currency, acc)].append({ "x": tdate_ms, "y": round(amt.totalprice.quantity, 2), "currency": amt.totalprice.currency, "transaction": tstr }) return json.dumps(returndict).encode("utf-8")
def __render_json_history(self, request, upr): if not upr.path == b'/accounthistory.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" self.groupid_next = 0 groupid = defaultdict(self.__getnextgroupid) qryaccts = query["account"] frs = ledger.registerFromRunningSum( ledger.filterRunningSum( running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts)) limit = int(query["limit"][0]) if "limit" in query else 60 returnlist = [] for tdate, account_currency_sum in itail(frs, limit): for acc, currdict in account_currency_sum.items(): if not acc in qryaccts: continue for currency, amt in currdict.items(): returnlist.append({ "x": tdate, "y": round(amt.quantity, 2), "group": groupid["%s in %s" % (amt.currency, acc)] }) #, "label":{"content":str(amt)} if amt.totalprice and amt.totalprice.currency != amt.currency: returnlist.append({ "x": tdate, "y": amt.totalprice.quantity, "group": groupid["%s in %s" % (amt.totalprice.currency, acc)] }) #, "label":str(amt.totalprice) grouplist = [{ "id": gid, "content": gname } for (gname, gid) in groupid.items()] return json.dumps({ "dataset": returnlist, "groupset": grouplist }).encode("utf-8")
def __render_json_canvasjs_history_days(self, request, upr): """ handle request and return json data formated for canvasjs graphlibrary show one account balance for each day that has at least one transaction """ if not upr.path == b'/canvasjsaccounthistoryindays.json': return False query = urllib.parse.parse_qs(upr.query.decode("utf8"), strict_parsing=False) request.setHeader(b"content-type", b"application/json") if not "account" in query: return b"[]" qryaccts = query["account"] frs = ledger.registerFromRunningSum( ledger.filterRunningSum( running_sum_, fromdate=query["fromdate"][0] if "fromdate" in query else None, todate=query["todate"][0] if "todate" in query else None, account=qryaccts)) limit = int(query["limit"][0]) if "limit" in query else 1000 returndict = defaultdict(list) for tdate, account_currency_sum in itail(frs, limit): tdate_ms = int( datetime.datetime.strptime( tdate, ledger.dateformat_hledger_csvexport_).timestamp() * 1000) for acc, currdict in account_currency_sum.items(): if not acc in qryaccts: continue for currency, amt in currdict.items(): datasetname = "%s in %s" % (amt.currency, acc) returndict[datasetname].append({ "x": tdate_ms, "y": round(amt.quantity, 2), "currency": currency }) if amt.totalprice and amt.totalprice.currency != amt.currency: returndict["%s in %s" % (amt.totalprice.currency, acc)].append({ "x": tdate_ms, "y": round(amt.totalprice.quantity, 2), "currency": amt.totalprice.currency }) return json.dumps(returndict).encode("utf-8")