Ejemplo n.º 1
0
async def system_risk(sg_id: str,
                      data_source: Optional[str] = None,
                      rq: RequestBody = Body(...)):
    # add various risk source options
    sg = services.get_system_graph(sg_id, repo)
    return dict(name="system_risk",
                payload=services.get_risk(sg, rq.data),
                data_source=data_source)
Ejemplo n.º 2
0
async def recommend_node_supplier(sg_id: str,
                                  alpha: float,
                                  budget: int,
                                  rq: RequestBody = Body(...)):
    sg = services.get_system_graph(sg_id, repo)
    updated = services.get_system_graph_optimized_suppliers(
        sg, rq.data, {
            "alpha": alpha,
            "budget": budget
        })
    services.put_system_graph(updated, repo)
    return dict(sg_id=updated.get_id(), system_graph=updated.dict())
Ejemplo n.º 3
0
async def node_importance_sensitivity(sg_id: str,
                                      data_source: str,
                                      rq: RequestBody = Body(...),
                                      node_id: Optional[str] = None):
    sg = services.get_system_graph(sg_id, repo)
    result = services.get_birnbaum_importances(sg, rq.data, data_source)
    if node_id is None:
        return dict(name="node_importance_sensitivity",
                    payload=result,
                    node_id=node_id,
                    data_source=data_source)
    else:
        return dict(name="node_importance_sensitivity",
                    payload={node_id: result[node_id]},
                    node_id=node_id,
                    data_source=data_source)
Ejemplo n.º 4
0
async def attribute_importance_fractional(sg_id: str,
                                          rq: RequestBody = Body(...),
                                          attribute: Optional[str] = None,
                                          value: Optional[bool] = None):
    sg = services.get_system_graph(sg_id, repo)
    if attribute is not None:
        return {
            "name": "attribute_importance_fractional",
            "payload": {
                "message": "Not Implemented"
            }
        }
    else:
        return dict(name="attribute_importance_fractional",
                    payload=services.get_fractional_importance_traits(
                        sg, rq.data),
                    attribute=attribute,
                    value=value)
Ejemplo n.º 5
0
async def attribute_importance_sensitivity(sg_id: str,
                                           data_source: str,
                                           rq: RequestBody = Body(...),
                                           attribute: Optional[str] = None,
                                           value: Optional[bool] = None):
    sg = services.get_system_graph(sg_id, repo)
    if attribute is not None:
        payload = services.get_birnbaum_importances_select(
            sg, rq.data, {attribute: value}, data_source)
        return dict(name="attribute_importance_sensitivity",
                    payload=payload,
                    data_source=data_source,
                    attribute=attribute,
                    value=value)
    else:
        payload = services.get_attribute_sensitivity(sg, rq.data, data_source)
        return dict(name="attribute_importance_sensitivity",
                    payload=payload,
                    data_source=data_source,
                    attribute=attribute,
                    value=value)