def salon(): id_Salon = request.args.get('id_Salon') print('mostrando salon especifico') sal = Salon(conexion, cursor) respuesta = sal.buscarSalon(id_Salon) return jsonify(respuesta)
def salones(): sal = Salon(conexion, cursor) print('mostrando todos los salones') resultado = sal.recuperar() print(resultado) return jsonify(resultado)
def crearS(): nombre = request.args.get('nombre') ubicacion = request.args.get('ubicacion') cp = request.args.get('cp') id = request.args.get('id') costo = request.args.get('costo') print('registrando salon') sal = Salon(conexion, cursor) resultado = make_response(str(sal.crear(nombre, ubicacion, cp, id, costo))) return resultado
def read_data(self): f = open(self.data_path, "r", encoding='utf-8') lines = csv.reader(f) csv_lines = 0 index = 0 for item in lines: csv_lines += 1 if csv_lines == 1: pass else: salon_new = Salon() salon_new.load_data(item) self.salons.append(salon_new) self.salon_map[salon_new.id] = index index += 1
def upb(): try: if request.method == "PUT": sid = request.form['sid'] sname = request.form['sname'] semail = request.form['semail'] spassword = request.form['spassword'] sphone = request.form['sphone'] saddress = request.form['saddress'] sarea = request.form['sarea'] spassword = algo.encrypt(spassword) Session = sessionmaker(bind=eng) ses = Session() su = Salon(sname, semail, spassword, sphone, saddress, sarea) salon = ses.query(Salon).filter_by(sid=sid).update( dict(sname=sname, semail=semail, spassword=spassword, sphone=sphone, saddress=saddress, sarea=sarea)) ses.commit() response = { 'status': 1, 'statusMessage': "Data Updated Successfully" } except Exception as e: response = {'status': 0, "statusMessage": str(e)} return jsonify(response)
def __init__(self, firstRoomAmount, secondRoomAmount, thirdRoomAmount, interval, requestPeriod, taskPeriod): self.salon = Salon(firstRoomAmount, secondRoomAmount, thirdRoomAmount) self.timeInterval = self.takeTimeInterval(interval) self.timePerOneDay = 0 self.numberOfDay = 0 self.timeStep = 0 self.countRequestDay = 0 self.allLostRequests = 0 self.allAverageSalary = 0 self.allAverageWorkTime = 0 self.allCompletedRequests = 0 self.allProfit = 0 self.allFreeTime = 0 self.timeRequestPeriod = self.takePeriod(requestPeriod) self.timeTaskPeriod = self.takePeriod(taskPeriod)
def add_sal(): try: if request.method == 'POST': sname = request.form['sname'] semail = request.form['semail'] spassword = request.form['spassword'] sphone = request.form['sphone'] saddress = request.form['saddress'] sarea = request.form['sarea'] spassword = algo.encrypt(spassword) Session = sessionmaker(bind=eng) ses = Session() su = Salon(sname, semail, spassword, sphone, saddress, sarea) ses.add_all([su]) ses.commit() response = {'status': 1, "statusMessage": "Data Inserted"} except Exception as e: response = {'status': 0, "statusMessage": str(e)} return jsonify(response)
from service import Service from nail_service import NailService from salon import Salon s = Salon("Salon 1", "username", "password") s.addService() s.addService() s.deleteService() s.sellService()
from fastapi import FastAPI from pydantic import BaseModel from salon import Salon class Car(BaseModel): id: int name: str speed: int app = FastAPI() salon = Salon() @app.get('/') def get_all_cars(): return salon.get_all_cars() @app.get('/{name}') def get_car_by_name(name: str): car = salon.get_car_by_name(name) if car is not None: return car else: return "There is no car with name: " + name
class Model: 'class for generation requests, running salon and returning statistics' DURATION_OF_DAY = 480 # длительность одного дня в минутах def __init__(self, firstRoomAmount, secondRoomAmount, thirdRoomAmount, interval, requestPeriod, taskPeriod): self.salon = Salon(firstRoomAmount, secondRoomAmount, thirdRoomAmount) self.timeInterval = self.takeTimeInterval(interval) self.timePerOneDay = 0 self.numberOfDay = 0 self.timeStep = 0 self.countRequestDay = 0 self.allLostRequests = 0 self.allAverageSalary = 0 self.allAverageWorkTime = 0 self.allCompletedRequests = 0 self.allProfit = 0 self.allFreeTime = 0 self.timeRequestPeriod = self.takePeriod(requestPeriod) self.timeTaskPeriod = self.takePeriod(taskPeriod) def takeTimeInterval(self, interval): switcher = { "15 минут": 15, "30 минут": 30, "1 час": 60 } return switcher.get(interval, 15) def takePeriod(self, str_period): period = re.findall(r'\d{1,3}', str_period) return period def nextStep(self): while (self.timeStep < self.timeInterval): self.salon.giveRequestMasters(self.timeStep + self.timePerOneDay, self.timeTaskPeriod) self.timeStep = self.timeStep + \ self.generateRequest(self.timeStep + self.timePerOneDay) self.countRequestDay = self.countRequestDay + 1 self.timePerOneDay = self.timePerOneDay + self.timeInterval self.salon.giveRequestMasters(self.timePerOneDay, self.timeTaskPeriod) if (self.timePerOneDay == self.DURATION_OF_DAY): self.numberOfDay = self.numberOfDay + 1 self.timePerOneDay = 0 self.timeStep = 0 return self.collectStatistics() else: self.timeStep = self.timeStep - self.timeInterval return None def collectStatistics(self): lostRequests = 0 averageSalary = 0 averageSpentTime = 0 completedRequests = 0 profit = 0 for key, _ in self.salon.house.items(): lostRequests = lostRequests + self.salon.house[key].wentAway averageSalary = averageSalary + \ int(self.salon.house[key].getAverageSalary()) averageSpentTime = averageSpentTime + \ int(self.salon.house[key].getAverageSpentTime()) completedRequests = completedRequests + \ int(self.salon.house[key].completedRequests) profit = profit + int(self.salon.house[key].getProfit()) self.allLostRequests = self.allLostRequests + lostRequests averageSalary = int(averageSalary / 3) averageSpentTime = int(averageSpentTime / 3) self.allAverageSalary += averageSalary self.allAverageWorkTime = self.allAverageWorkTime + averageSpentTime self.allCompletedRequests = self.allCompletedRequests + completedRequests self.allProfit = self.allProfit + profit freeTime = (self.DURATION_OF_DAY - averageSpentTime) * \ 100 / self.DURATION_OF_DAY self.allFreeTime = self.allFreeTime + freeTime self.salon.updateDataForNextDay() return Statistic(self.numberOfDay - 1, completedRequests, lostRequests, profit, averageSalary, averageSpentTime, freeTime) def generateRequest(self, currentTime): numberTask = random.randint(1, 3) # метод takeRequest self.salon.receiveRequest( Request(numberTask, currentTime)) timeUntilNextRequest = 0 if (self.numberOfDay > 4 or self.timePerOneDay > 300): timeUntilNextRequest = random.randint( int(self.timeRequestPeriod[0]), int(self.timeRequestPeriod[1])) else: timeUntilNextRequest = random.randint( int(self.timeRequestPeriod[0])+10, int(self.timeRequestPeriod[1])+10) return timeUntilNextRequest