QuestionQuestion

Transcribed TextTranscribed Text

A State Tracker For this final task, you develop a conditional trace. This allows (Such as, for example, minute programming, minute sports, satisfaction, pulse, ...) And define targets for these values. On the basis of the collected data can then Simple evaluations about the history, for example how often the set goals were achieved become. In the second part of the task you develop an additional functionality, A series of stress measurement values at the heart are first cleaned in a predetermined simplified scheme And normalized to then recognize certain patterns and calculate a heart rate therefrom. B.1 State tracking The relevant concepts are presented in this section. B.1.1Time model For simplicity, the days in the program are numbered consecutively starting at 0. The first week starts at day 0, the second at day 7, and so on. This means in particular that Week 1 includes days 0 to 6 (inclusive) B.1.2 Static types The user can create any type of stator. A static type must have a name that is only from lowercase letters and does not contain any special characters (including spaces). A status type has an aggregation method. This describes how values are collected for one day. The following aggregation methods exist: • • Sum (sum): Measured values are added up. • • Average (avg): The arithmetic mean (average) of the measured values is formed. • • Last value (last): Only the last value is taken into account. • • Minimum / Maximum (minmax): The minimum / maximum values are stored and further processed. The identifier of the aggregation method specified by the user is indicated in brackets behind the type In the interaction with the program. There is a predefined type pulse that has a Pulse measurement defined ( 1/min ) This has the aggregation method Minimum/Maximum. B.1.3 Measurements The user can enter measurements for existing stator types. For the pulse, this is, for example, one Pulse measurement or for the activity "programming" a number of minutes. The unit for a stator type Is not explicitly set or checked, but is implicitly fixed. B.1.4 Objectives The user can also set targets for created stat types. For each activity type, can oly be added one goeal at a time. Goals can also be overwritten or deleted. When evaluating the achieved goals or the current progress, only the currently defined goal is always taken into account (Also for historical analyzes). These are the following types of goals: (1) Lesser than the value: The aggregated value must be really lesser than value. In the aggregation method Minimum / maximum , the maximum must be really smaller than value. (2) Greater than value: The aggregated value must be true greater than value. In the aggregation method Minimum / Maximum , the minimum must be true greater than the value. (3) Between min and max: The aggregated value must be between min and max (not including). For the minimum / maximum aggregation method , the minimum is greater than min And the maximum is actually less than max. B.1.5 Initial state If the program is started, it is at day 0 . At the beginning there are no status types other than the predefined type pulse. There are no measurements or targets B.1.6 Commands The following describes the commands that your program must offer. The form of the command, errors, the possible values for arguments and, if necessary, an example input and output are given. The angle brackets (< and >) are not part of the command and are not entered by the user. They are placeholders that are to be filled by the user with values. The character ␣ stands for a space ('', ASCII 32, Unicode CodePoint U + 0020). A placeholder is always filled by the user by a string that does not contain a whitespace (space, tab, ...). C1 – add <type> <aggregation> Adds a new stator type. <Type> is the name of the new status type. It may only be made up of lowercase letters. <Aggregation> determines the aggregation type, that means the value sum, avg, last or Minmax Error: if the statustype already exists or the aggregation type is unknown. Output: Added <type> with aggregation <aggregation>. Example > add happiness minmax Added happiness with aggregation minmax. > add pulse sum Error, pulse already exists. C2 – goal <type> <goal description> Sets a new goal for the <type> or overwrites an existing goal. For occupancy of <goal description> there are the following options: • less-than <value> . • greater-than <value> . • between <min> and <max> . <value> , <min> und <max> are each positive or egative real numbers . that can contai a decimal part but dont have to. Valid values are : 100, -10, 5.0, -3.531. Error: if the status type doesnt exist or the goal is invalid. Output: New goal for <type>: <goal description>. C3 – remove-goal <type> Deletes the goal for the given status type. Error: if the status type does not exist or no target is set for this. Output: Removed goal for <type>. C4 – goals Returns all currently set goals. then gives a line of the form Number of goals: <number of goals>. Each goal is then output in its own line. Each line has the form <type>: <goal description>.The order of the rows for the output of the targets is not of relevance, the row that indicates the number of targets is always at the beginning of the output.l > goals Number of goals: 0 > goal pulse between 50 and 93.315 New goal for pulse: between 50.00 and 93.31. : > goals Number of goals: 1 pulse: between 50.00 and 93.31 C5 – record <type> <value> Records a value for the stat type <type> and returns the current state. The current state of a Status Type is the current aggregated value for the current day. For a stator type with the aggregation Method minimum / maximum is output <min> to <max>. This also applies if the two values are the same. Error: If a non-existent type or an incorrect value is put. Output: <type>: <new aggregated value> Example > record pulse 100 pulse: 100.00 to 100.00 > record pulse 50 pulse: 50.00 to 100.00 > record pulse 117 pulse: 50.00 to 117.00 C6 – state Returns for all status types the current (aggregated) value for the current day.If so far no value Is set to a status type, none is the output. Each status type is placed in its own line of form<Type>: <value>. The order of the outputted lines is not relevant. Example > state pulse: none > record pulse 100 pulse: 100.00 to 100.00 > state pulse: 100.00 to 100.00 C7 – progress Returns the progress for the current day. First, in one line is given the current day counter is in the form Day <current day>, Week <current week>. For each status type, a line is give in which is contained: • the name of the status type and the current value (<type>: <value>) • Whether a goal is reached (goal reached), not reached (goal not reached) or not present (No goal). Both data are separated by -. A goal for which the type of the stator has not yet been measured Is always not achieved . Example > progress Day 0, week 1 pulse: none - no goal > goal pulse less-than 120 New goal for pulse: less-than 120.00. : > record pulse 100 pulse: 100.00 to 100.00 > progress Day 0, week 1 pulse: 100.00 to 100.00 - goal reached C8 – top <n> <type> Returns the <n> days at which the value was highest. Previous days are here all the days with one day counter smaller or equal to the current day counter. If not yet on <n> days Values have been recorded, all previous days on which a value has been recorded are given in the correct order. If <n> is less than 1 or there is no corresponding day, a corresponding error message is given. In the aggregation type minmax, the highest value recorded on the tag is decisive, for all other aggregation types the aggregated value.For each day, a row of the form Day <day number> - <aggregated value>. In this case <Aggregated value> is the aggregated value and in the case of the aggregation type minmax the maximum value at Respective day. The days are sorted in a descending order by the correspodig value. A maximum of n days are is given as a output.If two days have the same aggregated value, its order is not defined (and thus does not matter for the correctness according to the task). C9 – goals-week <i> Indicates how many times this goal has been reached in week i . Week 1 refers to the first week, which includes days 0 to 6 (inclusive). For this purpose, a line of the form Number of goals: <currentNumber of goals> is output. Then A line with the following form is output for each currently set target (in any order): <Type>: <goal description> - <time goal has been reached in the week> A target can, as previously defined, be reached on one day only if there is at least one measurement. C10 – next-day Increases the day counter by 1 if a value is entered for all status types. If a value is not entered for all Status types, all such status types are output as follows: no entry for <type>. The day counter is then not increased. If a value is entered for all status types, the following twoLines are output and the counter is incremented by one: Goals reached: <number of goals reached on current day> / <number of set goals> Day <next day>, week <week for next day> Where <number of goals reached on current day> is the number of targets defined according to the definition The day before the day counter was reached; and <Number of set goals> the number of total goals defined. All three values (number of times reached Targets, total number of targets, new daily counter value) are displayed without decimal places , as integers output. Example > next-day no entry for pulse > record pulse 100 pulse: 100.00 to 100.00 > next-day Goals reached: 0/0 Day 1, week 1 > record pulse 50 pulse: 50.00 to 50.00 > goal pulse less-than 120 New goal for pulse: less-than > next-day Goals reached: 1/1 Day 2, week 1 120.00. : C11 – set-day <value> Sets the day counter to the passed value. The day (compared to the next-day command) Can also be changed if a value is not entered for all status types, and there will be no statistics output. <Value> must always be greater than or equal to 0. Output: Day <new day value>, week <new week value> . Beispiel > next-day no entry for pulse > set-day 1 Day 1, week 1 > goal pulse less-than 120 New goal for pulse: less-than 120.00. : > record pulse 100 pulse: 100.00 to 100.00 > set-day 0 Day 0, week 1 > progress Day 0, week 1 pulse: none - goal not reached > set-day 1 Day 1, week 1 > progress Day 1, week 1 pulse: 100.00 to 100.00 - goal reached C12 – quit Quits the programm. Output: Quit (Day <current day>, week <current week>) Beispiel > set-day 10 Day 10, week 2 > quit Quit (Day 10, week 2) B.2 Pulse measurement The program to be developed can include the functions for the management of measurements and targets as well To handle ECG measurements and process them according to a simple scheme and into a heart rate convert. To this end, the steps to be implemented are first explained using an example. The command line commands are then explained. B.2.1 Data processing steps For the processing of measured values, you first perform some generic operations on time series implemented. For simplicity, the data points are always equidistant, so they have the same Distance B.2.2 Smoothing with Sliding Window When smoothing with a sliding window of size n , n successive values of the Time series aggregated and output. In this task, you should always use the Average (the arithmetic average) of the values in the time window. Note: If n = 1, the time series output is not changed. N = number of values in the time series A time series is output which consists only of the average over the entire original time series. 0 1 2 3 4 5 6 7 8 9 y 0.190 0.348 0.259 0.257 0.360 0.406 0.382 0.257 0.281 0.348 s3(y) 0.266 0.288 0.292 0.341 0.383 0.348 0.307 0.295 Figure 1: Aaggregation of time series by averaging with a sliding window The arrows, which point out from y to the values of the series s 3 ( y ), show which values are combined by average formation. Y denotes the original Values, s 3 ( y ) the values obtained by the smoothing. The values are here to the third decimal place rounded. For example, the entry in the fourth place (index 3) is as follows:: s3(y)3 = y3 + y4 + y5 = 0.257 + 0.360 + 0.406 = 1.023 =0.341 3 3 3 B.2.3 Normalize Another common operator in the processing of measured values is to normalize to a pre given area. In the following, all values of the time series are to be scaled into a predetermined interval [ a, b ] where a <b . For this purpose, the smallest value (here referred to as min ( y )) or the largest value (here: max ( y )) Of the time series y displays to the value a or b . Intermediate values are applied linearly displayed to the interval. This means that the value y i is mapped to γ , so that: γ − a γ − a y i = max(y) +(1- )min(y) γ − b γ − b B.2.4 Detecting peaks A further step in dealing with time-series is the recognition of interesting time points. therefore Locations in the data should be found in which the series of a value less than a predetermined Threshold is at a value greater than this threshold value is changed and at least for n measured values above this threshold stays. This is shown for peaks in the time series ys3 with n = 1 and the threshold value 0.7. The blue Marked points represent the known indices, with the number to the left of the point representing the index (10, 35, 40, 56, 78, 101). At index 10, the value is greater than 0.7 for the first time and remains for 4 measured values above this threshold. Since 4 ≥ 1, the time 10 is output. Please note that the indexes 11, 12 And 13 are not outputted. In FIG. 7 the recognized indices for n = 2 are shown for the same time series (ys3) and the same threshold value (0.7). B.2.5 Commands Sequences of data points are always entered as a list with at least two elements, where the List elements are separated by a semicolon (;). The output is similar, but it can also output only one value. Please pay particular attention to the general guidelines for Formatting floating-point numbers. If the input is incorrect, that means that the window size is invalid, one of the entered data points or the list is invalidly formatted, a error message is given. C13 – sliding-window <n> <data> Smoothing the values with a sliding window of size <n> Example > sliding-window 3 0.190;0.348;0.259;0.257;0.360;0.406;0.382;0.257;0.281;0.348 0.26;0.28;0.29;0.34;0.38;0.34;0.30;0.29 C14 – normalize <smallest> <largest> <data> Normalizes the given data into the interval from <Smallest> to <largest>. If <largest> is not really greater than <smallest>, a suitable error is given. Beispiel > normalize 0 1 10;14.2;18;13.8;13.00;17.5;20.0 0.00;0.42;0.80;0.38;0.30;0.75;1.00 C15 – peaks <threshold> <n> <data> Finds peaks in the data with the threshold <threshold> and the minimum number of data points <N> . If the first index is already greater than threshold, this will be considered like a transition from a value less than that Threshold at the imaginary time -1. This means that the index 0 is output if at least the first n values are greater than the threshold value. Only the indices of the found peaks are output. The output happens as by semicolon Separated integers without decimal places Beispiel > peaks 5 3 1;6;6;1;6;6;6;1;1;6;1;6;6;6;6 4;11 C16 – pulse <data> Reads voltage measurements and determines an average heart rate. The data is recorded at 30Hz and thus has a distance of 1/30 s For this purpose, the transferred data (<data>) are first described as in the previous sections from your program with a sliding window of the size 3 smoothed. Then the values are normalized into the Interval [0,1 ]. Then, the peaks are determined with threshold value 0.7 and minimum number 2. On this base, the average distance between two peaks is determined. In the example The peak indices 10, 35, 56, 78 and 101 are obtained. The resulting distances are 35 - 10 = 25, 56 - 35 = 21, 78 - 56 = 22 and 101 - 78 = 23. The average distance is thus (25 + 21 + 22 + 23) /4 = 22.75. 4 The sample frequency 30Hz results in a distance of 22.75 · 1/30 s = 0.7583..s and thus a frequency of 1.3186. , .1 / s = 79.1208. , .1 / min. Thus, the particular heart rate is 79.12. When the command is called, the frequency is determined and output in the form pulse frequency: <pulse frequency>. The value is then processed further, as would be the case with a call to the record␣pulse␣ <pulsefrequency> command. The output is also the same as when the record command is called directly. Beispiel > record pulse 50 pulse: 50.00 to 50.00 > pulse 0.289;0.190;0.348;...;0.214;0.236;0.225 pulse frequency: 79.12 pulse: 50.00 to 79.12

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import edu.kit.informatik.Terminal;
import java.util.*;

