diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-03-10 12:27:53 +0000 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-03-10 12:27:53 +0000 |
| commit | 7c6c2e09e3ad1d41f26869cb7b9f9882175c8a6e (patch) | |
| tree | 10aa6710599230c889ec44407a065ee303a79348 /datasets/run_log/convert.py | |
| download | TCPD-7c6c2e09e3ad1d41f26869cb7b9f9882175c8a6e.tar.gz TCPD-7c6c2e09e3ad1d41f26869cb7b9f9882175c8a6e.zip | |
Initial commit
Diffstat (limited to 'datasets/run_log/convert.py')
| -rw-r--r-- | datasets/run_log/convert.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/datasets/run_log/convert.py b/datasets/run_log/convert.py new file mode 100644 index 0000000..a6309d9 --- /dev/null +++ b/datasets/run_log/convert.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Dataset conversion script + +Author: Gertjan van den Burg + +""" + +import argparse +import clevercsv +import json + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("input_file", help="File to convert") + parser.add_argument("output_file", help="File to write to") + return parser.parse_args() + + +def main(): + args = parse_args() + + with open(args.input_file, "r", newline="", encoding="ascii") as fp: + reader = clevercsv.reader( + fp, delimiter=",", quotechar="", escapechar="" + ) + rows = list(reader) + + header = rows.pop(0) + + name = "run_log" + longname = "Run Log" + + time = [r[0].rstrip("Z").replace("T", " ") for r in rows] + time_fmt = "%Y-%m-%d %H:%M:%S" + pace = [float(r[3]) for r in rows] + distance = [float(r[4]) for r in rows] + + series = [ + {"label": "Pace", "type": "float", "raw": pace}, + {"label": "Distance", "type": "float", "raw": distance}, + ] + + data = { + "name": name, + "longname": longname, + "n_obs": len(time), + "n_dim": len(series), + "time": { + "type": "string", + "format": time_fmt, + "index": list(range(len(time))), + "raw": time, + }, + "series": series, + } + + with open(args.output_file, "w") as fp: + json.dump(data, fp, indent="\t") + + +if __name__ == "__main__": + main() |
