Exemple #1
0
    def _populate_session(self):

        with self._service.transaction_scope() as session:

            user = User()
            user.username = "******"
            user.name = "Test User"
            user.email = "*****@*****.**"
            user.access_level = "CEH"

            session.add(user)

            pointDst = DatasetType()
            pointDst.type = "Point"

            coverDst = DatasetType()
            coverDst.type = "Coverage"

            resultDst = DatasetType()
            resultDst.type = "Result"

            session.add(pointDst)
            session.add(coverDst)
            session.add(resultDst)

            dataset_a = Dataset()
            dataset_a.dataset_type = pointDst
            dataset_a.viewable_by_user_id = self._user_id
            dataset_a.name = "Dataset1"

            session.add(dataset_a)

            dataset_b = Dataset()
            dataset_b.dataset_type = pointDst
            dataset_b.name = "Dataset2"

            session.add(dataset_b)

            dataset_c = Dataset()
            dataset_c.dataset_type = pointDst
            dataset_c.viewable_by_user_id = self._another_user_id
            dataset_c.name = "Dataset3"

            session.add(dataset_c)

            dataset_d = Dataset()
            dataset_d.dataset_type = resultDst
            dataset_d.name = "Results Dataset 1"
            dataset_d.viewable_by_user_id = 1

            session.add(dataset_d)

            analysis_a = Analysis()
            analysis_a.point_dataset = dataset_a
            analysis_a.coverage_datasets.append(AnalysisCoverageDataset(dataset_b))
            analysis_a.viewable_by = self._user_id
            analysis_a.result_dataset = dataset_d
            analysis_a.deleted = False

            analysis_b = Analysis()
            analysis_b.point_dataset = dataset_a
            analysis_b.coverage_datasets.append(AnalysisCoverageDataset(dataset_b))
            analysis_b.run_by = self._user_id
            analysis_b.result_dataset = dataset_d
            analysis_b.deleted = False

            analysis_c = Analysis()
            analysis_c.point_dataset = dataset_a
            analysis_c.coverage_datasets.append(AnalysisCoverageDataset(dataset_b))
            analysis_c.viewable_by = self._another_user_id
            analysis_c.result_dataset = dataset_d
            analysis_c.deleted = False

            session.add(analysis_a)
            session.add(analysis_b)
            session.add(analysis_c)
Exemple #2
0
    def create(self, name, point_dataset_id, coverage_dataset_ids,
               user_id, unit_of_time, random_group, model_variable,
               data_type, model_id, analysis_description,input_hash,
               time_indicies):
        """Creates a new analysis object
            Params:
                name - Friendly name for the analysis
                point_dataset_id - Id of dataset containing point data
                coverage_dataset_ids - List of coverage dataset ids, which should be
                    in the format <id>_<column_name>
                user_id - Who is creating this analysis?
                unit_of_time - unit of time selected
                random_group - additional input into the model
                model_variable - the variable that is being modelled
                data_type - data type of the variable
                model_id - id of the model to be used to generate the results
                analysis_description - a short string describing the analysis
                input_hash - used to quickly identify a duplicate analysis in terms of inputs
                time_indicies - if any columns in coverage datasets need time slicing, the index (i.e. the time slice)
                                to take will be stored against each relevant column in here
            Returns:
                ID of newly-inserted analysis
        """

        with self.transaction_scope() as session:

            analysis = Analysis()
            analysis.name = name
            analysis.run_by = user_id
            analysis.viewable_by = user_id
            analysis.point_data_dataset_id = int(point_dataset_id)
            analysis.deleted = False
            analysis.model_id = model_id
            analysis.description = analysis_description

            # Hook up the coverage datasets

            for id in coverage_dataset_ids:

                coverage_ds = AnalysisCoverageDataset()

                # The coverage dataset 'ID' is actually a
                # composite in the form <id>_<column-name>
                ds_id, column_name = id.split('_')
                id_as_int = int(ds_id)
                coverage_ds.dataset_id = id_as_int
                col = AnalysisCoverageDatasetColumn()

                # Check to see if we need to record a time index against
                # this column, will be used for time-slicing later
                if id in time_indicies:
                    col.time_index = time_indicies[id]

                col.column = column_name
                coverage_ds.columns.append(col)
                analysis.coverage_datasets.append(coverage_ds)

            # Parameters that are used in the analysis
            analysis.unit_of_time = unit_of_time
            analysis.random_group = random_group
            analysis.model_variable = model_variable
            analysis.data_type = data_type

            # Hash of input values for future comparison
            analysis.input_hash = input_hash

            session.add(analysis)

            # Flush and refresh to give us the generated ID for this new analysis
            session.flush([analysis])
            session.refresh(analysis)
            return analysis.id