def _getAnswer( self ): minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() result = {} if minfo.getRoomBookingModuleActive(): locationNames = map(lambda l: l.friendlyName, Location.allLocations) for loc in locationNames: roomEx = Factory.newRoom() roomEx.isActive = self._isActive for room in CrossLocationQueries.getRooms( location = loc, roomExample=roomEx ): result[str(room.guid)] = "%s: %s" % (loc, room.getFullName()) return result
def _getAnswer(self): minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() result = {} if minfo.getRoomBookingModuleActive(): locationNames = map(lambda l: l.friendlyName, Location.allLocations) for loc in locationNames: roomEx = Factory.newRoom() roomEx.isActive = self._isActive for room in CrossLocationQueries.getRooms(location=loc, roomExample=roomEx): result[str( room.guid)] = "%s: %s" % (loc, room.getFullName()) return result
def getAverageOccupation(**kwargs): """ FINAL (not intented to be overriden) Returns float <0, 1> representing how often - on the avarage - the rooms are booked during the working hours. (1 == all the time, 0 == never). """ name = kwargs.get('location', Location.getDefaultLocation().friendlyName) # Get active, publically reservable rooms from MaKaC.rb_factory import Factory roomEx = Factory.newRoom() roomEx.isActive = True roomEx.isReservable = True rooms = CrossLocationQueries.getRooms(roomExample=roomEx, location=name) # Find collisions with last month period from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum resvEx = ReservationBase() now = datetime.now() resvEx.endDT = datetime(now.year, now.month, now.day, 17, 30) resvEx.startDT = resvEx.endDT - timedelta( 30, 9 * 3600) # - 30 days and 9 hours resvEx.repeatability = RepeatabilityEnum.daily collisions = resvEx.getCollisions(rooms=rooms) totalWorkingDays = 0 weekends = 0 for day in iterdays(resvEx.startDT, resvEx.endDT): if day.weekday() in [5, 6]: # Skip Saturday and Sunday weekends += 1 continue # if c.startDT is CERN Holiday: continue totalWorkingDays += 1 booked = timedelta(0) for c in collisions: if c.startDT.weekday() in [5, 6]: # Skip Saturday and Sunday continue # if c.startDT is CERN Holiday: continue booked = booked + (c.endDT - c.startDT) totalBookableTime = totalWorkingDays * 9 * len(rooms) # Hours bookedTime = booked.days * 24 + 1.0 * booked.seconds / 3600 # Hours if totalBookableTime > 0: return bookedTime / totalBookableTime else: return 0 # Error (no rooms in db)
def getAverageOccupation( **kwargs ): """ FINAL (not intented to be overriden) Returns float <0, 1> representing how often - on the avarage - the rooms are booked during the working hours. (1 == all the time, 0 == never). """ name = kwargs.get( 'location', Location.getDefaultLocation().friendlyName ) # Get active, publically reservable rooms from MaKaC.rb_factory import Factory roomEx = Factory.newRoom() roomEx.isActive = True roomEx.isReservable = True rooms = CrossLocationQueries.getRooms( roomExample = roomEx, location = name ) # Find collisions with last month period from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum resvEx = ReservationBase() now = datetime.now() resvEx.endDT = datetime( now.year, now.month, now.day, 17, 30 ) resvEx.startDT = resvEx.endDT - timedelta( 30, 9 * 3600 ) # - 30 days and 9 hours resvEx.repeatability = RepeatabilityEnum.daily collisions = resvEx.getCollisions( rooms = rooms ) totalWorkingDays = 0 weekends = 0 for day in iterdays( resvEx.startDT, resvEx.endDT ): if day.weekday() in [5,6]: # Skip Saturday and Sunday weekends += 1 continue # if c.startDT is CERN Holiday: continue totalWorkingDays += 1 booked = timedelta( 0 ) for c in collisions: if c.startDT.weekday() in [5,6]: # Skip Saturday and Sunday continue # if c.startDT is CERN Holiday: continue booked = booked + ( c.endDT - c.startDT ) totalBookableTime = totalWorkingDays * 9 * len( rooms ) # Hours bookedTime = booked.days * 24 + 1.0 * booked.seconds / 3600 # Hours if totalBookableTime > 0: return bookedTime / totalBookableTime else: return 0 # Error (no rooms in db)
def getReservations(): from MaKaC.rb_room import RoomBase Test.dalManager.connect() roomEx = Factory.newRoom() roomEx.name = 'TH AMPHITHEATRE' resvEx = Factory.newReservation() resvEx.startDT = datetime( 2006, 12, 01, 10 ) resvEx.endDT = datetime( 2006, 12, 14, 15 ) #resvEx.bookedForName = 'Jean-Jacques Blais' resvs = ReservationBase.getReservations( resvExample = resvEx, rooms = [roomEx] ) for resv in resvs: print "=============================" print resv Test.dalManager.disconnect()
def getAverageOccupation(**kwargs): """ FINAL (not intented to be overriden) Returns float <0, 1> representing how often - on the avarage - the rooms are booked during the working hours. (1 == all the time, 0 == never). """ name = kwargs.get("location", Location.getDefaultLocation().friendlyName) # Get active, publically reservable rooms from MaKaC.rb_factory import Factory roomEx = Factory.newRoom() roomEx.isActive = True roomEx.isReservable = True rooms = CrossLocationQueries.getRooms(roomExample=roomEx, location=name) # Find collisions with last month period from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum resvEx = ReservationBase() resvEx.endDT = datetime.combine(date.today(), time(17, 30)) resvEx.startDT = resvEx.endDT.replace(hour=8) - timedelta(days=30) resvEx.repeatability = RepeatabilityEnum.daily collisions = resvEx.getCollisions(rooms=rooms) totalWorkingDays = sum(1 for day in iterdays(resvEx.startDT, resvEx.endDT) if day.weekday() not in (5, 6)) booked = timedelta() for c in collisions: if c.startDT.weekday() in (5, 6): # skip Saturday and Sunday continue booked += c.endDT - c.startDT totalBookableTime = totalWorkingDays * 9 * len(rooms) # Hours bookedTime = (booked.days * 86400 + booked.seconds) / 3600.0 if totalBookableTime > 0: return bookedTime / totalBookableTime else: return 0
def getRooms(*args, **kwargs): """ Returns list of rooms meeting specified conditions. It is 'query by example'. You specify conditions by creating the object and passing it to the method. All arguments are optional: roomID - just a shortcut. Will return ONE room (not a list) or None. roomName - just a shortcut. Will return ONE room (not a list) or None. roomExample - example RoomBase object. reservationExample - example ReservationBase object. Represents reservation period. available - Bool, true if room must be available, false if must be booked, None if do not care freeText - str, room will be found if this string will be found anywhere in the object i.e. in equipment list, comments, responsible etc. minCapacity - Bool, defaults to False. If True, then rooms of capacity >= will be found. Otherwise capacity it looks for rooms with capacity within 20% range. allFast - Bool, defaults to False. If True, ALL active rooms will be returned in ultra fast way, REGARDLESS of all other options. ownedBy - Avatar customAtts - for rooms with custom attributes. rooms with no .customAtts attributes will be filtered out if this parameter is present The customAtts attribute should be a list of dictionaries with the attributes "name", "allowEmpty", "filter". "name" -> the name of the custom attribute "allowEmpty" -> if we allow the custom attribute to be empty or not (empty = "" or string with only whitespaces) "filter" -> a function to which we will pass the value of the custom attribute and has to return True or False. If there is more than 1 dictionary in the list, it will be like doing an AND of the conditions they represent. (see example 6) Examples: # 1. Get all rooms rooms = RoomBase.getRooms() # 2. Get all rooms with capacity about 30 r = Factory.newRoom() r.capacity = 30 rooms = RoomBase.getRooms( roomExample = r ) # 3. Get all rooms reserved on the New Year 2007, # which have capacity about 30, are at Meyrin site and have 'jean' in comments. r = Factory.newRoom() r.capacity = 30 r.site = 'Meyrin' r.comments = 'jean' p = ReservationBase() p.startDT = datetime.datetime( 2007, 01, 01 ) p.endDT = datetime.datetime( 2007, 01, 01 ) p.repeatability = None rooms = RoomBase.getRooms( roomExample = r, reservationExample = p, available = False ) # 4. Get all rooms containing "sex" in their attributes rooms = RoomBase.getRooms( freeText = 'sex' ) # 5. Get room 'AT AMPHITHEATRE' oneRoom = RoomBase.getRooms( roomName = 'AT AMPHITHEATRE' ) #6. Get rooms with a H.323 IP defined rooms = RoomBase.getRooms ( customAtts = [{"name":'H323 IP', "allowEmpty":False, "filter": (lambda ip: validIP(ip))}]) """ # Simply redirect to the plugin from MaKaC.rb_factory import Factory return Factory.newRoom().getRooms(**kwargs)
def getRooms( *args, **kwargs ): """ Returns list of rooms meeting specified conditions. It is 'query by example'. You specify conditions by creating the object and passing it to the method. All arguments are optional: roomID - just a shortcut. Will return ONE room (not a list) or None. roomName - just a shortcut. Will return ONE room (not a list) or None. roomExample - example RoomBase object. reservationExample - example ReservationBase object. Represents reservation period. available - Bool, true if room must be available, false if must be booked, None if do not care freeText - str, room will be found if this string will be found anywhere in the object i.e. in equipment list, comments, responsible etc. minCapacity - Bool, defaults to False. If True, then rooms of capacity >= will be found. Otherwise capacity it looks for rooms with capacity within 20% range. allFast - Bool, defaults to False. If True, ALL active rooms will be returned in ultra fast way, REGARDLESS of all other options. ownedBy - Avatar customAtts - for rooms with custom attributes. rooms with no .customAtts attributes will be filtered out if this parameter is present The customAtts attribute should be a list of dictionaries with the attributes "name", "allowEmpty", "filter". "name" -> the name of the custom attribute "allowEmpty" -> if we allow the custom attribute to be empty or not (empty = "" or string with only whitespaces) "filter" -> a function to which we will pass the value of the custom attribute and has to return True or False. If there is more than 1 dictionary in the list, it will be like doing an AND of the conditions they represent. (see example 6) Examples: # 1. Get all rooms rooms = RoomBase.getRooms() # 2. Get all rooms with capacity about 30 r = Factory.newRoom() r.capacity = 30 rooms = RoomBase.getRooms( roomExample = r ) # 3. Get all rooms reserved on the New Year 2007, # which have capacity about 30, are at Meyrin site and have 'jean' in comments. r = Factory.newRoom() r.capacity = 30 r.site = 'Meyrin' r.comments = 'jean' p = ReservationBase() p.startDT = datetime.datetime( 2007, 01, 01 ) p.endDT = datetime.datetime( 2007, 01, 01 ) p.repeatability = None rooms = RoomBase.getRooms( roomExample = r, reservationExample = p, available = False ) # 4. Get all rooms containing "sex" in their attributes rooms = RoomBase.getRooms( freeText = 'sex' ) # 5. Get room 'AT AMPHITHEATRE' oneRoom = RoomBase.getRooms( roomName = 'AT AMPHITHEATRE' ) #6. Get rooms with a H.323 IP defined rooms = RoomBase.getRooms ( customAtts = [{"name":'H323 IP', "allowEmpty":False, "filter": (lambda ip: validIP(ip))}]) """ # Simply redirect to the plugin from MaKaC.rb_factory import Factory return Factory.newRoom().getRooms( **kwargs )
roomIDs = params.get("r").strip().split(",") if roomIDs == "": return """At least one roomID must be specified (http://....?r=1,42,14,...)""" try: roomIDs = map(lambda x: int(x), roomIDs) except ValueError: return """Room IDs must be integers separated by commas (http://....?r=1,42,14,...)""" if len(roomIDs) > 10: return "One can only export 10 rooms at most" #################### process ################### rooms = [] for roomID in roomIDs: roomEx = Factory.newRoom() roomEx.id = roomID rooms.append(roomEx) resvEx = Factory.newReservation() resvEx.isCancelled = False resvEx.isRejected = False resvEx.startDT = datetime(sd.year, sd.month, sd.day, 0, 0) resvEx.endDT = datetime(ed.year, ed.month, ed.day, 23, 59) resvs = CrossLocationQueries.getReservations(location="CERN", resvExample=resvEx, rooms=rooms) collisions = [] for resv in resvs: for p in resv.splitToPeriods(endDT=resvEx.endDT, startDT=resvEx.startDT): collisions.append(Collision( ( p.startDT, p.endDT ), resv )) of = params.get("of", "csv")