Esempio n. 1
0
 def delete_rel(self,noteid,tag):
     t = tag.first()
     session.query(Relate).filter(and_(Relate.marknoteid==noteid,
                                       Relate.tagid==t.id)).delete()
     session.commit()
     self.query_update(Tag,t.id,{'count':t.count-1})
     if t.count <= 0:
         tag.delete()
         session.commit()
Esempio n. 2
0
 def delete_rel(self, noteid, tag):
     t = tag.first()
     session.query(Relate).filter(
         and_(Relate.marknoteid == noteid, Relate.tagid == t.id)).delete()
     session.commit()
     self.query_update(Tag, t.id, {'count': t.count - 1})
     if t.count <= 0:
         tag.delete()
         session.commit()
Esempio n. 3
0
def get_nb_of_games_by_team_id(team_id, game_id, nb_of_days):
    # Dates
    game = session.query(Game).get(game_id)
    to_date = game.date
    from_date = game.date - timedelta(days=nb_of_days)

    rs = session.query(Game, TeamStat) \
        .join(TeamStat) \
        .filter(TeamStat.team_id == team_id) \
        .filter(Game.type == 'Season') \
        .filter(Game.date >= from_date) \
        .filter(Game.date < to_date) \
        .count()

    return rs
Esempio n. 4
0
 def query(self,table,order,num=0,offset=0):
     data = session.query(table).order_by(order)
     if offset!=0:
         data = data.offset(offset)
     if num!=0:
         return data.limit(num)
     return data
Esempio n. 5
0
def get_team_ids_by_game_id(game_id):
    team_ids = {}
    rs = session.query(TeamStat).filter_by(game_id=game_id)
    for obj in rs:
        team_ids[obj.ha] = obj.team_id

    return team_ids
Esempio n. 6
0
 def query(self, table, order, num=0, offset=0):
     data = session.query(table).order_by(order)
     if offset != 0:
         data = data.offset(offset)
     if num != 0:
         return data.limit(num)
     return data
Esempio n. 7
0
    def search(self,term,withtags="",findall=False):
        if withtags != "":
            notes = session.query(MarkNote).filter(
                        MarkNote.title.like('%'+term+'%'))
            note = []
            notag = False
            for i in notes:
                fit = False
                rel = self.query(Relate,Relate.id).filter(
                            Relate.marknoteid==i.id)

                for tag in withtags.split(','):
                    try:
                        tagid = self.query_bytitle(Tag,tag).first().id
                    except:
                        notag = True
                        break

                    for j in rel:
                        if j.tagid == tagid:
                            fit = True
                            break
                    else:
                        fit = False

                    if not fit:
                        break

                if fit:
                    note += [i]

                if notag:
                    del note[:]
                    break

        elif findall:
            note = session.query(MarkNote).filter(
                        or_(MarkNote.tags.like('%'+term+'%'),
                        MarkNote.title.like('%'+term+'%')))
        else:
            note = session.query(MarkNote).filter(
                        MarkNote.title.like('%'+term+'%'))

        return note
Esempio n. 8
0
    def search(self, term, withtags="", findall=False):
        if withtags != "":
            notes = session.query(MarkNote).filter(
                MarkNote.title.like('%' + term + '%'))
            note = []
            notag = False
            for i in notes:
                fit = False
                rel = self.query(Relate,
                                 Relate.id).filter(Relate.marknoteid == i.id)

                for tag in withtags.split(','):
                    try:
                        tagid = self.query_bytitle(Tag, tag).first().id
                    except:
                        notag = True
                        break

                    for j in rel:
                        if j.tagid == tagid:
                            fit = True
                            break
                    else:
                        fit = False

                    if not fit:
                        break

                if fit:
                    note += [i]

                if notag:
                    del note[:]
                    break

        elif findall:
            note = session.query(MarkNote).filter(
                or_(MarkNote.tags.like('%' + term + '%'),
                    MarkNote.title.like('%' + term + '%')))
        else:
            note = session.query(MarkNote).filter(
                MarkNote.title.like('%' + term + '%'))

        return note
Esempio n. 9
0
def get_eFGP_by_team_id(team_id, game_id):
    rs = session.query(
            func.sum(TeamStat.FG).label("FG"),
            func.sum(TeamStat.b3P).label("b3P"),
            func.sum(TeamStat.FGA).label("FGA"),
        ) \
        .join(Game)\
        .filter(TeamStat.team_id == team_id) \
        .filter(Game.type == 'Season') \
        .filter(Game.id < game_id) \
        .one()

    return rs
