Commit baeeafba authored by Dr.李's avatar Dr.李

update models

parent 9c34de87
...@@ -5,7 +5,8 @@ Created on 2017-6-29 ...@@ -5,7 +5,8 @@ Created on 2017-6-29
@author: cheng.li @author: cheng.li
""" """
from sqlalchemy import BigInteger, Column, DateTime, Float, Index, Integer, JSON, String, Text, Boolean, text from sqlalchemy import BigInteger, Column, DateTime, Float, Index, Integer, String, Text, Boolean, text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base() Base = declarative_base()
...@@ -800,7 +801,8 @@ class Models(Base): ...@@ -800,7 +801,8 @@ class Models(Base):
model_type = Column(String(30), nullable=False) model_type = Column(String(30), nullable=False)
model_version = Column(BigInteger, nullable=False) model_version = Column(BigInteger, nullable=False)
update_time = Column(DateTime, nullable=False) update_time = Column(DateTime, nullable=False)
model_desc = Column(JSON, nullable=False) model_desc = Column(JSONB, nullable=False)
is_primary = Column(Boolean, default=False)
model_id = Column(Integer, primary_key=True, server_default=text("nextval('models_model_id_seq'::regclass)")) model_id = Column(Integer, primary_key=True, server_default=text("nextval('models_model_id_seq'::regclass)"))
...@@ -856,7 +858,7 @@ class Positions(Base): ...@@ -856,7 +858,7 @@ class Positions(Base):
trade_date = Column(DateTime, primary_key=True, nullable=False) trade_date = Column(DateTime, primary_key=True, nullable=False)
portfolio = Column(String(50), primary_key=True, nullable=False) portfolio = Column(String(50), primary_key=True, nullable=False)
type = Column(String(50), primary_key=True, nullable=False) type = Column(String(50), primary_key=True, nullable=False)
weight = Column(JSON) weight = Column(JSONB)
class QuantileAnalysis(Base): class QuantileAnalysis(Base):
......
...@@ -534,11 +534,19 @@ class SqlEngine(object): ...@@ -534,11 +534,19 @@ class SqlEngine(object):
return total_data return total_data
def fetch_model(self, def fetch_model(self,
ref_date, ref_date=None,
model_type=None, model_type=None,
model_version=None) -> pd.DataFrame: model_version=None,
is_primary=True,
model_id=None) -> pd.DataFrame:
conditions = [Models.trade_date == ref_date] conditions = []
if ref_date:
conditions.append(Models.trade_date == ref_date)
if model_id:
conditions.append(Models.model_id == model_id)
if model_type: if model_type:
conditions.append(Models.model_type == model_type) conditions.append(Models.model_type == model_type)
...@@ -546,6 +554,8 @@ class SqlEngine(object): ...@@ -546,6 +554,8 @@ class SqlEngine(object):
if model_version: if model_version:
conditions.append(Models.model_version == model_version) conditions.append(Models.model_version == model_version)
conditions.append(Models.is_primary == is_primary)
query = select([Models]).where(and_(*conditions)) query = select([Models]).where(and_(*conditions))
model_df = pd.read_sql(query, self.engine) model_df = pd.read_sql(query, self.engine)
......
...@@ -8,5 +8,5 @@ scipy >= 0.19.0 ...@@ -8,5 +8,5 @@ scipy >= 0.19.0
simpleutils >= 0.1.0 simpleutils >= 0.1.0
sqlalchemy >= 1.1.9 sqlalchemy >= 1.1.9
pandas >= 0.19.2 pandas >= 0.19.2
psycopg2 >= 2.7.3 psycopg2 >= 2.7.1
Finance-Python >= 0.5.5 Finance-Python >= 0.5.5
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