Permalink
Browse files

Expand activity, use arrays for has_data and errors

  • Loading branch information...
1 parent 146edaf commit 45d7a1aa9b846adacb004144fa2d77da46349133 @scheibo committed Feb 28, 2014
Showing with 91 additions and 63 deletions.
  1. +2 −4 activity.c
  2. +74 −46 activity.h
  3. +11 −4 fix.c
  4. +4 −4 fix.h
  5. +0 −5 gpx.c
View
@@ -11,7 +11,8 @@ Activity *activity_new(void) {
a->sport = UnknownSport;
a->laps = NULL; /* TODO */
a->data_points = a->last_point = NULL;
- a->has_data = calloc(1, sizeof(*(a->has_data)));
+ memset(a->has_data, false, sizeof(a->has_data));
+ memset(a->errors, 0, sizeof(a->errors));
return a;
}
@@ -32,9 +33,6 @@ void activity_destroy(Activity *a) {
a->laps = NULL;
}
- free(a->has_data);
- a->has_data = NULL;
-
free(a);
a = NULL;
}
View
@@ -5,18 +5,26 @@
#include <stdio.h> /* TODO for fprintf in print data point */
#include <float.h>
-#define UNSET_TIMESTAMP UINT32_MAX
-#define UNSET_LATITUDE DBL_MAX
-#define UNSET_LONGITUDE DBL_MAX
-#define UNSET_ALTITUDE INT32_MAX
-#define UNSET_DISTANCE UINT32_MAX
-#define UNSET_SPEED UINT32_MAX
-#define UNSET_POWER UINT16_MAX
-#define UNSET_GRADE INT16_MAX
-#define UNSET_HEART_RATE UINT8_MAX
-#define UNSET_CADENCE UINT8_MAX
-#define UNSET_LR_BALANCE UINT8_MAX
-#define UNSET_TEMPERATURE INT8_MAX
+typedef enum {
+ false,
+ true
+} bool;
+
+typedef enum {
+ Timestamp,
+ Latitude,
+ Longitude,
+ Altitude,
+ Distance,
+ Speed,
+ Power,
+ Grade,
+ HeartRate,
+ Cadence,
+ LRBalance,
+ Temperature,
+ DataFieldCount
+} DataField;
typedef struct DataPoint {
uint32_t timestamp; /* s since Unix Epoch UTC */
@@ -34,6 +42,45 @@ typedef struct DataPoint {
struct DataPoint *next;
} DataPoint;
+typedef struct Summary {
+ unsigned lap; /* lap number 0 vs 1? */
+
+ uint8_t cadence_avg;
+ uint8_t heart_rate_avg;
+ int8_t temperature_avg;
+ uint8_t lr_balance_avg;
+
+ uint16_t calories;
+ uint32_t distance; /* 100 * m */
+ uint32_t elevation; /* 100 * m */
+ uint32_t time; /* s */
+ uint32_t time_elapsed; /* s */
+ uint32_t ascent; /* 100 * m */
+ uint32_t descent; /* 100 * m */
+ /* function to calc pace from speed */
+ uint32_t speed_avg; /* 1000 * m/s */
+ uint32_t speed_max; /* 1000 * m/s */
+
+ uint16_t power_avg; /* TODO 3s, 10s, 30s - for speed as well? */
+ uint16_t power_max;
+ uint16_t power_kj; /* TODO correct? */
+
+ /* TODO coggans powers - IF, NP, TSS, W/kg */
+} Summary;
+
+#define UNSET_TIMESTAMP UINT32_MAX
+#define UNSET_LATITUDE DBL_MAX
+#define UNSET_LONGITUDE DBL_MAX
+#define UNSET_ALTITUDE INT32_MAX
+#define UNSET_DISTANCE UINT32_MAX
+#define UNSET_SPEED UINT32_MAX
+#define UNSET_POWER UINT16_MAX
+#define UNSET_GRADE INT16_MAX
+#define UNSET_HEART_RATE UINT8_MAX
+#define UNSET_CADENCE UINT8_MAX
+#define UNSET_LR_BALANCE UINT8_MAX
+#define UNSET_TEMPERATURE INT8_MAX
+
#define UNSET_DATA_POINT(d) \
do { \
(d).timestamp = UNSET_TIMESTAMP; \
@@ -60,55 +107,36 @@ static inline void print_data_point(DataPoint *d) {
d->lr_balance, d->temperature, (void *)d->next);
}
-/*
- //TODO could also do these per lap
-typedef struct Summary {
- cadence_avg;
- heart_rate_avg;
- temperature_avg;
- lr_balance_avg;
- // totals
- calories;
- distance;
- elevation;
- laps; // and summar per laps? not just count?
- pace;
- time;
- time_elapsed;
- ascent;
- descent;
-
- speed_avg;
- speed_max;
-
- power_avg; // 3s, 10s, 30s
- power_max;
- power_kj;
-
- // coggans powers - IF, NP, TSS, W/kg
-} Summary;
-*/
-
typedef enum {
/* Swimming, */
Running,
Bicycling,
UnknownSport
} Sport;
+
+typedef enum {
+ InvalidGPS,
+ Dropouts,
+ PowerSpikes,
+ HeartRateSpikes,
+ HeartRateDropouts,
+ DataErrorCount
+} DataError;
+
+
/*****************
- * Read all individual points and compare it to summary data
+ * TODO Read all individual points and compare it to summary data
*/
typedef struct {
Sport sport;
uint32_t *laps; /* TODO array of timestamps, always at least one */
DataPoint *data_points;
DataPoint *last_point;
- DataPoint *has_data;
+ bool has_data[DataFieldCount];
+ unsigned errors[DataErrorCount];
/*
- //Summary summary; // can include derived statistics (totalAscent, NP, avg)
- //Summary * lap_summaries; // can include derived statistics (totalAscent, NP,
- avg)
+ //Summary *summaries; // laps + total can include derived statistics
*/
} Activity;
View
15 fix.c
@@ -6,14 +6,14 @@
/* used to handle gaps in recording by inserting interpolated/zero samples to
* ensure dataPoints are contiguous in time */
-int fix_gps(Activity *a) {
+int fix_invalid_gps(Activity *a);
DataPoint *fill_data, *last_good = NULL;
int errors = 0, last_good_index = -1, index = 0, fill_index;
double delta_latitude, delta_longitude;
// ignore null or files without GPS data
- if (!a || !a->data_points || !a->has_data->latitude ||
- !a->has_data->longitude) { /* TODO add has_data */
+ if (!a || !a->data_points || !a->has_data[Latitude] ||
+ !a->has_data[Longitude]) {
return -1;
}
@@ -62,9 +62,16 @@ int fix_gps(Activity *a) {
}
if (errors) {
- a->errors->gps = errors; /* TODO add errors */
+ a->errors[InvalidGPS] = errors;
return errors;
} else {
return 0;
}
}
+
+/*
+int fix_dropouts(Activity *a);
+int fix_power(Activity *a);
+int fix_heart_rate(Activity *a); // TODO probably needs HR max from athletes and other
+*/
+
View
8 fix.h
@@ -3,11 +3,11 @@
#include "activity.h"
-int fix_gps(Activity *a);
+int fix_invalid_gps(Activity *a);
/*
-int fix_gaps(Activity *a);
-int fix_spikes(Activity *a);
-int fix_hr(Activity *a); // TODO probably needs HR max from athletes and other
+int fix_dropouts(Activity *a);
+int fix_power(Activity *a);
+int fix_heart_rate(Activity *a); // TODO probably needs HR max from athletes and other
values?
*/
View
5 gpx.c
@@ -6,11 +6,6 @@
#include "mxml.h"
#include "util.h"
-typedef enum {
- false,
- true
-} bool;
-
typedef struct {
bool metadata;
bool first_element;

0 comments on commit 45d7a1a

Please sign in to comment.