-
Notifications
You must be signed in to change notification settings - Fork 424
Use UTC datetimes everywhere #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # -*- coding: utf-8 -*- | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.db import models, migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('history', '0003_auto_20160330_1920'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='balance', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True, db_index=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='balance', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='classifiertest', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='classifiertest', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='deposit', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True, db_index=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='deposit', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='performancecomp', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True, db_index=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='performancecomp', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='predictiontest', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='predictiontest', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='price', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True, db_index=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='price', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='trade', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True, db_index=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='trade', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='traderecommendation', | ||
| name='created_on', | ||
| field=models.DateTimeField(auto_now_add=True, db_index=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='traderecommendation', | ||
| name='modified_on', | ||
| field=models.DateTimeField(auto_now=True), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import pytz | ||
| from django.contrib.admin.views.decorators import staff_member_required | ||
| from history.models import ( | ||
| PredictionTest, Price, Trade, Balance, TradeRecommendation, get_time, PerformanceComp, | ||
| PredictionTest, Price, Trade, Balance, TradeRecommendation, PerformanceComp, | ||
| ClassifierTest) | ||
| from django.shortcuts import render_to_response | ||
| from django.utils import timezone | ||
|
|
@@ -383,8 +384,9 @@ def nn_chart_view(request): | |
| trainer_last_seen = None | ||
| try: | ||
| last_pt = PredictionTest.objects.filter(type='mock').order_by('-created_on').first() | ||
| is_trainer_running = last_pt.created_on > (get_time() - datetime.timedelta(minutes=int(15))) | ||
| trainer_last_seen = (last_pt.created_on - datetime.timedelta(hours=int(7))).strftime('%a %H:%M') | ||
| fifteen_ago = timezone.now() - datetime.timedelta(minutes=15) | ||
| is_trainer_running = last_pt.created_on > fifteen_ago | ||
| trainer_last_seen = timezone.localtime(last_pt.created_on).strftime('%a %H:%M') | ||
| except Exception: | ||
| is_trainer_running = False | ||
|
|
||
|
|
@@ -402,11 +404,11 @@ def nn_chart_view(request): | |
| cht = get_line_chart(pts, symbol, parameter) | ||
| charts.append(cht) | ||
| options = [] | ||
| chartnames.append("container"+str(i)) | ||
| chartnames.append("container" + str(i)) | ||
| metas.append({ | ||
| 'name': parameter, | ||
| 'container_class': 'show', | ||
| 'class': "container"+str(i), | ||
| 'class': "container" + str(i), | ||
| 'options': options, | ||
| }) | ||
|
|
||
|
|
@@ -473,8 +475,9 @@ def c_chart_view(request): | |
| trainer_last_seen = None | ||
| try: | ||
| last_pt = ClassifierTest.objects.filter(type='mock').order_by('-created_on').first() | ||
| is_trainer_running = last_pt.created_on > (get_time() - datetime.timedelta(minutes=int(15))) | ||
| trainer_last_seen = (last_pt.created_on - datetime.timedelta(hours=int(7))).strftime('%a %H:%M') | ||
| fifteen_ago = timezone.now() - datetime.timedelta(minutes=15) | ||
| is_trainer_running = last_pt.created_on > fifteen_ago | ||
| trainer_last_seen = timezone.localtime(last_pt.created_on).strftime('%a %H:%M') | ||
| except Exception: | ||
| is_trainer_running = False | ||
|
|
||
|
|
@@ -564,7 +567,8 @@ def profit_view(request): | |
| # get data | ||
| data = {} | ||
| for t in Trade.objects.filter(symbol=symbol, status='fill').order_by('-created_on').all(): | ||
| date = datetime.datetime.strftime(t.created_on-datetime.timedelta(hours=7), '%Y-%m-%d') | ||
| mst_dt = timezone.localtime(t.created_on, pytz.timezone('MST')) | ||
| date = datetime.datetime.strftime(mst_dt, '%Y-%m-%d') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had forgotten this one. It should be MST since it's in a view. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MST was just what i used because thats where i live. might be worth making this a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then DBs would be inconsistent between each other. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's best to leave it MST and look for a django-chartit alternative. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
could be solved with a migration
i dont feel strongly about this enoguh to hold up the PR. just a suggestion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well in that case we would have to store the data in UTC, but at that point it would be useless. We could remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, django-chartit requires the data to be available within the queryset, so a python property will likely not work. data is posted @ #2 (comment) not asking that you make the change, just telling you about this because now that you've made a PR you should at least have access to the data so you can trade :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this line be: dt = timezone.localtime(t.created_on, pytz.timezone(settings.DISPLAY_TZ))? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I think it should be |
||
| if date not in data.keys(): | ||
| data[date] = {'buyvol': [], 'sellvol': [], 'buy': [], 'sell': [], 'bal': 0.00} | ||
| data[date][t.type].append(t.price) | ||
|
|
@@ -663,8 +667,9 @@ def optimize_view(request): | |
|
|
||
| last_trade = TradeRecommendation.objects.order_by('-created_on').first() | ||
| if last_trade: | ||
| trader_last_seen = (last_trade.created_on - datetime.timedelta(hours=int(7))).strftime('%a %H:%M') | ||
| is_trader_running = last_trade.created_on > (get_time() - datetime.timedelta(minutes=int(15))) | ||
| fifteen_ago = timezone.now() - datetime.timedelta(minutes=15) | ||
| trader_last_seen = timezone.localtime(last_trade.created_on).strftime('%a %H:%M') | ||
| is_trader_running = last_trade.created_on > fifteen_ago | ||
| else: | ||
| trader_last_seen = None | ||
| is_trader_running = False | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has no effect since,
auto_now_addis used for modified_on?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! We are in the situation described here:
#75 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @owocki intention was to capture the time of creation on the poloniex server with this.
A proposal could be we add
deposit_created_ontoDepositmodel and usecreated_onfor the creation of the model in our database.In short:
deposit_created_on- time of creation at poloniex servercreated_on- time of saving in our databaseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. The only downside of this approach is that we will have to remember to use
deposit_created_oninstead ofcreated_on.