From 7c33fd58b0a59c23964a258367f4576779842ed1 Mon Sep 17 00:00:00 2001 From: sco1 Date: Thu, 27 Jul 2017 13:56:59 -0400 Subject: [PATCH 1/2] Add command line functionality --- AltiForce.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/AltiForce.py b/AltiForce.py index 9ad6838..2c106e9 100644 --- a/AltiForce.py +++ b/AltiForce.py @@ -1,11 +1,12 @@ import matplotlib -matplotlib.use("TkAgg") +matplotlib.use("TkAgg") # Keep matplotlib and tkinter from conflicting and segfaulting import matplotlib.pyplot as plt - from tkinter import Tk from tkinter.filedialog import askopenfilename import numpy as np from numpy.lib import recfunctions as rfn +import argparse +from pathlib import Path class AltiForce(): def __init__(self, filepath): @@ -52,11 +53,25 @@ def plotdata(self): if __name__ == "__main__": - root = Tk() - root.withdraw() - filepath = askopenfilename() - root.destroy() + parser = argparse.ArgumentParser(description=('Parsing for AltiForce GoPro Backpack CSV, ' + 'specify a file with the -f or --file flags ' + 'or leave blank for a GUI prompt' + ) + ) + parser.add_argument("-f", "--file", + help="Parse manually specified file (relative or absolute path)", + action="store") + args = parser.parse_args() + if args.file: + filepath = Path(args.file) + else: + root = Tk() + root.withdraw() + filepath = Path(askopenfilename()) + root.destroy() - if filepath: + if filepath.exists(): mydata = AltiForce(filepath) mydata.plotdata() + else: + raise(ValueError) \ No newline at end of file From e6846daf1beed802b0995ad6ff3bbf0fe43d88d6 Mon Sep 17 00:00:00 2001 From: sco1 Date: Thu, 27 Jul 2017 14:28:26 -0400 Subject: [PATCH 2/2] Rename to match GitHub, add readme --- README.md | 14 ++++++++++++++ AltiForce.py => pyAltiForce.py | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 README.md rename AltiForce.py => pyAltiForce.py (96%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e84b606 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# pyAltiForce +Python Parsing for AltiForce GoPro Backpack CSVs + +The CSV file is processed and a plot of time vs. total acceleration is displayed. + +## Usage +Calling `pyAltiForce` from the command line with no arguments opens a file selection GUI for the user to select a single CSV file to process and display. + +Calling `pyAltiForce` with the optional `-f` or `--file` flag will allow the user to specify a single CSV file to process. + +Examples Include: + + python pyAltiForce -f './Data/GOPR0024.CSV' + python pyAltiForce --file 'C:/My Data/GOPR0024.CSV' \ No newline at end of file diff --git a/AltiForce.py b/pyAltiForce.py similarity index 96% rename from AltiForce.py rename to pyAltiForce.py index 2c106e9..4eb9c1b 100644 --- a/AltiForce.py +++ b/pyAltiForce.py @@ -8,7 +8,7 @@ import argparse from pathlib import Path -class AltiForce(): +class pyAltiForce(): def __init__(self, filepath): self.filepath = filepath self.loadCSV() @@ -45,6 +45,7 @@ def plotdata(self): ax1.plot(x, y1, 'g-') ax2.plot(x, y2, 'b-') + fig.suptitle(self.filepath.name) ax1.set_xlabel('Time (seconds)') ax1.set_ylabel('Altitude (feet)', color='g') ax2.set_ylabel('Z Acceleration (Gees)', color='b') @@ -71,7 +72,7 @@ def plotdata(self): root.destroy() if filepath.exists(): - mydata = AltiForce(filepath) + mydata = pyAltiForce(filepath) mydata.plotdata() else: raise(ValueError) \ No newline at end of file