source: PerfectFit/Dialog/src/main/java/tudelft/mentalhealth/perfectfit/updatefuncs/Example.java

Last change on this file was 7, checked in by Wouter Pasman, 9 months ago

#124 release PerfectFit sources

File size: 2.7 KB
Line 
1package tudelft.mentalhealth.perfectfit.updatefuncs;
2
3import java.io.IOException;
4import java.util.Arrays;
5import java.util.List;
6
7import com.fasterxml.jackson.annotation.JsonCreator;
8import com.fasterxml.jackson.annotation.JsonProperty;
9
10import tudelft.dialogmanager.parameters.Parameters;
11import tudelft.dialogmanager.parameters.StringValue;
12import tudelft.dialogmanager.updatefunctions.UpdateFunction;
13import tudelft.mentalhealth.perfectfit.Characteristics;
14import tudelft.mentalhealth.perfectfit.GoalLine;
15import tudelft.mentalhealth.perfectfit.SortedGoals;
16
17/**
18 * function that fetches the intro and goalhow text from the database and stores
19 * it in given fields. Also stores current time. This function assumes that the
20 * 10 parameters godin_activity ..... household_size have all been been set
21 * properly to their non-normalized values.
22 */
23public class Example implements UpdateFunction {
24
25 private final Integer nr;
26 private final String introfieldname;
27 private final String goalhowfieldname;
28
29 /**
30 * @param nr get the nr-th best example. 0 is best, 1 is next
31 * best etc.
32 * @param introfieldname the field name where to store the intro text
33 * @param goalhowfieldname the field name where to store the goalhow text
34 * @throws IOException
35 */
36 @JsonCreator
37 public Example(@JsonProperty("nr") Integer nr,
38 @JsonProperty("introfieldname") String introfieldname,
39 @JsonProperty("goalhowfieldname") String goalhowfieldname)
40 throws IOException {
41 this.nr = nr;
42 this.introfieldname = introfieldname;
43 this.goalhowfieldname = goalhowfieldname;
44
45 }
46
47 @Override
48 public Parameters call(Parameters parameters) {
49 try {
50// System.out.println("user params:" + parameters);
51 Characteristics characteristics = Characteristics.normalize(
52 parameters.getDouble("godin_activity"),
53 parameters.getDouble("exercise_se"),
54 parameters.getDouble("exercise_identity"),
55 parameters.getDouble("extraversion"),
56 parameters.getDouble("ttm_pa"),
57 parameters.getDouble("openness_to_experiences"),
58 parameters.getDouble("sitting_weekend"),
59 parameters.getDouble("age"),
60 parameters.getDouble("household_income"),
61 parameters.getDouble("household_size"));
62 SortedGoals goals = new SortedGoals(characteristics);
63 GoalLine goal = goals.get(nr);
64 return parameters
65 .with(introfieldname,
66 new StringValue(
67 "🧍<em> " + goal.getIntro() + "</em>"))
68 .with(goalhowfieldname, new StringValue("🎯 <b>"
69 + goal.getGoal() + goal.getHow() + "</b>"));
70
71 } catch (IOException e) {
72 throw new RuntimeException("Bug. ", e);
73 }
74
75 }
76
77 @Override
78 public List<String> getAssignedParameters() {
79 return Arrays.asList(introfieldname, goalhowfieldname);
80 }
81
82}
Note: See TracBrowser for help on using the repository browser.