1
0
mirror of https://github.com/ellmau/adf-obdd.git synced 2025-12-19 09:29:36 +01:00

Start creating parsing only output for pmc-vis

This commit is contained in:
monsterkrampe 2024-03-28 10:26:08 +01:00
parent 5bb2ebc7eb
commit 8619cd9f83
No known key found for this signature in database
GPG Key ID: B8ADC1F5A5CE5057
3 changed files with 210 additions and 25 deletions

View File

@ -115,4 +115,27 @@ impl DoubleLabeledGraph {
hi_edges, hi_edges,
} }
} }
pub fn only_roots(&self) -> DoubleLabeledGraph {
todo!()
}
pub fn only_node_with_successors_roots(&self, node: String) -> DoubleLabeledGraph {
todo!()
}
pub fn nodes_iter(&self) -> impl Iterator<Item = (String, String)> + '_ {
self.node_labels.iter().map(|(k, v)| (k.clone(), v.clone()))
}
pub fn edges_iter(&self) -> impl Iterator<Item = (String, String, String)> + '_ {
self.lo_edges
.iter()
.map(|(k, v)| (k.clone(), v.clone(), "lo".to_string()))
.chain(
self.hi_edges
.iter()
.map(|(k, v)| (k.clone(), v.clone(), "hi".to_string())),
)
}
} }

View File

