Exemplo n.º 1
0
    def tune_history(self, tunes, desc=False, dates=None):
        order = PlayData.date
        if desc: order = sqlalchemy.desc(order)
        query = object_session(self).\
            query(PlayData.score.label('value'), PlayData.date,
                func.unix_timestamp(PlayData.date).label('unixtime')).\
            filter(PlayData.friend_id == self.friend_id).\
            filter(util.tune_conds(tunes, PlayData))

        if dates is not None:
            query = util.cutoff_dates(query, PlayData.date, dates)

        return query
Exemplo n.º 2
0
    def stat_history_by_query(self, stat, desc=False, dates=None):
        order = UserData.date
        if desc: order = sqlalchemy.desc(order)
        
        value_column = getattr(UserData, stat).label('value')
        query = object_session(self).\
            query(value_column, UserData.date,
                func.unix_timestamp(UserData.last_date).label('unixtime')).\
            filter(UserData.friend_id == self.friend_id)

        if dates is not None:
            query = util.cutoff_dates(query, UserData.last_date, dates)
        
        return query
Exemplo n.º 3
0
    def tune_history_ext(self, tune, desc=False, dates=None):
        order = PlayData.Detail.date
        if desc: order = sqlalchemy.desc(order)
        query = object_session(self).\
            query(PlayData.Detail,
                func.unix_timestamp(PlayData.Detail.date).
                    label('unixtime')).\
            filter(PlayData.Detail.friend_id == self.friend_id).\
            filter(PlayData.Detail.music_id == tune[0]).\
            filter(PlayData.Detail.dif_id == tune[1])

        if dates is not None:
            query = util.cutoff_dates(query, PlayData.date, dates)

        return query
Exemplo n.º 4
0
 def stat_history_by_property(self, stat, desc=False, dates=None):
     order = UserData.date
     if desc: order = sqlalchemy.desc(order)
     
     query = object_session(self).\
         query(UserData,
             func.unix_timestamp(UserData.last_date).label('unixtime')).\
         filter(UserData.friend_id == self.friend_id)
     
     if dates is not None:
         query = util.cutoff_dates(query, UserData.last_date, dates)
    
     HistItem = collections.namedtuple('HistItem',
                                       ['value', 'date', 'unixtime'])
     for row in query:
         yield HistItem(
             value=getattr(row.UserData, stat),
             date=row.UserData.last_date,
             unixtime=row.unixtime)