我正在写一个考勤/ 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