示例#1
0
文件: data.py 项目: spiritwing/Pcycle
    def POST(self):
        data = web.input(datafile={})
        """
        if not data.has_key("sessionId") or not data.sessionId:
            return web.notfound()
        """
        ##print data
	    ##print data['datafile']
        sessionId = data['datafile'].filename
        userid = getUserId(sessionId)
        if not userid:
            return json.dumps({"errorCode":1001})
        data_compressed = None
        try:
            data_compressed = zlib.decompress(data['datafile'].value, zlib.MAX_WBITS|32)
        except:
            print traceback.format_exc()
	    return json.dumps({"errorCode":1003})
        data_json = json.loads(data_compressed)["data"]
        for d in data_json:
            d.update({"userid":userid,"timeStamp":timestamp_to_date(d["timeStamp"])})
        r = models.datas.multiple_insert_data(data_json)
        last_timestamp = models.datas.getLastTimeStamp(userid)
        if r:
            return json.dumps({"code":1,"last_timestampe":last_timestamp})
        else:
            return json.dumps({"code":0,"last_timestampe":last_timestamp})
示例#2
0
 def POST(self):
     data = web.input(datafile={})
     """
     if not data.has_key("sessionId") or not data.sessionId:
         return web.notfound()
     """
     ##print data
     ##print data['datafile']
     sessionId = data['datafile'].filename
     userid = getUserId(sessionId)
     if not userid:
         return json.dumps({"errorCode": 1001})
     data_compressed = None
     try:
         data_compressed = zlib.decompress(data['datafile'].value,
                                           zlib.MAX_WBITS | 32)
     except:
         print traceback.format_exc()
         return json.dumps({"errorCode": 1003})
     data_json = json.loads(data_compressed)["data"]
     for d in data_json:
         d.update({
             "userid": userid,
             "timeStamp": timestamp_to_date(d["timeStamp"])
         })
     r = models.datas.multiple_insert_data(data_json)
     last_timestamp = models.datas.getLastTimeStamp(userid)
     if r:
         return json.dumps({"code": 1, "last_timestampe": last_timestamp})
     else:
         return json.dumps({"code": 0, "last_timestampe": last_timestamp})
示例#3
0
文件: user.py 项目: spiritwing/Pcycle
 def POST(self):
     data = web.input()
     if not data.has_key("sessionId"):
         return web.notfound()
     userid = getUserId(data.sessionId)
     user = models.users.getUserByID(userid)
     if not user:
         return json.dumps({"errorcode": 1001})
示例#4
0
文件: user.py 项目: spiritwing/Pcycle
 def POST(self):
     data = web.input()
     if not data.has_key("sessionId"):
         return web.notfound()
     userid = getUserId(data.sessionId)
     user = models.users.getUserByID(userid)
     if not user:
         return json.dumps({"errorcode":1001})
示例#5
0
文件: data.py 项目: spiritwing/Pcycle
 def POST(self):
     data = web.input()
     if not data.has_key("sessionId") or not data.sessionId:
         return web.notfound()
     sessionId = data.sessionId
     userid = getUserId(sessionId)
     if not userid:
         return json.dumps({"errorCode":1001})
     data_json = json.loads( urllib.unquote(data.data) )
     for d in data_json:
         d.update({"userid":userid,"userCyclingTimeStamp":timestamp_to_date(d["userCyclingTimeStamp"])})
     models.datas.multiple_insert_train(data_json)
     return json.dumps({"code":1})
示例#6
0
文件: user.py 项目: spiritwing/Pcycle
 def GET(self):
     data = web.input()
     if not data.has_key("sessionId"):
         return web.notfound()
     userid = getUserId(data.sessionId)
     user = models.users.getUserByID(userid)
     if not user:
         return json.dumps({"errorcode": 1001})
     """
         需要一个汇总表,记录每个人的汇总记录
     """
     ranks = models.users.getRanks(data.start, data.end)
     user_rank = models.users.getRank(user.userid)
     return json.dumps({"rank": user_rank, "ranks": ranks})
示例#7
0
文件: user.py 项目: spiritwing/Pcycle
 def GET(self):
     data = web.input()
     if not data.has_key("sessionId"):
         return web.notfound()
     userid = getUserId(data.sessionId)
     user = models.users.getUserByID(userid)
     if not user:
         return json.dumps({"errorcode":1001})
     """
         需要一个汇总表,记录每个人的汇总记录
     """
     ranks = models.users.getRanks(data.start,data.end)
     user_rank = models.users.getRank(user.userid)
     return json.dumps({"rank":user_rank,"ranks":ranks})
示例#8
0
文件: data.py 项目: spiritwing/Pcycle
 def GET(self):
     data = web.input()
     if not data.has_key("sessionId") or not data.sessionId \
         or not data.has_key("startStamp") or not data.startStamp \
         or not data.has_key("endStamp") or not data.endStamp:
         return web.notfound()
     userid = getUserId(data.sessionId)
     if not userid:
         return json.dumps({"errorCode":1001})
     l = list()
     user_datas = models.datas.getData(userid,timestamp_to_date(float(data.startStamp)),timestamp_to_date(float(data.endStamp)))
     for user_data in user_datas:
         user_data.timeStamp = date_to_timestamp(user_data.timeStamp)
         del user_data["userid"]
         del user_data["ID"]
         l.append(user_data)
     return zlib.compress(json.dumps({"data":l}))
