Exemple #1
0
def gbd_main(parent_dir, db_env):
    config = read_helper_files(parent_dir)
    process_version_id = config['process_version_id']
    gbd_conn = _GBD_CONN_DEF_MAP[db_env.value]

    cache_gbd_db('before', gbd_conn, parent_dir)

    logging.info("Create compare_version_id and add to GBD database")
    # Retrieve the latest compare version from the gbd database
    cv_id = get_latest_compare_version(
        gbd_round_id=GBD.GBD_ROUND_ID,
        conn_def=gbd_conn)
    # Instantiate the CompareVersion object
    current_cv = CompareVersion(compare_version_id=cv_id, env=db_env)
    # Get a list of process versions in the current CompareVersion
    # Exclude gbd_process_id 3 - CoDCorrect (we're adding a new one)
    # and gbd_process_id 14 - SEVs, not included in compare version string.
    process_versions = [pv for pv in current_cv.gbd_process_versions
                        if pv.gbd_process_id not in [3, 14]]
    # Create a tuple of gbd_process_version_id to gbd_process_version_note
    pv_id_note_tuple = [(pv.gbd_process_id, pv.gbd_process_version_note)
                        for pv in process_versions]
    # Format the respective descriptions used to create the new
    # compare version.
    cv_strs = [get_process_desc_from_id(pv_id, note) for pv_id, note
               in pv_id_note_tuple]
    codcorrect_desc = 'CoDCorrect: {}'.format(output_version_id)
    # Additional formatting to match pattern in database
    cv_strs += [codcorrect_desc]
    cv_strs = sorted(cv_strs)
    cv_desc = ', '.join(cv_strs)
    # Create new compare version
    new_cv = CompareVersion.add_new_version(
        gbd_round_id=GBD.GBD_ROUND_ID,
        compare_version_description=cv_desc,
        env=db_env)
    # Create list of process_version_ids
    pvids = [pv.gbd_process_version_id for pv in process_versions]
    pvids += [process_version_id]
    # Add gbd_process_version_ids to compare version
    new_cv.add_process_version(pvids)
    logging.info("Activating new process version")
    activate_new_process_version(process_version_id,
                                 gbd_conn)
    activate_new_compare_version(new_cv.compare_version_id, gbd_conn)

    cache_gbd_db('after', gbd_conn, parent_dir)

    logging.info("Cache saved to _temp. keys: 'process_version_before/after' "
                 "and 'compare_version_before/after'")
    logging.info("GBD Post Scriptum Finished.")
    def _create_compare_version(self):
        """Should record all process_versions created in the run, plus the
        CodCorrect and COMO process versions used as inputs"""
        description = self._generate_description()
        cv = CompareVersion.add_new_version(
            gbd_round_id=self.gbd_round_id,
            compare_version_description=description,
            env=self.upload_env)

        # Get this list of input process versions, including the burdenator
        # proc version
        process_versions = (list(self.input_process_versions.values()) +
                            list(self.output_process_versions.values()))
        cv.add_process_version(process_versions)

        self.compare_version_id = cv.compare_version_id
        return cv.compare_version_id
    def create_compare_version(self, process_version_id):

        cv = CompareVersion.get_best(gbd_round_id=self.gbd_round_id,
                                     decomp_step=self.decomp_step)

        if not cv:
            cv = CompareVersion.add_new_version(self.gbd_round_id,
                                                self.decomp_step,
                                                'MMR: ' + process_version_id)

        cv.add_process_version(process_version_id)

        bleeding_edge_df = bleeding_edge(cv.compare_version_id)

        # Add bleeding edge processes if they aren't MMR
        for idx in bleeding_edge_df.index.tolist():
            if (bleeding_edge_df.loc[idx, 'gbd_process_id'] !=
                    mmr_constants.MMR_GBD_PROCESS_ID):
                cv.add_process_version(
                    bleeding_edge_df.loc[idx, 'gbd_process_version_id'])