コード例 #1
0
ファイル: params.py プロジェクト: twongsi/lca_algebraic
def resetParams(db_name):
    """Reset project and activity parameters"""
    _param_registry().clear()
    ProjectParameter.delete().execute()
    ActivityParameter.delete().execute()
    DatabaseParameter.delete().execute()
    Group.delete().execute()
コード例 #2
0
ファイル: base_lci.py プロジェクト: pjamesjoyce/brightway2-io
    def _prepare_activity_parameters(self, data=None, delete_existing=True):
        data = self.data if data is None else data

        def supplement_activity_parameter(ds, dct):
            dct.update({'database': self.db_name, 'code': ds['code']})
            if 'group' not in dct:
                dct['group'] = "{}:{}".format(dct['database'], dct['code'])
            return dct

        activity_parameters = [
            supplement_activity_parameter(ds, dct)
            for ds in data
            for dct in ds.pop("parameters", [])
        ]
        by_group = lambda x: x['group']
        activity_parameters = sorted(activity_parameters, key=by_group)

        # Delete all parameterized exchanges because
        # all exchanges are re-written, even on
        # update, which means ids are unreliable
        # Must add exchanges again manually
        bad_groups = tuple({o[0] for o in ActivityParameter.select(
            ActivityParameter.group).where(
            ActivityParameter.database == self.db_name
        ).tuples()})
        ParameterizedExchange.delete().where(
            ParameterizedExchange.group << bad_groups
        ).execute()
        if delete_existing:
            # Delete existing parameters and p. exchanges if necessary
            ActivityParameter.delete().where(ActivityParameter.group << bad_groups
            ).execute()
        else:
            # Delete activity parameters
            # where the group name changed
            name_changed = tuple({o[0] for o in
                ActivityParameter.select(
                ActivityParameter.group).where(
                ActivityParameter.database == self.db_name,
                ActivityParameter.code << tuple(
                    [m['code'] for m in activity_parameters]
                ),
                ~(ActivityParameter.group << tuple(
                    [m['group'] for m in activity_parameters]
                ))
            ).tuples()})
            ActivityParameter.delete().where(ActivityParameter.group << name_changed
            ).execute()

        return activity_parameters
コード例 #3
0
def resetParams(db_name=None):
    """Clear parameters in live memory (registry) and on disk.
    Clear either all params (project and all db params) or db params from a single database (if db_name provided)"""
    _param_registry().clear(db_name)

    if db_name is None:
        ProjectParameter.delete().execute()
        ActivityParameter.delete().execute()
        DatabaseParameter.delete().execute()
    else:
        ActivityParameter.delete().where(
            ActivityParameter.database == db_name).execute()
        DatabaseParameter.delete().where(
            DatabaseParameter.database == db_name).execute()
        Group.delete().execute()
コード例 #4
0
 def clear_broken_activity_parameter(database: str, code: str, group: str) -> None:
     """Take the given information and attempt to remove all of the
     downstream parameter information.
     """
     with bw.parameters.db.atomic() as txn:
         bw.parameters.remove_exchanges_from_group(group, None, False)
         ActivityParameter.delete().where(
             ActivityParameter.database == database,
             ActivityParameter.code == code
         ).execute()
         # Do commit to ensure .exists() call does not include deleted params
         txn.commit()
         exists = (ActivityParameter.select()
                   .where(ActivityParameter.group == group)
                   .exists())
         if not exists:
             # Also clear Group if it is not in use anymore
             Group.delete().where(Group.name == group).execute()