Exemplo n.º 1
0
 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")
Exemplo n.º 2
0
 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")
Exemplo n.º 3
0
 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")
Exemplo n.º 4
0
 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")