From 4a47f589356f50d8997bc8913a935b69d0f49237 Mon Sep 17 00:00:00 2001 From: Cal Wing Date: Thu, 27 Feb 2025 21:55:45 +1000 Subject: [PATCH] Almost finish main --- a1.py | 73 +++++++++++++++++++++++-- test_data.txt => test/test_data.txt | 0 test_data_2.txt => test/test_data_2.txt | 0 3 files changed, 69 insertions(+), 4 deletions(-) rename test_data.txt => test/test_data.txt (100%) rename test_data_2.txt => test/test_data_2.txt (100%) diff --git a/a1.py b/a1.py index 153102b..ea1d6a8 100644 --- a/a1.py +++ b/a1.py @@ -204,12 +204,65 @@ def print_table(start_relative_elevation: float, step_size: float, print("#"*79) +def main(): + cmd, data = None, None + while True: + cmd = input("Please enter a command: ").lower() + + # Help CMD + if cmd[0] == "h": + print(HELP_MESSAGE) + + # Quit + if cmd[0] == "s": + while True: + cmd = input("Are you sure (y/n): ").lower() + if cmd in ['y', 'n']: + break + print("Please enter a valid reponse") + if cmd == 'y': + break + + # Read Data + elif cmd[0] == "r": + directory = input("Please specify the directory: ") + filename = input("Please specify the filename: ") + data = load_data(directory, filename) + + # Print Table + elif cmd[0] == "p": + if data is None: + print("Please load data before using this command") + + cmd = cmd.split() + if len(cmd) != 4: + print("Please enter the correct number of arguments") + continue + + print_table(*cmd[1:], *data) + + # Make Graph + elif cmd[0] == "s": + if data is None: + print("Please load data before using this command") + + print("Simulating water heights...") + heights = calc_heights_water_out(*data[0:5]) + + plot_water_height(heights, data[4]) + + # Catch All + else: + print("Please enter a valid command") + + + # See if I get what the task sheet wants # [NOTE] It seems I am witing my own test suite :/ that wasn't the initention lol # Tests do equal what I get when i test it in the shell def sheet_tasks(): from debug_lib import NO_EVAL, TUPLE_EVAL - from debug_lib import compair_outputs + from debug_lib import compair_outputs, auto_input # from a1_alex import calc_daily_profit @@ -225,10 +278,22 @@ def sheet_tasks(): ) compair_outputs(TASKS) + + print("\nTask 8") + print_table(280, 20, 6, 30, 20, 40000, 1, 30, 0.02, 0.005, 85) + + + print("\nTask 9") + global input + input = auto_input([ + "h", "s", "q", "n", + "r", "test", "test_data.txt", + "p 280 20 6", "s", + "q", "y" + ]) + main() if __name__ == '__main__': - #sheet_tasks() - - print_table(280, 20, 6, 30, 20, 40000, 1, 30, 0.02, 0.005, 85) \ No newline at end of file + sheet_tasks() \ No newline at end of file diff --git a/test_data.txt b/test/test_data.txt similarity index 100% rename from test_data.txt rename to test/test_data.txt diff --git a/test_data_2.txt b/test/test_data_2.txt similarity index 100% rename from test_data_2.txt rename to test/test_data_2.txt