def processTransactions(self): total = 0 if self.outputFile != None: base = os.path.splitext(self.outputFile)[0] base = base + '-' + str(self.outFileCount) + os.path.splitext( self.outputFile)[1] self.outFileCount += 1 f = open(base, mode="w") t = sorted(self.currentTransactions, key=lambda x: x["amount"]) else: t = self.currentTransactions for trans in t: if "empty" in trans: continue if self.outputFile != None: f.write('"{}", {}\n'.format(trans["description"], trans["amount"])) if not self.ignored(trans["description"]): total += trans["amount"] if self.outputFile != None: f.close() #is this month over? now = Dates.empty() then = self.currentTransactions[0]["date"] oldDate = Dates(then.month, then.year) days = oldDate.pastDays() + oldDate.remainingDays() if (now > Dates(then.month, then.year)): average = total / days projection = total else: #we are working with an incomplete month, use history average = total / self.date.pastDays() dailyProjection = self.history.calculateWeightedAverage( average, self.date) projection = dailyProjection * self.date.remainingDays() + total result = { "total": total, "dailyAverage": average, "projected": projection } return result