From a286c73fa1f661340d85c77a281eb5e21374cf6e Mon Sep 17 00:00:00 2001 From: anon Date: Fri, 3 Jun 2022 15:23:21 -0300 Subject: [PATCH] update from june 03 --- monerojnet/models.py | 12 +- monerojnet/templates/monerojnet/translog.html | 2 +- monerojnet/views.py | 198 +++++++++++++----- moneropro/settings.py | 6 +- time_test.txt | 60 ++++++ 5 files changed, 225 insertions(+), 53 deletions(-) create mode 100644 time_test.txt diff --git a/monerojnet/models.py b/monerojnet/models.py index 6212aa1..0f43679 100644 --- a/monerojnet/models.py +++ b/monerojnet/models.py @@ -43,4 +43,14 @@ class Rank(models.Model): rank = models.IntegerField() def __str__(self): - return self.rank \ No newline at end of file + return self.rank + +class Sfmodel(models.Model): + date = models.DateField() + priceusd = models.FloatField() + color = models.FloatField() + stocktoflow = models.FloatField() + greyline = models.FloatField() + + def __str__(self): + return self.date \ No newline at end of file diff --git a/monerojnet/templates/monerojnet/translog.html b/monerojnet/templates/monerojnet/translog.html index 6bbdfc6..6845924 100644 --- a/monerojnet/templates/monerojnet/translog.html +++ b/monerojnet/templates/monerojnet/translog.html @@ -58,7 +58,7 @@
- Highest Number Transactions
+ Highest Number of Transactions
{{ maximum }}
diff --git a/monerojnet/views.py b/monerojnet/views.py index ef99603..cc2757b 100644 --- a/monerojnet/views.py +++ b/monerojnet/views.py @@ -241,38 +241,113 @@ def reset(request, symbol): context = {'message': message} return render(request, 'monerojnet/maintenance.html', context) +# Populate database with especific chart variables +# Only authorized users can do this +@login_required +def populate_database(request): + count = 0 + + ################## + # SF model chart + ################## + timevar = 1283 + v0 = 0.002 + delta = (0.015 - 0.002)/(6*365) + supply = 0 + sf_aux = 0 + skipped = 0 + count_aux = 0 + + coins = Coin.objects.order_by('date').filter(name='xmr') + for coin in coins: + data = Sfmodel() + data.date = coin.date + data.priceusd = coin.priceusd + data.stocktoflow = coin.stocktoflow + date_aux1 = datetime.datetime.strptime('2017-12-29', '%Y-%m-%d') + date_aux2 = datetime.datetime.strftime(coin.date, '%Y-%m-%d') + date_aux2 = datetime.datetime.strptime(date_aux2, '%Y-%m-%d') + if date_aux2 < date_aux1: + lastprice = coin.priceusd + current_inflation = coin.inflation + data.greyline = 0 + count_aux = 0 + else: + day = date_aux2 - timedelta(timevar) + coin_aux1 = Coin.objects.filter(name='xmr').get(date=day) + day = date_aux2 - timedelta(timevar+1) + coin_aux2 = Coin.objects.filter(name='xmr').get(date=day) + date_aux3 = datetime.datetime.strptime('2017-12-29', '%Y-%m-%d') + + if date_aux3 + timedelta(int(count_aux*2)) < datetime.datetime.strptime('2021-07-03', '%Y-%m-%d'): + day = date_aux3 + timedelta(int(count_aux*2)) + coin_aux3 = Coin.objects.filter(name='xmr').get(date=day) + if coin_aux3: + if (coin_aux3.inflation/current_inflation) > 1.2 or (coin_aux3.inflation/current_inflation) < 0.8: + coin_aux3.inflation = current_inflation + else: + current_inflation = coin_aux3.inflation + supply2 = supply + else: + reward2 = (2**64 -1 - supply2) >> 19 + if reward2 < 0.6*(10**12): + reward2 = 0.6*(10**12) + supply2 += int(720*reward2) + current_inflation = 100*reward2*720*365/supply2 + + if coin_aux1 and coin_aux2: + lastprice += (coin_aux1.priceusd/coin_aux2.priceusd-1)*lastprice + actualprice = lastprice*(math.sqrt(coin.inflation/current_inflation)) + data.greyline = actualprice + if skipped < 12: + data.greyline = actualprice + else: + skipped = 0 + else: + data.greyline = 0 + skipped += 1 + + if coin.priceusd < 0.01: + coin.priceusd = 0.01 + if coin.stocktoflow > sf_aux*2+250: + coin.stocktoflow = sf_aux + if coin.stocktoflow < 0.1: + coin.stocktoflow = 0.1 + sf_aux = coin.stocktoflow + color = 30*coin.pricebtc/(count*delta + v0) + data.color = color + supply = int(coin.supply)*10**12 + count += 1 + count_aux += 1 + data.save() + + count_aux = 0 + for count_aux in range(650): + data = Sfmodel() + date_now = date.today() + timedelta(count_aux) + data.date = datetime.datetime.strftime(date_now, '%Y-%m-%d') + data.priceusd = 0 + data.greyline = 0 + reward = (2**64 -1 - supply) >> 19 + if reward < 0.6*(10**12): + reward = 0.6*(10**12) + supply += int(720*reward) + data.stocktoflow = (100/(100*reward*720*365/supply))**1.65 + count += 1 + + message = 'Total of ' + str(count) + ' data imported' + context = {'message': message} + return render(request, 'monerojnet/maintenance.html', context) + ########################################### # Other useful functions ########################################### # Get most recent metrics from a data provider of your choice for 'symbol' -def get_latest_metrics(symbol): - now = datetime.datetime.now() - current_time = int(now.strftime("%H")) - if current_time >= 3: - yesterday = date.today() - timedelta(1) - start_time = datetime.datetime.strftime(yesterday, '%Y-%m-%d') - try: - coin = Coin.objects.filter(name=symbol).get(date=yesterday) - if coin: - if (coin.inflation > 0) and (coin.priceusd > 0): - return False - else: - coin.delete() - update = True - else: - update = True - except: - update = True - else: - return False - +def get_latest_metrics(symbol, url): + update = True count = 0 - with open("settings.json") as file: - data = json.load(file) - file.close() - - url = data["metrics_provider"][0]["metrics_url"] + symbol + data["metrics_provider"][0]["metrics"] + '&start_time=' + start_time + while update: response = requests.get(url) data = json.loads(response.text) @@ -2431,22 +2506,55 @@ def compinflation(request): def sfmodel(request): dt = datetime.datetime.now(timezone.utc).timestamp() - #print('social') - check_new_social('Bitcoin') - check_new_social('Monero') - check_new_social('CryptoCurrency') - #print('metrics') - symbol = 'btc' - get_latest_metrics(symbol) - symbol = 'dash' - get_latest_metrics(symbol) - symbol = 'grin' - get_latest_metrics(symbol) - symbol = 'zec' - get_latest_metrics(symbol) + + update = True symbol = 'xmr' - get_latest_metrics(symbol) - #print('done') + + yesterday = date.today() - timedelta(1) + start_time = datetime.datetime.strftime(yesterday, '%Y-%m-%d') + try: + coin = Coin.objects.filter(name=symbol).get(date=yesterday) + if coin: + if (coin.inflation > 0) and (coin.priceusd > 0): + update = False + else: + now = datetime.datetime.now() + current_time = int(now.strftime("%H")) + if current_time >= 3: + coin.delete() + update = True + else: + update = True + except: + update = True + + if update: + #print('social') + check_new_social('Bitcoin') + check_new_social('Monero') + check_new_social('CryptoCurrency') + + #print('metrics') + with open("settings.json") as file: + data = json.load(file) + file.close() + + symbol = 'btc' + url = data["metrics_provider"][0]["metrics_url"] + symbol + data["metrics_provider"][0]["metrics"] + '&start_time=' + start_time + get_latest_metrics(symbol, url) + symbol = 'dash' + url = data["metrics_provider"][0]["metrics_url"] + symbol + data["metrics_provider"][0]["metrics"] + '&start_time=' + start_time + get_latest_metrics(symbol, url) + symbol = 'grin' + url = data["metrics_provider"][0]["metrics_url"] + symbol + data["metrics_provider"][0]["metrics"] + '&start_time=' + start_time + get_latest_metrics(symbol, url) + symbol = 'zec' + url = data["metrics_provider"][0]["metrics_url"] + symbol + data["metrics_provider"][0]["metrics"] + '&start_time=' + start_time + get_latest_metrics(symbol, url) + symbol = 'xmr' + url = data["metrics_provider"][0]["metrics_url"] + symbol + data["metrics_provider"][0]["metrics"] + '&start_time=' + start_time + get_latest_metrics(symbol, url) + #print('done') timevar = 1283 now_price = 0 @@ -2455,12 +2563,9 @@ def sfmodel(request): v0 = 0.002 delta = (0.015 - 0.002)/(6*365) count = 0 - maximum = 0 supply = 0 stock = 0.000001 dates = [] - inflations = [] - circulations = [] stock_to_flow = [] projection = [] color = [] @@ -2544,19 +2649,16 @@ def sfmodel(request): reward = 0.6*(10**12) supply += int(720*reward) inflation = 100*reward*720*365/supply - inflations.append(inflation) - circulations.append(supply) stock = (100/(inflation))**1.65 stock_to_flow.append(stock) now_price = "$"+ locale.format('%.2f', now_price, grouping=True) now_sf = "$"+ locale.format('%.2f', now_sf, grouping=True) - maximum = "$"+ locale.format('%.2f', maximum, grouping=True) now_inflation = locale.format('%.2f', now_inflation, grouping=True)+'%' dt = 'sfmodel.html ' + locale.format('%.2f', datetime.datetime.now(timezone.utc).timestamp() - dt, grouping=True)+' seconds' print(dt) - context = {'values': values, 'dates': dates, 'maximum': maximum, 'inflations': inflations, 'circulations': circulations, 'stock_to_flow': stock_to_flow, 'projection': projection, + context = {'values': values, 'dates': dates, 'stock_to_flow': stock_to_flow, 'projection': projection, 'now_price': now_price, 'now_inflation': now_inflation, 'now_sf': now_sf, 'color': color} return render(request, 'monerojnet/sfmodel.html', context) diff --git a/moneropro/settings.py b/moneropro/settings.py index beddf21..65cf638 100644 --- a/moneropro/settings.py +++ b/moneropro/settings.py @@ -32,9 +32,9 @@ STATICFILES_DIRS = [ SECRET_KEY = '' # SECURITY WARNING: don't run with debug turned on in production! -#DEBUG = True -DEBUG = False -STATIC_ROOT = "/var/www/moneropro/static/" +DEBUG = True +#DEBUG = False +#STATIC_ROOT = "/var/www/moneropro/static/" ALLOWED_HOSTS = ['www.moneroj.net', 'localhost', '127.0.0.1', 'moneroj.net'] diff --git a/time_test.txt b/time_test.txt new file mode 100644 index 0000000..8c89c49 --- /dev/null +++ b/time_test.txt @@ -0,0 +1,60 @@ +Charts that have to be changed + +transcost.html 17.95 seconds +marketcap.html 26.06 seconds +bitcoin.html 15.61 seconds +minerrevcap.html 15.37 seconds +minerrev.html 18.77 seconds +minerrevntv.html 18.68 seconds +minerfees.html 17.46 seconds +minerfeesntv.html 16.88 seconds +commit.html 15.27 seconds +commitntv.html 19.87 seconds +social.html 15.10 seconds +social6.html 15.24 seconds +social7.html 15.23 seconds +social4.html 17.45 seconds +social2.html 27.54 seconds +social3.html 15.11 seconds +social5.html 6.82 seconds +pricesats.html 5.61 seconds +transcostntv.html 15.63 seconds +percentage.html 12.20 seconds +metcalfesats.html 14.21 seconds +metcalfeusd.html 14.13 seconds +coins.html 15.35 seconds +extracoins.html 20.84 seconds +inflation.html 17.76 seconds +compinflation.html 28.91 seconds +dailyemission.html 19.64 seconds +dailyemissionntv.html 16.54 seconds +sfmodel.html 15.81 seconds + +Charts that won’t be changed + +translin.html 0.08 seconds +translog.html 0.08 seconds +pricelog.html 0.08 seconds +pricelin.html 0.09 seconds +fractal.html 0.05 seconds +inflationfractal.html 0.08 seconds +golden.html 0.14 seconds +competitors.html 0.23 seconds +competitorssats.html 0.17 seconds +competitorssatslin.html 0.23 seconds +inflationreturn.html 0.27 seconds +powerlaw.html 0.09 seconds +thermocap.html 0.08 seconds +sharpe.html 0.10 seconds +dominance.html 3.10 seconds +rank.html 2.13 seconds +sfmodellin.html 0.14 seconds +sfmultiple.html 0.12 seconds +hashrate.html 0.12 seconds +hashprice.html 0.16 seconds +hashvsprice.html 0.08 seconds +dread_subscribers.html 3.49 seconds +coincards.html 1.81 seconds +merchants.html 1.72 seconds +merchants_increase.html 1.68 seconds +merchants_percentage.html 1.76 seconds