From 9e201bd1b880ccab10ed701b98cde806867a3d5b Mon Sep 17 00:00:00 2001 From: Neal Probert Date: Fri, 22 Jan 2021 10:16:17 -0500 Subject: [PATCH] Initial commit of files --- README | 0 Templates/Project/README.txt | 0 Templates/Project/docs/conf.py | 0 Templates/Project/docs/index.rst | 0 Templates/Project/docs/quickstart.rst | 0 Templates/Project/foobar/__init__.py | 0 Templates/Project/foobar/cli.py | 0 Templates/Project/foobar/storage.py | 0 Templates/Project/foobar/tests/__init__.py | 0 Templates/Project/foobar/tests/test_cli.py | 0 .../Project/foobar/tests/test_storage.py | 0 Templates/Project/setup.cfg | 0 Templates/Project/setup.py | 0 classes/gpsmath.py | 37 +++++++++ classes/utils/audio.py | 22 +++++ classes/utils/logging.py | 81 +++++++++++++++++++ packages/PACKAGES.txt | 8 ++ packages/packages.sh | 14 ++++ 18 files changed, 162 insertions(+) create mode 100644 README create mode 100644 Templates/Project/README.txt create mode 100644 Templates/Project/docs/conf.py create mode 100644 Templates/Project/docs/index.rst create mode 100644 Templates/Project/docs/quickstart.rst create mode 100644 Templates/Project/foobar/__init__.py create mode 100644 Templates/Project/foobar/cli.py create mode 100644 Templates/Project/foobar/storage.py create mode 100644 Templates/Project/foobar/tests/__init__.py create mode 100644 Templates/Project/foobar/tests/test_cli.py create mode 100644 Templates/Project/foobar/tests/test_storage.py create mode 100644 Templates/Project/setup.cfg create mode 100644 Templates/Project/setup.py create mode 100644 classes/gpsmath.py create mode 100644 classes/utils/audio.py create mode 100644 classes/utils/logging.py create mode 100644 packages/PACKAGES.txt create mode 100755 packages/packages.sh diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/README.txt b/Templates/Project/README.txt new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/docs/conf.py b/Templates/Project/docs/conf.py new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/docs/index.rst b/Templates/Project/docs/index.rst new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/docs/quickstart.rst b/Templates/Project/docs/quickstart.rst new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/foobar/__init__.py b/Templates/Project/foobar/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/foobar/cli.py b/Templates/Project/foobar/cli.py new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/foobar/storage.py b/Templates/Project/foobar/storage.py new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/foobar/tests/__init__.py b/Templates/Project/foobar/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/foobar/tests/test_cli.py b/Templates/Project/foobar/tests/test_cli.py new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/foobar/tests/test_storage.py b/Templates/Project/foobar/tests/test_storage.py new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/setup.cfg b/Templates/Project/setup.cfg new file mode 100644 index 0000000..e69de29 diff --git a/Templates/Project/setup.py b/Templates/Project/setup.py new file mode 100644 index 0000000..e69de29 diff --git a/classes/gpsmath.py b/classes/gpsmath.py new file mode 100644 index 0000000..6c6516f --- /dev/null +++ b/classes/gpsmath.py @@ -0,0 +1,37 @@ +from math import sin, cos, asin, sqrt, radians + +earth_flatening = 1.0/298.257223563 +earth_radius = 6378137.0 + +def haversine(lat1, lon1, lat2, lon2): + """ + Calculate the great circle distance between two points + on the earth (specified in decimal degrees) + """ + # convert decimal degrees to radians + lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) + + # haversine formula + dlon = lon2 - lon1 + dlat = lat2 - lat1 + a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 + c = 2 * asin(sqrt(a)) + + # 6367 km is the radius of the Earth + return earth_radius * c + +def roydistance(lat1, lon1, lat2, lon2): + """ + Calculate the great circle distance between two points + on the earth (specified in decimal degrees) + """ + # convert decimal degrees to radians + lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) + + # Roy's method + f1 = (1.0 - earth_flatening) + + top = (pow((lon2-lon1), 2) * pow(cos(lat1), 2)) + pow(lat2-lat1, 2) + bot = pow(sin(lat1), 2) + (pow(f1, 2) * pow(cos(lat1), 2)) + + return f1 * earth_radius * sqrt(top/bot) diff --git a/classes/utils/audio.py b/classes/utils/audio.py new file mode 100644 index 0000000..48ca237 --- /dev/null +++ b/classes/utils/audio.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Jan 8 10:26:56 2021 + +@author: neal +""" + +import os +from sys import platform as _platform + +sound_args = "" + +def play_sound(file): + if _platform == "win32" or _platform == "win64" or _platform == "cygwin": + cmd = "wmplayer " + '"' + file + '"' + else: + cmd = "aplay -N " + sound_args + " " + file + " &" +# print(cmd) + os.system(cmd) + +#play_sound("../misc/boat-horn.wav") diff --git a/classes/utils/logging.py b/classes/utils/logging.py new file mode 100644 index 0000000..425f867 --- /dev/null +++ b/classes/utils/logging.py @@ -0,0 +1,81 @@ +import sys +from time import strftime, time +import csv +import json + +# +# Text logging +# +class LOGlog(): + def __init__(self): + self.filename = "" + self.handle = 0 + self.lineno = 0 + + def genname(dire="logs", basename="log-", ext="log"): + return dire + '/' + basename + strftime("%Y%m%d-%H%M.") + ext + + def create(self, dire="logs", basename="log-", ext="log"): + self.lineno = 0 + self.handle = open(dire + "/" + basename + strftime("%Y%m%d-%H%M.") + ext, 'a') + + def open(self, filename): + self.filename = filename + self.handle = open(filename, 'r') + + def write(self, str): + self.lineno = self.lineno + 1 + self.handle.write(str + "\n") + + def read(self): + self.lineno = self.lineno + 1 + return self.handle.read() + + def close(self): + self.handle.close() + + def lines(self): + return self.lineno + +# +# CSV logging +# +class CSVlog(LOGlog): + def __init__(self): + super().__init__() + self.header = "" + + def create(self, dire="logs", basename="log-"): + super().create(dire, basename, "csv") + + def open(self, filename): + self.reader = csv.reader(super().filename) + super().open(filename) + + def read(self): + return self.reader.next(super().handle) + + def readall(self, csvfile): + data = csv.reader(csvfile) + csv.close() + return list(data) + +# +# JSON logging +# +class JSONlog(LOGlog): + def __init__(self): + super().__init__() + + def create(self, dire="logs", basename="log-"): + super().create(dire, basename, "json") + + def open(self, filename): + super().open(filename) + + def write(self, data): + data['timestamp'] = time() + super().write(json.dumps(data)) + + def read(self, ): + return json.loads(super().read()) diff --git a/packages/PACKAGES.txt b/packages/PACKAGES.txt new file mode 100644 index 0000000..d60eede --- /dev/null +++ b/packages/PACKAGES.txt @@ -0,0 +1,8 @@ + +Required Python3 packages: +========================== +subversion +python3-all +python3-pil.imagetk +spyder3 + diff --git a/packages/packages.sh b/packages/packages.sh new file mode 100755 index 0000000..e690d88 --- /dev/null +++ b/packages/packages.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Python 3 +echo "Python 3 packages:" +sudo apt-get -y --ignore-missing install python3-all python3-dev python3-tk idle3 python3-pip python3-pyqt5 python3-serial python3-can python3-protobuf python3-numpy python3-pil.imagetk python3-gi + +# Python addons +sudo -H pip install --upgrade pip +sudo -H pip install configparser pyside2 pycrate + +# cleanup +sudo apt-get autoremove +sudo apt-get clean +