Exemple #1
0
def monitoring():
    from sqlalchemy import distinct, func
    from dallinger.experiment_server.experiment_server import Experiment, session
    from dallinger.models import Network

    exp = Experiment(session)
    panes = exp.monitoring_panels(**request.args.to_dict(flat=False))
    network_structure = exp.network_structure(**request.args.to_dict(
        flat=False))
    vis_options = exp.node_visualization_options()
    net_roles = (session.query(Network.role, func.count(
        Network.role)).group_by(Network.role).order_by(Network.role).all())
    net_ids = [
        i[0] for i in session.query(distinct(Network.id)).order_by(
            Network.id).all()
    ]
    return render_template(
        "dashboard_monitor.html",
        title="Experiment Monitoring",
        panes=panes,
        network_structure=json.dumps(network_structure, default=date_handler),
        net_roles=net_roles,
        net_ids=net_ids,
        vis_options=json.dumps(vis_options),
    )
Exemple #2
0
    def test_table_data(self, a, db_session):
        from dallinger.experiment_server.experiment_server import Experiment
        from dallinger.models import Network

        exp = Experiment(db_session)

        network = Network.query.all()[0]

        table = exp.table_data(model_type=["Network"])
        assert len(table["data"]) == 1
        assert table["data"][0]["id"] == network.id
        assert table["data"][0]["role"] == network.role
        assert len(table["columns"]) > 2
        for col in table["columns"]:
            if col["data"] == "role":
                assert col == {"data": "role", "name": "role"}
                break
        else:
            raise KeyError("'role' not in Network columns")

        source = a.source(network=network)

        table = exp.table_data(model_type="Node")
        assert len(table["data"]) == 1
        assert table["data"][0]["id"] == source.id
        assert table["data"][0]["type"] == source.type
        assert len(table["columns"]) > 2
        for col in table["columns"]:
            if col["data"] == "id":
                assert col == {"data": "id", "name": "id"}
                break
        else:
            raise KeyError("'id' not in Node columns")
Exemple #3
0
def database():
    from dallinger.experiment_server.experiment_server import Experiment, session

    title = "Database View"
    exp = Experiment(session)
    model_type = request.args.get("model_type")
    if model_type:
        title = "Database View: {}s".format(model_type)
    datatables_options = prep_datatables_options(
        exp.table_data(**request.args.to_dict(flat=False)))
    columns = [
        c.get("name") or c["data"]
        for c in datatables_options.get("columns", []) if c.get("data")
    ]

    # Extend with custom actions
    actions = {
        "extend": "collection",
        "text": "Actions",
        "buttons": [],
    }
    buttons = actions["buttons"]

    exp_actions = exp.dashboard_database_actions()
    for action in exp_actions:
        buttons.append({
            "extend": "route_action",
            "text": action["title"],
            "route_name": action["name"],
        })

    is_sandbox = getattr(recruiters.from_config(get_config()), "is_sandbox",
                         None)
    if is_sandbox is True or is_sandbox is False:
        buttons.append("compensate")
    else:
        is_sandbox = None

    if len(buttons):
        datatables_options["buttons"].append(actions)

    return render_template(
        "dashboard_database.html",
        title=title,
        columns=columns,
        is_sandbox=is_sandbox,
        datatables_options=json.dumps(datatables_options,
                                      default=date_handler,
                                      indent=True),
    )
Exemple #4
0
def database_action(route_name):
    from dallinger.experiment_server.experiment_server import Experiment, session

    data = request.json
    exp = Experiment(session)
    if route_name not in {a["name"] for a in exp.dashboard_database_actions()}:
        return error_response(
            error_text="Access to {} not allowed".format(route_name),
            status=403)
    route_func = getattr(exp, route_name, None)
    if route_func is None:
        return error_response(
            error_text="Method {} not found".format(route_name), status=404)
    result = route_func(data)
    session.commit()
    if result.get("message"):
        flash(result["message"], "success")
    return success_response(**result)
Exemple #5
0
def database():
    from dallinger.experiment_server.experiment_server import Experiment, session

    title = "Database View"
    exp = Experiment(session)
    model_type = request.args.get("model_type")
    if model_type:
        title = "Database View: {}s".format(model_type)
    datatables_options = prep_datatables_options(
        exp.table_data(**request.args.to_dict(flat=False)))
    columns = [
        c.get("name") or c["data"]
        for c in datatables_options.get("columns", []) if c.get("data")
    ]
    return render_template(
        "dashboard_database.html",
        title=title,
        columns=columns,
        datatables_options=json.dumps(datatables_options,
                                      default=date_handler,
                                      indent=True),
    )
Exemple #6
0
    def multinetwork_experiment(self, a, db_session):
        from dallinger.experiment_server.experiment_server import Experiment
        from dallinger.models import Network

        exp = Experiment(db_session)

        network = Network.query.all()[0]
        network2 = a.network(role="test")
        a.participant(
            recruiter_id="hotair",
            worker_id="1",
            hit_id="1",
            assignment_id="1",
            mode="test",
        )
        source = a.source(network=network)
        source2 = a.source(network=network2)
        info1 = a.info(origin=source, contents="contents1")
        info2 = a.info(origin=source, contents="contents2")
        info3 = a.info(origin=source2, contents="contents3")
        info4 = a.info(origin=source2, contents="contents3")
        a.transformation(info_in=info1, info_out=info2)
        a.transformation(info_in=info3, info_out=info4)
        yield exp
Exemple #7
0
    def test_network_structure(self, a, db_session):
        from dallinger.experiment_server.experiment_server import Experiment
        from dallinger.models import Network

        exp = Experiment(db_session)

        network = Network.query.all()[0]

        network_structure = exp.network_structure()
        assert len(network_structure["networks"]) == 1
        assert network_structure["networks"][0]["id"] == network.id
        assert network_structure["networks"][0]["role"] == network.role
        assert len(network_structure["nodes"]) == 0
        assert len(network_structure["vectors"]) == 0
        assert len(network_structure["infos"]) == 0
        assert len(network_structure["participants"]) == 0
        assert len(network_structure["trans"]) == 0

        source = a.source(network=network)

        network_structure = exp.network_structure()
        assert len(network_structure["nodes"]) == 1
        assert network_structure["nodes"][0]["type"] == source.type

        # Transformations are not included by default
        info1 = a.info(origin=source, contents="contents1")
        info2 = a.info(origin=source, contents="contents2")
        a.transformation(info_in=info1, info_out=info2)

        network_structure = exp.network_structure()
        assert len(network_structure["nodes"]) == 1
        assert len(network_structure["infos"]) == 2
        assert len(network_structure["trans"]) == 0

        network_structure = exp.network_structure(transformations="on")
        assert len(network_structure["trans"]) == 1
Exemple #8
0
def node_details(object_type, obj_id):
    from dallinger.experiment_server.experiment_server import Experiment, session

    exp = Experiment(session)
    html_data = exp.node_visualization_html(object_type, obj_id)
    return Response(html_data, status=200, mimetype="text/html")