Skip to content
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

Guanchu #79

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ gunicorn = "*"
whitenoise = "==4.0"
dj-database-url = "*"
psycopg2-binary = "*"
yfinance = "*"
google = "*"

[dev-packages]

Expand Down
49 changes: 24 additions & 25 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
{
"name": "Django VueJs Template",
"description": "",
"repository": "https://github.com/gtalarico/django-vue-template",
"keywords": ["django", "vue", "vuejs", "template", "django rest framework"],
"env": {
"DJANGO_SETTINGS_MODULE": {
"description": "Set Django Settings to Production",
"value": "backend.settings.prod"
}
},
"engines": {
"yarn": "1.4.0",
"npm": "6.2.0"
},
"addons": [
"name": "Django VueJs Template",
"description": "none",
"repository": "https://github.com/gtalarico/django-vue-template",
"keywords": ["django", "vue", "vuejs", "template", "django rest framework"],
"env": {
"DJANGO_SETTINGS_MODULE": {
"description": "Set Django Settings to Production",
"value": "backend.settings.prod"
}
},
"engines": {
"yarn": "1.4.0",
"npm": "6.2.0"
},
"addons": [

],
"buildpacks": [
{
"url": "heroku/nodejs"
},
{
"url": "heroku/python"
}
]
}
],
"buildpacks": [{
"url": "heroku/nodejs"
},
{
"url": "heroku/python"
}
]
}
6 changes: 3 additions & 3 deletions backend/api/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.apps import AppConfig
from django.apps import AppConfig # pragma: no cover


class AppConfig(AppConfig):
name = 'api'
class AppConfig(AppConfig): # pragma: no cover
name = 'backend.api' # pragma: no cover
39 changes: 39 additions & 0 deletions backend/api/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"user1":{
"exist": 1,
"user_name": "GC",
"short_tax_rate": 0.4,
"long_tax_rate": 0.01,
"stocks": {
"AAPL":{
"purchase_price": 100.0,
"purchase_date": "2020-10-21",
"target_price": 200.0
},
"NIO":{
"purchase_price": 27.0,
"purchase_date": "2020-11-19",
"target_price": 40.0
}
}
},
"user2":{
"exist": 1,
"user_name": "HY",
"short_tax_rate": 0.3,
"long_tax_rate": 0.02,
"stocks": {
"TSLA":{
"purchase_price": 500.0,
"purchase_date": "2021-1-21",
"target_price": 1000.0
},
"BA":{
"purchase_price": 100.0,
"purchase_date": "2020-5-21",
"target_price": 200.0
}
}
}
}

20 changes: 20 additions & 0 deletions backend/api/json2bytes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json # pragma: no cover

def json_convert(input_dict): # pragma: no cover
str_json = json.dumps(input_dict, indent=2)
btye_json = bytes(str_json, encoding="utf-8")
return btye_json

# a = {
# "haha": 1
# }
#
# c = json_convert(a)
# d = json.loads(c.decode("utf-8"))
#
# print(d)
#
# '''
# get:
# {'haha':1}
# '''
4 changes: 2 additions & 2 deletions backend/api/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Generated by Django 2.1 on 2018-08-10 00:59

from django.db import migrations, models
from django.db import migrations, models # pragma: no cover


class Migration(migrations.Migration):
class Migration(migrations.Migration): # pragma: no cover

initial = True

Expand Down
38 changes: 38 additions & 0 deletions backend/api/migrations/0002_stock_userprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 3.2 on 2021-04-24 03:25

from django.db import migrations, models # pragma: no cover
import django.db.models.deletion # pragma: no cover


class Migration(migrations.Migration): # pragma: no cover

dependencies = [
('api', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Userprofile',
fields=[
('user_id', models.CharField(max_length=40, primary_key=True, serialize=False)),
('user_name', models.CharField(default='DATAHACK', max_length=30)),
('email_address', models.CharField(default='', max_length=200)),
('short_tax_rate', models.FloatField(default=0.0)),
('long_tax_rate', models.FloatField(default=0.0)),
('invest_horizon', models.FloatField(default=0.0)),
],
),
migrations.CreateModel(
name='Stock',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=30)),
('name', models.CharField(max_length=50)),
('purchase_price', models.FloatField(default=-1.0)),
('target_price', models.FloatField(default=0.0)),
('expect_return_rate', models.FloatField(default=0.0)),
('purchase_date', models.CharField(max_length=100)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stocks', to='api.userprofile')),
],
),
]
23 changes: 23 additions & 0 deletions backend/api/migrations/0003_auto_20210424_0959.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2 on 2021-04-24 09:59

