Skip to content

Commit

Permalink
feat: Add min to nano converter script
Browse files Browse the repository at this point in the history
  • Loading branch information
Sage Silberman committed Feb 16, 2024
1 parent 2c32a99 commit c4ea372
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
19 changes: 0 additions & 19 deletions pyulog/crop_ulog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#pylint: disable=too-many-locals, invalid-name, consider-using-enumerate



def main():
"""Command line interface"""
print("\nStarting argument parsing ...")
Expand All @@ -38,23 +36,6 @@ def main():
args = parser.parse_args()
print("Completed argument parsing")

# Convert HH:MM format to seconds
flight_start_seconds = convert_to_seconds(args.flight_start)
flight_end_seconds = convert_to_seconds(args.flight_end)

crop_ulog(args.ulog_file, flight_start_seconds, flight_end_seconds)

print(" complete")

def convert_to_seconds(time_str):
"""Converts time in HH:MM format to seconds"""
if time_str is None:
return None

hours, minutes = map(int, time_str.split(':'))
return hours * 3600 + minutes * 60



def crop_ulog(ulog_file_name, flight_start, flight_end):
"""
Expand Down
26 changes: 26 additions & 0 deletions pyulog/min2nano.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import time

def convert_to_nanoseconds(minutes_seconds_str):
"""Converts time in MM:SS format to nanoseconds since epoch"""
if minutes_seconds_str is None:
return None

# Parse minutes:seconds format
minutes, seconds = map(int, minutes_seconds_str.split(':'))

# Get current time in seconds since epoch
current_time_seconds = int(time.time())

# Calculate total seconds since epoch for the given minutes:seconds
total_seconds = current_time_seconds + (minutes * 60) + seconds

# Convert total seconds to nanoseconds
return total_seconds * 1e9

start_MMSS = input("Enter you're starting time value in the format minues:seconds (MM:SS)")
flight_start_ns = convert_to_nanoseconds(start_MMSS)
print("Flight start time in nanoseconds:", flight_start_ns)

end_MMSS = input("Enter you're ending time value in the format minues:seconds (MM:SS)")
flight_end_ns = convert_to_nanoseconds(end_MMSS)
print("Flight end time in nanoseconds:", flight_end_ns)

0 comments on commit c4ea372

Please sign in to comment.