def getTrainData(userid,start,end): return dbconn.query(""" select * from user_train_data where id in( select max(id) from user_train_data where userid=$userid and userCyclingTimeStamp between $start and $end group by date(userCyclingTimeStamp) ) """,vars=dict(userid=userid,start=start,end=end))
def getTrainData(userid, start, end): return dbconn.query(""" select * from user_train_data where id in( select max(id) from user_train_data where userid=$userid and userCyclingTimeStamp between $start and $end group by date(userCyclingTimeStamp) ) """, vars=dict(userid=userid, start=start, end=end))
def getLastTimeStamp(userid): r = web.listget( dbconn.query( "select max(timeStamp) as timeStamp from user_data where userid=$userid", vars=dict(userid=userid)), 0, None) if r: return date_to_timestamp(r.timeStamp) return None
def getUserByID(userid): res = dbconn.query(""" select * from user_info ui where ui.userid = $userid """, vars=dict(userid=userid)) u = web.listget(res, 0, None) return u
def updatenafens(brand=None,market=None): if not market: return res = dbconn.query("select * from naifen where processed is null and market = $market and brand = $brand",vars=dict(market=market,brand=brand)) dp = None if market == "tmall": dp = Tmall() elif market == "amazon": dp = Amazon() elif market == "jd": dp = Jd() for r in res: dp.initNf(r.itemid)
def get_rank(userid): rs = dbconn.query(""" select userid,max(userCyclingStamina) as max_stamina from user_train_data where userCyclingTimeStamp > $sunday group by userid order by max(userCyclingStamina) desc """,vars=dict(sunday=get_last_Sunday())) rank = 1 for r in rs: print type(r.userid) print type(userid) if r.userid == userid: print "===========" return {"rank":rank,"userCyclingStamina":r.max_stamina} rank += 1
def get_rank(userid): rs = dbconn.query(""" select userid,max(userCyclingStamina) as max_stamina from user_train_data where userCyclingTimeStamp > $sunday group by userid order by max(userCyclingStamina) desc """, vars=dict(sunday=get_last_Sunday())) rank = 1 for r in rs: print type(r.userid) print type(userid) if r.userid == userid: print "===========" return {"rank": rank, "userCyclingStamina": r.max_stamina} rank += 1
def get_ranks(start,end): rs = dbconn.query(""" select username,max(userCyclingStamina) as max_stamina from user_train_data ut join user_info ui on ui.userid = ut.userid where userCyclingTimeStamp > $sunday group by ut.userid order by max(userCyclingStamina) desc limit $start,$n """, vars = dict(start=(start-1),n=(end-start+1),sunday=get_last_Sunday()) ) l = list() for r in rs: l.append({"username":r.username,"rank":start,"stamina":r.max_stamina}) start += 1 return l
def get_ranks(start, end): rs = dbconn.query(""" select username,max(userCyclingStamina) as max_stamina from user_train_data ut join user_info ui on ui.userid = ut.userid where userCyclingTimeStamp > $sunday group by ut.userid order by max(userCyclingStamina) desc limit $start,$n """, vars=dict(start=(start - 1), n=(end - start + 1), sunday=get_last_Sunday())) l = list() for r in rs: l.append({ "username": r.username, "rank": start, "stamina": r.max_stamina }) start += 1 return l
def hasUserName(userName): return web.listget( dbconn.query("select * from user_info where userName=$userName", vars=dict(userName=userName)), 0, None)
def insertpre(itemid,market): dbconn.query("insert into prenaifen (name,duration,weight,spec,brand,series,sellto,age,duan,pack,place,price,img) select name,duration,weight,spec,brand,series,sellto,age,duan,pack,place,price,img from naifen where itemid = $itemid and market=$market",vars=dict(itemid=itemid,market=market)) "" return web.listget(dbconn.query("SELECT last_insert_id() as newid"),0,None).newid
def get_session(session_id): res = dbconn.query("select * from sessions where session_id = $session_id",vars=dict(session_id=session_id)) return web.listget(res,0,None)
def getLastTimeStamp(userid): r = web.listget( dbconn.query("select max(timeStamp) as timeStamp from user_data where userid=$userid",vars=dict(userid=userid)), 0, None) if r: return date_to_timestamp(r.timeStamp) return None
def getData(userid,start,end): return dbconn.query("select * from user_data where userid=$userid and timeStamp between $start and $end",vars=dict(userid=userid,start=start,end=end))
def get_session(session_id): res = dbconn.query("select * from sessions where session_id = $session_id", vars=dict(session_id=session_id)) return web.listget(res, 0, None)
def getfamsp(pid): return dbconn.query("select * from formalitem where pid = $pid and picked=0 order by generalscore desc",vars=dict(pid=pid))
def getsp(spid): return web.listget(dbconn.query("select * from formalitem where id=$spid",vars=dict(spid=spid)),0,None)
def getData(userid, start, end): return dbconn.query( "select * from user_data where userid=$userid and timeStamp between $start and $end", vars=dict(userid=userid, start=start, end=end))
def getUserByEmail(email): return web.listget( dbconn.query("select * from user_info where email=$email", vars=dict(email=email)), 0, None)