diff --git a/Manifest.toml b/Manifest.toml index 7bd8da7..07979e2 100755 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.8.2" manifest_format = "2.0" -project_hash = "c29e8447aeee171858dde0b54605eebd985a214b" +project_hash = "c18c5eaab58f1afb699d93a8a6f512a73acf8b7c" [[deps.ArgParse]] deps = ["Logging", "TextWrap"] @@ -140,6 +140,12 @@ git-tree-sha1 = "0fa3b52a04a4e210aeb1626def9c90df3ae65268" uuid = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615" version = "1.1.0" +[[deps.FileIO]] +deps = ["Pkg", "Requires", "UUIDs"] +git-tree-sha1 = "94f5101b96d2d968ace56f7f2db19d0a5f592e28" +uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +version = "1.15.0" + [[deps.FilePathsBase]] deps = ["Compat", "Dates", "Mmap", "Printf", "Test", "UUIDs"] git-tree-sha1 = "e27c4ebe80e8699540f2d6c805cc12203b614f12" @@ -230,6 +236,12 @@ git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" uuid = "82899510-4779-5014-852e-03e436cf321d" version = "1.0.0" +[[deps.JLD2]] +deps = ["FileIO", "MacroTools", "Mmap", "OrderedCollections", "Pkg", "Printf", "Reexport", "TranscodingStreams", "UUIDs"] +git-tree-sha1 = "1c3ff7416cb727ebf4bab0491a56a296d7b8cf1d" +uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +version = "0.4.25" + [[deps.JLLWrappers]] deps = ["Preferences"] git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1" @@ -317,6 +329,12 @@ git-tree-sha1 = "dedbebe234e06e1ddad435f5c6f4b85cd8ce55f7" uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" version = "2.2.2" +[[deps.MacroTools]] +deps = ["Markdown", "Random"] +git-tree-sha1 = "3d3e902b31198a27340d0bf00d6ac452866021cf" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.9" + [[deps.Markdown]] deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" diff --git a/Project.toml b/Project.toml index a0aae69..30dbb34 100755 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Genie = "c43c736e-a2d1-11e8-161f-af95117fbd1e" HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" Inflector = "6d011eab-0732-4556-8808-e463c76bf3b6" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/app/resources/results/Results.jl b/app/resources/results/Results.jl index 4a0bae4..920dc7d 100644 --- a/app/resources/results/Results.jl +++ b/app/resources/results/Results.jl @@ -2,7 +2,7 @@ module Results using SearchLight using ..Main.UserApp.Surveys, Dates -using DataFrames, CSV, JSON3, SQLite +using DataFrames, CSV, JSON3, SQLite, JLD2 export surveys, questions, responseids, results, register!, deregister!, save!, clear! @@ -112,6 +112,17 @@ function results(survey::SurveyID, resids::Vector{ResponseID}; @info "" DataFrame(data) DataFrame(data) |> if format == :DataFrame identity + elseif format == :jld2 + df -> (mktemp() do path, _ + df.id = resids + jldsave(path; results = select(df, :id, :), + responses = map(res) do r + (; id=r.id, exip=r.exip, started=r.started, + completed=r.completed, r.page) + end |> DataFrame, + questions = questions(survey; cache)) + read(path) + end) elseif format == :csv df -> sprint(CSV.write, df) elseif format == :tsv diff --git a/app/resources/results/ResultsController.jl b/app/resources/results/ResultsController.jl index a862560..f574a84 100644 --- a/app/resources/results/ResultsController.jl +++ b/app/resources/results/ResultsController.jl @@ -28,6 +28,9 @@ function resultsfile(survey::SurveyID, format::AbstractString) elseif format == "db" || format == "sqlite" HTTP.Response(200, ["Content-Type" => "application/octet-stream"], body = results(survey, format=:sqlite)) + elseif format == "jld2" + HTTP.Response(200, ["Content-Type" => "application/x-hdf5"], + body = results(survey, format=:jld2)) else error("format $format not recognised") end @@ -50,6 +53,9 @@ function resultsfile(survey::SurveyID, responseid::ResponseID, format::AbstractS elseif format == "db" || format == "sqlite" HTTP.Response(200, ["Content-Type" => "application/octet-stream"], body = results(survey, [responseid], format=:sqlite)) + elseif format == "jld2" + HTTP.Response(200, ["Content-Type" => "application/x-hdf5"], + body = results(survey, [responseid], format=:jld2)) else error("format $format not recognised") end diff --git a/app/resources/results/views/survey.jl.html b/app/resources/results/views/survey.jl.html index e7823a1..fa9a5e5 100644 --- a/app/resources/results/views/survey.jl.html +++ b/app/resources/results/views/survey.jl.html @@ -15,12 +15,13 @@

$(name)

- $(size(sresults, 1)) results also available as + $(size(sresults, 1)) results also available as Text, CSV, TSV, JSON, - SQLite DB + SQLite DB, + JLD2
diff --git a/routes.jl b/routes.jl index 0c048cc..5a26592 100755 --- a/routes.jl +++ b/routes.jl @@ -27,20 +27,20 @@ route("/results/:survey#([A-Za-z0-9]+)", ResultsController.resultsindex(surveyid) end -route("/results/:surveyandformat#([A-Za-z0-9]+\\.[a-z]+)") do +route("/results/:surveyandformat#([A-Za-z0-9]+\\.[a-z0-9]+)") do @info "" payload(:surveyandformat) - survey, format = match(r"([A-Za-z0-9]+)\.([a-z]+)", payload(:surveyandformat)).captures + survey, format = match(r"([A-Za-z0-9]+)\.([a-z0-9]+)", payload(:surveyandformat)).captures surveyid = tryparse(SurveysController.SurveyID, survey, base=10) ResultsController.resultsfile(surveyid, format) end -route("/results/:survey#([A-Za-z0-9]+)/:format#([a-z]+)", +route("/results/:survey#([A-Za-z0-9]+)/:format#([a-z0-9]+)", named = :surveyresult) do surveyid = tryparse(SurveysController.SurveyID, payload(:survey), base=10) ResultsController.resultsfile(surveyid, payload(:format)) end -route("/results/:survey#([A-Za-z0-9]+)/:responsefile#([A-Za-z0-9]+\\.[a-z]+)", +route("/results/:survey#([A-Za-z0-9]+)/:responsefile#([A-Za-z0-9]+\\.[a-z0-9]+)", named = :result) do surveyid = tryparse(SurveysController.SurveyID, payload(:survey), base=10) response, format = split(payload(:responsefile), '.')