def decodeRequestOld(request_json): ''' Maps the request Json to Request class :param request_json: json sent by the user with the request :return: request class with the info in the json ''' dict = json.loads(request_json) request = Request(1, 1, 1, 1) for key in dict: if key == 'request_id': request.request_id = dict[key] if key == 'resource_id': request.resource_id = dict[key] if key == 'template_id': request.template_id = dict[key] if key == 'user_id': request.aged_id = dict[key] if key == 'category': request.category = dict[key] if key == 'from_date': request.from_date = dict[key] if key == 'to_date': request.to_date = dict[key] if key == 'subjects': request.subjects = dict[key] return request
def decodeRequest(request_json): ''' Maps the request Json to Request class :param request_json: json sent by the user with the request :return: request class with the info in the json ''' request = Request(1, request_json['resource_id'], request_json['template_id'], request_json['aged_id']) request.from_date = datetime.strptime(request_json['from_date'], '%d %b %Y') request.to_date = datetime.strptime(request_json['to_date'], '%d %b %Y') return request
def decodeRequestPendulum(request_post): ''' Maps the request Json to Request class :param request_post: json sent by the user with the request :return: request class with the info in the json ''' request = Request(1, request_post.form['pilot_id'], request_post.form['intervention_session_id'],request_post.form['resource_id'], request_post.form['template_id'], request_post.form['aged_id'], request_post.form['miniplan_local_id']) request.from_date = pendulum.parse(request_post.form['from_date']) request.to_date = pendulum.parse(request_post.form['to_date']) return request
def findById(self, id): query = """ SELECT replyHost, replyPort, replyChannel FROM request WHERE id = ? """ parameters = (id, ) cursor = self.__connection.cursor() cursor.execute(query, parameters) resultSet = cursor.fetchone() request = Request() request.setId(id) request.setReplyHost(resultSet[0]) request.setReplyPort(resultSet[1]) request.setReplyChannel(resultSet[2]) cursor.close() return request
def create_shift_table_by_team(team=1): conn = psycopg2.connect(host=pg_credential.hostname, port=pg_credential.port, user=pg_credential.username, password=pg_credential.password, database=pg_credential.path[1:]) # To remove slash cursor = conn.cursor() members = [] cursor.execute("SELECT * FROM members WHERE team = {} ORDER BY id".format(team)) for m in cursor: members.append(m[0]) cursor.execute("SELECT days_in_shift, max_shift_count_in_routine FROM teams WHERE id={}".format(team)) (days_in_shift, max_shift_count_in_routine) = cursor.fetchone() print("days_in_shift: {}, max_shift_count_in_routine: {}".format(days_in_shift, max_shift_count_in_routine)) cursor.execute("SELECT * FROM requests WHERE team={} AND start_time >= current_date".format(team)) requests = [Request(r) for r in cursor] optimized_shifts = optimize_shifts(team, members, requests) # Now optimal for s in optimized_shifts: ((status, time_table), start_date) = s json_time_table = json.dumps({ 'time_table': time_table.tolist() }) ret = cursor.execute("INSERT INTO shifts (team, start_date, time_table) VALUES(%s, %s, %s)", (team, start_date, json_time_table)) conn.commit() cursor.close() conn.close()
def update(self): # генерация заявок self.currentRequest = Request.instance() if self.hotel.isCanApply(self.currentRequest): self.applyRequest.append(self.currentRequest) else: self.rejectedRequest.append(self.currentRequest) # обновление состояния отеля self.hotel.update()
def save(self, request): query = """ INSERT INTO request (replyHost, replyPort, replyChannel) values (?, ?, ?) """ cursor = self.__connection.cursor() replyHost = str(request.getReplyHost()) replyPort = str(request.getReplyPort()) replyChannel = str(request.getReplyChannel()) parameters = (replyHost, replyPort, replyChannel) cursor.execute(query, parameters) requestSaved = Request() requestSaved.setId(cursor.lastrowid) requestSaved.setReplyHost(request.getReplyHost()) requestSaved.setReplyPort(request.getReplyPort()) requestSaved.setReplyChannel(request.getReplyChannel()) requestSaved.setMethod(request.getMethod()) requestSaved.setUri(request.getUri()) requestSaved.setHeader(request.getHeader()) requestSaved.setBody(request.getBody()) cursor.close() return requestSaved