def handle(self, *args, **options):
        cursor = connection.cursor()
        projects = Project.objects.all()
        project_ids = [p.id for p in projects]

        self.stdout.write(
            'Recreating treenode_edge, treenode_connector_edge, connector_geom'
        )
        rebuild_edge_tables(log=lambda msg: self.stdout.write(msg))

        self.stdout.write('Recreating catmaid_stats_summary')
        cursor.execute("TRUNCATE catmaid_stats_summary")
        for p in projects:
            populate_stats_summary(p.id, False, False)

        self.stdout.write('Recreating catmaid_skeleton_summary')
        cursor.execute("""
            TRUNCATE catmaid_skeleton_summary;
            SELECT refresh_skeleton_summary_table();
        """)

        self.stdout.write('Recreating node_query_cache')
        update_node_query_cache(log=lambda x: self.stdout.write(x))

        self.stdout.write('Done')
    def handle(self, *args, **options):
        cursor = connection.cursor()

        project_ids = options['project_id']
        if project_ids:
            projects = Project.objects.filter(id__in=project_ids)
        else:
            projects = Project.objects.all()

        delete = False
        clean = options['clean']
        if clean:
            if project_ids:
                delete = True
            else:
                # Removing statistics for all projects is much faster this way.
                cursor.execute("TRUNCATE catmaid_stats_summary")

        incremental = not clean
        for p in projects:
            populate_stats_summary(p.id, delete, incremental)
            self.stdout.write(f'Computed statistics for project {p.id}')
    def handle(self, *args, **options):
        cursor = connection.cursor()
        projects = Project.objects.all()
        project_ids = [p.id for p in projects]

        self.stdout.write('Recreating treenode_edge, treenode_connector_edge, connector_geom')
        rebuild_edge_tables(log=lambda msg: self.stdout.write(msg))

        self.stdout.write('Recreating catmaid_stats_summary')
        cursor.execute("TRUNCATE catmaid_stats_summary")
        for p in projects:
            populate_stats_summary(p.id, False, False)

        self.stdout.write('Recreating catmaid_skeleton_summary')
        cursor.execute("""
            TRUNCATE catmaid_skeleton_summary;
            SELECT refresh_skeleton_summary_table();
        """)

        self.stdout.write('Recreating node_query_cache')
        update_node_query_cache(log=lambda x: self.stdout.write(x))

        self.stdout.write('Done')
Exemplo n.º 4
0
    def test_stats_user_history_with_utc_offset(self):
        self.fake_authentication()

        self.add_test_treenodes()
        self.add_test_connector_links()
        self.add_test_reviews()

        expected_stats = {
            'days': [
                '20170701', '20170702', '20170703', '20170704', '20170705',
                '20170706', '20170707', '20170708', '20170709', '20170710',
                '20170711', '20170712', '20170713', '20170714', '20170715',
                '20170716', '20170717', '20170718', '20170719', '20170720',
                '20170721', '20170722', '20170723', '20170724', '20170725',
                '20170726', '20170727', '20170728', '20170729', '20170730',
                '20170731', '20170801'
            ],
            'daysformatted': [
                'Sat 01, Jul 2017', 'Sun 02, Jul 2017', 'Mon 03, Jul 2017',
                'Tue 04, Jul 2017', 'Wed 05, Jul 2017', 'Thu 06, Jul 2017',
                'Fri 07, Jul 2017', 'Sat 08, Jul 2017', 'Sun 09, Jul 2017',
                'Mon 10, Jul 2017', 'Tue 11, Jul 2017', 'Wed 12, Jul 2017',
                'Thu 13, Jul 2017', 'Fri 14, Jul 2017', 'Sat 15, Jul 2017',
                'Sun 16, Jul 2017', 'Mon 17, Jul 2017', 'Tue 18, Jul 2017',
                'Wed 19, Jul 2017', 'Thu 20, Jul 2017', 'Fri 21, Jul 2017',
                'Sat 22, Jul 2017', 'Sun 23, Jul 2017', 'Mon 24, Jul 2017',
                'Tue 25, Jul 2017', 'Wed 26, Jul 2017', 'Thu 27, Jul 2017',
                'Fri 28, Jul 2017', 'Sat 29, Jul 2017', 'Sun 30, Jul 2017',
                'Mon 31, Jul 2017', 'Tue 01, Aug 2017'
            ],
            'stats_table': {
                '1': {
                    '20170701': {},
                    '20170702': {
                        'new_cable_length': 10.0,
                        'new_connectors': 1,
                        'new_reviewed_nodes': 1,
                        'new_treenodes': 1,
                    },
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                },
                '2': {
                    '20170701': {},
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                },
                '3': {
                    '20170701': {
                        'new_cable_length': 4.0,
                        'new_connectors': 3,
                        'new_reviewed_nodes': 3,
                        'new_treenodes': 3,
                    },
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                },
                '4': {
                    '20170701': {},
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                },
                '5': {
                    '20170701': {},
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                }
            }
        }

        response = self.client.get(
            '/%d/stats/user-history' % (self.test_project_id, ), {
                'start_date': '2017-07-01',
                'end_date': '2017-08-01',
                'time_zone': 'America/New_York'
            })
        self.assertStatus(response)
        parsed_response = json.loads(response.content.decode('utf-8'))
        self.assertEqual(expected_stats, parsed_response)

        # Init summary tables and test again
        stats.populate_stats_summary(self.test_project_id)

        response = self.client.get(
            '/%d/stats/user-history' % (self.test_project_id, ), {
                'start_date': '2017-07-01',
                'end_date': '2017-08-01',
                'time_zone': 'America/New_York'
            })
        self.assertStatus(response)
        parsed_response = json.loads(response.content.decode('utf-8'))
        self.assertEqual(expected_stats, parsed_response)
