我正在寫一個考勤/ PTO跟蹤應用程序,並且我絕對難以確定如何確定在兩個給定日期時間(開始和結束)之間工作的代理的最小數量。這將用於確定代理是否可以請求關閉(如果他們將在任何時候獨處,他們將被自動拒絕)。鑑於以下數據庫模式:確定在時間範圍內可用的最小用戶數
metadata = MetaData(engine) #< engine is an already established mysql conn
# Users table declaration
self.Users = Table(
'Users', metadata,
Column(u'ID', Integer(), primary_key=True, nullable=False,
index=True),
Column(u'Username', Unicode(16), nullable=False, index=True),
Column(u'Firstname', Unicode(16), nullable=False),
Column(u'Lastname', Unicode(50), nullable=False, index=True),
Column(u'Nickname', Unicode(16), nullable=False),
Column(u'Email', Unicode(16), nullable=False),
Column(u'AvayaID', Integer(), nullable=False, index=True),
Column(u'ManagerID', Integer(), nullable=False, index=True),
Column(u'ShiftID', Integer(), ForeignKey('Shifts.ID'), nullable=False),
Column(u'DaysID', Integer(), ForeignKey('Days.ID'), nullable=False),
)
# Shifts table declaration - Shift times
self.Shifts = Table(
'Shifts', metadata,
Column(u'ID', Integer(), primary_key=True, nullable=False, index=True),
Column(u'Start', DateTime()),
Column(u'End', DateTime()),
)
# Days table declaration - Days of week worked
self.Days = Table(
'Days', metadata,
Column(u'ID', Integer(), primary_key=True, nullable=False),
Column(u'Sat', Integer(1), nullable=False),
Column(u'Sun', Integer(1), nullable=False),
Column(u'Mon', Integer(1), nullable=False),
Column(u'Tue', Integer(1), nullable=False),
Column(u'Wed', Integer(1), nullable=False),
Column(u'Thu', Integer(1), nullable=False),
Column(u'Fri', Integer(1), nullable=False),
)
Users
表有兩個外鍵,對應於Shifts
表ShiftID
並在Days
表DaysID
。 Shifts
表只保存可能的移位開始/結束時間,Days
表包含可能的工作組合。整個表加入我產生類似的結構:
{
'Username' : str, #< Agent username
'ManagerID' : int, #< Agent manager ID
'Shift.Start' : time,#< Agent shift start time
'Shift.End' : time, #< Agent shift end time
'Days.Sat' : bool, #< If agent works this day normally
'Days.Sun' : bool, #< If agent works this day normally
'Days.Mon' : bool, #< If agent works this day normally
'Days.Tue' : bool, #< If agent works this day normally
'Days.Wed' : bool, #< If agent works this day normally
'Days.Thu' : bool, #< If agent works this day normally
'Days.Fri' : bool, #< If agent works this day normally
}
我需要確定的代理選擇代理的轉變過程中,將提供的最低金額。
我在這裏遇到了一些問題,其中一個是我必須考慮過夜班次(start_time> end_time),另一個只是圍繞編寫這個查詢來包裝我的頭腦。我在想,我的數據庫模式是這裏的問題,但我想不出更好的結果,Google也沒有幫助。
如果您對答案感到滿意,請接受它。 – ACV