package ask
Create/Answer questionnaires
Install
Dune Dependency
Authors
Maintainers
Sources
0.2.0.tar.gz
md5=05a93836d4cb56962eb57c56387dc1aa
sha512=91fae426d7ef0745262e62e201204e9bfda3d9165d165f110661bc917648fec60e6041d800a9d9fa5258f6a457487a17726c304c837305f8df950822ffaad990
Description
Generating and answering questions should be easy
Published: 30 Mar 2021
README
Ask
Questionnaires with support for creating and answering questions
Note that it's still under active development and it only supports mariadb so far.
Ask package
About
Ask allows you to create and answer Questionnaires. Additionaly it provides templating for quesitonnaires.
Usage
let empty_questionnaire_with_three_questions ~label =
let open AskService.Questionnaire in
(* Create a template, e.g. label:"details-template" *)
let* template_id = create_template ~label () in
(* Creating Questions *)
let question1 =
Model.Question.Text
( Uuidm.create `V4 |> Uuidm.to_string
, Some "age"
, None
, "How old are you?"
, None
, ""
, true )
in
let question2 =
Model.Question.YesNo
( Uuidm.create `V4 |> Uuidm.to_string
, Some "student"
, None
, "Are you a student?"
, false )
in
let question3 =
Model.Question.File
( Uuidm.create `V4 |> Uuidm.to_string
, Some "diploma"
, None
, "Upload your diploma."
, [ "application/pdf" ]
, 100000
, true )
in
(* Adding the questions to the template *)
let* _ = add_question ~template_id ~order:0 question1 in
let* _ = add_question ~template_id ~order:1 question2 in
let* _ = add_question ~template_id ~order:2 question3 in
(* Instantiate a new questionnaire *)
let* questionnaire_id =
instantiate_questionnaire
~template_id
~questionnaire_id:(Uuidm.create `V4 |> Uuidm.to_string)
in
(* Find previously created questionnaire *)
let* questionnaire =
find questionnaire_id
|> Lwt.map (Option.to_result ~none:"Seed failed, can not create questionnaire")
|> Lwt.map CCResult.get_or_failwith
in
Lwt.return (questionnaire, question1, question2, question3)
;;
let questionnaire_with_three_answered_questions ~label =
let open AskService.Questionnaire in
(* Creating an empty questionnaire with the function above *)
(* e.g. label:"details-template" *)
let* questionnaire, question1, question2, question3 =
empty_questionnaire_with_three_questions ~label
in
(* Create answers *)
let answer1 = Some (Model.AnswerInput.Text "18") in
let answer2 = Some (Model.AnswerInput.Text "Yes") in
let answer3 =
Some
(Model.AnswerInput.Asset
(None, "new_diploma.pdf", 12345, "application/pdf", "aGVsbG9vb28="))
in
(* answering questions *)
let* () = answer questionnaire [ question1, answer1; question2, answer2 ] in
(* We have to upload file separately *)
let* () = answer questionnaire [ question3, answer3 ] in
(* find answered questionnaire *)
let questionnaire_id = Model.Questionnaire.uuid questionnaire in
let* questionnaire =
find questionnaire_id
|> Lwt.map (Option.to_result ~none:"No questionnaire found")
|> Lwt.map CCResult.get_or_failwith
in
Lwt.return (Ok (questionnaire, question1, question2, question3))
;;
Ask integrator package
A helper to assign a questionniare to any type which has a uuid.
Quest allows you to create Questionnaires, add some questions and answer them in an easy way. The integrator adds the opportunity to add the questionnaire to any type which has an uuid.
Usage
let ask_integrator_with_one_filled_questionnaire =
let open Ask_integrator.Model in
(* member id has the format uuid and is used to link one of your models (e.g. to a User) *)
let member_id = Uuidm.create `V4 |> Uuidm.to_string in
(* member label is a string which should help you where the member id is comming from *)
let member_label = "user" in
(* questionnaire_label is a label for the linked questionnaire, it's possible to search for that label for a specified integrator *)
let questionnaire_label = "personal details" in
(* Create an answered questionnaire, see function above *)
let* questionnaire, _, _, _ =
QuestTest.questionnaire_with_three_answered_questions ~label:"details-template"
|> Lwt.map CCResult.get_or_failwith
in
(* Create the integrator object *)
AskService.create
~member_id
~member_label
~questionnaires:[ questionnaire_label, questionnaire ]
;;
Development
The project is prepared for development with VS Code and DevContainers.
Dependencies (7)
-
ppx_fields_conv
>= "0.13.0"
-
lwt_ssl
>= "1.1.3"
-
conformist
= "0.4.0"
-
sihl-storage
= "0.4.0"
-
sihl
= "0.4.0"
-
ocaml
>= "4.11"
-
dune
>= "2.7"
Dev Dependencies (4)
-
odoc
with-doc
-
ocamlformat
dev
-
caqti-driver-mariadb
>= "1.2.1" & with-test
-
alcotest-lwt
>= "1.3.0" & with-test
Used by (1)
Conflicts
None
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page