Esempio n. 1
0
    def delete_parameter(self, parameter: ParameterBase) -> None:
        """ Remove the given parameter from the project.

        If there are multiple `ActivityParameters` for a single activity, only
        delete the selected instance, otherwise use `bw.parameters.remove_from_group`
        to clear out the `ParameterizedExchanges` as well.
        """
        if isinstance(parameter, ActivityParameter):
            db = parameter.database
            code = parameter.code
            amount = (ActivityParameter.select()
                      .where((ActivityParameter.database == db) &
                             (ActivityParameter.code == code))
                      .count())

            if amount > 1:
                with bw.parameters.db.atomic():
                    parameter.delete_instance()
            else:
                group = parameter.group
                act = bw.get_activity((db, code))
                bw.parameters.remove_from_group(group, act)
                # Also clear the group if there are no more parameters in it
                exists = (ActivityParameter.select()
                          .where(ActivityParameter.group == group).exists())
                if not exists:
                    with bw.parameters.db.atomic():
                        Group.delete().where(Group.name == group).execute()
        else:
            with bw.parameters.db.atomic():
                parameter.delete_instance()
        # After deleting things, recalculate and signal changes
        bw.parameters.recalculate()
        signals.parameters_changed.emit()
Esempio n. 2
0
 def modify_parameter(param: ParameterBase, field: str, value: object) -> None:
     if hasattr(param, field):
         setattr(param, field, value)
     else:
         param.data[field] = value
     param.save()
     signals.parameters_changed.emit()
Esempio n. 3
0
 def modify_parameter(self, param: ParameterBase, field: str,
                      value: Union[str, float, list]) -> None:
     with bw.parameters.db.atomic() as transaction:
         try:
             if hasattr(param, field):
                 setattr(param, field, value)
             elif field == "order":
                 # Store the given order in the Group used by the parameter
                 if param.group in value:
                     value.remove(param.group)
                 group = Group.get(name=param.group)
                 group.order = value
                 group.expire()
             else:
                 param.data[field] = value
             param.save()
             bw.parameters.recalculate()
         except Exception as e:
             # Anything wrong? Roll the transaction back and throw up a
             # warning message.
             transaction.rollback()
             QMessageBox.warning(
                 self.window, "Could not save changes", str(e),
                 QMessageBox.Ok, QMessageBox.Ok
             )
     signals.parameters_changed.emit()
Esempio n. 4
0
 def modify_parameter_uncertainty(param: ParameterBase, uncertain: dict) -> None:
     unc_fields = {"loc", "scale", "shape", "minimum", "maximum"}
     for k, v in uncertain.items():
         if k in unc_fields and isinstance(v, str):
             # Convert empty values into nan, accepted by stats_arrays
             v = float("nan") if not v else float(v)
         param.data[k] = v
     param.save()
     signals.parameters_changed.emit()
Esempio n. 5
0
 def modify_parameter_pedigree(param: ParameterBase, pedigree: dict) -> None:
     param.data["pedigree"] = pedigree
     param.save()
     signals.parameters_changed.emit()