示例#1
0
 def get(cls, user_name):
     with session_scope() as session:
         user = session.query(cls).filter(
             cls.user_name == user_name).first()
     if user is None:
         return None
     return user
示例#2
0
文件: events.py 项目: yydevelop/study
 def get_signal_events_by_count(cls, count, prduct_code=settings.product_code):
     with session_scope() as session:
         rows = session.query(cls).filter(cls.product_code == prduct_code).order_by(desc(cls.time)).limit(count).all()
         if rows is None:
             return []
         rows.reverse()
         return rows
示例#3
0
 def get(cls, time):
     with session_scope() as session:
         log = session.query(cls).filter(
             cls.time == time).first()
     if log is None:
         return None
     return log
示例#4
0
    def get_fraction_candle(cls, product_code=settings.product_code):
        recent_time = cls.get_all_candles(limit=1)[0].time
        with session_scope() as session:
            table = factory_candle_class(product_code=product_code,
                                         duration=constants.DURATION_5S)
            candles = session.query(table).filter(
                table.time >= recent_time).order_by(desc(table.time)).all()

        if candles is None:
            return None

        time = candles[0].time
        high = candles[0].high
        low = candles[0].low
        close = candles[0].close
        open = candles[-1].open
        volume = 0
        for i in range(len(candles)):
            high = max(candles[i].high, high)
            low = min(candles[i].low, low)
            volume += candles[i].volume

        candle = cls(time=time,
                     open=open,
                     close=close,
                     high=high,
                     low=low,
                     volume=volume)
        return candle
示例#5
0
 def get(cls, time):
     with session_scope() as session:
         candle = session.query(cls).filter(
             cls.time == time).first()
     if candle is None:
         return None
     return candle
示例#6
0
 def create(cls, user_name, password):
     user = cls(user_name=user_name, password=GetHashValue(password))
     try:
         with session_scope() as session:
             session.add(user)
         return user
     except IntegrityError:
         return False
示例#7
0
    def get_signal_events_after_time(cls, time):
        with session_scope() as session:
            rows = session.query(cls).filter(cls.time >= time).all()

            if rows is None:
                return []

            return rows
示例#8
0
 def create(cls, time, name, message):
     log = cls(time=time,name=name,message=message,show=0)
     try:
         with session_scope() as session:
             session.add(log)
         return log
     except IntegrityError:
         return False
示例#9
0
    def get_all_users(cls, limit=100):
        with session_scope() as session:
            users = session.query(cls).order_by(asc(
                cls.user_id)).limit(limit).all()

        if len(users) == 0:
            return None

        return users
示例#10
0
    def get_all_logs(cls, limit=10):
        with session_scope() as session:
            logs = session.query(cls).order_by(
                desc(cls.time)).limit(limit).all()

        if len(logs) == 0:
            return None

        return logs
示例#11
0
    def get_all_candles(cls, limit=100):
        with session_scope() as session:
            candles = session.query(cls).order_by(desc(
                cls.time)).limit(limit).all()

        if candles is None:
            return None

        candles.reverse()
        return candles
示例#12
0
    def get_all_Show_logs(cls):
        with session_scope() as session:
            logs = session.query(cls).filter(
                cls.show == 0).order_by(
                desc(cls.time)).all()

        if len(logs) == 0:
            return None

        return logs
示例#13
0
 def create(cls, time, open, close, high, low, volume):
     candle = cls(time=time,
                  open=open,
                  close=close,
                  high=high,
                  low=low,
                  volume=volume)
     try:
         with session_scope() as session:
             session.add(candle)
         return candle
     except IntegrityError:
         return False
示例#14
0
 def save(self):
     with session_scope() as session:
         session.add(self)
示例#15
0
 def DeleteAllRecord(cls):
     with session_scope() as session:
         logs = session.query(cls).all()
         for log in logs:
             session.delete(log)
示例#16
0
 def save(self):
     """
     DBのローソク足を更新します。
     """
     with session_scope() as session:
         session.add(self)
示例#17
0
 def get_user_one_by_name(cls, user_name):
     with session_scope() as session:
         user = session.query(cls).filter(
             cls.user_name == user_name).one_or_none()
     return user
示例#18
0
 def DeleteAllRecord(cls):
     with session_scope() as session:
         users = session.query(cls).all()
         for user in users:
             session.delete(user)