Repository for the HealthTool which enables Apple users to analyse their health data from the Apple health app and prepares the data for contributing it for future studies on wearable data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
5.6 KiB

3 years ago
  1. package application.helpers;
  2. import java.text.SimpleDateFormat;
  3. import application.res.Colors;
  4. import application.res.Text;
  5. import javafx.scene.layout.Border;
  6. import javafx.scene.layout.BorderStroke;
  7. import javafx.scene.layout.BorderStrokeStyle;
  8. import javafx.scene.layout.BorderWidths;
  9. /**
  10. * Gathers some of the data structures an methods more widely used.
  11. *
  12. * @author Bianca
  13. *
  14. */
  15. public class Utils
  16. {
  17. /**
  18. * Attributes of an activity summary row (10 in total)
  19. */
  20. public static final String[] ACTIV_SUMM_ATTR = new String[]
  21. { "dateComponents", "activeEnergyBurned", "activeEnergyBurnedGoal", "activeEnergyBurnedUnit", "appleExerciseTime",
  22. "appleExerciseTimeGoal", "appleStandHours", "appleStandHoursGoal", "appleMoveMinutes",
  23. "appleMoveMinutesGoal"
  24. // appleMoveMinutes /-Goal couldn't be tested due to missing test data
  25. };
  26. /**
  27. * Attributes of a workout row (12 attributes +WorkoutEvents) Important: nested attributes need to be at the end of the array!
  28. */
  29. public static final String[] workoutAttributes = new String[]
  30. { "workoutActivityType", "duration", "durationUnit", "totalDistance", "totalDistanceUnit", "totalEnergyBurned",
  31. "totalEnergyBurnedUnit", //"sourceName", left out because of privacy
  32. "sourceVersion", "creationDate", "startDate", "endDate", "device",
  33. Text.TAG_NAME_WORKOUT_EVENT //, Text.TAG_NAME_META_DATA_ENTRY, Text.TAG_NAME_WORKOUT_ROUTE left out because of privacy
  34. };
  35. /**
  36. * Attributes of a record row (8 attributes + HRMetaList(+IBperMinute)
  37. * +MetaData) Important: nested attributes need to be at the end of the array!
  38. */
  39. public static final String[] recordAttributes = new String[]
  40. { "type", "unit", "value", // "sourceName", left out because of privacy
  41. "sourceVersion", "device", "creationDate", "startDate", "endDate",// Text.TAG_NAME_META_DATA_ENTRY, left out due to privacy
  42. Text.TAG_NAME_HR_LIST };
  43. /**
  44. * Attributes of a meta data entry (2 attributes in total)
  45. */
  46. public static String[] META_DATA_ATTR = new String[]
  47. { "key", "value" };
  48. /**
  49. * Attributes of a workout event entry (4 attributes in total)
  50. */
  51. public static String[] WORKOUT_EVENT_ATTR = new String[]
  52. { "type", "date", "duration", "durationUnit" };
  53. /**
  54. * Attributes of a workout route entry (6 attributes + MetaData)
  55. * (Currently excluded due to privacy)
  56. */
  57. public static String[] WORKOUT_ROUTE_ATTR = new String[]
  58. { "sourceName", "sourceVersion", "device", "creationDate", "startDate", "endDate", Text.TAG_NAME_META_DATA_ENTRY };
  59. /**
  60. * Attributes of a hr_list entry (only ib_per_minutes entries)
  61. */
  62. public static String[] HR_LIST_ATTR = new String[]
  63. { Text.TAG_NAME_IB_PER_MINUTES };
  64. /**
  65. * Attributes of a ib per mintes entry (2 attributes in total)
  66. */
  67. public static String[] IB_PER_MINUTES_ATTR = new String[]
  68. { "bpm", "time" };
  69. /**
  70. * This format is according to the format the date of birth is saved in the
  71. * health data
  72. */
  73. public static final SimpleDateFormat formatDateOfBirth = new SimpleDateFormat("yyyy-MM-dd");
  74. /**
  75. * Especially sub workouts / records start with something like 'HK...' and
  76. * aren't very readable for the user. This method tries to remove the
  77. * unnecessary parts to make it more readable. Based on https://developer.apple.com/documentation/healthkit/data_types
  78. *
  79. * @param input The string to shorten
  80. * @return the shortened result
  81. */
  82. public static String shortenHKStrings(String input)
  83. {
  84. // Subclasses
  85. // class HKCharacteristicType
  86. // A type that represents data that does not typically change over time.
  87. String res = input.replace("HKCharacteristicType", "");
  88. // class HKQuantityType
  89. // A type that identifies samples that store numerical values.
  90. res = res.replace("HKQuantityType", "");
  91. // class HKCategoryType
  92. // A type that identifies samples that contain a value from a small set of possible values.
  93. res = res.replace("HKCategoryType", "");
  94. // class HKCorrelationType
  95. // A type that identifies samples that group multiple subsamples.
  96. res = res.replace("HKCorrelationType", "");
  97. // class HKActivitySummaryType
  98. // A type that identifies activity summary objects.
  99. res = res.replace("HKActivitySummaryType", "");
  100. // class HKAudiogramSampleType
  101. // A type that identifies samples that contain audiogram data.
  102. res = res.replace("HKAudiogramSampleType", "");
  103. // class HKElectrocardiogramType
  104. // A type that identifies samples containing electrocardiogram data.
  105. res = res.replace("HKElectrocardiogramType", "");
  106. // class HKSeriesType
  107. // A type that indicates the data stored in a series sample.
  108. res = res.replace("HKSeriesType", "");
  109. // class HKClinicalType
  110. // A type that identifies samples that contain clinical record data.
  111. res = res.replace("HKClinicalType", "");
  112. // class HKWorkoutType
  113. // A type that identifies samples that store information about a workout.
  114. res = res.replace("HKWorkoutType", "");
  115. res = res.replace("HKWorkoutActivityType", "");
  116. res = res.replace("Identifier", "");
  117. return res;
  118. }
  119. public static Border darkBlueBorder = new Border(new BorderStroke(Colors.darkBlue, Colors.darkBlue, Colors.darkBlue,
  120. Colors.darkBlue, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID,
  121. BorderStrokeStyle.SOLID, null, new BorderWidths(2), null));
  122. public static Border redBorder = new Border(new BorderStroke(Colors.red, Colors.red, Colors.red, Colors.red,
  123. BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, null,
  124. new BorderWidths(2), null));
  125. public static Border darkGreyBorderBR = new Border(new BorderStroke(null, Colors.darkGrey, Colors.darkGrey, null,
  126. BorderStrokeStyle.NONE, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.NONE, null,
  127. new BorderWidths(1), null));
  128. }