calculate min and max values per period
This commit is contained in:
@@ -19,6 +19,43 @@ class Calc:
|
||||
"diffPercentage": (CurrentRate.rate-Decimal(rateMinusXDay[0]))/Decimal(rateMinusXDay[0])*100, "rateUSD": None}
|
||||
return None
|
||||
|
||||
def CalcHistory(self, Hours, Crypto, Fiat):
|
||||
with connection.cursor() as cursor:
|
||||
startDate = datetime.datetime.today() - datetime.timedelta(hours=Hours)
|
||||
endDate = datetime.datetime.today()
|
||||
sql = """SELECT datetime_valid, rate FROM exchangerate
|
||||
WHERE crypto_currency = %s AND fiat_currency = %s
|
||||
AND datetime_valid BETWEEN %s AND %s
|
||||
ORDER BY datetime_valid ASC LIMIT 1"""
|
||||
cursor.execute(sql, [Crypto, Fiat, startDate, endDate])
|
||||
startRate = cursor.fetchone()
|
||||
if not startRate:
|
||||
return {}
|
||||
sql = """SELECT datetime_valid, rate FROM exchangerate
|
||||
WHERE crypto_currency = %s AND fiat_currency = %s
|
||||
AND datetime_valid BETWEEN %s AND %s
|
||||
ORDER BY datetime_valid DESC LIMIT 1"""
|
||||
cursor.execute(sql, [Crypto, Fiat, startDate, endDate])
|
||||
endRate = cursor.fetchone()
|
||||
sql = """SELECT datetime_valid, rate FROM exchangerate
|
||||
WHERE crypto_currency = %s AND fiat_currency = %s
|
||||
AND datetime_valid BETWEEN %s AND %s
|
||||
ORDER BY rate DESC LIMIT 1"""
|
||||
cursor.execute(sql, [Crypto, Fiat, startDate, endDate])
|
||||
maxRate = cursor.fetchone()
|
||||
sql = """SELECT datetime_valid, rate FROM exchangerate
|
||||
WHERE crypto_currency = %s AND fiat_currency = %s
|
||||
AND datetime_valid BETWEEN %s AND %s
|
||||
ORDER BY rate ASC LIMIT 1"""
|
||||
cursor.execute(sql, [Crypto, Fiat, startDate, endDate])
|
||||
minRate = cursor.fetchone()
|
||||
return {"startdate": startRate[0], "startvalue": startRate[1],
|
||||
"curdate": endRate[0], "curvalue": endRate[1],
|
||||
"mindate": minRate[0], "minvalue": minRate[1],
|
||||
"maxdate": maxRate[0], "maxvalue": maxRate[1]}
|
||||
return None
|
||||
|
||||
|
||||
def GetCurrentValue(self, userid, crypto, total_investment, current_value, total_tax_free):
|
||||
amount_kept = 0
|
||||
out = {}
|
||||
@@ -70,6 +107,15 @@ class Calc:
|
||||
if diffrate:
|
||||
out["rates"].append(diffrate)
|
||||
|
||||
out["graphs"] = []
|
||||
out["graphs"].append({"id": "h48", "active": "active", "label": "48 hours", "period": "number_of_hours=48", **self.CalcHistory(24*2, crypto, 'EUR')})
|
||||
out["graphs"].append({"id": "d3", "label": "3 days", "period": "number_of_hours=72", **self.CalcHistory(24*3, crypto, 'EUR')})
|
||||
out["graphs"].append({"id": "w1", "label": "1 week", "period": "number_of_hours=168", **self.CalcHistory(24*7, crypto, 'EUR')})
|
||||
out["graphs"].append({"id": "m1", "label": "1 month", "period": "number_of_days=30", **self.CalcHistory(24*30, crypto, 'EUR')})
|
||||
out["graphs"].append({"id": "m6", "label": "6 months", "period": "number_of_days=180", **self.CalcHistory(24*180, crypto, 'EUR')})
|
||||
out["graphs"].append({"id": "y1", "label": "1 year", "period": "number_of_days=360", **self.CalcHistory(24*360, crypto, 'EUR')})
|
||||
out["graphs"].append({"id": "y10", "label": "10 years", "period": "number_of_days=3600", **self.CalcHistory(24*3600, crypto, 'EUR')})
|
||||
|
||||
amount_within_past_year = 0
|
||||
with connection.cursor() as cursor:
|
||||
sql = """SELECT SUM(amount_after_fee) as amount FROM `transaction` WHERE amount > 0 and crypto_currency=%s and owner_id=%s and date_valid>%s"""
|
||||
|
||||
@@ -97,34 +97,16 @@
|
||||
</table>
|
||||
|
||||
</div>
|
||||
<div class="tab-pane active" id="h48{{ c.crypto }}">
|
||||
<h4>48 hours</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&number_of_hours=48" loading="lazy">
|
||||
</div>
|
||||
<div class="tab-pane" id="d3{{ c.crypto }}">
|
||||
<h4>3 days</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&number_of_hours=72" loading="lazy">
|
||||
</div>
|
||||
<div class="tab-pane" id="w1{{ c.crypto }}">
|
||||
<h4>1 week</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&number_of_hours=168" loading="lazy">
|
||||
</div>
|
||||
<div class="tab-pane" id="m1{{ c.crypto }}">
|
||||
<h4>1 month</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&number_of_days=30" loading="lazy">
|
||||
</div>
|
||||
<div class="tab-pane" id="m6{{ c.crypto }}">
|
||||
<h4>6 months</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&number_of_days=180" loading="lazy">
|
||||
</div>
|
||||
<div class="tab-pane" id="y1{{ c.crypto }}">
|
||||
<h4>1 year</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&number_of_days=360" loading="lazy">
|
||||
</div>
|
||||
<div class="tab-pane" id="y10{{ c.crypto }}">
|
||||
<h4>10 years</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&number_of_days=3600" loading="lazy">
|
||||
{% for g in c.graphs %}
|
||||
<div class="tab-pane {{g.active}}" id="{{ g.id }}{{ c.crypto }}">
|
||||
<h4>{{ g.label }}</h4>
|
||||
<img src="/graph?crypto={{ c.crypto }}&fiat=EUR&{{g.period}}" loading="lazy"><br/>
|
||||
Start: {{ g.startdate }} {{ g.startvalue|floatformat:2 }} EUR<br/>
|
||||
Min: {{ g.mindate }} {{ g.minvalue|floatformat:2 }} EUR<br/>
|
||||
Max: {{ g.maxdate }} {{ g.maxvalue|floatformat:2 }} EUR<br/>
|
||||
Now: {{ g.curdate }} {{ g.curvalue|floatformat:2 }} EUR<br/>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user