コード例 #1
0
    def _query_create (self, cls, **kwargs) :
        _obj = queryset_django.create(cls, **kwargs)
        _obj = MethodCreateIndex.attach_create_index(_obj)

        _obj.to_create_index = None

        return _obj
コード例 #2
0
    def find_or_make_variables(possible_variables: QuerySet,
                               instrument_id: int,
                               reduction_arguments: dict,
                               run_number: Optional[int] = None,
                               experiment_reference: Optional[int] = None,
                               from_webapp=False) -> List:
        """
        Find appropriate variables from the possible_variables QuerySet, or make the necessary variables

        :param possible_variables: A queryset holding the possible variables to be re-used
        :param instrument_id: ID of the instrument object
        :param reduction_arguments: A dictionary holding all required reduction arguments
        :param run_number: Optional, the run number from which these variables will be active
        :param expriment_reference: Optional, the experiment number for which these variables WILL ALWAYS be used.
                                    Variables set for experiment are treated as top-priority.
                                    They can only be changed or deleted from the web app.
                                    They will not be affected by variables for a run range or changing
                                    the values in reduce_vars.
        :param from_webapp: If the call is made from the web app we want to ignore the variable's own tracks_script flag
                            and ALWAYS overwrite the value of the variable with what has been passed in
        """
        all_vars: List[Tuple[str, Any, bool]] = [(name, value, False)
                                                 for name, value in reduction_arguments["standard_vars"].items()]
        all_vars.extend([(name, value, True) for name, value in reduction_arguments["advanced_vars"].items()])

        if len(all_vars) == 0:
            return []

        variables = []
        for name, value, is_advanced in all_vars:
            script_help_text = InstrumentVariablesUtils.get_help_text(
                'standard_vars' if not is_advanced else 'advanced_vars', name, reduction_arguments)
            new_value = str(value).replace('[', '').replace(']', '')
            new_type = VariableUtils.get_type_string(value)

            # Try to find a suitable variable to re-use from the ones that already exist
            variable = InstrumentVariablesUtils.find_appropriate_variable(possible_variables, name,
                                                                          experiment_reference)
            # if no suitable variable is found - create a new one
            if variable is None:
                var_kwargs = {
                    'name': name,
                    'value': new_value,
                    'type': new_type,
                    'help_text': script_help_text,
                    'is_advanced': is_advanced,
                    'instrument_id': instrument_id
                }
                variable = possible_variables.create(**var_kwargs)
                # if the variable was just created then set it to track the script
                # and that it starts on the current run
                # if it was found already existing just leave it as it is
                if experiment_reference:
                    variable.experiment_reference = experiment_reference
                else:
                    variable.start_run = run_number
                    variable.tracks_script = not from_webapp
                variable.save()
            else:
                InstrumentVariablesUtils.update_if_necessary(variable, experiment_reference, run_number, new_value,
                                                             new_type, script_help_text, from_webapp)
            variables.append(variable)
        return variables