1use serde::Deserialize;
2
3const QUESTION_API: &str =
4 "https://eyodmpf7zi.execute-api.us-east-1.amazonaws.com/prod/public/question";
5
6#[derive(Deserialize, Debug)]
7pub struct Question {
8 pub date: String,
9 pub title: String,
10 pub content: String,
11 pub choices: Vec<String>,
12 pub notebook: Option<String>,
13 pub answers: u32,
14 pub performance: f32,
15 #[serde(default)]
16 pub answer: String,
17 #[serde(default)]
18 pub explanation: String,
19 #[serde(default)]
20 pub references: String,
21}
22
23#[derive(Deserialize, Debug)]
24struct Today {
25 question: Question,
26}
27
28#[derive(Deserialize, Debug)]
29pub struct Answer {
30 pub answer: String,
31 pub date: String,
32 pub choices: u8,
33 pub correct: u8,
34}
35
36#[derive(Deserialize, Debug)]
37struct Resp {
38 today: Today,
39}
40
41#[derive(Deserialize, Debug)]
42pub struct Response {
43 pub question: Question,
44 pub answer: Answer,
45}
46
47pub fn get_question() -> Question {
48 let resp: Resp = reqwest::blocking::get(QUESTION_API)
49 .expect("Expected to get question")
50 .json()
51 .unwrap();
52 resp.today.question
55}
56
57pub fn get_answer(choices: String) -> Response {
59 let mut map = ::std::collections::HashMap::new();
60 map.insert("answer", choices);
61
62 let client = reqwest::blocking::Client::new();
63 let resp: Response = client
64 .post(QUESTION_API)
65 .json(&map)
66 .send()
67 .unwrap()
68 .json()
69 .unwrap();
70 resp
73}
74
75const _SAMPLE_GET_RESP: &str = r#"
76{
77 "today": {
78 "question": {
79 "date": "20220817",
80 "title": "A classification model",
81 "content": "Natalie has been a software developer for quite some time. Although her job keeps her motivated, she wants to take her career to the next level.\n\nA critical step she wants to take is introducing machine learning into her work. She started learning some of the fundamentals and is now ready to apply what she's learned.\n\nShe researched one of her company's problems and learned she needed to build a supervised learning classification model. She had enough labeled data, so it seemed like a good fit.\n\n**Based on this, which of the following better describes what Natalie needs to accomplish?**",
82 "choices": [
83 "She needs to train a model that returns a numerical prediction for each sample of data.",
84 "She needs to train a model that clusters the data into different groups based on their characteristics.",
85 "She needs to train a model to predict the class of every sample of data out of a predefined list of classes.",
86 "She needs to train a model that returns the optimal policy that maximizes the potential outcomes of her problem."
87 ],
88 "notebook": null,
89 "answers": 1206,
90 "performance": 0.9
91 }
92 }
93}
94"#;
95
96const _SAMPLE_POST_RESP: &str = r#"
97{
98 "question": {
99 "date": "20220817",
100 "title": "A classification model",
101 "content": "Natalie has been a software developer for quite some time. Although her job keeps her motivated, she wants to take her career to the next level.\n\nA critical step she wants to take is introducing machine learning into her work. She started learning some of the fundamentals and is now ready to apply what she's learned.\n\nShe researched one of her company's problems and learned she needed to build a supervised learning classification model. She had enough labeled data, so it seemed like a good fit.\n\n**Based on this, which of the following better describes what Natalie needs to accomplish?**",
102 "choices": [
103 "She needs to train a model that returns a numerical prediction for each sample of data.",
104 "She needs to train a model that clusters the data into different groups based on their characteristics.",
105 "She needs to train a model to predict the class of every sample of data out of a predefined list of classes.",
106 "She needs to train a model that returns the optimal policy that maximizes the potential outcomes of her problem."
107 ],
108 "notebook": null,
109 "answers": 1183,
110 "performance": 0.9,
111 "answer": "0010",
112 "explanation": "Natalie's problem requires her to predict the class of every sample of data out of a predefined list of classes. That's the goal of machine learning classification models.\n\nThe first choice refers to a [regression](https://en.wikipedia.org/wiki/Regression_analysis) model. Here we want the model to output a single, continuous value. For example, imagine we want to return the predicted price of a house or the predicted highest temperature for the weekend. \n\nThe second choice refers to a [clustering](https://en.wikipedia.org/wiki/Cluster_analysis) model. These unsupervised learning techniques are helpful when we don't have labels for our data and want the algorithm to group every sample into dynamically generated groups.\n\nThe fourth choice is a loose description of a [reinforcement learning](https://en.wikipedia.org/wiki/Reinforcement_learning) approach, where we want an agent to learn the optimal policy that maximizes a reward function.",
113 "references": "* [\"4 Types of Classification Tasks in Machine Learning\"](https://machinelearningmastery.com/types-of-classification-in-machine-learning/) is an excellent introduction to classification models in machine learning.\n* For an introduction to classification models, check [\"Classification in Machine Learning: What it is and Classification Models\"](https://www.simplilearn.com/tutorials/machine-learning-tutorial/classification-in-machine-learning)"
114 },
115 "answer": {
116 "answer": "1010",
117 "date": "20220817",
118 "choices": 4,
119 "correct": 3
120 }
121}
122"#;