コード例 #1
0
ファイル: parameters.py プロジェクト: cmutel/activity-browser
 def recalculate_exchanges():
     """ Will iterate through all activity parameters and rerun the
     formula interpretation for all exchanges.
     """
     for param in ActivityParameter.select().iterator():
         act = bw.get_activity((param.database, param.code))
         bw.parameters.add_exchanges_to_group(param.group, act)
         ActivityParameter.recalculate_exchanges(param.group)
     signals.parameters_changed.emit()
コード例 #2
0
ファイル: parameters.py プロジェクト: cmutel/activity-browser
    def parameterize_exchanges(self, key: tuple) -> None:
        """ Used whenever a formula is set on an exchange in an activity.

        If no `ActivityParameter` exists for the key, generate one immediately
        """
        if ActivityParameter.get_or_none(database=key[0], code=key[1]) is None:
            signals.add_activity_parameter.emit(key)

        param = ActivityParameter.get(database=key[0], code=key[1])
        act = bw.get_activity(key)
        bw.parameters.remove_exchanges_from_group(param.group, act)
        bw.parameters.add_exchanges_to_group(param.group, act)
        ActivityParameter.recalculate_exchanges(param.group)
        signals.parameters_changed.emit()
コード例 #3
0
    def parameterize_exchanges(self, key: tuple) -> None:
        """ Used whenever a formula is set on an exchange in an activity.

        If no `ActivityParameter` exists for the key, generate one immediately
        """
        group = bc.build_activity_group_name(key)
        if not (ActivityParameter.select()
                .where(ActivityParameter.group == group).count()):
            ActivityParameterTable.add_parameter(key)

        act = bw.get_activity(key)
        with bw.parameters.db.atomic():
            bw.parameters.remove_exchanges_from_group(group, act)
            bw.parameters.add_exchanges_to_group(group, act)
            ActivityParameter.recalculate_exchanges(group)
        signals.parameters_changed.emit()