Пример #1
0
    def remove_conflict_schedule(cls, all_conflict_schedules, date, start_time,
                                 end_time):
        for sched in all_conflict_schedules:

            #participants =
            participants = Schedule.get_participants(sched)
            Schedule.delete_meeting_from_schedule(date, participants,
                                                  start_time, end_time)
        ''''
Пример #2
0
 def delete_user(self, user_email):
     user = User.get_by_email(user_email)
     if user is not None and user.company == self.company:
         if Order.remove_user(user_email):
             Friends.remove_user(user_email)
             Schedule.remove_user(user_email)
             Database.remove('users', {'email': user_email})
             return True
     return False
Пример #3
0
 def cancel_order(self, order_id):
     """
     this method delete the order that match this order_id from the 'orders' table in db
     and delete the meeting from the schedule of each participant that invited to this meeting.
     only the user taht create this order can cancel it
     :param order_id:
     """
     if Order.who_create_order(order_id) == self.email:
         Order.delete_order(order_id)
         Schedule.delete_order(order_id)
Пример #4
0
 def create_meeting(self,
                    start_time,
                    end_time,
                    order_id,
                    room_id,
                    date=datetime.utcnow().strftime('%d/%m/%y'),
                    participants=[]):
     if self.email not in participants:
         participants.append(self.email)
     Schedule.assign_all(date, participants, start_time, end_time, order_id,
                         room_id)
Пример #5
0
    def cancel_meeting(self, meeting_id):
        """
        this user won't come to this meeting so the user decide to cancel it
        :param meeting_id:
        """

        order_id = Schedule.cancel_meeting(meeting_id)
        if Order.who_create_order(order_id) == self.email:
            return self.cancel_order(order_id)
        if order_id is not None:
            Order.participant_cancel(self.email, order_id)
            meetings = Schedule.get_by_order(order_id)
            for m in meetings:
                m.remove_participants(self.email)
Пример #6
0
def test_schedules_orders():
    Database.initialize()
    Database.dropAll()
    Manager.manager_register("*****@*****.**", 'admin', 'Admin admin', '000000000', 'eng', 1, 'YAHOO', 'matam')

    status, room_id = Room.add_room(2, 30, 1, 3, 'YAHOO', 'matam', True)
    assert status is True
    status, room_id = Room.add_room(2, 30, 3, 4, 'YAHOO', 'matam', False)
    assert status is True
    assert Room.remove_room(room_id) is True
    status, room_id = Room.add_room(2, 30, 3, 4, 'YAHOO', 'matam', True)

    num1 = Database.count('orders')
    Database.remove('orders', {'_id': '23/05/18'})
    num2 = Database.count('orders')
    Database.remove('orders', {'date': '26/05/18'})
    num3 = Database.count('orders')
    num_users1 = Database.count('users')
    Manager.user_register("*****@*****.**", '123', 'foox', '000002600', 'eng', 3, 'YAHOO', 'matam')
    Manager.user_register("*****@*****.**", '123', 'yan', '026000000', 'eng', 3, 'YAHOO', 'matam')
    num_users2 = Database.count('users')

    manager = Manager.get_by_email('*****@*****.**')
    assert manager is None
    manager = Manager.get_by_email('*****@*****.**')
    assert manager is not None
    try:
        manager.import_rooms(os.getcwd() + '\\rooms.csv')
        manager.import_employee(os.getcwd() + '\\employee.csv')
    # should'nt works on travis
    except Exception as e:
        pass
    num_users2 = Database.count('users')

    user = User.get_by_email('*****@*****.**')
    participants = ['*****@*****.**', '*****@*****.**']
    date = datetime.utcnow().strftime('%d/%m/%y')
    date = '26/06/18'
    status, string = user.new_order(date, participants, 1, 2, "YAHOO", 'matam')
    print(string)
    orders = user.get_orders()
    num_orders = len(orders)
    assert len(user.get_orders()) > 0
    schedules = user.get_schedule()
    assert len(schedules) > 0
    schedules = Schedule.get_schedules('*****@*****.**')
    assert len(Schedule.get_by_room("YAHOO matam 1")) > 0
    assert len(Room.available_rooms('11/11/11', 2, 1, 2, 2, 'YAHOO', 'matam')) > 0
Пример #7
0
 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)
Пример #8
0
    def available_rooms_simulation(cls, date, num_employee, begin_meeting,
                                   end_meeting, permission, company, facility):
        """

        :param date:
        :param num_employee: the participent in the room
        :param begin_meeting:
        :param end_meeting:
        :return: a list of all the room that have enough  space >= available_spaces  for a meeting on the given time
        """
        available_rooms = []

        rooms = Room.get_by_capacity_simulation(num_employee, company,
                                                facility, permission)
        for room in rooms:
            room_capacity = room.capacity
            room_schedule = Schedule.get_by_room_and_date_simulation(
                room._id, date)

            for sched in room_schedule:
                if room.intersection(begin_meeting, end_meeting, sched):
                    room_capacity = room_capacity - len(sched.participants)

            if room_capacity >= num_employee:
                # this room is empty
                available_rooms.append(room)
        return available_rooms
Пример #9
0
def meeting_info():
    email = session['email']
    user = User.get_by_email(email)
    meeting = Schedule.get_by_id(request.form.get('meeting_id'))
    return render_template('meeting.html',
                           manager=user.manager,
                           meeting=meeting)
Пример #10
0
 def check_room_friends(cls, room_id, date, start_time, end_time,
                        min_friends, max_friends):
     participants = Schedule.get_participants_by_room_date_and_hour(
         room_id, date, start_time, end_time)
     if len(participants) >= min_friends and len(
             participants) <= max_friends:
         return True
     return False
Пример #11
0
 def get_occupancy_simulation(cls, time, room_id):
     schedules = Schedule.get_by_room_and_date_simulation(
         room_id, time.strftime('%d/%m/%Y'))
     lengthes = []
     lengthes = map(lambda a: len(a.participants), schedules)
     sum = 0
     for length in lengthes:
         sum += length
     return sum
Пример #12
0
 def add_item_to_Schedule(self, **kwargs):
     scheduleItem = Schedule(day=kwargs["day"],
                             chet=kwargs["chet"],
                             group_id=kwargs["group_id"],
                             interval_id=kwargs["interval_id"],
                             subject_id=kwargs["subject_id"],
                             lecturer_id=kwargs["lecturer_id"])
     self.db.session.add(scheduleItem)
     self.db.session.commit()
Пример #13
0
 def get_all_participants_in_facility(manager, facility_name):
     rooms = Room.get_by_facility(manager.company, facility_name)
     if rooms is None:
         return
     sum_visits = 0
     for room in rooms:
         schedules = Schedule.get_by_room_and_date(
             room._id,
             datetime.now().strftime('%d/%m/%Y'))
         for sched in schedules:
             sum_visits += len(sched.participants)
     return sum_visits
Пример #14
0
    def new_order(cls, _id, user_email, date, participants, start_time,
                  end_time, company, facility, min_permission):
        """

        :param min_permission:
        :param _id:
        :param facility:
        :param company:
        :param user_email:
        :param date:
        :param participants:
        :param start_time:
        :param end_time:
        :return: True if we can create new order:
        if this user_email already had an order on this time --> false
        if one of the participants already have a meeting on this time --> false
        else --> true
        """

        new_order = cls(_id, user_email, date, participants, start_time,
                        end_time, company, facility)
        # todo - schedule algorithm, after it run we know the room_id that we will assign them in.
        # todo - this algorithm try to assign the new order into specific room.
        # todo - if it can't do this then it start to change other orders.

        status, room_id = new_order.try_schedule_simple_algorithm(
            company, facility, min_permission, len(participants))

        print(room_id)
        if status:
            new_order.save_to_mongodb()
            #if cls.is_send_mail(date):
            #   cls.send_mail(user_email, room_id, date, start_time, end_time)
            return True, new_order._id, room_id
        else:
            if cls.is_send_mail(date) == False:
                pass
                all_conflict_orders = Order.find_by_date_and_time_facility(
                    date, start_time, end_time, facility)
                all_conflict_orders.append(new_order)
                all_conflict_schedules = Schedule.get_by_date_and_hour(
                    date, start_time, end_time)
                cls.remove_conflict_schedule(all_conflict_schedules, date,
                                             start_time, end_time)
                status, room_id = cls.bactracking_algorithm(
                    all_conflict_orders, facility, date, start_time, end_time)
                if status == True:
                    new_order.save_to_mongodb()
                    if cls.is_send_mail(date):
                        cls.send_mail(cls, user_email, room_id, date,
                                      start_time, end_time)
                    return True, new_order._id, room_id
        return False, "There is not empty room", 'failed'
Пример #15
0
 def simple_algo_simulation(cls, all_conflict_orders, all_rooms, date,
                            start_time, end_time):
     index_room = 0
     already_scheduled = []
     for order in all_conflict_orders:
         order_id = order.get_id()
         participents_order = order.get_participents()
         index_room = Room.get_next_room_from_list_simulation(
             all_rooms, index_room, len(participents_order), date,
             start_time, end_time)
         if index_room == -1:
             cls.remove_conflict_schedule_simulation(
                 already_scheduled, date, start_time, end_time)
             return False, "There is no room"
         room = all_rooms[index_room]
         room_id = room.get_id_room()
         Schedule.assign_all_simulation(date, participents_order,
                                        start_time, end_time, order_id,
                                        room_id)
         scheds_by_order = Schedule.get_by_order_simulation(order_id)
         already_scheduled.append(scheds_by_order[0])
     return True, room_id
Пример #16
0
 def aux_backtracking(cls, all_conflict_orders, index_order, all_rooms,
                      num_rooms, date, start_time, end_time):
     if index_order > len(all_conflict_orders) - 1:
         return True
     for i in range(num_rooms):
         if all_conflict_orders[index_order] <= all_rooms[i]:
             room = all_rooms[i]
             room_occupation_current = room.occupation_room(
                 date, start_time, end_time)
             order = all_conflict_orders[index_order]
             order_id = order.get_id()
             demanded_space = order.get_num_parctipents()
             participents_order = order.get_participents()
             after_occupency_room = room_occupation_current - demanded_space
             room_id = room.get_id_room()
             Schedule.assign_all(date, participents_order, start_time,
                                 end_time, order_id, room_id)
             #all_rooms[i] = room_occupation_current  - all_conflict_orders[index_order].
             return cls.aux_backtracking(all_conflict_orders,
                                         index_order + 1, all_rooms,
                                         num_rooms)
     return False
Пример #17
0
    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, end_time)

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

        if status:
            # not finish yet
            Schedule.assign_all_simulation(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
Пример #18
0
 def get_all_participants_in_facility_simulation(manager, facility_name,
                                                 duration):
     rooms = Room.get_by_facility_simulation(manager.company, facility_name)
     if rooms is None:
         return
     sum_visits = 0
     for day in range(duration):
         for room in rooms:
             schedules = Schedule.get_by_room_and_date_simulation(
                 room._id, (datetime.now() +
                            timedelta(days=day)).strftime('%d/%m/%Y'))
             for sched in schedules:
                 sum_visits += len(sched.participants)
     return sum_visits / duration
Пример #19
0
 def get_schedules(self):
     return Schedule.get_by_room(self._id)
Пример #20
0
def test_schedules_orders3():
    User.print_values()
    Database.initialize()
    Database.dropAll()
    # Database.find_one('orders', {'_id' : '23/05/18' })
    # num1 = Database.count('orders')
    # Database.remove('orders', {'_id': '23/05/18'})
    # num2 = Database.count('orders')

    Manager.manager_register("*****@*****.**", 'admin', 'Admin admin', '000000000', 'eng', 1, 'YAHOO', 'matam')

    status, room_id = Room.add_room(2, 2, 1, 3, 'YAHOO', 'matam',
                                    True)  ########################################changed capacity
    assert status is True
    status, room_id = Room.add_room(2, 1, 3, 4, 'YAHOO', 'matam', False)
    assert status is True
    assert Room.remove_room(room_id) is True
    status, room_id = Room.add_room(2, 1, 3, 4, 'YAHOO', 'matam', True)
    status, room_id = Room.add_room(2, 2, 4, 4, 'YAHOO', 'matam', True)

    num1 = Database.count('orders')
    Database.remove('orders', {'_id': '23/05/18'})
    num2 = Database.count('orders')
    Database.remove('orders', {'date': '26/05/18'})
    num3 = Database.count('orders')
    num_users1 = Database.count('users')
    Manager.user_register("*****@*****.**", '123', 'foox', '000002600', 'eng', 3, 'YAHOO', 'matam')
    Manager.user_register("*****@*****.**", '123', 'yan', '026000000', 'eng', 3, 'YAHOO', 'matam')
    Manager.user_register("*****@*****.**", '456', 'bim', '313324360', 'eng', 3, 'YAHOO', 'matam')
    num_users2 = Database.count('users')
    user2 = User.get_by_email('*****@*****.**')
    user3 = User.get_by_email('*****@*****.**')

    manager = Manager.get_by_email('*****@*****.**')
    assert manager is None
    manager = Manager.get_by_email('*****@*****.**')
    assert manager is not None
    try:
        manager.import_rooms(os.getcwd() + '\\rooms.csv')
        manager.import_employee(os.getcwd() + '\\employee.csv')
    # should'nt works on travis
    except Exception as e:
        pass
    num_users2 = Database.count('users')

    user1 = User.get_by_email('*****@*****.**')
    user2 = User.get_by_email('*****@*****.**')
    user3 = User.get_by_email('*****@*****.**')
    participants1 = ['*****@*****.**', '*****@*****.**']
    participants2 = ['*****@*****.**']
    participants3 = ['*****@*****.**', '*****@*****.**']
    date = datetime.utcnow().strftime('%d/%m/%y')
    # date ='12/06/18'
    status2, string2 = user2.new_order(date, participants2, 6, 7, "YAHOO", 'matam')
    schedules2 = user2.get_schedule()

    status1, string1 = user1.new_order(date, participants1, 6, 7, "YAHOO", 'matam')
    schedules1 = user1.get_schedule()
    schedules2 = user2.get_schedule()

    status1, string1 = user3.new_order(date, participants3, 7, 8, "YAHOO", 'matam')
    schedules1 = user1.get_schedule()
    schedules2 = user2.get_schedule()
    schedules3 = user3.get_schedule()
    assert len(schedules1) > 0
    assert len(schedules2) > 0
    assert len(schedules3) == 0

    print(string1)

    orders = user1.get_orders()
    num_orders = len(orders)
    assert len(user1.get_orders()) > 0
    schedules1 = user1.get_schedule()
    assert len(schedules1) > 0
    schedules = Schedule.get_schedules('*****@*****.**')
    assert len(Schedule.get_by_room("YAHOO matam 1")) > 0
    schedules2 = user2.get_schedule()
    assert len(schedules2) > 0
Пример #21
0
 def __init__(self):
     self.parser = reqparse.RequestParser()
     self.interface = FirebaseInterface()
     self.schedule = Schedule()
Пример #22
0
class SchedulesController(Resource):
    def __init__(self):
        self.parser = reqparse.RequestParser()
        self.interface = FirebaseInterface()
        self.schedule = Schedule()

    def post(self):
        req = request.get_json()

        try:
            office_id = req["id_oficina"]
            office = self.interface.getData("offices", office_id)

            if office is None:
                raise Exception("Oficina não encontrada")

            self.schedule.buildObject(req)
            self.schedule.validateFields(office["agenda"])
            self.schedule.setId()

            office["agenda"].append(self.schedule.__dict__)
            self.interface.updateData(office, "offices", office["id"])

            result = "Evento criado com sucesso"
            http_return_code = 201

        except Exception as e:
            http_return_code = 400
            result = str(e)

        return result, http_return_code

    def delete(self, office_id, event_id):
        try:
            office = self.interface.getData("offices", office_id)

            if office is None:
                raise Exception("Oficina não encontrada")

            index = self.schedule.findIdIndex(int(event_id), office["agenda"])
            office["agenda"].pop(index)

            self.interface.updateData(office, "offices", office_id)

            result = "Evento removido com sucesso"
            http_return_code = 200

        except Exception as e:
            http_return_code = 400
            result = str(e)

        return result, http_return_code

    def get(self, office_id):
        try:
            office = self.interface.getData("offices", office_id)

            if office is None:
                raise Exception("Oficina não encontrada")

            schedule = {"data": office["agenda"]}

            data = json.dumps(schedule)
            result = json.loads(data)
            http_return_code = 200

        except Exception as e:
            result = str(e)
            http_return_code = 400

        return result, http_return_code

    def put(self):
        req = request.get_json()

        try:
            office_id = req["id_oficina"]
            office = self.interface.getData("offices", office_id)

            if office is None:
                raise Exception("Oficina não encontrada")

            self.schedule.buildObject(req)
            self.schedule.validateFields(office["agenda"])

            id = req["id_evento"]
            index = self.schedule.findIdIndex(id, office["agenda"])
            self.schedule.id = id

            office["agenda"][index] = self.schedule.__dict__
            self.interface.updateData(office, "offices", office_id)

            result = "Evento alterado com sucesso"
            http_return_code = 200

        except Exception as e:
            result = str(e)
            http_return_code = 400

        return result, http_return_code
Пример #23
0
 def _create_schedule(cls):
     schedule = Schedule()
     unique_token = "%.6f" % time.time()
     schedule.set_priority(1)
     schedule.set_comment("Test comment for schedule %s" % unique_token)
     schedule.set_pitch(2)
     schedule.set_speed(80)
     schedule.set_next_repetition('2020-12-12')
     return schedule
Пример #24
0
 def get_schedules_simulation(self):
     return Schedule.get_by_room_simulation(self._id)