Пример #1
0
    def test_calendar_time_sum(self):
        task = setup_task_history(self)
        df = work_time_df([task.project])

        # Duplicate the amount of work completed by creating a ficitonal
        # second set of tasks.  The calendar times are the same, so the
        # project shouldn't have double the calendar time.
        duplicate = df.copy(deep=True)
        duplicate['task_id'] = duplicate.task_id + 1
        df = concat([df, duplicate])

        header = ['calendar_time']

        # Test grouping by project ID
        expected = DataFrame(
            [(timedelta(hours=3, minutes=13))],
            columns=header)
        returned = calendar_time_sum(df, ['project_id'])
        assert_frame_equal(returned[header], expected)

        # Test grouping by task ID
        expected = DataFrame(
            [(timedelta(hours=3, minutes=13),),
             (timedelta(hours=3, minutes=13),)],
            columns=header)
        returned = calendar_time_sum(df, ['project_id', 'task_id'])
        assert_frame_equal(returned[header], expected)
Пример #2
0
    def test_work_time_df(self):
        task = setup_task_history(self)
        returned = work_time_df([task.project])

        self.assertEquals(returned.project_id.nunique(), 1)
        self.assertEquals(returned.task_id.nunique(), 1)

        header = ['assignment_level', 'worker', 'iteration', 'start_datetime',
                  'end_datetime', 'calendar_time', 'work_time']
        expected = DataFrame(
            [(1, 'test_user_5', 0, parse('2015-10-12T01:00:00+00:00'), parse('2015-10-12T02:00:00+00:00'), timedelta(hours=1), timedelta(seconds=0)),  # noqa
             (1, 'test_user_5', 1, parse('2015-10-12T02:00:00+00:00'), parse('2015-10-12T02:02:00+00:00'), timedelta(minutes=2), timedelta(seconds=35)),  # noqa
             (2, 'test_user_6', 0, parse('2015-10-12T02:02:00+00:00'), parse('2015-10-12T03:00:00+00:00'), timedelta(minutes=58), timedelta(seconds=0)),  # noqa
             (2, 'test_user_6', 1, parse('2015-10-12T03:00:00+00:00'), parse('2015-10-12T03:01:00+00:00'), timedelta(minutes=1), timedelta(seconds=36)),  # noqa
             (1, 'test_user_5', 2, parse('2015-10-12T03:01:00+00:00'), parse('2015-10-12T03:05:00+00:00'), timedelta(minutes=4), timedelta(seconds=37)),  # noqa
             (2, 'test_user_6', 2, parse('2015-10-12T03:05:00+00:00'), parse('2015-10-12T03:07:00+00:00'), timedelta(minutes=2), timedelta(seconds=38)),  # noqa
             (3, 'test_user_7', 0, parse('2015-10-12T03:07:00+00:00'), parse('2015-10-12T04:00:00+00:00'), timedelta(minutes=53), timedelta(seconds=0)),  # noqa
             (3, 'test_user_7', 1, parse('2015-10-12T04:00:00+00:00'), parse('2015-10-12T04:02:00+00:00'), timedelta(minutes=2), timedelta(seconds=36)),  # noqa
             (2, 'test_user_6', 3, parse('2015-10-12T04:02:00+00:00'), parse('2015-10-12T04:03:00+00:00'), timedelta(minutes=1), timedelta(seconds=35)),  # noqa
             (3, 'test_user_7', 2, parse('2015-10-12T04:03:00+00:00'), parse('2015-10-12T04:13:00+00:00'), timedelta(minutes=10), timedelta(seconds=38)),  # noqa
            ],
            columns=header)

        expected['start_datetime'] = (
            expected['start_datetime'].astype('datetime64[ns]'))
        expected['end_datetime'] = (
            expected['end_datetime'].astype('datetime64[ns]'))

        assert_frame_equal(returned[header], expected)
Пример #3
0
    def test_calendar_time_sum(self):
        task = setup_task_history(self)
        df = work_time_df([task.project])

        # Duplicate the amount of work completed by creating a ficitonal
        # second set of tasks.  The calendar times are the same, so the
        # project shouldn't have double the calendar time.
        duplicate = df.copy(deep=True)
        duplicate['task_id'] = duplicate.task_id + 1
        df = concat([df, duplicate])

        header = ['calendar_time']

        # Test grouping by project ID
        expected = DataFrame([(timedelta(hours=3, minutes=13))],
                             columns=header)
        returned = calendar_time_sum(df, ['project_id'])
        assert_frame_equal(returned[header], expected)

        # Test grouping by task ID
        expected = DataFrame([(timedelta(hours=3, minutes=13), ),
                              (timedelta(hours=3, minutes=13), )],
                             columns=header)
        returned = calendar_time_sum(df, ['project_id', 'task_id'])
        assert_frame_equal(returned[header], expected)
Пример #4
0
    def test_work_time_sum(self):
        task = setup_task_history(self)
        df = work_time_df([task.project])

        header = ['work_time']
        expected = DataFrame([(timedelta(minutes=4, seconds=15))],
                             columns=header)
        returned = work_time_sum(df, ['project_id'])

        assert_frame_equal(returned[header], expected)
Пример #5
0
    def test_work_time_sum(self):
        task = setup_task_history(self)
        df = work_time_df([task.project])

        header = ['work_time']
        expected = DataFrame(
            [(timedelta(minutes=4, seconds=15))],
            columns=header)
        returned = work_time_sum(df, ['project_id'])

        assert_frame_equal(returned[header], expected)