Exemplo n.º 5
0
    def test_stats_user_history_with_utc_offset(self):
        self.fake_authentication()

        self.add_test_treenodes()
        self.add_test_connector_links()
        self.add_test_reviews()

        expected_stats = {
            'days': [
                 '20170701',
                 '20170702',
                 '20170703',
                 '20170704',
                 '20170705',
                 '20170706',
                 '20170707',
                 '20170708',
                 '20170709',
                 '20170710',
                 '20170711',
                 '20170712',
                 '20170713',
                 '20170714',
                 '20170715',
                 '20170716',
                 '20170717',
                 '20170718',
                 '20170719',
                 '20170720',
                 '20170721',
                 '20170722',
                 '20170723',
                 '20170724',
                 '20170725',
                 '20170726',
                 '20170727',
                 '20170728',
                 '20170729',
                 '20170730',
                 '20170731',
                 '20170801'
            ],
            'daysformatted': [
                  'Sat 01, Jul 2017',
                  'Sun 02, Jul 2017',
                  'Mon 03, Jul 2017',
                  'Tue 04, Jul 2017',
                  'Wed 05, Jul 2017',
                  'Thu 06, Jul 2017',
                  'Fri 07, Jul 2017',
                  'Sat 08, Jul 2017',
                  'Sun 09, Jul 2017',
                  'Mon 10, Jul 2017',
                  'Tue 11, Jul 2017',
                  'Wed 12, Jul 2017',
                  'Thu 13, Jul 2017',
                  'Fri 14, Jul 2017',
                  'Sat 15, Jul 2017',
                  'Sun 16, Jul 2017',
                  'Mon 17, Jul 2017',
                  'Tue 18, Jul 2017',
                  'Wed 19, Jul 2017',
                  'Thu 20, Jul 2017',
                  'Fri 21, Jul 2017',
                  'Sat 22, Jul 2017',
                  'Sun 23, Jul 2017',
                  'Mon 24, Jul 2017',
                  'Tue 25, Jul 2017',
                  'Wed 26, Jul 2017',
                  'Thu 27, Jul 2017',
                  'Fri 28, Jul 2017',
                  'Sat 29, Jul 2017',
                  'Sun 30, Jul 2017',
                  'Mon 31, Jul 2017',
                  'Tue 01, Aug 2017'
            ],
            'stats_table': {
                '1': {
                    '20170701': {},
                    '20170702': {
                        'new_cable_length': 10.0,
                        'new_connectors': 1,
                        'new_reviewed_nodes': 1,
                        'new_treenodes': 1,
                    },
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                },
                '2': {
                    '20170701': {},
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                },
                '3': {
                    '20170701': {
                        'new_cable_length': 4.0,
                        'new_connectors': 3,
                        'new_reviewed_nodes': 3,
                        'new_treenodes': 3,
                    },
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}},
                '4': {
                    '20170701': {},
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                },
                '5': {
                    '20170701': {},
                    '20170702': {},
                    '20170703': {},
                    '20170704': {},
                    '20170705': {},
                    '20170706': {},
                    '20170707': {},
                    '20170708': {},
                    '20170709': {},
                    '20170710': {},
                    '20170711': {},
                    '20170712': {},
                    '20170713': {},
                    '20170714': {},
                    '20170715': {},
                    '20170716': {},
                    '20170717': {},
                    '20170718': {},
                    '20170719': {},
                    '20170720': {},
                    '20170721': {},
                    '20170722': {},
                    '20170723': {},
                    '20170724': {},
                    '20170725': {},
                    '20170726': {},
                    '20170727': {},
                    '20170728': {},
                    '20170729': {},
                    '20170730': {},
                    '20170731': {},
                    '20170801': {}
                }
            }
        }

        response = self.client.get('/%d/stats/user-history' % (self.test_project_id,), {
                'start_date': '2017-07-01',
                'end_date': '2017-08-01',
                'time_zone': 'America/New_York'
            })
        self.assertEqual(response.status_code, 200)
        parsed_response = json.loads(response.content.decode('utf-8'))
        self.assertEqual(expected_stats, parsed_response)

        # Init summary tables and test again
        stats.populate_stats_summary(self.test_project_id)

        response = self.client.get('/%d/stats/user-history' % (self.test_project_id,), {
                'start_date': '2017-07-01',
                'end_date': '2017-08-01',
                'time_zone': 'America/New_York'
            })
        self.assertEqual(response.status_code, 200)
        parsed_response = json.loads(response.content.decode('utf-8'))
        self.assertEqual(expected_stats, parsed_response)