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