mirror of
https://github.com/Rushilwiz/pushup-contest.git
synced 2025-04-17 15:40:16 -04:00
finished general functionality
This commit is contained in:
parent
bc06642fe7
commit
84fe5aa38d
21
pushup/management/commands/generate_stock.py
Normal file
21
pushup/management/commands/generate_stock.py
Normal file
|
@ -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()
|
|
@ -4,6 +4,7 @@
|
||||||
<div class="row mt-md-3">
|
<div class="row mt-md-3">
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
<canvas id="stockChart"></canvas>
|
<canvas id="stockChart"></canvas>
|
||||||
|
<span class="text-center"><h4>Current Value: </h4><h1 style="color: #21CE99">{{current_value}}</h1></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
<div class="content-section">
|
<div class="content-section">
|
||||||
|
@ -43,9 +44,8 @@
|
||||||
data: {
|
data: {
|
||||||
labels: {{times|safe}},
|
labels: {{times|safe}},
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: 'My First dataset',
|
label: 'Pushup Value',
|
||||||
backgroundColor: 'rgb(255, 99, 132)',
|
borderColor: '#21CE99',
|
||||||
borderColor: 'rgb(255, 99, 132)',
|
|
||||||
data: {{values|safe}}
|
data: {{values|safe}}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,6 +10,8 @@ import datetime
|
||||||
def home(request):
|
def home(request):
|
||||||
times = []
|
times = []
|
||||||
values = []
|
values = []
|
||||||
|
current_value = get_current_stock_value()
|
||||||
|
|
||||||
users = Profile.objects.order_by('-pushups')
|
users = Profile.objects.order_by('-pushups')
|
||||||
print(users)
|
print(users)
|
||||||
|
|
||||||
|
@ -23,6 +25,10 @@ def home(request):
|
||||||
'times': times,
|
'times': times,
|
||||||
'values': values,
|
'values': values,
|
||||||
'users': users,
|
'users': users,
|
||||||
|
'current_value': current_value
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'pushup/index.html', context=context)
|
return render(request, 'pushup/index.html', context=context)
|
||||||
|
|
||||||
|
def get_current_stock_value():
|
||||||
|
return float(StockValue.objects.order_by('-time').first().value)
|
18
users/migrations/0003_auto_20201019_0252.py
Normal file
18
users/migrations/0003_auto_20201019_0252.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.1.2 on 2020-10-19 06:52
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0002_auto_20201019_0157'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='profile',
|
||||||
|
name='pushups',
|
||||||
|
field=models.DecimalField(decimal_places=3, max_digits=5),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,5 +1,11 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
from django.contrib.auth import authenticate
|
||||||
|
from django.contrib.auth import login as auth_login
|
||||||
|
from django.contrib.auth import logout as auth_logout
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def login(request):
|
def login(request):
|
||||||
return None
|
return None
|
||||||
|
@ -7,5 +13,7 @@ def login(request):
|
||||||
def signup(request):
|
def signup(request):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@login_required
|
||||||
def logout(request):
|
def logout(request):
|
||||||
return None
|
auth_logout(request)
|
||||||
|
return render(request, 'users/logout.html')
|
Loading…
Reference in New Issue
Block a user