def getfbos(conn): #Returns a list of all user's FBO's in the log c=getpaydbcon(conn) print("Getting list of FBO's...") fbos=[] for place in c.execute('SELECT DISTINCT fbo FROM payments WHERE payto = ?',(fseutils.getname(),)): if place[0]!="N/A": fbos.append(place[0]) return fbos
def plotpayments(conn,fromdate,todate): #Plot payment totals per category c=getpaydbcon(conn) user=fseutils.getname() delta=timedelta(days=1) fyear,fmonth,fday=fromdate.split('-', 2) tyear,tmonth,tday=todate.split('-', 2) fdate=date(int(fyear),int(fmonth),int(fday)) tdate=date(int(tyear),int(tmonth),int(tday)) rentexp, rentinc, assnmtexp, assnmtinc, pltfee, addcrewfee, gndcrewfee, bkgfee, ref100, refjet, mxexp, eqinstl, acsold, acbought, fboref100, fborefjet, fbogndcrew, fborepinc, fborepexp, fboeqpexp, fboeqpinc, ptrentinc, ptrentexp, fbosell, fbobuy, wsbuy100, wssell100, wsbuyjet, wsselljet, wsbuybld, wssellbld, wsbuysupp, wssellsupp, grpay=([[fdate,0]] for i in range(34)) allthat=[rentexp, rentinc, assnmtexp, assnmtinc, pltfee, addcrewfee, gndcrewfee, bkgfee, ref100, refjet, mxexp, eqinstl, acsold, acbought, fboref100, fborefjet, fbogndcrew, fborepinc, fborepexp, fboeqpexp, fboeqpinc, ptrentinc, ptrentexp, fbosell, fbobuy, wsbuy100, wssell100, wsbuyjet, wsselljet, wsbuybld, wssellbld, wsbuysupp, wssellsupp, grpay] categories=[("Rental of aircraft", rentinc, rentexp), ("Pay for assignment", assnmtinc, assnmtexp), ("Crew fee", addcrewfee, addcrewfee), ("FBO ground crew fee", fbogndcrew, gndcrewfee), ("Booking Fee", bkgfee, bkgfee), ("Refuelling with JetA", fborefjet, refjet), ("Refuelling with 100LL", fboref100, ref100), ("Aircraft maintenance", fborepinc, mxexp), ("Aircraft sale", acsold, acbought), ("Sale of wholesale JetA", wsselljet, wsbuyjet), ("Sale of wholesale 100LL", wssell100, wsbuy100), ("Sale of supplies", wssellsupp, wsbuysupp), ("Sale of building materials", wssellbld, wsbuybld), ("Group payment", grpay, grpay), ("Pilot fee", pltfee, pltfee), ("Installation of equipment in aircraft", fboeqpinc, eqinstl)] i=0 print('Tallying daily payments from %i-%i to %i-%i...' % (fdate.year,fdate.month,tdate.year,tdate.month)) #(date text, to text, from text, amount real, reason text, location real, aircraft real) while fdate <= tdate: fdateq=fdate.isoformat()+" 00:00:01" #To match logged format tdateq=fdate.isoformat()+" 23:59:59" if i>0: for var in allthat: var.append([fdate,var[i-1][1]]) #Carry over the previous totals to new date for payment in c.execute('SELECT payfrom, amount, reason FROM payments WHERE date BETWEEN ? AND ?',(fdateq,tdateq)): for cat in categories: if payment[2]==cat[0]: #Test if category matches if payment[0]!=user: #If payment not from user cat[1][i][1]+=payment[1] else: cat[2][i][1]+=payment[1] break fdate += delta i += 1 plotdates([refjet, addcrewfee, gndcrewfee],"Money","Money",['-'],None,0)
k=0 #Index of month in list listofdays=[] listofmonths=[] today = date.today() month=today.month year=today.year day=today.day listofmonths.append(month) for j in range(daysago): history=today - timedelta(j+1) listofdays.append(history) # print(str(listofdays[j].month)+"/"+str(listofdays[j].day)) if history.month!=listofmonths[k]: listofmonths.append(history.month) k+=1 me=fseutils.getname() ns = {'sfn': 'http://server.fseconomy.net'} #namespace for XML stuff plogs=[] firstrqtime=int(time.time()) print("Sending request for aircraft list...") requests+=1 airplanes = fseutils.fserequest_new('aircraft','key','Aircraft','xml',1,1) #print(airplanes) print("Processing list...") for plane in airplanes: thisac=fseutils.getbtns(plane, [("Registration", 0), ("MakeModel", 0), ("SerialNumber", 0)]) plogs.append((thisac[0],[])) for eachmonth in listofmonths: if requests>8: printsleep(120) requests=0
def getwkrev(conn): #Gets the revenue/week of FBO's c=getpaydbcon(conn) print("Getting FBO logs...") categories=("FBO ground crew fee", "Refuelling with JetA", "Refuelling with 100LL", "Aircraft maintenance", "Sale of wholesale JetA", "Sale of wholesale 100LL", "Sale of supplies", "Sale of building materials", "Installation of equipment in aircraft") revs=[] #List of revenue per week for each week fbos=getfbos(conn) #FBO's we care about wk=0 #Track which week is being added for pay in c.execute('SELECT date, amount, reason, fbo, comment FROM payments WHERE payto = ? ORDER BY date DESC',(fseutils.getname(),)): for cat in categories: if log[2]==cat: for fbo in fbos: if log[3]==fbo: #Ok we actually care about this payment and FBO thedate=fseutils.getdtime(pay[0]) if wk==0: #Add first payment info wk=1 revs.append([thedate,pay[1]]) else: #Figure it out I guess delta=thedate-revs[0][0] thisweek=timedelta.total_seconds(delta)/604800 if thisweek<wk: #Add to current week revs[wk-1][1]+=log[1] else: #Add new week revs.append([thedate,pay[1]]) break break return revs
def getfborev(conn): #Gets the revenues for FBO's c=getpaydbcon(conn) print("Getting FBO logs...") #galjet=["","",0] #1st date, last date, total #gal100=["","",0] #assnmtcost,gndcrew,refjet,ref100,repinc,wsjet,ws100,wssupp,wsbld,eqpinstl=([["","",0]] for i in range(10)) categories=("FBO ground crew fee", "Refuelling with JetA", "Refuelling with 100LL", "Aircraft maintenance", "Sale of wholesale JetA", "Sale of wholesale 100LL", "Sale of supplies", "Sale of building materials", "Installation of equipment in aircraft") revs=[] for fbo in getfbos(conn): revs.append([fbo,0,"",""]) #location, revenue total, first revenue, last revenue #(date text, payto text, payfrom text, amount real, reason text, location text, fbo text, aircraft text, pid real, comment text) for log in c.execute('SELECT date, amount, reason, fbo, comment FROM payments WHERE payto = ? ORDER BY date DESC',(fseutils.getname(),)): for cat in categories: #See if payment is a category we care about if log[2]==cat: for rev in revs: #See if payment is for FBO we care about if log[3]==rev[0]: rev[1]+=log[1] #Add the revenue dt=fseutils.getdtime(log[0]) if rev[2]=="": #First payment, set the dates rev[2]=dt rev[2]=dt else: #Last payment, update the last date rev[3]=dt break else: print("Did not recognize FBO: "+log[3]) break for fbo in revs: delta=fbo[3]-fbo[2] if delta>0: weeks=timedelta.total_seconds(delta)/604800 #Number of seconds in a week fbo[1]/=weeks else: #Can't divide by zero fbo[1]=0 #gals=float(log[4].split(':',3)[2].split(',')[0]) return revs
k = 0 #Index of month in list listofdays = [] listofmonths = [] today = date.today() month = today.month year = today.year day = today.day listofmonths.append(month) for j in range(daysago): history = today - timedelta(j + 1) listofdays.append(history) # print(str(listofdays[j].month)+"/"+str(listofdays[j].day)) if history.month != listofmonths[k]: listofmonths.append(history.month) k += 1 me = fseutils.getname() ns = {'sfn': 'http://server.fseconomy.net'} #namespace for XML stuff plogs = [] firstrqtime = int(time.time()) print("Sending request for aircraft list...") requests += 1 airplanes = fseutils.fserequest_new('aircraft', 'key', 'Aircraft', 'xml', 1, 1) #print(airplanes) print("Processing list...") for plane in airplanes: thisac = fseutils.getbtns(plane, [("Registration", 0), ("MakeModel", 0), ("SerialNumber", 0)]) plogs.append((thisac[0], [])) for eachmonth in listofmonths: if requests > 8: printsleep(120)