本文整理汇总了Python中MaKaC.rb_reservation.ReservationBase.getCollisions方法的典型用法代码示例。如果您正苦于以下问题:Python ReservationBase.getCollisions方法的具体用法?Python ReservationBase.getCollisions怎么用?Python ReservationBase.getCollisions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaKaC.rb_reservation.ReservationBase
的用法示例。
在下文中一共展示了ReservationBase.getCollisions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _postprocess
# 需要导入模块: from MaKaC.rb_reservation import ReservationBase [as 别名]
# 或者: from MaKaC.rb_reservation.ReservationBase import getCollisions [as 别名]
def _postprocess(self, obj, fossil, iface):
if iface is IRoomMetadataWithReservationsFossil:
(startDT, endDT) = (self._fromDT or MIN_DATETIME,
self._toDT or MAX_DATETIME)
if self._fromDT or self._toDT:
toDate = self._toDT.date() if self._toDT else None
fromDate = self._fromDT.date() if self._fromDT else None
resvEx = ReservationBase()
resvEx.startDT = startDT
resvEx.endDT = endDT
resvEx.room = obj
resvEx.isRejected = False
resvEx.isCancelled = False
if fromDate != toDate:
resvEx.repeatability = RepeatabilityEnum.daily
resvs = set(c.withReservation for c in resvEx.getCollisions())
else:
resvs = obj.getReservations()
iresvs1, iresvs2 = itertools.tee(itertools.ifilter(self._resvFilter, resvs), 2)
fresvs = fossilize(iresvs1, IRoomReservationMetadataFossil, tz=self._tz, naiveTZ=self._serverTZ)
for fresv, resv in itertools.izip(iter(fresvs), iresvs2):
self._addOccurrences(fresv, resv, startDT, endDT)
fossil['reservations'] = fresvs
return fossil
示例2: getAverageOccupation
# 需要导入模块: from MaKaC.rb_reservation import ReservationBase [as 别名]
# 或者: from MaKaC.rb_reservation.ReservationBase import getCollisions [as 别名]
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)
示例3: getMyAverageOccupation
# 需要导入模块: from MaKaC.rb_reservation import ReservationBase [as 别名]
# 或者: from MaKaC.rb_reservation.ReservationBase import getCollisions [as 别名]
def getMyAverageOccupation( self, period="pastmonth" ):
"""
FINAL (not intented to be overriden)
Returns float <0, 1> representing how often - on the avarage -
the room is booked during the working hours. (1 == all the time, 0 == never).
"""
# Find collisions with last month period
from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum
resvEx = ReservationBase()
now = datetime.now()
if period == "pastmonth":
resvEx.endDT = datetime( now.year, now.month, now.day, 17, 30 )
resvEx.startDT = resvEx.endDT - timedelta( 30, 9 * 3600 ) # - 30 days and 9 hours
elif period == "thisyear":
resvEx.endDT = datetime( now.year, now.month, now.day, 17, 30 )
resvEx.startDT = datetime( now.year, 1, 1, 0, 0 )
resvEx.repeatability = RepeatabilityEnum.daily
collisions = resvEx.getCollisions( rooms = [self] )
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 # Hours
bookedTime = booked.days * 24 + 1.0 * booked.seconds / 3600 # Hours
if totalBookableTime > 0:
return bookedTime / totalBookableTime
else:
return 0
示例4: getAverageOccupation
# 需要导入模块: from MaKaC.rb_reservation import ReservationBase [as 别名]
# 或者: from MaKaC.rb_reservation.ReservationBase import getCollisions [as 别名]
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
示例5: getMyAverageOccupation
# 需要导入模块: from MaKaC.rb_reservation import ReservationBase [as 别名]
# 或者: from MaKaC.rb_reservation.ReservationBase import getCollisions [as 别名]
def getMyAverageOccupation(self, period="pastmonth"):
"""
FINAL (not intented to be overriden)
Returns float <0, 1> representing how often - on the avarage -
the room is booked during the working hours. (1 == all the time, 0 == never).
"""
# Find collisions with the givenmonth period
from MaKaC.rb_reservation import ReservationBase, RepeatabilityEnum
resvEx = ReservationBase()
resvEx.endDT = datetime.combine(date.today(), time(17, 30))
if period == "thisyear":
resvEx.startDT = datetime(date.today().year, 1, 1, 8, 30)
elif period == "pastmonth":
resvEx.startDT = resvEx.endDT.replace(hour=8) - timedelta(days=30)
elif period == "pastyear":
resvEx.startDT = resvEx.endDT.replace(hour=8) - timedelta(days=365)
else:
raise ValueError("Invalid period: {0}".format(period))
resvEx.repeatability = RepeatabilityEnum.daily
collisions = resvEx.getCollisions(rooms=[self])
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 # Hours
bookedTime = (booked.days * 86400 + booked.seconds) / 3600.0
if totalBookableTime > 0:
return bookedTime / totalBookableTime
else:
return 0