def test_remove_after(self):
        _, agent_id = self._insert_agent_to_stat_agent()
        stats = {
            dt(2012, 1, 1): {
                agent_id: {
                    'login_time': timedelta(minutes=15),
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 2): {
                agent_id: {
                    'login_time': timedelta(minutes=20),
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 3): {
                agent_id: {
                    'login_time': timedelta(minutes=25),
                    'pause_time': timedelta(minutes=13)
                },
            },
        }

        self.session.begin()
        for period_start, agents_stats in stats.iteritems():
            stat_agent_periodic_dao.insert_stats(self.session, agents_stats, period_start)
        self.session.commit()

        stat_agent_periodic_dao.remove_after(self.session, dt(2012, 1, 2))

        res = self.session.query(StatAgentPeriodic.time)

        self.assertEqual(res.count(), 1)
        self.assertEqual(res[0].time, dt(2012, 1, 1))
Ejemplo n.º 2
0
def insert_periodic_stat(dao_sess, start, end):
    time_computer = AgentTimeComputer(start, end, INTERVAL)

    login_intervals = stat_dao.get_login_intervals_in_range(
        dao_sess, start, end)
    pause_intervals = stat_dao.get_pause_intervals_in_range(
        dao_sess, start, end)

    periodic_stats_login = time_computer.compute_login_time_in_period(
        login_intervals)
    periodic_stats_pause = time_computer.compute_pause_time_in_period(
        pause_intervals)
    periodic_stats_wrapup = queue_log_dao.get_wrapup_times(
        dao_sess, start, end, INTERVAL)
    dao_sess.flush()

    periodic_stats = _merge_update_agent_statistics(
        periodic_stats_login,
        periodic_stats_pause,
        periodic_stats_wrapup,
    )

    for period, stats in periodic_stats.items():
        stat_agent_periodic_dao.insert_stats(dao_sess, stats, period)
    dao_sess.flush()
Ejemplo n.º 3
0
    def test_remove_after(self):
        _, agent_id = self._insert_agent_to_stat_agent()
        stats = {
            dt(2012, 1, 1): {
                agent_id: {
                    'login_time': timedelta(minutes=15),
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 2): {
                agent_id: {
                    'login_time': timedelta(minutes=20),
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 3): {
                agent_id: {
                    'login_time': timedelta(minutes=25),
                    'pause_time': timedelta(minutes=13)
                },
            },
        }

        self.session.begin()
        for period_start, agents_stats in stats.iteritems():
            stat_agent_periodic_dao.insert_stats(self.session, agents_stats,
                                                 period_start)
        self.session.commit()

        stat_agent_periodic_dao.remove_after(self.session, dt(2012, 1, 2))

        res = self.session.query(StatAgentPeriodic.time)

        self.assertEqual(res.count(), 1)
        self.assertEqual(res[0].time, dt(2012, 1, 1))
Ejemplo n.º 4
0
    def test_insert_periodic_stat(self):
        _, agent_id_1 = self._insert_agent_to_stat_agent()
        _, agent_id_2 = self._insert_agent_to_stat_agent()
        stats = {
            dt(2012, 01, 01, 01, 00, 00): {
                agent_id_1: {
                    'login_time': timedelta(minutes=50),
                    'pause_time': timedelta(minutes=13)
                },
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 01, 01, 02, 00, 00): {
                agent_id_1: {
                    'login_time': timedelta(minutes=20),
                    'pause_time': timedelta(minutes=33)
                },
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 01, 01, 03, 00, 00): {
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': ONE_HOUR
                },
            },
            dt(2012, 01, 01, 04, 00, 00): {
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': ONE_HOUR
                },
            }
        }

        self.session.begin()
        for period_start, agents_stats in stats.iteritems():
            stat_agent_periodic_dao.insert_stats(self.session, agents_stats,
                                                 period_start)
        self.session.commit()

        period_start = dt(2012, 01, 01, 01, 00, 00)

        try:
            result = (self.session.query(StatAgentPeriodic).filter(
                StatAgentPeriodic.time == period_start).filter(
                    StatAgentPeriodic.agent_id == agent_id_1)[0])

            self.assertEqual(result.login_time, timedelta(minutes=50))
        except LookupError:
            self.fail('Should have found a row')
Ejemplo n.º 5
0
    def test_insert_periodic_stat(self):
        _, agent_id_1 = self._insert_agent_to_stat_agent()
        _, agent_id_2 = self._insert_agent_to_stat_agent()
        stats = {
            dt(2012, 1, 1, 1, 0, 0, tzinfo=UTC): {
                agent_id_1: {
                    'login_time': timedelta(minutes=50),
                    'pause_time': timedelta(minutes=13)
                },
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 1, 2, 0, 0, tzinfo=UTC): {
                agent_id_1: {
                    'login_time': timedelta(minutes=20),
                    'pause_time': timedelta(minutes=33)
                },
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 1, 3, 0, 0, tzinfo=UTC): {
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': ONE_HOUR
                },
            },
            dt(2012, 1, 1, 4, 0, 0, tzinfo=UTC): {
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': ONE_HOUR
                },
            }
        }

        with flush_session(self.session):
            for period_start, agents_stats in six.iteritems(stats):
                stat_agent_periodic_dao.insert_stats(self.session,
                                                     agents_stats,
                                                     period_start)

        period_start = dt(2012, 1, 1, 1, 0, 0, tzinfo=UTC)

        try:
            result = (self.session.query(StatAgentPeriodic).filter(
                StatAgentPeriodic.time == period_start).filter(
                    StatAgentPeriodic.stat_agent_id == agent_id_1)[0])

            self.assertEqual(result.login_time, timedelta(minutes=50))
        except LookupError:
            self.fail('Should have found a row')
    def test_insert_periodic_stat(self):
        _, agent_id_1 = self._insert_agent_to_stat_agent()
        _, agent_id_2 = self._insert_agent_to_stat_agent()
        stats = {
            dt(2012, 01, 01, 01, 00, 00): {
                agent_id_1: {
                    'login_time': timedelta(minutes=50),
                    'pause_time': timedelta(minutes=13)
                },
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': timedelta(minutes=13)},
            },
            dt(2012, 01, 01, 02, 00, 00): {
                agent_id_1: {
                    'login_time': timedelta(minutes=20),
                    'pause_time': timedelta(minutes=33)
                },
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 01, 01, 03, 00, 00): {
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': ONE_HOUR
                },
            },
            dt(2012, 01, 01, 04, 00, 00): {
                agent_id_2: {
                    'login_time': ONE_HOUR,
                    'pause_time': ONE_HOUR
                },
            }
        }

        self.session.begin()
        for period_start, agents_stats in stats.iteritems():
            stat_agent_periodic_dao.insert_stats(self.session, agents_stats, period_start)
        self.session.commit()

        period_start = dt(2012, 01, 01, 01, 00, 00)

        try:
            result = (self.session.query(StatAgentPeriodic)
                      .filter(StatAgentPeriodic.time == period_start)
                      .filter(StatAgentPeriodic.agent_id == agent_id_1)[0])

            self.assertEqual(result.login_time, timedelta(minutes=50))
        except LookupError:
            self.fail('Should have found a row')
    def test_clean_table(self):
        _, agent_id = self._insert_agent_to_stat_agent()
        stats = {
            agent_id: {
                'login_time': timedelta(minutes=15),
                'pause_time': ONE_HOUR
            },
        }

        stat_agent_periodic_dao.insert_stats(self.session, stats, dt(2012, 1, 1))

        stat_agent_periodic_dao.clean_table(self.session)

        total = self.session.query(func.count(StatAgentPeriodic.time))[0][0]

        self.assertEqual(total, 0)
