Skip to content

Commit 8086081

Browse files
committed
Make created_on_str always MST
1 parent bc5494b commit 8086081

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

history/management/commands/compare_perf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
from django.core.management.base import BaseCommand
32
from django.conf import settings
4-
from history.tools import get_fee_amount
3+
from history.tools import get_fee_amount, utc_to_mst_str
54
from history.models import Price, TradeRecommendation, PerformanceComp
65
import datetime
76
from django.db import transaction
@@ -55,5 +54,5 @@ def handle(self, *args, **options):
5554
weighted_avg_nn_rec=weighted_avg_nn_rec,
5655
directionally_same=directionally_same,
5756
directionally_same_int=1 if directionally_same else 0,
58-
created_on_str=tr_timerange_end.strftime('%Y-%m-%d %H:%M'))
57+
created_on_str=utc_to_mst_str(tr_timerange_end))
5958
pc.save()

history/management/commands/pull_balance.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
21
from django.core.management.base import BaseCommand
32
from django.conf import settings
4-
from history.tools import get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd, get_deposit_balance
3+
from history.tools import (get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd, get_deposit_balance,
4+
utc_to_mst_str)
55
from history.models import Balance, Trade
66
import datetime
77
from django.db import transaction
@@ -41,15 +41,13 @@ def handle(self, *args, **options):
4141
b = Balance(symbol=ticker,coin_balance=val,btc_balance=btc_val,exchange_to_btc_rate=exchange_rate_coin_to_btc,usd_balance=usd_val,exchange_to_usd_rate=exchange_rate_coin_to_btc,deposited_amount_btc=deposited_amount_btc if ticker =='BTC' else 0.00, deposited_amount_usd=deposited_amount_usd if ticker =='BTC' else 0.00)
4242
b.save()
4343

44-
for b in Balance.objects.filter(date_str='0'):
45-
# django timezone stuff , FML
46-
b.date_str = datetime.datetime.strftime(b.created_on - datetime.timedelta(hours=int(7)),'%Y-%m-%d %H:%M')
44+
for b in Balance.objects.filter(date_str=''):
45+
b.date_str = utc_to_mst_str(b.created_on)
4746
b.save()
4847

4948
#normalize trade recommendations too. merp
5049
for tr in Trade.objects.filter(created_on_str=''):
51-
# django timezone stuff , FML
52-
tr.created_on_str = datetime.datetime.strftime(tr.created_on - datetime.timedelta(hours=int(7)),'%Y-%m-%d %H:%M')
50+
tr.created_on_str = utc_to_mst_str(tr.created_on)
5351
tr.save()
5452

5553

history/management/commands/pull_deposits.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
from django.core.management.base import BaseCommand
32
from django.conf import settings
43
import datetime
54
from django.db import transaction
65
import time
7-
from history.tools import get_utc_unixtime
6+
from history.tools import get_utc_unixtime, utc_to_mst_str
87
from history.models import Deposit
98

109
class Command(BaseCommand):
@@ -40,5 +39,5 @@ def handle(self, *args, **options):
4039
d.status = status
4140
d.created_on = created_on
4241
d.modified_on = created_on
43-
d.created_on_str = datetime.datetime.strftime(created_on - datetime.timedelta(hours=int(7)),'%Y-%m-%d %H:%M')
42+
d.created_on_str = utc_to_mst_str(created_on)
4443
d.save()

history/management/commands/pull_prices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
from history.tools import utc_to_mst_str
22
from django.core.management.base import BaseCommand
33
from django.conf import settings
44

@@ -25,6 +25,6 @@ def handle(self, *args, **options):
2525
p.lowestask = price[ticker]['lowestAsk']
2626
p.highestbid = price[ticker]['highestBid']
2727
p.symbol = ticker
28-
p.created_on_str = str(p.created_on)
28+
p.created_on_str = utc_to_mst_str(p.created_on)
2929
p.save()
3030

history/management/commands/trade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from history.predict import predict_v2
33
from history.models import (Price, PredictionTest, Trade, TradeRecommendation,
44
Balance, ClassifierTest)
5-
from history.tools import get_utc_unixtime, print_and_log
5+
from history.tools import get_utc_unixtime, print_and_log, utc_to_mst_str
66
import datetime
77
import time
88
from history.poloniex import poloniex
@@ -187,7 +187,7 @@ def run_predictor(self, nn_index):
187187
confidence=confidence,
188188
recommendation=recommend,
189189
net_amount=-1 if recommend == 'SELL' else (1 if recommend == 'BUY' else 0),
190-
created_on_str=timezone.now().strftime('%Y-%m-%d %H:%M'))
190+
created_on_str=utc_to_mst_str(timezone.now()))
191191
tr.save()
192192
self.trs[nn_index] = tr
193193
return recommend

history/tools.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import time
2+
import pytz
23
import datetime
3-
from django.conf import settings
44
import numpy as np
5+
from django.conf import settings
6+
from django.utils import timezone
57
from django.core.exceptions import ImproperlyConfigured
68

79

@@ -12,14 +14,17 @@ def print_and_log(log_string):
1214

1315

1416
def get_utc_unixtime():
15-
import time
16-
import datetime
17-
1817
d = datetime.datetime.now()
1918
unixtime = time.mktime(d.timetuple())
2019
return int(unixtime)
2120

2221

22+
def utc_to_mst_str(dt):
23+
mst = pytz.timezone('MST')
24+
local = timezone.localtime(dt, mst)
25+
return datetime.datetime.strftime(local, '%Y-%m-%d %H:%M')
26+
27+
2328
def create_sample_row(data, i, size):
2429
sample = ()
2530
for k in range(0, size):

0 commit comments

Comments
 (0)