From e9a17348932b02c472cf91833f72528f05a2cb0c Mon Sep 17 00:00:00 2001 From: Hayden Free Date: Thu, 16 Jan 2020 20:27:36 -0500 Subject: [PATCH] Update Project.toml --- Project.toml | 2 +- src/API.jl | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/API.jl diff --git a/Project.toml b/Project.toml index 1ee9c649..10c9816c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CurricularAnalytics" uuid = "593ffa3d-269e-5d81-88bc-c3b6809c35a6" authors = ["Greg Heileman ", "Hayden Free ", "Orhan Abar ", "Will Thompson "] -version = "0.6.3" +version = "0.6.4" [deps] Blink = "ad839575-38b3-5650-b840-f874b8c74a25" diff --git a/src/API.jl b/src/API.jl new file mode 100644 index 00000000..d3375c7b --- /dev/null +++ b/src/API.jl @@ -0,0 +1,44 @@ +#TODO - Include documentation in this file such that it builds to GitHub Pages + +using Bukdu + +struct RESTController <: ApplicationController + conn::Conn +end + +function healthcheck(c::RESTController) + render(JSON, "Healthy") +end + +function validate(c::RESTController) + @info :PAYLOAD (c.params.curriculum) + @info "Validating recieved degree plan..." + degreeplan = json_to_julia(c.params.curriculum) + result = isvalid_degree_plan(degreeplan) + if(result) + @info "Curriculum is valid." + else + @info "Curriculum is invalid" + end + render(JSON, julia_to_json(degreeplan)) +end + +function calculate_metrics(c::RESTController) + @info "Calculating degree plan metrics..." + degreeplan = json_to_julia(c.params.curriculum) + @info "Blocking factor: $(blocking_factor(degreeplan.curriculum))" + @info "Delay factor: $(delay_factor(degreeplan.curriculum))" + @info "Centrality: $(centrality(degreeplan.curriculum))" + @info "Complexity: $(complexity(degreeplan.curriculum))" + render(JSON, julia_to_json(degreeplan)) +end + +routes() do + get("/healthcheck", RESTController, healthcheck) + post("/validate", RESTController, validate) + post("/metrics", RESTController, calculate_metrics) + # create degree plan from curriculum + plug(Plug.Parsers, parsers=[:json]) +end + +Bukdu.start(8080, host="0.0.0.0") \ No newline at end of file