def book(id1, id2): event = getARoom(User.get(id=id1), User.get(id=id2)) return jsonify([ event[0], "room number {} in {}".format(event[1]["roomid"], event[1]["roomname"]) ])
def upload(id): if 'file' not in request.files: return {"msg": "err", "error": "No file part"} file = request.files['file'] if file.filename == '': return {"msg": "err", "error": "No selected file"} content = file.read() new_filename = str(hashlib.sha1(content).hexdigest()) # TODO: Save the picture in the db user = User.get(User.id == id) Picture.create(user=user, hash=new_filename) with open(os.path.join("./static/", new_filename), "wb") as image: image.write(content) return {"msg": "ok", "value": new_filename}
def photo_list(id): hashes = [ "/static/" + picture.hash for picture in User.get(User.id == id).pictures ] return {"photos": [hashes]}
def get_matched(): user = User.get(username=username) return [model_to_dict(i) for i in getMatched(user)]
def swiped(username): user = User.get(username=username) match = User.get(id=request.args.get('id')) Match.create(user=user, match=match) return {"msg": "ok"}
def getSoulMate(username): user = User.get(username=username) return jsonify([[model_to_dict(i[0], backrefs=True), i[1]] for i in matchSchedules(user.id)])
def matchSchedules(id): # given a User id, return compatibility with other schedules mySchedule = scheduleToArray(json.loads(User.get(id=id).schedule)["timetable"]) #User's schedule otherSchedules = [[i, scheduleToArray(json.loads(i.schedule)["timetable"])] for i in User.select()] return sorted([[other[0], matchSchedule(mySchedule, other[1])] for other in otherSchedules], key = lambda x : x[1])
score += t.hour * 5 score *= 10/(10 + int(room["capacity"])) print(score) if score > current_score: current_best = room current_score = score current_time = datetime.combine(date.today(), t) + timedelta(days=delta) return current_best, current_time def getARoom(u1, u2): s1 = scheduleToArray(json.loads(u1.schedule)["timetable"]) s2 = scheduleToArray(json.loads(u2.schedule)["timetable"]) print(s1) free1 = getFreeTime(s1) free2 = getFreeTime(s2) combinedFree = [list(set([j.isoformat() for j in free1[i]]) & set([j.isoformat() for j in free2[i]])) for i in range(0, len(free1))] place, time = getFreeRooms(combinedFree) return[time, place] if __name__=="__main__": s1=scheduleToArray(json.loads(User.get(username="******").schedule)["timetable"]) s2=scheduleToArray(json.loads(User.get(username="******").schedule)["timetable"]) print(getFreeRooms(getDateTimes(s1,s2)))
def get_matched(): user = User.get(username=json.loads(request.data)["username"]) return [model_to_dict(i) for i in getMatched(user)]
def getSoulMate(): print(request.data) user = User.get(username=json.loads(request.data)["username"]) return jsonify([[model_to_dict(i[0], backrefs=True), i[1]] for i in matchSchedules(user.id)])
def swiped(): user = User.get(username=json.loads(request.data)["username"]) match = User.get(id=json.loads(request.data)["id"]) Match.create(user=user, match=match) return {"msg": "ok"}