Beispiel #1
0
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)
Beispiel #2
0
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)})
Beispiel #3
0
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)
Beispiel #4
0
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')})