Ejemplo n.º 8
0
    def test_clean_table(self):
        _, agent_id = self._insert_agent_to_stat_agent()
        stats = {
            agent_id: {
                'login_time': timedelta(minutes=15),
                'pause_time': ONE_HOUR
            },
        }

        stat_agent_periodic_dao.insert_stats(self.session, stats,
                                             dt(2012, 1, 1))

        stat_agent_periodic_dao.clean_table(self.session)

        total = self.session.query(func.count(StatAgentPeriodic.time))[0][0]

        self.assertEqual(total, 0)
Ejemplo n.º 9
0
def insert_periodic_stat(dao_sess, start, end):
    logger.info('Inserting agent periodic stat')
    time_computer = AgentTimeComputer(start, end, INTERVAL)

    dao_sess.begin()
    login_intervals = stat_dao.get_login_intervals_in_range(dao_sess, start, end)
    pause_intervals = stat_dao.get_pause_intervals_in_range(dao_sess, start, end)

    periodic_stats_login = time_computer.compute_login_time_in_period(login_intervals)
    periodic_stats_pause = time_computer.compute_pause_time_in_period(pause_intervals)
    periodic_stats_wrapup = queue_log_dao.get_wrapup_times(dao_sess, start, end, INTERVAL)
    dao_sess.commit()

    periodic_stats = _merge_update_agent_statistics(
        periodic_stats_login,
        periodic_stats_pause,
        periodic_stats_wrapup,
    )

    dao_sess.begin()
    for period, stats in periodic_stats.iteritems():
        stat_agent_periodic_dao.insert_stats(dao_sess, stats, period)
    dao_sess.commit()
Ejemplo n.º 10
0
    def test_remove_after(self):
        _, agent_id = self._insert_agent_to_stat_agent()
        stats = {
            dt(2012, 1, 1, tzinfo=UTC): {
                agent_id: {
                    'login_time': timedelta(minutes=15),
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 2, tzinfo=UTC): {
                agent_id: {
                    'login_time': timedelta(minutes=20),
                    'pause_time': timedelta(minutes=13)
                },
            },
            dt(2012, 1, 3, tzinfo=UTC): {
                agent_id: {
                    'login_time': timedelta(minutes=25),
                    'pause_time': timedelta(minutes=13)
                },
            },
        }

        with flush_session(self.session):
            for period_start, agents_stats in six.iteritems(stats):
                stat_agent_periodic_dao.insert_stats(self.session,
                                                     agents_stats,
                                                     period_start)

        stat_agent_periodic_dao.remove_after(self.session,
                                             dt(2012, 1, 2, tzinfo=UTC))

        res = self.session.query(StatAgentPeriodic.time)

        self.assertEqual(res.count(), 1)
        self.assertEqual(res[0].time, dt(2012, 1, 1, tzinfo=UTC))