def api_preclustering_rock(project_id): database = DBSESSION() project = database.query(Project).get(project_id) if project is None: return abort(404) parameters = {x: request.form.get(x) for x in request.form} project.preclustering_rock_parameters = json.dumps(parameters) project.preclustering_rock_status = FilterStatus.RUNNING new_positions = RockPreclustering.apply(input_data=project.dataset.data, parameters=parameters) project.preclustering_rock_data = pickle.dumps(new_positions) project.preclustering_rock_status = FilterStatus.READY project.knn_graph_generation_status = FilterStatus.RECALULATION_NEEDED print('len(project.expression_list)', len(project.expression_list)) database.query(Result).filter(Result.project_id == project.id).delete() if len(project.expression_list) > 0: project.expression_list[0].new_calculation_required(database=database) database.commit() return_dict = project.to_dict() database.close() return jsonify(return_dict)
def api_project(id): database = DBSESSION() project = database.query(Project).get(id) if project is None: return abort(404) return_dict = project.to_dict() database.commit() database.close() return jsonify(return_dict)
def get_project_picture_graph_generation(id): database = DBSESSION() project = database.query(Project).get(id) if project is None: return abort(404) parameter = {x: request.form.get(x) for x in request.form} image = project.get_picture(parameter) database.commit() picture = image.picture database.close() return jsonify({'picture': picture})
def get_expression_picture(expression_id): database = DBSESSION() expression = database.query(Expression).get(expression_id) if expression is None: return abort(404) parameter = {x: request.form.get(x) for x in request.form} image = expression.get_picture(parameter) database.commit() picture = image.picture database.close() return jsonify({'picture': picture})
def api_delete_expression(expression_id): database = DBSESSION() expression = database.query(Expression).get(expression_id) if expression is None: return abort(404) project = expression.project project.expression_list.remove(expression) # fix linkage if expression.parent_expression is not None: expression.parent_expression.child_expression = expression.child_expression database.commit() database.close() return jsonify({'success': True, 'expression_id': expression_id})
def get_filter_picture(filter_id): database = DBSESSION() filter = database.query(Filter).get(filter_id) if filter is None: return abort(404) parameter = {x: request.form.get(x) for x in request.form} if filter.get_current_result() is None: return abort(404) image = filter.get_picture(parameter) database.commit() picture = image.picture database.close() return jsonify({'picture': picture})
def get_dataset_picture(dataset_id): database = DBSESSION() dataset = database.query(Dataset).get(dataset_id) if dataset is None: return abort(404) parameter = {x: request.form.get(x) for x in request.form} picture, picture_was_found = dataset.get_picture(parameter) if not picture_was_found: image = Image(parameter=parameter, picture=picture) dataset.image_list.append(image) database.commit() database.close() return jsonify({'picture': picture})
def api_delete_filter(filter_id): database = DBSESSION() filter = database.query(Filter).get(filter_id) if filter is None: return abort(404) expression = filter.expression expression.filter_list.remove(filter) expression.status = FilterStatus.RECALULATION_NEEDED expression.results.clear() if expression.child_expression is not None: expression.child_expression.new_calculation_required(database) database.commit() database.close() return jsonify({'success': True, 'filter_id': filter_id})
def api_expression_apply(expression_id): database = DBSESSION() expression = database.query(Expression).get(expression_id) if expression is None: return abort(404) expression.required_filter = int(float(request.form.get('required_filter'))) expression.apply() expression.status = FilterStatus.READY if expression.child_expression is not None: expression.child_expression.new_calculation_required(database) database.commit() return_dict = expression.to_dict() database.close() return jsonify(return_dict)
def api_generate_new_expression(project_id): database = DBSESSION() project = database.query(Project).get(project_id) if project is None: return abort(404) new_expression = Expression() if len(project.expression_list) > 0: new_expression.parent_expression = project.expression_list[len(project.expression_list) - 1] new_expression.parent_expression.child_expression = new_expression database.add(new_expression) project.expression_list.append(new_expression) database.commit() return_dict = new_expression.to_dict() database.close() return jsonify(return_dict)
def api_create_new_project(): dataset_id = int(request.form.get('dataset')) project_name = request.form.get('name') database = DBSESSION() dataset = database.query(Dataset).get(dataset_id) if dataset is None: return abort(404) project = Project(name=project_name, dataset=dataset) database.add(project) database.commit() project_id = project.id database.close() return jsonify({'success': True, 'url_to_project': url_for('view_project', project_id=project_id)})
def api_add_filter(expression_id): database = DBSESSION() expression = database.query(Expression).get(expression_id) if expression is None: return abort(404) filter_name = request.form.get('filter_name') new_filter = Filter(name=filter_name) database.add(new_filter) expression.filter_list.append(new_filter) expression.status = FilterStatus.RECALULATION_NEEDED expression.results.clear() if expression.child_expression is not None: expression.child_expression.new_calculation_required(database) database.commit() return_dict = new_filter.to_dict() database.close() return jsonify(return_dict)
def api_generate_initial_knn_graph(project_id): database = DBSESSION() project = database.query(Project).get(project_id) if project is None: return abort(404) project.knn_graph_generation_status = FilterStatus.RUNNING database.commit() parameters = {x: request.form.get(x) for x in request.form} if project.preclustering_rock_data is None: input_data = project.dataset.data else: input_data = pickle.loads(project.preclustering_rock_data) initial_graph_creation_result = generate_initial_knn_graph(data=input_data, parameters=parameters) project.set_knn_graph_generation_parameters(parameters=parameters) result = Result(parameter=parameters, intermediate_result=dict(), directed_knn_graph=initial_graph_creation_result.directed_knn_graph, undirected_knn_graph=initial_graph_creation_result.undirected_knn_graph, deletion_set=set(), data=input_data, knn_distances=initial_graph_creation_result.distances) project.knn_graph_generation_status = FilterStatus.READY if len(project.expression_list) > 0: project.expression_list[0].new_calculation_required(database=database) project.results.clear() project.results.append(result) database.commit() return_dict = project.to_dict() database.close() return jsonify(return_dict)
def api_upload_dataset(): dataset_raw = request.files.get('dataset').read().decode() dataset_name = request.form.get('name') data = list() for line in dataset_raw.split('\n'): line = line.strip() if len(line) == 0: continue point = list() for x in line.split(','): x = x.strip() x = float(x) point.append(x) data.append(point) data = numpy.array(data) database = DBSESSION() new_dataset = Dataset(name=dataset_name, data=data, number_of_rows=len(data), number_of_dimensions=len(data[0])) database.add(new_dataset) database.commit() database.close() return jsonify({'success': True, 'url_redirect': url_for('view_datasets_overview')})
def api_filter_apply(filter_id): filter_parameter = {x: request.form.get(x) for x in request.form} database = DBSESSION() filter = database.query(Filter).get(filter_id) if filter is None: return abort(404) if filter_parameter is not None: filter.update_parameter(filter_parameter) filter.apply() filter.status = FilterStatus.READY expression = filter.expression expression.status = FilterStatus.RECALULATION_NEEDED expression.results.clear() if expression.child_expression is not None: expression.child_expression.new_calculation_required(database) database.commit() database.close() return jsonify({'success': True, 'filter_id': filter_id})
def get_project_picture_preclustering_rock(id): database = DBSESSION() project = database.query(Project).get(id) if project is None: return abort(404) if project.preclustering_rock_data is None: dataset = project.dataset parameter = {x: request.form.get(x) for x in request.form} image = dataset.get_picture(parameter) project.parameter_dataset_image = image database.commit() picture = image.picture database.close() return jsonify({'picture': picture}) parameter = {x: request.form.get(x) for x in request.form} project.preclustering_rock_image_parameters = json.dumps(parameter) image_creator = ImageCreator() image = image_creator.create_image(data=pickle.loads(project.preclustering_rock_data), knn_graph=None, parameter=parameter) project.preclustering_rock_image = image database.commit() picture = image.picture database.close() return jsonify({'picture': picture})