rewrite frontend and logic in core app
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from django.core.management import BaseCommand
|
||||
from django.utils import timezone
|
||||
|
||||
from core.models import Subject
|
||||
from core.prediction import predict_transactions
|
||||
|
||||
past_lookup_delta = relativedelta(weeks=2)
|
||||
future_lookup_delta = relativedelta(months=2)
|
||||
from core.prediction import predict_all
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -21,29 +17,11 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
start_balance = Decimal(options["start"])
|
||||
|
||||
today = datetime.now().date()
|
||||
past_lookup_bound = today - past_lookup_delta
|
||||
future_lookup_bound = today + future_lookup_delta
|
||||
|
||||
transaction_dict = {}
|
||||
for subject in Subject.objects.all():
|
||||
transactions = []
|
||||
for tr in subject.transactions.order_by("booking_date"):
|
||||
if past_lookup_bound <= tr.booking_date <= future_lookup_bound:
|
||||
transactions.append(tr)
|
||||
predicted_transaction, prediction_info = predict_transactions(subject)
|
||||
if predicted_transaction:
|
||||
first_predicted_date = predicted_transaction[0].booking_date
|
||||
if first_predicted_date >= past_lookup_bound:
|
||||
# if two weeks after the first predicted transaction have passed, the subject is considered done
|
||||
for tr in predicted_transaction:
|
||||
if past_lookup_bound <= tr.booking_date <= future_lookup_bound:
|
||||
transactions.append(tr)
|
||||
transaction_dict[subject] = (transactions, prediction_info)
|
||||
prediction_list = predict_all(Subject.objects.order_by("name"))
|
||||
today = timezone.now().date()
|
||||
|
||||
future_transactions = []
|
||||
for subject, prediction in transaction_dict.items():
|
||||
transactions, info = prediction[0], prediction[1]
|
||||
for subject, transactions, info in prediction_list:
|
||||
print(f">>> {subject}")
|
||||
if info:
|
||||
rec_days, rec_months, day_of_month = \
|
||||
|
||||
Reference in New Issue
Block a user