Commit 78bf307a authored by wang zhengwei's avatar wang zhengwei

基金行家手机端

parent c485365b
FROM centos:centos7 FROM registry.cn-shanghai.aliyuncs.com/tamp/pcal:V2.1
# RUN echo http://mirrors.aliyun.com/alpine/v3.12/main > /etc/apk/repositories # RUN echo http://mirrors.aliyun.com/alpine/v3.12/main > /etc/apk/repositories
# RUN echo http://mirrors.aliyun.com/alpine/v3.12/community >> /etc/apk/repositories # RUN echo http://mirrors.aliyun.com/alpine/v3.12/community >> /etc/apk/repositories
...@@ -25,6 +25,6 @@ COPY app/ app ...@@ -25,6 +25,6 @@ COPY app/ app
COPY start.sh . COPY start.sh .
# RUN pip --no-cache-dir install -i ${PIPURL} --upgrade pip # RUN pip --no-cache-dir install -i ${PIPURL} --upgrade pip
RUN pip3 --no-cache-dir install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple RUN pip3 --no-cache-dir install -r requirements.txt -i https://pypi.douban.com/simple
CMD sh start.sh CMD sh start.sh
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
import logging # import logging
import redis import redis
import os import os
import sys import sys
...@@ -102,12 +102,12 @@ redis = redis.StrictRedis( ...@@ -102,12 +102,12 @@ redis = redis.StrictRedis(
db=config[env]['redis']['db'] db=config[env]['redis']['db']
) )
logging.basicConfig(level=logging.INFO, # logging.basicConfig(level=logging.INFO,
filename=work_dir + config[env]['log']['filename'], # filename=work_dir + config[env]['log']['filename'],
filemode=config[env]['log']['filemode'], # filemode=config[env]['log']['filemode'],
format=config[env]['log']['format'], # format=config[env]['log']['format'],
datefmt=config[env]['log']['datefmt'] # datefmt=config[env]['log']['datefmt']
) # )
class TAMP_SQL(object): class TAMP_SQL(object):
"""[sqlalchemy 封装] """[sqlalchemy 封装]
......
...@@ -40,7 +40,7 @@ class ReportHandlers(Resource): ...@@ -40,7 +40,7 @@ class ReportHandlers(Resource):
return {"code":40005,"data":None,"lang":"zh_CN","msg":"请登陆"} return {"code":40005,"data":None,"lang":"zh_CN","msg":"请登陆"}
ifa_id = ifa_id.replace('\'', '') ifa_id = ifa_id.replace('\'', '')
customer_id = args['customer_id'] customer_id = args['customer_id']
pdf_name = str(uuid.uuid4()) + '.pdf' pdf_name = str(ifa_id) + str(customer_id) + '.pdf'
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app: with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_app_session = tamp_diagnose_app.session tamp_diagnose_app_session = tamp_diagnose_app.session
...@@ -61,10 +61,10 @@ class ReportHandlers(Resource): ...@@ -61,10 +61,10 @@ class ReportHandlers(Resource):
auth = oss2.Auth(config[env]['oss']['account'], config[env]['oss']['password']) auth = oss2.Auth(config[env]['oss']['account'], config[env]['oss']['password'])
# Endpoint以杭州为例,其它Region请按实际情况填写。 # Endpoint以杭州为例,其它Region请按实际情况填写。
bucket = oss2.Bucket(auth, 'http://oss-cn-shanghai.aliyuncs.com', 'tamperdev') bucket = oss2.Bucket(auth, 'http://oss-cn-shanghai.aliyuncs.com', config[env]['oss']['env'])
# 生成下载文件的签名URL,有效时间为60s。 # 生成下载文件的签名URL,有效时间为60s。
path = bucket.sign_url('GET', 'productionenv/Start/' + pdf_name, 60) path = bucket.sign_url('GET', config[env]['oss']['path'] + pdf_name, 60)
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app: with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_app_session = tamp_diagnose_app.session tamp_diagnose_app_session = tamp_diagnose_app.session
sql = "update hold_report set update_time='{}', update_status='{}', file='{}' where ifa_id='{}' and customer_id='{}'".format( sql = "update hold_report set update_time='{}', update_status='{}', file='{}' where ifa_id='{}' and customer_id='{}'".format(
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
# pool_pre_ping=True) # pool_pre_ping=True)
# con = db.connect() # con = db.connect()
import logging # import logging
logging.basicConfig(level=logging.INFO) # logging.basicConfig(level=logging.INFO)
from app.api.engine import tamp_fund_engine, TAMP_SQL, tamp_product_engine from app.api.engine import tamp_fund_engine, TAMP_SQL, tamp_product_engine
from app.utils.week_evaluation import * from app.utils.week_evaluation import *
...@@ -51,7 +51,7 @@ def get_nav(fund, start_date, rollback=False, invest_type='public'): ...@@ -51,7 +51,7 @@ def get_nav(fund, start_date, rollback=False, invest_type='public'):
df.rename({'price_date': 'end_date', 'cumulative_nav': 'adj_nav'}, axis=1, inplace=True) df.rename({'price_date': 'end_date', 'cumulative_nav': 'adj_nav'}, axis=1, inplace=True)
if df['adj_nav'].count() == 0: if df['adj_nav'].count() == 0:
logging.log(logging.ERROR, "CAN NOT FIND {}".format(fund)) # logging.log(logging.ERROR, "CAN NOT FIND {}".format(fund))
return None return None
df['end_date'] = pd.to_datetime(df['end_date']) df['end_date'] = pd.to_datetime(df['end_date'])
...@@ -79,7 +79,7 @@ def get_frequency(df): ...@@ -79,7 +79,7 @@ def get_frequency(df):
index_series = df.index.to_series() index_series = df.index.to_series()
# freq_series = index_series - index_series.shift(1) # freq_series = index_series - index_series.shift(1)
freq_series = index_series.diff(1) freq_series = index_series.diff(1)
logging.log(logging.DEBUG, freq_series.describe()) # logging.log(logging.DEBUG, freq_series.describe())
try: try:
f = freq_series.mode()[0].days f = freq_series.mode()[0].days
except: except:
...@@ -275,12 +275,12 @@ def fund_rank(start_date, end_date, invest_type='private'): ...@@ -275,12 +275,12 @@ def fund_rank(start_date, end_date, invest_type='private'):
try: try:
if df.index[-1] - df.index[0] < 0.6 * (end_date - start_date): if df.index[-1] - df.index[0] < 0.6 * (end_date - start_date):
skipped_funds.append(fund) skipped_funds.append(fund)
logging.log(logging.INFO, 'Skipped {}'.format(fund)) # logging.log(logging.INFO, 'Skipped {}'.format(fund))
continue continue
n = get_frequency(df) n = get_frequency(df)
except Exception as e: except Exception as e:
# logging.log(logging.ERROR, repr(e)) # logging.log(logging.ERROR, repr(e))
logging.log(logging.INFO, 'Skipped {}'.format(fund)) # logging.log(logging.INFO, 'Skipped {}'.format(fund))
continue continue
df = resample(df, trading_cal, n) df = resample(df, trading_cal, n)
...@@ -290,7 +290,7 @@ def fund_rank(start_date, end_date, invest_type='private'): ...@@ -290,7 +290,7 @@ def fund_rank(start_date, end_date, invest_type='private'):
except ValueError: except ValueError:
continue continue
logging.log(logging.INFO, "Dealing with {}".format(fund)) # logging.log(logging.INFO, "Dealing with {}".format(fund))
net_worth = df['adj_nav'].astype(float) net_worth = df['adj_nav'].astype(float)
end_df, begin_df = net_worth.values[-1], net_worth.values[0] end_df, begin_df = net_worth.values[-1], net_worth.values[0]
......
...@@ -12,7 +12,7 @@ import uuid ...@@ -12,7 +12,7 @@ import uuid
import oss2 import oss2
from app.api.engine import logging, pdf_folder, tamp_diagnose_app_engine, config, env from app.api.engine import pdf_folder, tamp_diagnose_app_engine, config, env
import os import os
from app.api.engine import tamp_user_engine, tamp_order_engine, TAMP_SQL from app.api.engine import tamp_user_engine, tamp_order_engine, TAMP_SQL
...@@ -82,7 +82,7 @@ def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name): ...@@ -82,7 +82,7 @@ def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name):
except OSError: except OSError:
print('IFA: {}, 客户: {}的基金月报已经生成,耗时{}秒'.format(ifauser_name, customer_name, time.time()-start)) print('IFA: {}, 客户: {}的基金月报已经生成,耗时{}秒'.format(ifauser_name, customer_name, time.time()-start))
except Exception as e: except Exception as e:
logging.error("IFAID{}: IFAName{}, 客户ID{}, 客户Name: {}的基金月报生成异常,错误追踪:{}".format(ifauser_id, ifauser_name, customer_id, customer_name, traceback.format_exc())) # logging.error("IFAID{}: IFAName{}, 客户ID{}, 客户Name: {}的基金月报生成异常,错误追踪:{}".format(ifauser_id, ifauser_name, customer_id, customer_name, traceback.format_exc()))
print("IFA: {}, 客户: {}的基金月报生成异常,错误追踪:{}".format(ifauser_name, customer_name, traceback.format_exc())) print("IFA: {}, 客户: {}的基金月报生成异常,错误追踪:{}".format(ifauser_name, customer_name, traceback.format_exc()))
finally: finally:
auth = oss2.Auth(config[env]['oss']['account'], config[env]['oss']['password']) auth = oss2.Auth(config[env]['oss']['account'], config[env]['oss']['password'])
......
#!/bin/bash #!/bin/bash
gunicorn -w 2 -k gevent -D -p tamp_order.pid -b 127.0.0.1:8000 app.api.app:api prod gunicorn -w 2 -p tamp_order.pid -b 127.0.0.1:8000 --log-level=debug app.api.app:api prod
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment