@@ -0,0 +1,3101 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%22%22%22%0ALoad data extracted from scrape and raw data snapshot into OCD models.%0A%22%22%22%0Afrom django.apps import apps%0Afrom django.utils.timezone import now%0Afrom django.core.management import call_command%0Afrom calaccess_processed.models import ProcessedDataVersion%0Afrom calaccess_processed.management.commands import CalAccessCommand%0A%0A%0Aclass Command(CalAccessCommand):%0A    %22%22%22%0A    Load data extracted from scrape and raw data snapshot into OCD models.%0A    %22%22%22%0A    help = 'Load data extracted from scrape and raw data snapshot into OCD models'%0A%0A    def handle(self, *args, **options):%0A        %22%22%22%0A        Make it happen.%0A        %22%22%22%0A        super(Command, self).handle(*args, **options)%0A%0A        self.processed_version = ProcessedDataVersion.objects.latest()%0A%0A        self.start_datetime = now()%0A        self.load()%0A        self.finish_datetime = now()%0A        self.archive()%0A%0A        self.success('Done!')%0A        self.duration()%0A%0A    def load(self):%0A        %22%22%22%0A        Load all of the processed models.%0A        %22%22%22%0A        call_command(%0A            'loadparties',%0A            verbosity=self.verbosity,%0A            no_color=self.no_color,%0A        )%0A        self.duration()%0A%0A        call_command(%0A            'loadballotmeasurecontests',%0A            verbosity=self.verbosity,%0A            no_color=self.no_color,%0A        )%0A        self.duration()%0A%0A        call_command(%0A            'loadretentioncontests',%0A            verbosity=self.verbosity,%0A            no_color=self.no_color,%0A        )%0A        self.duration()%0A%0A        call_command(%0A            'loadcandidatecontests',%0A            verbosity=self.verbosity,%0A            no_color=self.no_color,%0A        )%0A        self.duration()%0A%0A        call_command(%0A            'mergecandidates',%0A            verbosity=self.verbosity,%0A            no_color=self.no_color,%0A        )%0A        self.duration()%0A%0A        call_command(%0A            'loadcandidaciesfrom501s',%0A            verbosity=self.verbosity,%0A            no_color=self.no_color,%0A        )%0A        self.duration()%0A%0A        call_command(%0A            'loadincumbentofficeholders',%0A            verbosity=self.verbosity,%0A            no_color=self.no_color,%0A        )%0A        self.duration()%0A%0A    def archive(self):%0A        %22%22%22%0A        Save a csv file for each loaded OCD model.%0A        %22%22%22%0A        ocd_models = %5B%0A            m._meta.object_name for m in apps.get_app_config(%0A                'opencivicdata'%0A            ).get_models()%0A            if not m._meta.abstract and%0A            m.objects.count() %3E 0%0A        %5D%0A%0A        for m in ocd_models:%0A            processed_data_file, created = self.processed_version.files.get_or_create(%0A                file_name=m,%0A            )%0A            processed_data_file.process_start_time = self.start_datetime%0A            processed_data_file.save()%0A            call_command(%0A                'archivecalaccessprocessedfile',%0A                'opencivicdata',%0A                m,%0A            )%0A            processed_data_file.process_finish_time = self.finish_datetime%0A            processed_data_file.save()%0A%0A        self.duration()%0A

Create ProcessedDataModels for OCD models, group loading into one cmd