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

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

#124 release PerfectFit sources

File size: 1.6 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.DoubleValue;
11import tudelft.dialogmanager.parameters.Parameters;
12import tudelft.dialogmanager.updatefunctions.UpdateFunction;
13
14/**
15 * Function to get difference between two timestamps (in seconds since 1970).
16 *
17 */
18public class TimeDifference implements UpdateFunction {
19
20 private final String previousTimeFieldname;
21 private final String differenceFieldname;
22
23 /**
24 *
25 * @param previousTimeFieldname the name of the parameter containing the
26 * previous time
27 * @param differenceFieldname the parameter name that will be filled with
28 * the difference (seconds) between now and
29 * previous time.
30 */
31 @JsonCreator
32 public TimeDifference(
33 @JsonProperty("previousTimeFieldname") String previousTimeFieldname,
34 @JsonProperty("differenceFieldname") String differenceFieldname)
35 throws IOException {
36 this.previousTimeFieldname = previousTimeFieldname;
37 this.differenceFieldname = differenceFieldname;
38 }
39
40 @Override
41 public Parameters call(Parameters parameters) {
42 return parameters.with(differenceFieldname,
43 new DoubleValue(System.currentTimeMillis() / 1000d
44 - parameters.getDouble(previousTimeFieldname)));
45 }
46
47 @Override
48 public List<String> getAssignedParameters() {
49 return Arrays.asList(differenceFieldname);
50 }
51
52}
Note: See TracBrowser for help on using the repository browser.