@ -18,20 +18,18 @@ use actix_cors::Cors;
mod adf; mod adf;
mod config; mod config;
mod double_labeled_graph; mod double_labeled_graph;
mod user;
mod pmc_vis; mod pmc_vis;
mod user;
use adf::{ use adf::{
add_adf_problem, delete_adf_problem, get_adf_problem, get_adf_problems_for_user, add_adf_problem, delete_adf_problem, get_adf_problem, get_adf_problems_for_user,
solve_adf_problem, solve_adf_problem,
}; };
use config::{AppState, ASSET_DIRECTORY, COOKIE_DURATION}; use config::{AppState, ASSET_DIRECTORY, COOKIE_DURATION};
use pmc_vis::{pmc_vis_get_initial, pmc_vis_get_outgoing};
use user::{ use user::{
create_username_index, delete_account, login, logout, register, update_user, user_info, create_username_index, delete_account, login, logout, register, update_user, user_info,
}; };
use pmc_vis::{
pmc_vis_get_initial, pmc_vis_get_outgoing,
};
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {

View File

@ -1,8 +1,12 @@
use crate::{
adf::{AcAndGraph, AdfProblem, OptionWithError},
config::{AppState, RunningInfo, Task, ADF_COLL, COMPUTE_TIME, DB_NAME, USER_COLL},
double_labeled_graph::DoubleLabeledGraph,
};
use actix_identity::Identity; use actix_identity::Identity;
use actix_web::{get, web, HttpResponse, Responder, http::header}; use actix_web::{get, http::header, web, HttpResponse, Responder};
use serde::Deserialize; use mongodb::bson::doc;
use crate::config::AppState; use serde::{Deserialize, Serialize};
const DUMMY_INITIAL: &str = r#"{ const DUMMY_INITIAL: &str = r#"{
"nodes": [ "nodes": [
@ -802,18 +806,131 @@ const DUMMY_OUTGOING : &str = r#"{
] ]
}"#; }"#;
#[get("/{problem_id}/initial")] #[derive(Serialize)]
struct PmcVisNode {
id: String,
name: String,
#[serde(rename = "type")]
node_type: String,
}
#[derive(Serialize)]
struct PmcVisEdge {
source: String,
target: String,
label: String,
}
struct PmcVisGraph {
nodes: Vec<PmcVisNode>,
edges: Vec<PmcVisEdge>,
}
impl From<DoubleLabeledGraph> for PmcVisGraph {
fn from(graph: DoubleLabeledGraph) -> Self {
PmcVisGraph {
nodes: graph
.nodes_iter()
.map(|(k, v)| PmcVisNode {
id: k,
name: v,
node_type: "s".to_string(),
})
.collect(),
edges: graph
.edges_iter()
.map(|(s, t, l)| PmcVisEdge {
source: s,
target: t,
label: l,
})
.collect(),
}
}
}
#[derive(Serialize)]
struct PmcVisInfo {
#[serde(rename = "ID")]
id: String,
}
#[derive(Serialize)]
struct PmcVisDto {
nodes: Vec<PmcVisNode>,
edges: Vec<PmcVisEdge>,
info: PmcVisInfo,
}
impl PmcVisDto {
fn from_pmc_vis_graph_and_id(graph: PmcVisGraph, id: String) -> Self {
Self {
nodes: graph.nodes,
edges: graph.edges,
info: PmcVisInfo { id },
}
}
}
#[get("/{problem_name}/initial")]
async fn pmc_vis_get_initial( async fn pmc_vis_get_initial(
_app_state: web::Data<AppState>, app_state: web::Data<AppState>,
_identity: Option<Identity>, identity: Option<Identity>,
path: web::Path<String>, path: web::Path<String>,
) -> impl Responder { ) -> impl Responder {
let _problem_id = path.into_inner(); let problem_name = path.into_inner();
HttpResponse::Ok() let adf_coll: mongodb::Collection<AdfProblem> = app_state
.append_header(header::ContentType::json()) .mongodb_client
.body(DUMMY_INITIAL) .database(DB_NAME)
// HttpResponse::Ok().json(...) .collection(ADF_COLL);
let username = match identity.map(|id| id.id()) {
None => {
return HttpResponse::Unauthorized().body("You need to login to get an ADF problem.")
}
Some(Err(err)) => return HttpResponse::InternalServerError().body(err.to_string()),
Some(Ok(username)) => username,
};
let adf_problem = match adf_coll
.find_one(doc! { "name": &problem_name, "username": &username }, None)
.await
{
Err(err) => return HttpResponse::InternalServerError().body(err.to_string()),
Ok(None) => {
return HttpResponse::NotFound()
.body(format!("ADF problem with name {problem_name} not found."))
}
Ok(Some(prob)) => prob,
};
let parse_only_graph: DoubleLabeledGraph = match adf_problem.acs_per_strategy.parse_only {
OptionWithError::None => {
return HttpResponse::BadRequest().body("The ADF problem has not been parsed yet.")
}
OptionWithError::Error(err) => {
return HttpResponse::BadRequest().body(format!(
"The ADF problem could not be parsed. Update it and try again. Error: {err}"
))
}
OptionWithError::Some(acs_and_graphs) => {
acs_and_graphs
.first()
.expect("There should be exacly one graph in the parsing result.")
.clone()
.graph
}
};
HttpResponse::Ok().json(PmcVisDto::from_pmc_vis_graph_and_id(
PmcVisGraph::from(parse_only_graph.only_roots()),
problem_name,
))
// HttpResponse::Ok()
// .append_header(header::ContentType::json())
// .body(DUMMY_INITIAL)
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -823,16 +940,63 @@ struct OutgoingQuery {
#[get("/{problem_id}/outgoing")] #[get("/{problem_id}/outgoing")]
async fn pmc_vis_get_outgoing( async fn pmc_vis_get_outgoing(
_app_state: web::Data<AppState>, app_state: web::Data<AppState>,
_identity: Option<Identity>, identity: Option<Identity>,
path: web::Path<String>, path: web::Path<String>,
query: web::Query<OutgoingQuery>, query: web::Query<OutgoingQuery>,
) -> impl Responder { ) -> impl Responder {
let _problem_id = path.into_inner(); let problem_name = path.into_inner();
let _node_id = &query.id; let node_id = &query.id;
HttpResponse::Ok() let adf_coll: mongodb::Collection<AdfProblem> = app_state
.append_header(header::ContentType::json()) .mongodb_client
.body(DUMMY_OUTGOING) .database(DB_NAME)
// HttpResponse::Ok().json(...) .collection(ADF_COLL);
let username = match identity.map(|id| id.id()) {
None => {
return HttpResponse::Unauthorized().body("You need to login to get an ADF problem.")
}
Some(Err(err)) => return HttpResponse::InternalServerError().body(err.to_string()),
Some(Ok(username)) => username,
};
let adf_problem = match adf_coll
.find_one(doc! { "name": &problem_name, "username": &username }, None)
.await
{
Err(err) => return HttpResponse::InternalServerError().body(err.to_string()),
Ok(None) => {
return HttpResponse::NotFound()
.body(format!("ADF problem with name {problem_name} not found."))
}
Ok(Some(prob)) => prob,
};
let parse_only_graph: DoubleLabeledGraph = match adf_problem.acs_per_strategy.parse_only {
OptionWithError::None => {
return HttpResponse::BadRequest().body("The ADF problem has not been parsed yet.")
}
OptionWithError::Error(err) => {
return HttpResponse::BadRequest().body(format!(
"The ADF problem could not be parsed. Update it and try again. Error: {err}"
))
}
OptionWithError::Some(acs_and_graphs) => {
acs_and_graphs
.first()
.expect("There should be exacly one graph in the parsing result.")
.clone()
.graph
}
};
HttpResponse::Ok().json(PmcVisDto::from_pmc_vis_graph_and_id(
PmcVisGraph::from(parse_only_graph.only_node_with_successors_roots(node_id.to_string())),
problem_name,
))
// HttpResponse::Ok()
// .append_header(header::ContentType::json())
// .body(DUMMY_OUTGOING)
} }