From 84fe5aa38de6f125532a0abea295b48308c13f8b Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya <2023rumareti@tjhsst.edu> Date: Mon, 19 Oct 2020 03:20:28 -0400 Subject: [PATCH] finished general functionality --- pushup/management/commands/generate_stock.py | 21 ++++++++++++++++++++ pushup/templates/pushup/index.html | 6 +++--- pushup/views.py | 8 +++++++- users/migrations/0003_auto_20201019_0252.py | 18 +++++++++++++++++ users/views.py | 10 +++++++++- 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 pushup/management/commands/generate_stock.py create mode 100644 users/migrations/0003_auto_20201019_0252.py diff --git a/pushup/management/commands/generate_stock.py b/pushup/management/commands/generate_stock.py new file mode 100644 index 0000000..9c78895 --- /dev/null +++ b/pushup/management/commands/generate_stock.py @@ -0,0 +1,21 @@ +from django.core.management.base import BaseCommand, CommandError +from pushup.models import StockValue +import random + +def get_current_stock_value(): + return float(StockValue.objects.order_by('-time').first().value) + +class Command(BaseCommand): + help = 'Generate a new stock value' + + def handle(self, *args, **options): + current_val = get_current_stock_value() + if current_val <= 0.5: + new_value = StockValue(value=round(current_val + round(random.uniform(0.0, 0.5), 3), 3)) + if current_val >= 2: + new_value = StockValue(value=round(current_val + round(random.uniform(-0.15, 0.10), 3), 3)) + else: + new_value = StockValue(value=round(current_val + round(random.uniform(-0.09, 0.10), 3), 3)) + + + new_value.save() \ No newline at end of file diff --git a/pushup/templates/pushup/index.html b/pushup/templates/pushup/index.html index 8befc7f..647c912 100644 --- a/pushup/templates/pushup/index.html +++ b/pushup/templates/pushup/index.html @@ -4,6 +4,7 @@