def region_month_userdevice_data(): result = {} load_result_bool = False load_result = {} info = None try: month = request.form.get("month", None) regionshort = request.form.get("region", None) # time = 'March 2015' if month is None or regionshort is None: raise Exception('Invalid args, month or region cannot be None') clock = str_2_clock(month, '%B %Y') r = region.query.filter_by(regionshort=regionshort).first() if r is None: raise Exception(' region input does not exist') rc_result = {} region_counts = r.counts.filter('clock >=' + str(clock)).all() for rc in region_counts: if rc.clock not in rc_result: rc_result[rc.clock] = {} rc_result[rc.clock][rc.counttype.counttypename] = rc.value load_result['data'] = rc_result info = 'success' load_result_bool = True except Exception, e: info = str(e) print info load_result = {} load_result_bool = False
def ladata(): result = {} info = None load_result_bool = False load_result = {} try: time = request.args.get('time', None) linkedaccountname = request.args.get('laname', None) load_collapse_id = request.args.get('render_selector_id', None) # time = 'March 2015' if time is None or linkedaccountname is None: raise Exception('Invalid args') l = linkedaccount.query.filter_by( linkedaccountname=linkedaccountname).first() if l is None: raise Exception('Linked account do not exist with name:' + linkedaccountname) clock = str_2_clock(time, '%B %Y') load_result['data'] = l.build_list(clock) load_result['time'] = time load_result['laname'] = linkedaccountname load_result['load_collapse_id'] = load_collapse_id info = 'success' load_result_bool = True except Exception, e: info = str(e) load_result_bool = False load_result = None
def monthdata(): result = {} load_result_bool = False load_result = {} info = None try: month = request.args.get('month', None) # time = 'March 2015' if month is None: raise Exception('Invalid args, month cannot be None') clock = str_2_clock(month, '%B %Y') odm = odmonth.query.filter_by(beginclock=clock).first() load_result['data'] = [] if odm is not None: load_result['data'] = odm.gen_table_content() load_result['month'] = month info = 'success' load_result_bool = True except Exception, e: info = str(e) print info load_result = {} load_result_bool = False
def build_db_record_from_row(self, row, headers): if row is None or headers is None: raise Exception('Invalid input in ' + \ 'CsvToDbRecord.build_db_record_from_row') # invoice tmp_invoiceid = row[headers.index(INVOICEID)] assert tmp_invoiceid != '' tmp_invoice = invoice.query.get(tmp_invoiceid) if tmp_invoiceid != 'Estimated': if tmp_invoice is None: tmp_invoice = invoice(tmp_invoiceid) db.session.add(tmp_invoice) tmp_billingstarttime = row[headers.index(BILLINGPERIODSTARTDATE)] tmp_billingendtime = row[headers.index(BILLINGPERIODENDDATE)] assert tmp_billingstarttime != '' assert tmp_billingendtime != '' start_clock = str_2_clock(tmp_billingstarttime, TIME_FORMAT) end_clock = str_2_clock(tmp_billingendtime, TIME_FORMAT) assert start_clock != None assert end_clock != None tmp_billtingtime = billingtime.query.filter_by(billingperiodstartdate=\ start_clock, billingperiodenddate=end_clock).first() if tmp_billtingtime is None: tmp_billtingtime = billingtime(start_clock, end_clock) db.session.add(tmp_billtingtime) # payeraccount tmp_payeraccountid = row[headers.index(PAYERACCOUNTID)] assert tmp_payeraccountid != '' tmp_payeraccount = payeraccount.query.get(tmp_payeraccountid) if tmp_payeraccount is None: tmp_payeraccountname = row[headers.index(PAYERACCOUNTNAME)] tmp_payerponumber = self.parse_empty_str_2_none(\ row[headers.index(PAYERPONUMBER)]) assert tmp_payeraccountname != '' tmp_payeraccount = payeraccount(tmp_payeraccountid, \ tmp_payeraccountname, tmp_payerponumber) db.session.add(tmp_payeraccount) # linkedaccount tmp_linkedaccountid = row[headers.index(LINKEDACCOUNTID)] tmp_linkedaccount = None if tmp_linkedaccountid != '': tmp_linkedaccount = linkedaccount.query.get(tmp_linkedaccountid) if tmp_linkedaccount is None: tmp_linkedaccountname = row[headers.index(LINKEDACCOUNTNAME)] assert tmp_linkedaccountname != '' tmp_taxationaddress = self.parse_empty_str_2_none(\ row[headers.index(TAXATIONADDRESS)]) tmp_linkedaccount = linkedaccount(tmp_linkedaccountid, \ tmp_linkedaccountname, tmp_taxationaddress) db.session.add(tmp_linkedaccount) # awsservice tmp_productcode = row[headers.index(PRODUCTCODE)] tmp_productname = row[headers.index(PRODUCTNAME)] assert tmp_productname != '' and tmp_productcode != '' tmp_awsservice = awsservice.query.\ filter_by(productcode=tmp_productcode).first() if tmp_awsservice is None: tmp_awsservice = awsservice(tmp_productcode, tmp_productname) db.session.add(tmp_awsservice) # apioperation tmp_operationname = row[headers.index(OPERATION)] tmp_apioperation = None if tmp_operationname != '': tmp_apioperation = apioperation.query.\ filter_by(apioperationname=tmp_operationname).first() if tmp_apioperation is None: tmp_apioperation = apioperation(tmp_operationname) db.session.add(tmp_apioperation) tmp_usagetype = self.parse_empty_str_2_none(\ row[headers.index(USAGETYPE)]) assert tmp_usagetype != '' tmp_availablezone = None tmp_region_name = availablezone.get_region_name_from_usagetype(\ tmp_usagetype) tmp_availablezone = availablezone.query.filter_by(regionname=\ tmp_region_name).first() if tmp_availablezone is None: tmp_availablezone = availablezone(tmp_region_name) db.session.add(tmp_availablezone) # billingrow tmp_billingperiodstartdate = self.parse_empty_str_2_none(\ row[headers.index(BILLINGPERIODSTARTDATE)]) tmp_billingperiodenddate = self.parse_empty_str_2_none(\ row[headers.index(BILLINGPERIODENDDATE)]) tmp_invoicedate = self.parse_empty_str_2_none(\ row[headers.index(INVOICEDATE)]) tmp_sellerofrecord = self.parse_empty_str_2_none(\ row[headers.index(SELLEROFRECORD)]) tmp_usagetype = self.parse_empty_str_2_none(\ row[headers.index(USAGETYPE)]) tmp_rateid = self.parse_empty_str_2_none(\ row[headers.index(RATEID)]) tmp_itemdescription = self.parse_empty_str_2_none(\ row[headers.index(ITEMDESCRIPTION)]) tmp_usagestartdate = self.parse_empty_str_2_none(\ row[headers.index(USAGESTARTDATE)]) tmp_usageenddate = self.parse_empty_str_2_none(\ row[headers.index(USAGEENDDATE)]) tmp_usagequantity = self.parse_empty_str_2_none(\ row[headers.index(USAGEQUANTITY)]) tmp_blendedrate = self.parse_empty_str_2_none(\ row[headers.index(BLENDEDRATE)]) tmp_currencycode = self.parse_empty_str_2_none(\ row[headers.index(CURRENCYCODE)]) tmp_costbeforetax = self.parse_empty_str_2_none(\ row[headers.index(COSTBEFORETAX)]) tmp_credits = self.parse_empty_str_2_none(\ row[headers.index(CREDITS)]) tmp_taxamount = self.parse_empty_str_2_none(\ row[headers.index(TAXAMOUNT)]) tmp_taxtype = self.parse_empty_str_2_none(\ row[headers.index(TAXTYPE)]) tmp_totalcost = self.parse_empty_str_2_none(\ row[headers.index(TOTALCOST)]) assert tmp_billingperiodstartdate != '' and\ tmp_billingperiodenddate !='' and\ tmp_invoicedate !='' and\ tmp_usagestartdate !='' and\ tmp_usageenddate !='' and \ tmp_usagequantity !='' and \ tmp_totalcost != '' tmp_bsdc = str_2_clock(tmp_billingperiodstartdate, TIME_FORMAT) tmp_br = billingrow.query.filter_by(billingperiodstartdate=tmp_bsdc,\ invoice=tmp_invoice, apioperation=tmp_apioperation, payeraccount=\ tmp_payeraccount, linkedaccount=tmp_linkedaccount, awsservice=\ tmp_awsservice, usagetype=tmp_usagetype, \ itemdescription=tmp_itemdescription ).first() if tmp_br is not None: db.session.delete(tmp_br) tmp_billingrow = billingrow(str_2_clock(tmp_billingperiodstartdate,\ TIME_FORMAT),\ str_2_clock(tmp_billingperiodenddate, TIME_FORMAT) ,\ str_2_clock(tmp_invoicedate, TIME_FORMAT) ,\ tmp_sellerofrecord,\ tmp_usagetype,\ tmp_rateid,\ tmp_itemdescription,\ str_2_clock(tmp_usagestartdate, TIME_FORMAT) ,\ str_2_clock(tmp_usageenddate, TIME_FORMAT) ,\ tmp_usagequantity,\ tmp_blendedrate,\ tmp_currencycode,\ tmp_costbeforetax, \ tmp_credits, \ tmp_taxamount, \ tmp_taxtype, \ tmp_totalcost, \ tmp_invoice, \ tmp_apioperation, \ tmp_payeraccount, \ tmp_linkedaccount, \ tmp_awsservice,\ tmp_availablezone,\ tmp_billtingtime) db.session.add(tmp_billingrow) db.session.commit()
def billsreport(): result = {} info = None load_result_bool = False load_result = {} try: time = request.args.get('time', None) # time = 'March 2015' if time is None: raise Exception('Invalid args, time cannot be None') clock = str_2_clock(time, '%B %Y') consolidated_bill_data = {} for s in awsservice.query.all(): tmps_r = s.build_list(clock) if len(tmps_r['region_info']) > 0: consolidated_bill_data[s.productname] = tmps_r linkedaccount_data = {} for l in linkedaccount.query.all(): if l.fee_of_time(clock) is None: continue linkedaccount_data[l.linkedaccountname] = l.fee_of_time(clock) summary_data = {} summary_data['Total'] = 0 summary_data['payers'] = {} for p in payeraccount.query.all(): if p.fee_of_time(clock) is None: continue summary_data['Total'] += p.fee_of_time(clock) summary_data['payers'][p.payeraccountid] = {} summary_data['payers'][p.payeraccountid]['Total'] = \ p.fee_of_time(clock) summary_data['payers'][p.payeraccountid]['InvoiceDate'] = \ p.billingrows.filter_by(billingperiodstartdate=clock)\ .first().invoicedate region_data = {} region_data['Total'] = 0 region_data['regions'] = {} for az in availablezone.query.all(): tmp_fee = az.fee_of_time(clock) if tmp_fee is None: continue region_data['Total'] += tmp_fee region_data['regions'][az.regionname] = {} region_data['regions'][az.regionname]['Total'] = tmp_fee region_data['regions'][az.regionname]['lc'] = {} for l in linkedaccount.query.all(): if az.fee_of_time(clock, l) is not None: region_data['regions'][az.regionname]['lc']\ [l.linkedaccountname] = az.fee_of_time(clock, l) load_result['time'] = time load_result['consolidated_bill_data'] = consolidated_bill_data load_result['linkedaccount_data'] = linkedaccount_data load_result['summary_data'] = summary_data load_result['region_data'] = region_data info = 'success' load_result_bool = True except Exception, e: traceback.print_exc(file=sys.stdout) info = str(e)