Push a1.zip

This commit is contained in:
Cal Wing 2025-02-14 20:11:00 +01:00
commit 35db58265a
3 changed files with 53 additions and 0 deletions

51
a1_support.py Normal file
View File

@ -0,0 +1,51 @@
import matplotlib.pyplot as plt
GRAVITY_ACC = 9.81
WATER_DENSITY = 997.13
HELP_MESSAGE = """
'h' - provide help message
'r' - read test data from a file
'p' - {start_relative_elevation, step, no_steps} - print a table showing daily profit and total energy for various values of relative elevation
'q' - terminate the program
"""
def load_data(directory: str, filename: str):
"""
Loads the data from a txt file
Parameters:
directory (str): the directory of the file
filename (str): the name of the file
Returns:
(list): the data from the file
"""
with open(directory + '/' + filename, 'r') as f:
data = [float(i) for i in f.readlines()[0].strip().split(',')]
return data
def plot_water_height(water_heights: tuple[float, ...], time_inc: float):
"""
Plots the water height over time
Parameters:
water_heights (tuple): the water heights
time_inc (float): the time increment
Returns:
None
"""
time = [i*time_inc for i in range(len(water_heights))]
plt.plot(time, water_heights, label='Dam Water Height')
plt.plot(time[0], water_heights[0], 'ro', label='Start')
plt.plot(time[-1], water_heights[-1], 'ro', label='End')
plt.xlabel("Time (s)")
plt.ylabel("Water Height (m)")
plt.title("Water Height vs Time")
plt.legend()
plt.show()

1
test_data.txt Normal file
View File

@ -0,0 +1 @@
30, 20, 40000, 1, 30, 0.02, 0.005, 85

1
test_data_2.txt Normal file
View File

@ -0,0 +1 @@
1000, 10, 0.01, 0.005, 1, 0.1, 0.05, 90