Modified logger to write to new file each start.

pull/12/head
Mark Jessop 2019-09-13 21:03:20 +09:30
rodzic 54b21bdc66
commit ca4c22a018
4 zmienionych plików z 19 dodań i 9 usunięć

Wyświetl plik

@ -23,14 +23,14 @@ def getDensity(altitude):
tempGrad = -0.0065 # Temperature gradient [deg K/m] tempGrad = -0.0065 # Temperature gradient [deg K/m]
RGas = 8.31432 # Gas constant [kg/Mol/K] RGas = 8.31432 # Gas constant [kg/Mol/K]
R = 287.053 R = 287.053
deltaTemperature = 0.0; deltaTemperature = 0.0
# Lookup Tables # Lookup Tables
altitudes = [0, 11000, 20000, 32000, 47000, 51000, 71000, 84852] altitudes = [0, 11000, 20000, 32000, 47000, 51000, 71000, 84852]
pressureRels = [1, 2.23361105092158e-1, 5.403295010784876e-2, 8.566678359291667e-3, 1.0945601337771144e-3, 6.606353132858367e-4, 3.904683373343926e-5, 3.6850095235747942e-6] pressureRels = [1, 2.23361105092158e-1, 5.403295010784876e-2, 8.566678359291667e-3, 1.0945601337771144e-3, 6.606353132858367e-4, 3.904683373343926e-5, 3.6850095235747942e-6]
temperatures = [288.15, 216.65, 216.65, 228.65, 270.65, 270.65, 214.65, 186.946] temperatures = [288.15, 216.65, 216.65, 228.65, 270.65, 270.65, 214.65, 186.946]
tempGrads = [-6.5, 0, 1, 2.8, 0, -2.8, -2, 0] tempGrads = [-6.5, 0, 1, 2.8, 0, -2.8, -2, 0]
gMR = gravity * airMolWeight / RGas; gMR = gravity * airMolWeight / RGas
# Pick a region to work in # Pick a region to work in
i = 0 i = 0
@ -68,7 +68,7 @@ def seaLevelDescentRate(descent_rate, altitude):
''' Calculate the descent rate at sea level, for a given descent rate at altitude ''' ''' Calculate the descent rate at sea level, for a given descent rate at altitude '''
rho = getDensity(altitude) rho = getDensity(altitude)
return math.sqrt((rho / 1.22) * math.pow(descent_rate, 2)) return math.sqrt((rho / 1.225) * math.pow(descent_rate, 2))
@ -86,7 +86,7 @@ def time_to_landing(current_altitude, current_descent_rate=-5.0, ground_asl=0.0,
# Calculate the sea level descent rate. # Calculate the sea level descent rate.
_desc_rate = math.fabs(seaLevelDescentRate(current_descent_rate, current_altitude)) _desc_rate = math.fabs(seaLevelDescentRate(current_descent_rate, current_altitude))
_drag_coeff = _desc_rate*1.1045 # Magic multiplier from predict.php _drag_coeff = _desc_rate*1.106797 # Multiply descent rate by square root of sea-level air density (1.225).
_alt = current_altitude _alt = current_altitude

Wyświetl plik

@ -11,7 +11,7 @@ import logging
import os import os
import pytz import pytz
import time import time
from threading import Thread from threading import Thread, Lock
try: try:
# Python 2 # Python 2
from Queue import Queue from Queue import Queue
@ -25,17 +25,25 @@ class ChaseLogger(object):
Log all chase data into a file as lines of JSON. Log all chase data into a file as lines of JSON.
""" """
def __init__(self, filename): def __init__(self, filename=None, log_dir="./log_files"):
self.filename = filename if filename is not None:
# Use user-supplied filename if provided
self.filename = filename
else:
# Otherwise, create a filename based on the current time.
self.filename = os.path.join(log_dir, datetime.datetime.utcnow().strftime("%Y%m%d-%H%MZ.log"))
self.file_lock = Lock()
# Input Queue. # Input Queue.
self.input_queue = Queue() self.input_queue = Queue()
# Open the file. # Open the file.
try: try:
self.f = open(self.filename, 'a') self.f = open(self.filename, 'a')
logging.info("Logging - Opened log file %s." % self.filename)
except Exception as e: except Exception as e:
self.log_error("Logging - Could not open log file - %s" % str(e)) self.log_error("Logging - Could not open log file - %s" % str(e))
return return
@ -125,6 +133,7 @@ class ChaseLogger(object):
while self.input_processing_running: while self.input_processing_running:
# Process everything in the queue. # Process everything in the queue.
self.file_lock.acquire()
while self.input_queue.qsize() > 0: while self.input_queue.qsize() > 0:
try: try:
_data = self.input_queue.get_nowait() _data = self.input_queue.get_nowait()
@ -133,6 +142,7 @@ class ChaseLogger(object):
except Exception as e: except Exception as e:
self.log_error("Error processing data - %s" % str(e)) self.log_error("Error processing data - %s" % str(e))
self.file_lock.release()
# Sleep while waiting for some new data. # Sleep while waiting for some new data.
time.sleep(5) time.sleep(5)

Wyświetl plik

@ -837,7 +837,7 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", type=str, default="horusmapper.cfg", help="Configuration file.") parser.add_argument("-c", "--config", type=str, default="horusmapper.cfg", help="Configuration file.")
parser.add_argument("-v", "--verbose", action="store_true", default=False, help="Verbose output.") parser.add_argument("-v", "--verbose", action="store_true", default=False, help="Verbose output.")
parser.add_argument("-l", "--log", type=str, default="chaselog.log", help="Log file name.") parser.add_argument("-l", "--log", type=str, default=None, help="Custom log file name. (Default: ./log_files/<timestamp>.log")
args = parser.parse_args() args = parser.parse_args()
# Configure logging # Configure logging
@ -858,7 +858,7 @@ if __name__ == "__main__":
logging.getLogger().addHandler(web_handler) logging.getLogger().addHandler(web_handler)
# Start the Chase Logger # Start the Chase Logger
chase_logger = ChaseLogger(args.log) chase_logger = ChaseLogger(filename=args.log)
# Attempt to read in config file. # Attempt to read in config file.
chasemapper_config = read_config(args.config) chasemapper_config = read_config(args.config)