Skip to content

Commit

Permalink
fix dockerfile entry point and remove try/except in logging to hunt w…
Browse files Browse the repository at this point in the history
…hy it can't create sensordata.csv
  • Loading branch information
tdubsFO committed Jan 3, 2024
1 parent 6351cd5 commit ab1a615
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ LABEL links='{\
}'
LABEL requirements="core >= 1.1"

ENTRYPOINT python /app/main.py
ENTRYPOINT ["python", "-u", "/app/main.py"]
Binary file modified app/.DS_Store
Binary file not shown.
84 changes: 42 additions & 42 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,51 @@ def main():
print("main started")
while (logging_active == True): # Main loop for logging data
print("in while")
try: # Send GET requests to the REST APIs
print("in try")
distance_response = requests.get(distance_url)
gps_response = requests.get(gps_url)
yaw_response = requests.get(yaw_url)
if distance_response.status_code == 200 and gps_response.status_code == 200 and yaw_response.status_code == 200: # Check if the requests were successful
print("data good")
distance_data = distance_response.json()['message'] # Extract the data from the responses
gps_data = gps_response.json()['message']
yaw_data = yaw_response.json()['message']
column_labels = ['Unix Timestamp', 'Date', 'Time','Distance (cm)', 'Confidence (%)', 'Yaw (deg)','Latitude', 'Longitude']
timestamp = int(time.time() * 1000) # Convert current time to milliseconds
dt = datetime.fromtimestamp(timestamp / 1000) # Convert timestamp to datetime object
unix_timestamp = timestamp
timenow = dt.strftime('%H:%M:%S')
date = dt.strftime('%m/%d/%y')
distance = distance_data['current_distance']
confidence = distance_data['signal_quality']
yawRad = yaw_data['yaw']
yawDeg = math.degrees(yawRad)
yaw = round(((yawDeg + 360) % 360),2)
latitude = gps_data['lat'] / 1e7
longitude = gps_data['lon'] / 1e7
data = [unix_timestamp, date, timenow, distance, confidence, yaw, latitude, longitude]
with open(log_file, 'a', newline='') as csvfile: # Create or append to the log file and write the data
writer = csv.writer(csvfile)
if csvfile.tell() == 0: # Write the column labels as the header row (only for the first write)
writer.writerow(column_labels)
writer.writerow(data) # Write the data as a new row
row_counter += 1 # Increment the row counter
#try: # Send GET requests to the REST APIs
print("in try")
distance_response = requests.get(distance_url)
gps_response = requests.get(gps_url)
yaw_response = requests.get(yaw_url)
if distance_response.status_code == 200 and gps_response.status_code == 200 and yaw_response.status_code == 200: # Check if the requests were successful
print("data good")
distance_data = distance_response.json()['message'] # Extract the data from the responses
gps_data = gps_response.json()['message']
yaw_data = yaw_response.json()['message']
column_labels = ['Unix Timestamp', 'Date', 'Time','Distance (cm)', 'Confidence (%)', 'Yaw (deg)','Latitude', 'Longitude']
timestamp = int(time.time() * 1000) # Convert current time to milliseconds
dt = datetime.fromtimestamp(timestamp / 1000) # Convert timestamp to datetime object
unix_timestamp = timestamp
timenow = dt.strftime('%H:%M:%S')
date = dt.strftime('%m/%d/%y')
distance = distance_data['current_distance']
confidence = distance_data['signal_quality']
yawRad = yaw_data['yaw']
yawDeg = math.degrees(yawRad)
yaw = round(((yawDeg + 360) % 360),2)
latitude = gps_data['lat'] / 1e7
longitude = gps_data['lon'] / 1e7
data = [unix_timestamp, date, timenow, distance, confidence, yaw, latitude, longitude]
with open(log_file, 'a', newline='') as csvfile: # Create or append to the log file and write the data
writer = csv.writer(csvfile)
if csvfile.tell() == 0: # Write the column labels as the header row (only for the first write)
writer.writerow(column_labels)
writer.writerow(data) # Write the data as a new row
row_counter += 1 # Increment the row counter

else:
# Print an error message if any of the requests were unsuccessful
print(f"Error: Ping2 Data - {distance_response.status_code} - {distance_response.reason}")
print(f"Error: GPS Data - {gps_response.status_code} - {gps_response.reason}")
print(f"Error: Attitude Data - {yaw_response.status_code} - {yaw_response.reason}")
else:
# Print an error message if any of the requests were unsuccessful
print(f"Error: Ping2 Data - {distance_response.status_code} - {distance_response.reason}")
print(f"Error: GPS Data - {gps_response.status_code} - {gps_response.reason}")
print(f"Error: Attitude Data - {yaw_response.status_code} - {yaw_response.reason}")

if row_counter % (log_rate * feedback_interval) == 0:
print(f"Rows added to CSV: {row_counter}")
time.sleep(1 / log_rate)
if row_counter % (log_rate * feedback_interval) == 0:
print(f"Rows added to CSV: {row_counter}")

time.sleep(1 / log_rate)

except Exception as e:
print(f"An error occurred: {e}")
break
#except Exception as e:
# print(f"An error occurred: {e}")
# break

@app.route('/')
def home():
Expand Down

0 comments on commit ab1a615

Please sign in to comment.