Пример #6
0
    def test_work_time_df(self):
        task = setup_task_history(self)
        returned = work_time_df([task.project])

        self.assertEquals(returned.project_id.nunique(), 1)
        self.assertEquals(returned.task_id.nunique(), 1)

        header = [
            'assignment_level', 'worker', 'iteration', 'start_datetime',
            'end_datetime', 'calendar_time', 'work_time'
        ]
        expected = DataFrame(
            [
                (1, 'test_user_5', 0, parse('2015-10-12T01:00:00+00:00'),
                 parse('2015-10-12T02:00:00+00:00'), timedelta(hours=1),
                 timedelta(seconds=0)),  # noqa
                (1, 'test_user_5', 1, parse('2015-10-12T02:00:00+00:00'),
                 parse('2015-10-12T02:02:00+00:00'), timedelta(minutes=2),
                 timedelta(seconds=35)),  # noqa
                (2, 'test_user_6', 0, parse('2015-10-12T02:02:00+00:00'),
                 parse('2015-10-12T03:00:00+00:00'), timedelta(minutes=58),
                 timedelta(seconds=0)),  # noqa
                (2, 'test_user_6', 1, parse('2015-10-12T03:00:00+00:00'),
                 parse('2015-10-12T03:01:00+00:00'), timedelta(minutes=1),
                 timedelta(seconds=36)),  # noqa
                (1, 'test_user_5', 2, parse('2015-10-12T03:01:00+00:00'),
                 parse('2015-10-12T03:05:00+00:00'), timedelta(minutes=4),
                 timedelta(seconds=37)),  # noqa
                (2, 'test_user_6', 2, parse('2015-10-12T03:05:00+00:00'),
                 parse('2015-10-12T03:07:00+00:00'), timedelta(minutes=2),
                 timedelta(seconds=38)),  # noqa
                (3, 'test_user_7', 0, parse('2015-10-12T03:07:00+00:00'),
                 parse('2015-10-12T04:00:00+00:00'), timedelta(minutes=53),
                 timedelta(seconds=0)),  # noqa
                (3, 'test_user_7', 1, parse('2015-10-12T04:00:00+00:00'),
                 parse('2015-10-12T04:02:00+00:00'), timedelta(minutes=2),
                 timedelta(seconds=36)),  # noqa
                (2, 'test_user_6', 3, parse('2015-10-12T04:02:00+00:00'),
                 parse('2015-10-12T04:03:00+00:00'), timedelta(minutes=1),
                 timedelta(seconds=35)),  # noqa
                (3, 'test_user_7', 2, parse('2015-10-12T04:03:00+00:00'),
                 parse('2015-10-12T04:13:00+00:00'), timedelta(minutes=10),
                 timedelta(seconds=38)),  # noqa
            ],
            columns=header)

        expected['start_datetime'] = (
            expected['start_datetime'].astype('datetime64[ns]'))
        expected['end_datetime'] = (
            expected['end_datetime'].astype('datetime64[ns]'))

        assert_frame_equal(returned[header], expected)
Пример #7
0
def main(options):
    print(work_time_df(Project.objects.filter(id=1)))
Пример #8
0
def main(options):
    print(work_time_df(Project.objects.filter(id=1)))
Пример #9
0
def project_management_information(project_id):
    project = Project.objects.get(id=project_id)
    df = work_time_df([project], human_only=False, complete_tasks_only=False)
    project_information = get_project_information(project.id)
    project_information['project']['status'] = dict(
        Project.STATUS_CHOICES).get(project.status, None)
    project_information['project']['admin_url'] = urljoin(
        settings.ORCHESTRA_URL,
        urlresolvers.reverse('admin:orchestra_project_change',
                             args=(project_id, )))

    for slug, task in project_information['tasks'].items():
        task['admin_url'] = urljoin(
            settings.ORCHESTRA_URL,
            urlresolvers.reverse('admin:orchestra_task_change',
                                 args=(task['id'], )))

        for assignment in task['assignments']:
            assignment['admin_url'] = urljoin(
                settings.ORCHESTRA_URL,
                urlresolvers.reverse('admin:orchestra_taskassignment_change',
                                     args=(assignment['id'], )))

            iterations = df[(df.worker == assignment['worker']['username'])
                            & (df.task_id == task['id'])]
            iterations = iterations[['start_datetime', 'end_datetime']]
            assignment['iterations'] = []
            for idx, info in iterations.T.items():
                iteration = info.to_dict()
                assignment['iterations'].append(iteration)
            if assignment['status'] == 'Processing':
                last_iteration_end = assignment['start_datetime']
                last_assignment = last_snapshotted_assignment(task['id'])
                if last_assignment and len(assignment['iterations']) > 1:
                    last_iteration_end = (
                        last_assignment.snapshots['snapshots'][-1]['datetime'])

                assignment['iterations'].append({
                    'start_datetime': last_iteration_end,
                    'end_datetime': timezone.now()
                })

        if task['status'] in ('Awaiting Processing', 'Pending Review'):
            last_assignment_end = task['start_datetime']
            last_assignment = last_snapshotted_assignment(task['id'])
            if last_assignment:
                last_assignment_end = (
                    last_assignment.snapshots['snapshots'][-1]['datetime'])
            task['assignments'].append({
                'iterations': [{
                    'start_datetime': last_assignment_end,
                    'end_datetime': timezone.now()
                }],
                'snapshots':
                empty_snapshots(),
                'start_datetime':
                last_assignment_end,
                'status':
                'Processing',
                'task':
                task['id'],
                'worker': {
                    'id': None,
                    'username': None
                },
            })
    return project_information