def test4(): data = Data() data.add_user(123456, 'Will', User("Will", Schedule())) [print('%s: %s\n' % (k, v)) for k, v in data.db['users'].items()] print(data.db) # print(data.db['users']['Will'].schedule.events['Skate'].time.in_time(data.db['users']['Michael'].schedule.courses['CSCI140'].time.start)) #print(data.db) data.write_data()
def test3(): print("Test 3:") michael = User("Michael", Schedule()) michael.schedule.add_course( Course("CSCI140", EventTime(("Mon", "Wed", "Fri"), 1200, 1400), "GOL")) print(michael.schedule.courses["CSCI140"].time.in_time(1300)) # True michael.schedule.add_event(Event("Skate", EventTime(("Mon"), 1800, 1900))) print(michael)
def postschedule(): req = request.json print(req) stuno = req.get('stuno') schedule = req.get('schedule') stu1 = Student.query.filter(Student.stuNo == stuno).first() newsch = Schedule(*schedule) stu1.schedule = newsch db.session.add(newsch) db.session.commit() return jsonify({'res': True})
def adminSchedule(request): if "login_user" not in request.session: return redirect("/") adminScheduler = loader.get_template("../UI/addSchedule.html") context={} faculty = request.POST["faculty"] subject = request.POST["subject"] day = request.POST["day"] classno = request.POST["classno"] fulltime = request.POST["fulltime"] schedule = Schedule() schedule.subject=subject schedule.faculty = faculty schedule.class_no = classno schedule.day_no = day if fulltime == "11": schedule.start_time = "11:00" schedule.end_time = "12:00" elif fulltime == "12": schedule.start_time = "12:00" schedule.end_time = "01:00" elif fulltime == "1": schedule.start_time = "01:00" schedule.end_time = "02:00" elif fulltime == "2.5": schedule.start_time = "02:30" schedule.end_time = "03:30" elif fulltime == "3.5": schedule.start_time = "03:30" schedule.end_time = "04:30" subjectRepo = SubjectRepo() schedule.subject_id=subjectRepo.get_subjectid(faculty, subject)[0] if schedule.subject_id is None: context["error_msg"] = "Subject didn't matched the faculty" elif not schedule.class_no: context["error_msg"] = "Please enter the class no" else: created_at= timestamp() scheduleRepo = ScheduleRepo() if scheduleRepo.save(schedule,created_at): context["success_msg"] = "Schedule added" else: context["error_msg"] = "Schedule not added" return HttpResponse(adminScheduler.render(context,request))
def add_user(self, user_id, name): self.db['users'][user_id] = User(name, Schedule(dict(), dict()))
def test2(): print("Test 2:") reynaldo = User("Reynaldo", Schedule()) reynaldo.schedule.add_course( Course("CSCI141", EventTime(("Mon"), 1000, 1200), "GOL")) print(reynaldo)
def test1(): print("Test 1:") will = User("Will", Schedule()) print(will)
def matrix_to_schedule(problem:dict, solution: ndarray) -> Schedule: """ Convert matrix data to schedule object :param solution: [ n_clouds + n_fogs, t_tasks ] :return: Schedule obj or None """ clouds = problem["clouds"] fogs = problem["fogs"] tasks = problem["tasks"] fogs_dict = make_dict_from_list_object(fogs) clouds_dict = make_dict_from_list_object(clouds) tasks_dict = make_dict_from_list_object(tasks) n_clouds = problem["n_clouds"] n_fogs = problem["n_fogs"] n_tasks = problem["n_tasks"] n_peers = problem["n_peers"] schedule = Schedule(problem) matrix_cloud, matrix_fog = solution[:n_clouds,], solution[n_clouds:,] # convert matrix_cloud to schedule.schedule_clouds_tasks list_task_stt = argmin(matrix_cloud, axis=0) # List of [task-stt: cloud-stt] (not task_id) for cl_stt in range(n_clouds): list_task_id = [] for task_stt, cloud_stt in enumerate(list_task_stt): if cl_stt == cloud_stt: list_task_id.append(tasks[task_stt].id) schedule.schedule_clouds_tasks[clouds[cl_stt].id] = list_task_id # convert matrix_fog to schedule.schedule_flogs_tasks list_task_stt = argmin(matrix_fog, axis=0) for fg_stt in range(n_fogs): list_task_id = [] for task_stt, fog_stt in enumerate(list_task_stt): if fg_stt == fog_stt: list_task_id.append(tasks[task_stt].id) schedule.schedule_fogs_tasks[fogs[fg_stt].id] = list_task_id # create a schedule for blockchain peers task_peers = {} # task_id: list[Peer] for fog_id, list_task_id in schedule.schedule_fogs_tasks.items(): fog = fogs_dict[fog_id] list_peers = fog.linked_peers for task_id in list_task_id: task_peers[task_id] = list_peers for cloud_id, list_task_id in schedule.schedule_clouds_tasks.items(): cloud = clouds_dict[cloud_id] list_peers = cloud.linked_peers for task_id in list_task_id: if task_id in task_peers.keys(): task_peers[task_id] = list(set(task_peers[task_id] + list_peers)) ### Remove task which not saved in blockchain task_peers_important = {} for task_id, peers in task_peers.items(): if tasks_dict[task_id].label == DefaultData.TASK_LABEL_IMPORTANT: task_peers_important[task_id] = peers ### peer_tasks = {} for task_id, list_peer_id in task_peers_important.items(): for peer_id in list_peer_id: if peer_id in peer_tasks: peer_tasks[peer_id].append(task_id) else: peer_tasks[peer_id] = [task_id] schedule.schedule_peers_tasks = peer_tasks return schedule