/*
* StateTracker class which contains main program
*/
public class StateTracker {

// Dictionary maintaining states
HashMap<String,State> states;
// Current day
int day;

// Constructor
public StateTracker() {
    states = new HashMap<String,State>();
    day = 0;
    states.put("pulse",new State("pulse","minmax"));
}

// Method which executes a command line (parsing logic)
public void execute(String line) {
    String[] params = line.split("\\s+");
    if (params.length == 0) {
      return;
    }
    if (params[0].equals("add") && params.length == 3) {
      String type = params[1];
      String aggregation = params[2];
      if (aggregation.equals("sum") || aggregation.equals("avg") || aggregation.equals("last") || aggregation.equals("minmax")) {
       if (!states.containsKey(type)) {
          states.put(type,new State(type,aggregation));
          Terminal.printLine("Added "+type+" with aggregation "+aggregation+".");
       } else {
          Terminal.printError(type+" already exists.");
       }
      } else {
       Terminal.printError("Invalid aggregation.");
      }
    } else if (params[0].equals("goal") && (params.length == 4 || params.length == 6)) {
      String type = params[1];
      String description = params[2];
      if ((description.equals("less-than") || description.equals("greater-than")) && params.length == 4) {
       if (states.containsKey(type)) {
          State state = states.get(type);
          double value = Double.parseDouble(params[3]);
          Goal goal = new Goal(type, description, value, value, state);
          state.goal = goal;
          Terminal.printLine("New goal for "+goal+".");
       } else {
          Terminal.printError(type+" does not exist.");
       }
      } else if (description.equals("between") && params.length == 6) {
       if (states.containsKey(type)) {
          State state = states.get(type);
          double min = Double.parseDouble(params[3]);
          double max = Double.parseDouble(params[5]);
          Goal goal = new Goal(type, description, min, max, state);
          state.goal = goal;
          Terminal.printLine("New goal for "+goal+".");
       } else {
          Terminal.printError(type+" does not exist.");
       }
      } else {
       Terminal.printError("Invalid goal description.");
      }
    } else if (params[0].equals("remove-goal") && params.length == 2) {
      String type = params[1];
      if (!states.containsKey(type)) {
       Terminal.printError(type+" does not exist.");
      } else {
       states.get(type).goal = null;
       Terminal.printLine("Removed goal for "+type+".");
      }
    } else if (params[0].equals("goals")) {
      ArrayList<Goal> goals = new ArrayList<Goal>();
      for (String type: states.keySet()) {
       Goal goal = states.get(type).goal;
       if (goal != null) {
          goals.add(goal);
       }
      }
      Terminal.printLine("Number of goals: "+goals.size());
      for (Goal goal: goals) {
       Terminal.printLine(goal);
      }
    } else if (params[0].equals("record") && params.length == 3) {
      String type = params[1];
      Double value = Double.parseDouble(params[2]);
      if (!states.containsKey(type)) {
       Terminal.printError(type+" does not exist.");
      } else {
       states.get(type).record(day,value);
       Terminal.printLine(states.get(type).getAggregatedValueString(day));
      }
    } else if (params[0].equals("state")) {
      for (String type: states.keySet()) {
       Terminal.printLine(states.get(type).getAggregatedValueString(day));
      }
    } else if (params[0].equals("progress")) {
      Terminal.printLine("Day "+day+", week "+(day/7+1));
      for (String type: states.keySet()) {
       State state = states.get(type);
       Goal goal = state.goal;
       Terminal.printLine(state.getGoalStateString(day));
      }
    } else if (params[0].equals("top") && params.length == 3) {
      Integer n = Integer.parseInt(params[1]);
      if (n >= 0) {
       String type = params[2];
       State state = states.get(type);
       ArrayList<Day> days = new ArrayList<Day>();
       for (int i = 0; i < day; i++) {
          days.add(new Day(i,state.getAggregatedValueSingle(i)));
       }
       Collections.sort(days);
       while (days.size() > n) {
          days.remove(0);
       }
       for (Day day: days) {
          Terminal.printLine("Day "+day.i+" - "+day.value);
       }
      } else {
       Terminal.printError("negative n entered.");
      }
    } else if (params[0].equals("goals-week") && params.length == 2) {
      Integer i = Integer.parseInt(params[1]);
      if (i >= 1) {
       ArrayList<Goal> goals = new ArrayList<Goal>();
       for (String type: states.keySet()) {
          Goal goal = states.get(type).goal;
          if (goal != null) {
            goals.add(goal);
          }
       }
       Terminal.printLine("Number of goals: "+goals.size());
       for (Goal goal: goals) {
          int count = 0;
          for (int dayNum = 7*(i-1); dayNum <= 7*i-1; dayNum++) {
            if (goal.state.getGoalState(dayNum))
             count++;
          }
          Terminal.printLine(goal+" - "+count);
       }
      
      } else {
       Terminal.printError("non-positive week entered.");
      }
    } else if (params[0].equals("next-day")) {
      boolean allEntered = true;
      for (String type: states.keySet()) {
       if (states.get(type).records.get(day) == null || states.get(type).records.get(day).isEmpty()) {
          allEntered = false;
          Terminal.printLine("no entry for "+type);
       }
      }
      if (allEntered) {
       ArrayList<Goal> goals = new ArrayList<Goal>();
       for (String type: states.keySet()) {
          Goal goal = states.get(type).goal;
          if (goal != null) {
            goals.add(goal);
          }
       }
       int count = 0;
       for (Goal goal: goals) {
          if (goal.state.getGoalState(day))
            count...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$90.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats