Skip to content

Commit

Permalink
Backend: continue to change the reservation algorithm such that it wo…
Browse files Browse the repository at this point in the history
…rks for the simulation as well. start to write the function that generate random orders

I go over the algorithm and continue to change it. I continue to write functions that do the same work for the simulation engine. I start to write the function that generate random orders in poisson distribution
#165
  • Loading branch information
aviadRozenknof committed Jun 7, 2018
1 parent 1bfec2d commit aa61495
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
32 changes: 22 additions & 10 deletions common/Simulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime,timedelta

from models.Room import Room
from models.Schedule import Schedule
Expand All @@ -16,6 +16,7 @@
NUM_FACILITIES = 0
DURATION = 0
HOURS_PER_DAY = 10
DATE = datetime.now()

def add_random_users_simulation(maxEmployees, manager):
'''
Expand Down Expand Up @@ -56,19 +57,30 @@ def order_rooms_simulation(duration):
global DURATION
global HOURS_PER_DAY
global NUM_EMPLOYEES
global DATE
DURATION = duration
duration_hours = DURATION * HOURS_PER_DAY
lamda = 0
if NUM_EMPLOYEES > 10:
lamda = NUM_EMPLOYEES/10
else:
lamda = 1
poisson_dest = np.random.poisson(lamda, duration_hours)
#TODO: order rooms for employees according to the poisson


poisson_dest = np.random.poisson((NUM_EMPLOYEES/20 +1), duration_hours)
day_need_to_add = 0
for hour in range(duration_hours-1):
time = 8 + (hour % 10)
DATE += timedelta(days = day_need_to_add)
for i in range(poisson_dest[hour]-1):
user_index = random.randint(1, NUM_EMPLOYEES)
user = User.get_by_email_simulation("simulationEmp" + str(user_index) +"@gmail.com")
# TODO: add participants to order
user.new_order_simulation(DATE,[],time, time+1, 'Simulation', user.facility)
if hour%10 == 0:
day_need_to_add += 1


def simulation_engine():
global DATE
Database.initialize()
Manager.manager_register_simulation("simulation@gmail.com", 'admin', 'simulation admin', '000000000', 'eng', 1, 'Simulation', 'sim')
DATE = datetime.utcnow().strftime('%d/%m/%y')





21 changes: 20 additions & 1 deletion models/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,32 @@ def remove_friend(self, friend_email):
return Friends.remove_friend(self.email, friend_email)

def get_orders(self, start=None, end=None):
# todo
return Order.find_by_user_email(self.email)

def get_schedule(self, date=None, start_time=None, end_time=None, room_id=None):
return Schedule.get_schedules(self.email, date, start_time, end_time, room_id)

def new_order(self, date, participants, start_time, end_time, company, facility):
if self.email not in participants:
participants.append(self.email)
problematic_participants = Schedule.all_participants_are_free(date, participants, start_time,
end_time)

if len(problematic_participants) > 0:
return False, problematic_participants
min_permission = User.min_permission(participants)
_id = self.email + ' ' + date + ' ' + str(start_time) + ' ' + str(end_time)
status, order_id, room_id = Order.new_order(_id, self.email, date, participants, start_time, end_time, company,
facility, min_permission)

if status:
print ("what was that")
# not finish yet
Schedule.assign_all(date, participants, start_time, end_time, order_id, room_id)
#self.create_meeting(start_time, end_time, order_id, room_id, date, participants)
return status, order_id

def new_order_simulation(self, date, participants, start_time, end_time, company, facility):
if self.email not in participants:
participants.append(self.email)
problematic_participants = Schedule.all_participants_are_free_simulation(date, participants, start_time,
Expand Down

0 comments on commit aa61495

Please sign in to comment.