def _main(args): yesterday = date.today() - relativedelta(days=1) past_month = yesterday - relativedelta(days=29) past_year = yesterday - relativedelta(years=1) if not args.locations: rooms = Room.find_all() else: rooms = Room.find_all(Location.name.in_(args.locations), _join=Location) print 'Month\tYear\tRoom' for room in rooms: print '{1:.3f}\t{2:.3f}\t{0}'.format(room.full_name, calculate_rooms_occupancy([room], past_month, yesterday) * 100, calculate_rooms_occupancy([room], past_year, yesterday) * 100)
def _main(location): yesterday = date.today() - relativedelta(days=1) past_month = yesterday - relativedelta(days=29) past_year = yesterday - relativedelta(years=1) if not location: rooms = Room.find_all() else: rooms = Room.find_all(Location.name.in_(location), _join=Location) print('Month\tYear\tPublic?\tRoom') for room in rooms: print('{2:.2f}%\t{3:.2f}%\t{1}\t{0}'.format( room.full_name, "Y" if room.is_public else "N", calculate_rooms_occupancy([room], past_month, yesterday) * 100, calculate_rooms_occupancy([room], past_year, yesterday) * 100))
def get_room_statistics(room): data = { 'count': { 'id': 'times_booked', 'values': [], 'note': False }, 'percentage': { 'id': 'occupancy', 'values': [], 'note': True } } ranges = [7, 30, 365] end_date = date.today() for days in ranges: start_date = date.today() - relativedelta(days=days) count = (ReservationOccurrence.query.join( ReservationOccurrence.reservation).join(Reservation.room).filter( Room.id == room.id, ReservationOccurrence.is_valid, db_dates_overlap(ReservationOccurrence, 'start_dt', datetime.combine(start_date, time()), 'end_dt', datetime.combine(end_date, time.max))).count()) percentage = calculate_rooms_occupancy([room], start_date, end_date) * 100 if count > 0 or percentage > 0: data['count']['values'].append({'days': days, 'value': count}) data['percentage']['values'].append({ 'days': days, 'value': percentage }) return data
def _process(self): rooms = sorted(self._location.rooms, key=lambda r: natural_sort_key(r.full_name)) kpi = {} if self._with_kpi: kpi['occupancy'] = calculate_rooms_occupancy( self._location.rooms.all()) kpi['total_rooms'] = self._location.rooms.count() kpi['active_rooms'] = self._location.rooms.filter_by( is_active=True).count() kpi['reservable_rooms'] = self._location.rooms.filter_by( is_reservable=True).count() kpi['reservable_capacity'] = (self._location.rooms.with_entities( func.sum( Room.capacity)).filter_by(is_reservable=True).scalar()) kpi['reservable_surface'] = (self._location.rooms.with_entities( func.sum( Room.surface_area)).filter_by(is_reservable=True).scalar()) kpi['booking_stats'] = compose_rooms_stats( self._location.rooms.all()) kpi['booking_count'] = Reservation.find( Reservation.room_id.in_( r.id for r in self._location.rooms)).count() return WPRoomBookingAdminLocation( self, location=self._location, rooms=rooms, action_succeeded=self._actionSucceeded, equipment_types=self._location.equipment_types.all(), attributes=self._location.attributes.all(), kpi=kpi).display()
def _process(self): rooms = sorted(self._location.rooms, key=lambda r: natural_sort_key(r.full_name)) kpi = {} if self._with_kpi: kpi['occupancy'] = calculate_rooms_occupancy(self._location.rooms) kpi['total_rooms'] = len(self._location.rooms) kpi['active_rooms'] = sum(1 for room in self._location.rooms if room.is_active) kpi['reservable_rooms'] = sum(1 for room in self._location.rooms if room.is_reservable) kpi['reservable_capacity'] = sum(room.capacity or 0 for room in self._location.rooms if room.is_reservable) kpi['reservable_surface'] = sum(room.surface_area or 0 for room in self._location.rooms if room.is_reservable) kpi['booking_stats'] = compose_rooms_stats(self._location.rooms) kpi['booking_count'] = Reservation.find( Reservation.room.has(Room.location == self._location)).count() return WPRoomBookingAdminLocation( self, 'rb-rooms', location=self._location, rooms=rooms, action_succeeded=self._actionSucceeded, equipment_types=self._location.equipment_types.all(), attributes=self._location.attributes.all(), kpi=kpi).display()
def get_room_statistics(room): data = { 'count': { 'id': 'times_booked', 'values': [], 'note': False }, 'percentage': { 'id': 'occupancy', 'values': [], 'note': True } } ranges = [7, 30, 365] end_date = date.today() for days in ranges: start_date = date.today() - relativedelta(days=days) count = (ReservationOccurrence.query .join(ReservationOccurrence.reservation) .join(Reservation.room) .filter(Room.id == room.id, ReservationOccurrence.is_valid, db_dates_overlap(ReservationOccurrence, 'start_dt', datetime.combine(start_date, time()), 'end_dt', datetime.combine(end_date, time.max))) .count()) percentage = calculate_rooms_occupancy([room], start_date, end_date) * 100 if count > 0 or percentage > 0: data['count']['values'].append({'days': days, 'value': count}) data['percentage']['values'].append({'days': days, 'value': percentage}) return data
def _main(location): yesterday = date.today() - relativedelta(days=1) past_month = yesterday - relativedelta(days=29) past_year = yesterday - relativedelta(years=1) if not location: rooms = Room.find_all() else: rooms = Room.find_all(Location.name.in_(location), _join=Location) print 'Month\tYear\tPublic?\tRoom' for room in rooms: print '{2:.2f}%\t{3:.2f}%\t{1}\t{0}'.format(room.full_name, "Y" if room.is_public else "N", calculate_rooms_occupancy([room], past_month, yesterday) * 100, calculate_rooms_occupancy([room], past_year, yesterday) * 100)
def _process(self): return WPRoomBookingRoomStats( self, room=self._room, period=self._occupancy_period, occupancy=calculate_rooms_occupancy([self._room], self._start, self._end), stats=compose_rooms_stats([self._room])).display()
def _main(args): today = date.today() past_month = today - relativedelta(months=1) past_year = today - relativedelta(years=1) if not args.locations: rooms = Room.find_all() else: rooms = Room.find_all(Location.name.in_(args.locations), _join=Location) print 'Month\tYear\tRoom' for room in rooms: print '{1:.3f}\t{2:.3f}\t{0}'.format( room.full_name, calculate_rooms_occupancy([room], past_month, today) * 100, calculate_rooms_occupancy([room], past_year, today) * 100)
def _main(location): yesterday = date.today() - relativedelta(days=1) past_month = yesterday - relativedelta(days=29) past_year = yesterday - relativedelta(years=1) query = Room.query if location: query = query.join(Location).filter(Location.name.in_(location)) rooms = sorted( query, key=lambda r: natural_sort_key(r.location_name + r.full_name)) print('Month\tYear\tPublic?\tRoom') for room in rooms: print('{2:.2f}%\t{3:.2f}%\t{1}\t{0}'.format( room.full_name, "Y" if room.is_public else "N", calculate_rooms_occupancy([room], past_month, yesterday) * 100, calculate_rooms_occupancy([room], past_year, yesterday) * 100))
def _process(self): return WPRoomBookingRoomStats( self, room=self._room, period=self._occupancy_period, occupancy=calculate_rooms_occupancy([self._room], self._start, self._end), stats=compose_rooms_stats([self._room]), ).display()
def _process(self): last_year = str(date.today().year - 1) last_month_date = date.today() - relativedelta(months=1, day=1) last_month = '{:d}-{:02d}'.format(last_month_date.year, last_month_date.month) return WPRoomBookingRoomStats(self, room=self._room, period=self._occupancy_period, last_year=last_year, last_month=last_month, occupancy=calculate_rooms_occupancy([self._room], self._start, self._end), stats=compose_rooms_stats([self._room])).display()
def _process(self): rooms = sorted(self._location.rooms, key=lambda r: natural_sort_key(r.full_name)) kpi = {} if self._with_kpi: kpi['occupancy'] = calculate_rooms_occupancy(self._location.rooms) kpi['total_rooms'] = len(self._location.rooms) kpi['active_rooms'] = sum(1 for room in self._location.rooms if room.is_active) kpi['reservable_rooms'] = sum(1 for room in self._location.rooms if room.is_reservable) kpi['reservable_capacity'] = sum(room.capacity or 0 for room in self._location.rooms if room.is_reservable) kpi['reservable_surface'] = sum(room.surface_area or 0 for room in self._location.rooms if room.is_reservable) kpi['booking_stats'] = compose_rooms_stats(self._location.rooms) kpi['booking_count'] = Reservation.find(Reservation.room.has(Room.location == self._location)).count() return WPRoomBookingAdminLocation(self, 'rb-rooms', location=self._location, rooms=rooms, action_succeeded=self._actionSucceeded, equipment_types=self._location.equipment_types.all(), attributes=self._location.attributes.all(), kpi=kpi).display()
def _process(self): rooms = sorted(self._location.rooms, key=lambda r: natural_sort_key(r.full_name)) kpi = {} if self._with_kpi: kpi['occupancy'] = calculate_rooms_occupancy(self._location.rooms.all()) kpi['total_rooms'] = self._location.rooms.count() kpi['active_rooms'] = self._location.rooms.filter_by(is_active=True).count() kpi['reservable_rooms'] = self._location.rooms.filter_by(is_reservable=True).count() kpi['reservable_capacity'] = (self._location.rooms.with_entities(func.sum(Room.capacity)) .filter_by(is_reservable=True).scalar()) kpi['reservable_surface'] = (self._location.rooms.with_entities(func.sum(Room.surface_area)) .filter_by(is_reservable=True).scalar()) kpi['booking_stats'] = compose_rooms_stats(self._location.rooms.all()) kpi['booking_count'] = Reservation.find(Reservation.room_id.in_(r.id for r in self._location.rooms)).count() return WPRoomBookingAdminLocation(self, location=self._location, rooms=rooms, action_succeeded=self._actionSucceeded, equipment_types=self._location.equipment_types.all(), attributes=self._location.attributes.all(), kpi=kpi).display()