Spaces:
Runtime error
Runtime error
huggingface112
commited on
Commit
•
2899e7b
1
Parent(s):
588011f
use correct stocks_details table
Browse files- .vscode/launch.json +30 -0
- instance/local.db +2 -2
- pipeline.py +7 -7
.vscode/launch.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
// Use IntelliSense to learn about possible attributes.
|
3 |
+
// Hover to view descriptions of existing attributes.
|
4 |
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
5 |
+
"version": "0.2.0",
|
6 |
+
"configurations": [
|
7 |
+
{
|
8 |
+
"name": "Python: Current File",
|
9 |
+
"type": "python",
|
10 |
+
"request": "launch",
|
11 |
+
"program": "${file}",
|
12 |
+
"console": "integratedTerminal",
|
13 |
+
"justMyCode": true
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"name": "panel serve",
|
17 |
+
"type": "python",
|
18 |
+
"request": "launch",
|
19 |
+
"program": "-m",
|
20 |
+
"args": [
|
21 |
+
"panel",
|
22 |
+
"serve",
|
23 |
+
"${relativeFile}",
|
24 |
+
"--show"
|
25 |
+
],
|
26 |
+
"console": "integratedTerminal",
|
27 |
+
"justMyCode": true
|
28 |
+
},
|
29 |
+
]
|
30 |
+
}
|
instance/local.db
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8fd14d31ea743ba8f323922dafbc3e49c2b577a7c84a4c95959e8c8ef3c8effa
|
3 |
+
size 2240512
|
pipeline.py
CHANGED
@@ -14,7 +14,7 @@ import utils
|
|
14 |
import api
|
15 |
import numpy as np
|
16 |
import pytz
|
17 |
-
import table_schema as
|
18 |
# fetch new stock price
|
19 |
stock_price_stream = Stream()
|
20 |
|
@@ -113,11 +113,11 @@ def update_stocks_details_to_db():
|
|
113 |
'''
|
114 |
df = api.get_all_stocks_detail()
|
115 |
# validation
|
116 |
-
if not _validate_schema(df,
|
117 |
raise ValueError(
|
118 |
'df has different schema than STOCKS_DETAILS_TABLE_SCHEMA')
|
119 |
with create_engine(db_url).connect() as conn:
|
120 |
-
df.to_sql(
|
121 |
if_exists='replace', index=False)
|
122 |
|
123 |
|
@@ -174,7 +174,7 @@ def processing():
|
|
174 |
|
175 |
def add_details_to_stock_df(stock_df):
|
176 |
with create_engine(db_url).connect() as conn:
|
177 |
-
detail_df = pd.read_sql(
|
178 |
merged_df = pd.merge(stock_df, detail_df[
|
179 |
['sector', 'name',
|
180 |
'aggregate_sector',
|
@@ -222,15 +222,15 @@ def save_stock_price_to_db(df: pd.DataFrame):
|
|
222 |
def update_portfolio_profile_to_db(portfolio_df):
|
223 |
'''overwrite the portfolio profile table in db'''
|
224 |
|
225 |
-
if (_validate_schema(portfolio_df,
|
226 |
raise ValueError(
|
227 |
'portfoliijuo_df has different schema than PORTFOLIO_DB_SCHEMA')
|
228 |
|
229 |
with create_engine(db_url).connect() as conn:
|
230 |
print("updating profile to db")
|
231 |
try:
|
232 |
-
portfolio_df[
|
233 |
-
|
234 |
return True
|
235 |
except:
|
236 |
return False
|
|
|
14 |
import api
|
15 |
import numpy as np
|
16 |
import pytz
|
17 |
+
import table_schema as ts
|
18 |
# fetch new stock price
|
19 |
stock_price_stream = Stream()
|
20 |
|
|
|
113 |
'''
|
114 |
df = api.get_all_stocks_detail()
|
115 |
# validation
|
116 |
+
if not _validate_schema(df, ts.STOCKS_DETAILS_TABLE_SCHEMA):
|
117 |
raise ValueError(
|
118 |
'df has different schema than STOCKS_DETAILS_TABLE_SCHEMA')
|
119 |
with create_engine(db_url).connect() as conn:
|
120 |
+
df.to_sql(ts.STOCKS_DETAILS_TABLE, con=conn,
|
121 |
if_exists='replace', index=False)
|
122 |
|
123 |
|
|
|
174 |
|
175 |
def add_details_to_stock_df(stock_df):
|
176 |
with create_engine(db_url).connect() as conn:
|
177 |
+
detail_df = pd.read_sql(ts.STOCKS_DETAILS_TABLE, con=conn)
|
178 |
merged_df = pd.merge(stock_df, detail_df[
|
179 |
['sector', 'name',
|
180 |
'aggregate_sector',
|
|
|
222 |
def update_portfolio_profile_to_db(portfolio_df):
|
223 |
'''overwrite the portfolio profile table in db'''
|
224 |
|
225 |
+
if (_validate_schema(portfolio_df, ts.PORTFOLIO_TABLE_SCHEMA)):
|
226 |
raise ValueError(
|
227 |
'portfoliijuo_df has different schema than PORTFOLIO_DB_SCHEMA')
|
228 |
|
229 |
with create_engine(db_url).connect() as conn:
|
230 |
print("updating profile to db")
|
231 |
try:
|
232 |
+
portfolio_df[ts.PORTFOLIO_TABLE_SCHEMA.keys()].to_sql(
|
233 |
+
ts.PORTFOLIO_TABLE, con=conn, if_exists='append', index=False)
|
234 |
return True
|
235 |
except:
|
236 |
return False
|