def get(self): email = str(request.args.get('email')) userid = utils.userId(email) conn = db.connect() cursor = conn.cursor() sql = "SET @DAY := -1;" cursor.execute(sql) cursor.fetchall() sql = "SELECT @DAY := @DAY +1 as DAY, (SELECT COUNT(*) FROM diet WHERE day = @DAY and user_id=%d and date between DATE_ADD(NOW(), INTERVAL -1 WEEK) AND NOW()) as eat FROM diet WHERE @DAY < 3 order by DAY;" % ( userid) cursor.execute(sql) result = cursor.fetchall() db.close(conn) style = week.personType(userid) res = { "mon": result[0]['eat'], "lun": result[1]['eat'], "din": result[2]['eat'], "sna": result[3]['eat'], "style": style } print(res) return res
def get(self): print('hello') print(request.args) email = str(request.args.get('email')) userid = utils.userId(email) tan, dan, ji = week.weekAnalyze(userid) img = week.drawGraph(tan, dan, ji) return send_file(img, mimetype='image/png')
def get(self): email = str(request.args.get('email')) date = request.args.get('datetime') userid = utils.userId(email) print(userid) conn = db.connect() cursor = conn.cursor() sql = "select d.day as day, f.korean as food_name, f.calories as cal, f.gram as gram from diet as d JOIN food as f on d.food_id = f.food_id where user_id= %d and DATE(date)='%s' ORDER BY day " % ( userid, date) print(sql) cursor.execute(sql) result = cursor.fetchall() db.close(conn) return result
def post(self): foodid = request.form['food_id'] email = str(request.form['email']) day = request.form['day'] print(email) userid = utils.userId(email) print(userid) conn = db.connect() cursor = conn.cursor() sql = "insert into diet(user_id, date, day, food_id) values(%d, NOW(), %d, %d)" % ( int(userid), int(day), int(foodid)) print(sql) cursor.execute(sql) conn.commit() db.close(conn) return {"result": "success"}
def get(self): email = str(request.args.get('email')) date = request.args.get('datetime') conn = db.connect() cursor = conn.cursor() userid = utils.userId(email) kicho = utils.userhcal(email) #해당 날짜의 섭취한 음식을 모두 빼내고 sql = "select * from diet where user_id = %d and DATE(date)='%s'" % ( userid, date) cursor.execute(sql) result = cursor.fetchall() print(result) kcal = 0 tan = 0 dan = 0 ji = 0 if len(result) > 0: for res in result: food_id = int(res['food_id']) sql = "select * from food where food_id = %d" % (food_id) cursor.execute(sql) out = cursor.fetchall()[0] kcal += out['calories'] tan += out['carbohydrate'] dan += out['protein'] ji += out['fat'] db.close(conn) return { "result": "success", "calories": kcal, "carbohydrate": tan, "protein": dan, "fat": ji, "kicho": kicho } else: db.close(conn) return {"result": "fail"}
def get(self): email = str(request.args.get('email')) userid = utils.userId(email) print(userid) tan, dan, ji = week.weekAnalyze(userid) print(tan) print(dan) print(ji) total = tan + dan + ji tanper = 50 - tan / total * 100 danper = 30 - dan / total * 100 jiper = 20 - ji / total * 100 return { "result": "success", "carbohydrate": tanper, "protein": danper, "fat": jiper, "tan": tan, "dan": dan, "ji": ji }