Esempio n. 10
0
def get_wl_ratio_by_team_id(team_id, game_id):
    wl_ratio = {}
    for wl in ['W', 'L']:
        rs = session.query(TeamStat, Game)\
            .join(Game)\
            .filter(TeamStat.team_id == team_id)\
            .filter(TeamStat.result == wl)\
            .filter(Game.type == 'Season') \
            .filter(Game.id < game_id) \
            .count()

        wl_ratio[wl] = rs

    return wl_ratio
Esempio n. 11
0
def get_days(startday):
    allDays = np.array(session.query(Day).order_by(Day.dateofconsum).all())[startday:]
    weights = np.array([x.weight for x in allDays])    
    kcal = np.array([sum([ m.kcal for m in x.meals]) for x in allDays])
    
   

    weights = interpolate(weights)
    weightdeltaLb = (weights[-2]-weights[0])/LbinKg
    #MaintenanceKcal = (sum(kcal)-weightdeltaLb*kcalPerLb)/np.size(kcal)
    MaintenanceKcal = 2500
    print("Maintenance Kcal :",MaintenanceKcal)
    x = np.arange(1,np.size(weights)+1)
    #y1 = ((weights/max(weights)))
    #plt.plot(x,y1)
    #y2= kcal/max(kcal)
    y2= kcal
    plt.plot(x,y2)
    #y3=np.ones(np.size(weights))*(MaintenanceKcal/max(kcal))
    y3=np.ones(np.size(weights))*(MaintenanceKcal)
    plt.plot(x,y3)
   #print(np.trapz((y2-y3)*max(kcal),x))
    plt.show()
Esempio n. 12
0
 def count(self, table):
     return session.query(table).count()
Esempio n. 13
0
 def query_update(self,table,id,update):
     data = session.query(table).filter(table.id==id).update(update)
     session.commit()
Esempio n. 14
0
 def query_bytitle(self,table,title):
     return session.query(table).filter(table.title==title)
Esempio n. 15
0
 def query_byid(self,table,id):
     return session.query(table).filter(table.id==id)
Esempio n. 16
0
File: main.py Progetto: fr4nt1x/eat
def getNumberOfDays():
    res = session.query(Day).count()
    return res
Esempio n. 17
0
File: main.py Progetto: fr4nt1x/eat
def getLastDays(numberOfDays):
    res = session.query(Day).order_by(desc(Day.dateofconsum)).limit(numberOfDays).all()
    return res
Esempio n. 18
0
 def query_byid(self, table, id):
     return session.query(table).filter(table.id == id)
Esempio n. 19
0
 def query_bytitle(self, table, title):
     return session.query(table).filter(table.title == title)
Esempio n. 20
0
 def query_update(self, table, id, update):
     data = session.query(table).filter(table.id == id).update(update)
     session.commit()
Esempio n. 21
0
 def count(self,table):
     return session.query(table).count()
Esempio n. 22
0
File: main.py Progetto: fr4nt1x/eat
def getLastDay():
    res = session.query(Day).order_by(desc(Day.dateofconsum)).first()
    return res
Esempio n. 23
0
def get_price_per_day(startday):
    allDays = np.array(session.query(Day).order_by(Day.dateofconsum).all())[startday:]
    price = np.array([sum([z.price for z in x.meals if z.price!= None]) for x in allDays])    
    print(sum(price)/allDays.size)
Esempio n. 24
0
    rs = session.query(Game, TeamStat) \
        .join(TeamStat) \
        .filter(TeamStat.team_id == team_id) \
        .filter(Game.type == 'Season') \
        .filter(Game.date >= from_date) \
        .filter(Game.date < to_date) \
        .count()

    return rs


data = []
index = -1

#rs = session.query(TeamStat).all()
rs = session.query(Game).filter_by(type='Season')

for game in rs:
    index += 1
    data.append(index)
    data[index] = []
    #print obj.game_id, obj.team_id, obj.ha, obj.result, obj.STLP

    data[index].append(game.dce)

    # Get team_id of each team
    team_ids = get_team_ids_by_game_id(game.id)

    # Get WL ratio
    hWL = get_wl_ratio_by_team_id(team_ids['H'], game.id)
    aWL = get_wl_ratio_by_team_id(team_ids['A'], game.id)