from django.db import migrations, models # pragma: no cover



class Migration(migrations.Migration): # pragma: no cover

dependencies = [
('api', '0002_stock_userprofile'),
]

operations = [
migrations.AlterField(
model_name='stock',
name='purchase_date',
field=models.DateTimeField(verbose_name='data purchase this stock.'),
),
migrations.AlterUniqueTogether(
name='stock',
unique_together={('user', 'code')},
),
]
22 changes: 22 additions & 0 deletions backend/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@ class Message(models.Model):
subject = models.CharField(max_length=200)
body = models.TextField()

class Userprofile(models.Model):
user_id = models.CharField(max_length=40, primary_key=True)
user_name = models.CharField(max_length=30, default="DATAHACK")
email_address = models.CharField(max_length=200, default="")
short_tax_rate = models.FloatField(default=0.0)
long_tax_rate = models.FloatField(default=0.0)
invest_horizon = models.FloatField(default=0.0)

class Stock(models.Model):
user = models.ForeignKey(Userprofile, on_delete=models.CASCADE, related_name="stocks")
code = models.CharField(max_length=30)
name = models.CharField(max_length=50)
purchase_price = models.FloatField(default=-1.0)
target_price = models.FloatField(default=0.0)
expect_return_rate = models.FloatField(default=0.0)
#purchase_date = models.CharField(max_length=100)
purchase_date = models.DateTimeField("data purchase this stock.")

class Meta:
unique_together = ("user", "code") #这是重点


class MessageSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Message
fields = ('url', 'subject', 'body', 'pk')

113 changes: 113 additions & 0 deletions backend/api/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

class Stock:
def __init__(self, code, name, purchase_price, purchase_date, target_price, expect_return_rate):

self.code = code
self.name = name
self.purchase_price = purchase_price
self.purchase_date = purchase_date
self.target_price = target_price
self.expect_return_rate = expect_return_rate

# self.code = 0,
# # self.close_price,
# self.purchase_price,
# self.purchase_date.isoformat()[:10] = "01234567890",
# self.target_price = 0,
# self.expect_return_rate = 0.

def stock_info(self):
return {'code': self.code,
'name': self.name,
'purchase_price': self.purchase_price,
'purchase_date': self.purchase_date,
'target_price': self.target_price,
'expect_return_rate': self.expect_return_rate,
}

def delete(self):
pass


class StockDatabase:
def __init__(self):
self.stock_buf = []
self.code2stock = dict()

pass

def create(self, code, name, purchase_price, purchase_date, target_price, expect_return_rate):
new_stock = Stock(code, name, purchase_price, purchase_date, target_price, expect_return_rate)
self.stock_buf.append(new_stock)
self.code2stock[name] = new_stock

def all(self):
return self.stock_buf

def stock_profile(self):
return self.code2stock

def get(self, code):
return self.code2stock[code]


class Userinfo:
def __init__(self, user_id, email_address, user_name, short_tax_rate=0., long_tax_rate=0., invest_horizon=0.):

self.user_id = user_id
self.email_address = email_address
self.user_name = user_name
self.stocks = StockDatabase()
self.short_tax_rate = short_tax_rate
self.long_tax_rate = long_tax_rate
self.invest_horizon = invest_horizon

def user_request(self, **kwargs):

request = dict()
request['id'] = self.user_id
for key, value in kwargs.items():
request[key] = value

return request

def user_profile(self):
return {'user_id': self.user_id,
'user_name': self.user_name,
'short_tax_rate': self.short_tax_rate,
'long_tax_rate': self.long_tax_rate,
'investment_horizon': self.invest_horizon,
'stocks': self.stocks.stock_profile(),
}

def save(self):
pass


class UserDatabase:

def __init__(self):
self.user_buf = []
self.id2user = dict()
self.objects = self
pass

def add_new_user(self, new_user):
# new_user = Userinfo(user_id, email_address, user_name)
self.user_buf.append(new_user)
self.id2user[new_user.user_id] = new_user

def get(self, user_id):
return self.id2user[user_id]


USER1 = Userinfo(user_id=12345, email_address="[email protected]", user_name="zhangsan")
USER2 = Userinfo(user_id=23456, email_address="[email protected]", user_name="lisi")
STOCK1 = Stock(code=12345, name="AAA", purchase_price=0., purchase_date=0., target_price=0., expect_return_rate=0.)
Userprofile = UserDatabase()
Userprofile.add_new_user(USER1)
Userprofile.add_new_user(USER2)




2 changes: 1 addition & 1 deletion backend/api/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.test import TestCase
from django.test import TestCase # pragma: no cover

# Create your tests here.
Loading