示例#9
0
    def GET(self):
        data = web.input()
        if not data.has_key("sessionId") or not data.sessionId:
            return web.notfound()
        sessionId = data.sessionId
        userid = getUserId(sessionId)
        if not userid:
            return json.dumps({"errorCode": 1001})

        ##defult start = 1 , end = 10
        start = data.start if data.has_key("start") and data.start else 1
        end = data.end if data.has_key("end") and data.end else 10

        user_rank = models.datas.get_rank(userid)
        user_ranks = models.datas.get_ranks(start, end)

        return json.dumps({"rank": user_rank, "ranks": user_ranks})
示例#10
0
文件: user.py 项目: spiritwing/Pcycle
 def GET(self):
     data = web.input()
     if not data.has_key("sessionId"):
         return web.notfound()
     user = None
     if data.has_key("sessionId"):
         userid = getUserId(data.sessionId)
         user = models.users.getUserByID(userid)
     if user:
         return json.dumps({
             "userName": user.userName,
             "userPhoneNumber": user.userPhoneNumber,
             "userWeight": user.userWeight,
             "userHeight": user.userHeight,
             "userAge": user.userAge,
         })
     else:
         return json.dumps({"errorcode": 1001})
示例#11
0
 def POST(self):
     data = web.input()
     if not data.has_key("sessionId") or not data.sessionId:
         return web.notfound()
     sessionId = data.sessionId
     userid = getUserId(sessionId)
     if not userid:
         return json.dumps({"errorCode": 1001})
     data_json = json.loads(urllib.unquote(data.data))
     for d in data_json:
         d.update({
             "userid":
             userid,
             "userCyclingTimeStamp":
             timestamp_to_date(d["userCyclingTimeStamp"])
         })
     models.datas.multiple_insert_train(data_json)
     return json.dumps({"code": 1})
示例#12
0
文件: user.py 项目: spiritwing/Pcycle
 def GET(self):
     data = web.input()
     if not data.has_key("sessionId"):
         return web.notfound()
     user = None
     if data.has_key("sessionId"):
         userid = getUserId(data.sessionId)
         user = models.users.getUserByID(userid)
     if user:
         return json.dumps({
             "userName": user.userName,
             "userPhoneNumber": user.userPhoneNumber,
             "userWeight": user.userWeight,
             "userHeight": user.userHeight,
             "userAge": user.userAge, 
         })
     else:
         return json.dumps({"errorcode":1001})
示例#13
0
文件: data.py 项目: spiritwing/Pcycle
    def GET(self):
        data = web.input()
        if not data.has_key("sessionId") or not data.sessionId:
            return web.notfound()
        sessionId = data.sessionId
        userid = getUserId(sessionId)
        if not userid:
            return json.dumps({"errorCode":1001})


        ##defult start = 1 , end = 10
        start = data.start if data.has_key("start") and data.start else 1
        end = data.end if data.has_key("end") and data.end else 10


        user_rank = models.datas.get_rank(userid)
        user_ranks = models.datas.get_ranks(start,end)

        return json.dumps({"rank":user_rank,"ranks":user_ranks})
示例#14
0
 def GET(self):
     data = web.input()
     if not data.has_key("sessionId") or not data.sessionId \
         or not data.has_key("startStamp") or not data.startStamp \
         or not data.has_key("endStamp") or not data.endStamp:
         return web.notfound()
     userid = getUserId(data.sessionId)
     if not userid:
         return json.dumps({"errorCode": 1001})
     l = list()
     user_datas = models.datas.getData(
         userid, timestamp_to_date(float(data.startStamp)),
         timestamp_to_date(float(data.endStamp)))
     for user_data in user_datas:
         user_data.timeStamp = date_to_timestamp(user_data.timeStamp)
         del user_data["userid"]
         del user_data["ID"]
         l.append(user_data)
     return zlib.compress(json.dumps({"data": l}))
示例#15
0
文件: user.py 项目: spiritwing/Pcycle
 def POST(self):
     data = web.input()
     if not data.has_key("sessionId"):
         return json.dumps({"code": 0, "errorCode": 1001})
     userid = getUserId(data.sessionId)
     if not userid:
         return json.dumps({"code": 0, "errorCode": 1001})
     u_dict = dict()
     if data.has_key("userName") and data.userName:
         u_dict.update({"userName": data.userName})
     if data.has_key("userWeight") and data.userWeight:
         u_dict.update({"userWeight": int(data.userWeight)})
     if data.has_key("userHeight") and data.userHeight:
         u_dict.update({"userHeight": int(data.userHeight)})
     if data.has_key("userAge") and data.userAge:
         u_dict.update({"userAge": int(data.userAge)})
     if data.has_key("userPhoneNumber") and data.userPhoneNumber:
         u_dict.update({"userPhoneNumber": data.userPhoneNumber})
     if models.users.update(userid, u_dict):
         return json.dumps({"code": 1})
     return json.dumps({"code": 0})
示例#16
0
文件: user.py 项目: spiritwing/Pcycle
 def POST(self):
     data = web.input() 
     if not data.has_key("sessionId"):
         return json.dumps({"code":0 ,"errorCode":1001})
     userid = getUserId(data.sessionId)
     if not userid:
         return json.dumps({"code":0 ,"errorCode":1001})
     u_dict = dict()
     if data.has_key("userName") and data.userName:
         u_dict.update({"userName":data.userName})
     if data.has_key("userWeight") and data.userWeight:
         u_dict.update({"userWeight":int(data.userWeight)})
     if data.has_key("userHeight") and data.userHeight:
         u_dict.update({"userHeight":int(data.userHeight)})
     if data.has_key("userAge") and data.userAge:
         u_dict.update({"userAge":int(data.userAge)})
     if data.has_key("userPhoneNumber") and data.userPhoneNumber:
         u_dict.update({"userPhoneNumber":data.userPhoneNumber})
     if models.users.update(userid,u_dict):
         return json.dumps({"code":1})
     return json.dumps({"code":0})