Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch to clang format 3.4

  • Loading branch information...
commit c7387f43df6df3106615c69f3e124f09c0845c54 1 parent c8a41b8
@scheibo authored
View
24 activity.c
@@ -3,7 +3,7 @@
#include "activity.h"
-#define alloc_nr(x) (((x)+16)*3/2)
+#define alloc_nr(x) (((x) + 16) * 3 / 2)
/*
* Realloc the buffer pointed at by variable 'x' so that it can hold
@@ -12,16 +12,16 @@
*
* DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
*/
-#define ALLOC_GROW(x, nr, alloc) \
- do { \
- if ((nr) > alloc) { \
- if (alloc_nr(alloc) < (nr)) \
- alloc = (nr); \
- else \
- alloc = alloc_nr(alloc); \
- x = realloc((x), alloc * sizeof(*(x))); \
- } \
- } while (0)
+#define ALLOC_GROW(x, nr, alloc) \
+ do { \
+ if ((nr) > alloc) { \
+ if (alloc_nr(alloc) < (nr)) \
+ alloc = (nr); \
+ else \
+ alloc = alloc_nr(alloc); \
+ x = realloc((x), alloc * sizeof(*(x))); \
+ } \
+ } while (0)
Activity *activity_new(void) {
Activity *a;
@@ -67,7 +67,7 @@ int activity_add_point(Activity *a, DataPoint *dp) {
/* TODO fill in inferred missing values a la gpx/tcx */
for (i = 0; i < DataFieldCount; i++) {
- a->data_points[a->num_points].data[i] = dp->data[i];;
+ a->data_points[a->num_points].data[i] = dp->data[i];
}
a->num_points++;
View
19 activity.h
@@ -28,8 +28,13 @@ typedef enum {
DataFieldCount
} DataField;
-typedef struct { double data[DataFieldCount]; } DataPoint;
-static const char *DATA_FIELDS[DataFieldCount] = { "timestamp", "latitude", "longitude", "altitude", "distance", "speed", "power", "grade", "heart_rate", "cadence", "lr_balance", "temperature" };
+typedef struct {
+ double data[DataFieldCount];
+} DataPoint;
+static const char *DATA_FIELDS[DataFieldCount] = {
+ "timestamp", "latitude", "longitude", "altitude",
+ "distance", "speed", "power", "grade",
+ "heart_rate", "cadence", "lr_balance", "temperature"};
/* TODO convert to array...
//typedef struct Summary {
@@ -70,10 +75,12 @@ static inline void unset_data_point(DataPoint *dp) {
static inline void print_data_point(DataPoint *dp) {
double *d = dp->data;
fprintf(stderr,
- "time: %.0f, lat: %.15f, lon: %.15f, alt: %.2f, dist: %.2f, speed: %.2f, pow: %.0f, "
+ "time: %.0f, lat: %.15f, lon: %.15f, alt: %.2f, dist: %.2f, speed: "
+ "%.2f, pow: %.0f, "
"grd: %.2f, hr: %.0f, cad: %.0f, bal: %.0f, temp: %.0f\n",
- d[Timestamp], d[Latitude], d[Longitude], d[Altitude], d[Distance], d[Speed], d[Power],
- d[Grade], d[HeartRate], d[Cadence], d[LRBalance], d[Temperature]);
+ d[Timestamp], d[Latitude], d[Longitude], d[Altitude], d[Distance],
+ d[Speed], d[Power], d[Grade], d[HeartRate], d[Cadence], d[LRBalance],
+ d[Temperature]);
}
typedef enum {
@@ -83,7 +90,6 @@ typedef enum {
UnknownSport
} Sport;
-
typedef enum {
InvalidGPS,
Dropouts,
@@ -93,7 +99,6 @@ typedef enum {
DataErrorCount
} DataError;
-
/*****************
* TODO Read all individual points and compare it to summary data
*/
View
11 csv.c
@@ -10,7 +10,7 @@ static DataField name_to_field(char *name) {
!strcmp(name, "long")) {
return Longitude;
} else if (!strcmp(name, "altitude") || !strcmp(name, "elevation") ||
- !strcmp(name, "alt") || !strcmp(name, "ele") ) {
+ !strcmp(name, "alt") || !strcmp(name, "ele")) {
return Altitude;
} else if (!strcmp(name, "distance") || !strcmp(name, "dist")) {
return Distance;
@@ -32,7 +32,7 @@ static DataField name_to_field(char *name) {
} else if (!strcmp(name, "temperature") || !strcmp(name, "atemp") ||
!strcmp(name, "temp")) {
return Cadence;
- } else { /* not found */
+ } else {/* not found */
return DataFieldCount;
}
}
@@ -41,7 +41,8 @@ static DataField name_to_field(char *name) {
* all are doubles in base SI unit which we then convert into our format */
int csv_read(char *filename, Activity *a) {
FILE *f = NULL;
- DataField data_fields[DataFieldCount]; // TODO worry all set to zero which is Timestamp
+ DataField data_fields[DataFieldCount]; // TODO worry all set to zero which is
+ // Timestamp
DataPoint point;
char buf[CSV_BUFSIZ];
@@ -70,7 +71,8 @@ int csv_read(char *filename, Activity *a) {
return 0;
}
-static int write_csv(FILE *f, const char *format, size_t i, DataField f, Activity *a, CSVOptions o, bool *first) {
+static int write_csv(FILE *f, const char *format, size_t i, DataField f,
+ Activity *a, CSVOptions o, bool *first) {
double d = a->data_points[i].data[field];
if (!o.remove_unset || a->has_data[field]) {
if (d == UNSET_FIELD) {
@@ -85,7 +87,6 @@ static int write_csv(FILE *f, const char *format, size_t i, DataField f, Activit
}
}
-
int csv_write(char *filename, Activity *a, CSVOptions o) {
FILE *f = NULL;
unsigned i;
View
3  csv.h
@@ -3,7 +3,8 @@
#include "activity.h"
-#define DEFAULT_CSV_OPTIONS { false, "NA" }
+#define DEFAULT_CSV_OPTIONS \
+ { false, "NA" }
#define CSV_BUFSIZ 4096
typedef struct {
View
4 fitparse.c
@@ -22,10 +22,10 @@
*/
/* indexed by FileFormat */
-static ReadFn *readers[] = { csv_read, fit_read, gpx_read, tcx_read };
+static ReadFn *readers[] = {csv_read, fit_read, gpx_read, tcx_read};
/* indexed by FileFormat */
-static WriteFn *writers[] = { csv_write, fit_write, gpx_write, tcx_write };
+static WriteFn *writers[] = {csv_write, fit_write, gpx_write, tcx_write};
static FileFormat file_format_from_name(char *filename) {
char ext[4];
View
108 fix.c
@@ -7,71 +7,71 @@
/* used to handle gaps in recording by inserting interpolated/zero samples to
* ensure dataPoints are contiguous in time */
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;
+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]) {
- return -1;
- }
+// ignore null or files without GPS data
+if (!a || !a->data_points || !a->has_data[Latitude] ||
+ !a->has_data[Longitude]) {
+ return -1;
+}
- for (data = a->data_points; data; data = data->next, index++) {
- /* is this one decent? */
- if (data->latitude >= -90 && data->latitude <= 90 &&
- data->longitude >= -180 && data->longitude <= 180) {
- if (last_good && (last_good->next != data)) {
- /* interpolate from last_good to here then set last_good to here */
- delta_latitude = (data->latitude - last_good->latitude) /
- (double)(index - last_good_index);
- delta_longitude = (data->longitude - last_good->longitude) /
- (double)(index - last_good_index);
- for (fill_data = last_good->next, fill_index = last_good_index + 1;
- fill_data != data; fill_data = fill_data->next, fill_index++) {
- fill_data->latitude =
- last_good->latitude +
- (double)((fill_index - last_good_index) * delta_latitude);
- fill_data->longitude =
- last_good->longitude +
- (double)((fill_index - last_good_index) * delta_longitude);
- errors++;
- }
- } else if (!last_good) {
- /* fill to front */
- for (fill_data = a->data_points; fill_data != data;
- fill_data = fill_data->next) {
- fill_data->latitude = data->latitude;
- fill_data->longitude = data->longitude;
- errors++;
- }
+for (data = a->data_points; data; data = data->next, index++) {
+ /* is this one decent? */
+ if (data->latitude >= -90 && data->latitude <= 90 &&
+ data->longitude >= -180 && data->longitude <= 180) {
+ if (last_good && (last_good->next != data)) {
+ /* interpolate from last_good to here then set last_good to here */
+ delta_latitude = (data->latitude - last_good->latitude) /
+ (double)(index - last_good_index);
+ delta_longitude = (data->longitude - last_good->longitude) /
+ (double)(index - last_good_index);
+ for (fill_data = last_good->next, fill_index = last_good_index + 1;
+ fill_data != data; fill_data = fill_data->next, fill_index++) {
+ fill_data->latitude =
+ last_good->latitude +
+ (double)((fill_index - last_good_index) * delta_latitude);
+ fill_data->longitude =
+ last_good->longitude +
+ (double)((fill_index - last_good_index) * delta_longitude);
+ errors++;
+ }
+ } else if (!last_good) {
+ /* fill to front */
+ for (fill_data = a->data_points; fill_data != data;
+ fill_data = fill_data->next) {
+ fill_data->latitude = data->latitude;
+ fill_data->longitude = data->longitude;
+ errors++;
}
- last_good = data;
- last_good_index = index;
}
+ last_good = data;
+ last_good_index = index;
}
+}
- /* fill to end... */
- if (last_good && last_good->next) {
- /* fill from last_good to end with last_good */
- for (fill_data = last_good->next; fill_data; fill_data = fill_data->next) {
- fill_data->latitude = last_good->latitude;
- fill_data->longitude = last_good->longitude;
- errors++;
- }
+/* fill to end... */
+if (last_good && last_good->next) {
+ /* fill from last_good to end with last_good */
+ for (fill_data = last_good->next; fill_data; fill_data = fill_data->next) {
+ fill_data->latitude = last_good->latitude;
+ fill_data->longitude = last_good->longitude;
+ errors++;
}
+}
- if (errors) {
- a->errors[InvalidGPS] = errors;
- return errors;
- } else {
- return 0;
- }
+if (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
+int fix_heart_rate(Activity *a); // TODO probably needs HR max from athletes and
+other
*/
-
View
3  fix.h
@@ -7,7 +7,8 @@ int fix_invalid_gps(Activity *a);
/*
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
+int fix_heart_rate(Activity *a); // TODO probably needs HR max from athletes and
+other
values?
*/
View
9 gpx.c
@@ -20,7 +20,7 @@ int allspace(const char *str) {
return !*str;
}
-static inline void parse_field(DataField field, State* state, const char *str) {
+static inline void parse_field(DataField field, State *state, const char *str) {
char *end;
state->dp.data[field] = strtod(str, &end);
if (*end) state->dp.data[field] = UNSET_FIELD;
@@ -38,7 +38,7 @@ static int sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *sax_data) {
if (state->first_element && strcmp(name, "gpx")) {
fprintf(stderr, "error\n"); /* TODO */
- return 1; /* stop reading the file */
+ return 1; /* stop reading the file */
}
if (!strcmp(name, "metadata")) {
@@ -70,7 +70,8 @@ static int sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *sax_data) {
parse_field(HeartRate, state, data);
} else if (!strcmp(name, "gpxdata:temp") || !strcmp(name, "gpxtpx:atemp")) {
parse_field(Temperature, state, data);
- } else if (!strcmp(name, "gpxdata:cadence") || !strcmp(name, "gpxtpx:cad")) {
+ } else if (!strcmp(name, "gpxdata:cadence") ||
+ !strcmp(name, "gpxtpx:cad")) {
parse_field(Cadence, state, data);
} else if (!strcmp(name, "gpxdata:bikepower")) {
parse_field(Power, state, data);
@@ -88,7 +89,7 @@ static int sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *sax_data) {
int gpx_read(char *filename, Activity *activity) {
FILE *f = NULL;
- State state = { false, true, true, {{0}} };
+ State state = {false, true, true, {{0}}};
unset_data_point(&(state.dp));
if (!(f = fopen(filename, "r"))) {
View
6 util.c
@@ -9,11 +9,13 @@
uint32_t parse_timestamp(const char *date) {
unsigned long timestamp;
int offset;
- return (parse_date_basic(date, &timestamp, &offset) < 0) ? UNSET_FIELD : (uint32_t) timestamp;
+ return (parse_date_basic(date, &timestamp, &offset) < 0)
+ ? UNSET_FIELD
+ : (uint32_t)timestamp;
}
int format_timestamp(char *buf, uint32_t timestamp) {
- time_t time = (time_t) timestamp;
+ time_t time = (time_t)timestamp;
struct tm *tm = gmtime(&time);
return !strftime(buf, 21, "%Y-%m-%dT%H:%M:%SZ", tm) ? -1 : 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.