Task 2
This commit is contained in:
parent
b60cfd67af
commit
cc97e16ff9
27
a1.py
27
a1.py
@ -31,12 +31,12 @@ def determine_power_used(water_mass: float, elevation: float, pumping_time: floa
|
|||||||
|
|
||||||
# Actual amount of energy needed based on eff
|
# Actual amount of energy needed based on eff
|
||||||
# Here an 85% eff means an extra 15% is needed to pump the water up
|
# Here an 85% eff means an extra 15% is needed to pump the water up
|
||||||
electrical_energy = potenital_energy * (1 + (1 - efficiency/100)) # J = J * SCALER
|
electrical_energy = potenital_energy / (efficiency/100) # J = J * SCALER
|
||||||
|
|
||||||
# Actual electrial power used to pump the water
|
# Actual electrial power used to pump the water
|
||||||
power_used = electrical_energy / (pumping_time*60*60) # W = J / S = J / (hr*60*60)
|
power_used = electrical_energy / (pumping_time*60*60) # W = J / S = J / (hr*60*60)
|
||||||
|
|
||||||
return power_used / 10e3 # W -> kW
|
return power_used / 1e3 # W -> kW
|
||||||
|
|
||||||
# Task 2
|
# Task 2
|
||||||
def determine_water_released(gen_power: float, elevation: float, pumping_time: float, efficiency: float) -> float:
|
def determine_water_released(gen_power: float, elevation: float, pumping_time: float, efficiency: float) -> float:
|
||||||
@ -54,22 +54,22 @@ def determine_water_released(gen_power: float, elevation: float, pumping_time: f
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# How much electrical engery was generated?
|
# How much electrical engery was generated?
|
||||||
electrical_energy = (gen_power * 10e3) * (pumping_time*60*60) # J = W * S = (kW * 10^3) * (hrs*60*60)
|
electrical_energy = (gen_power * 1e3) * (pumping_time*60*60) # J = W * S = (kW * 10^3) * (hrs*60*60)
|
||||||
|
|
||||||
# Need more potential energy to get electrial energy
|
# Need more potential energy to get electrial energy
|
||||||
# Again here for 85% eff need 15% more potenitial enegry to get pot-eng
|
# Again here for 85% eff need 15% more potenitial enegry to get pot-eng
|
||||||
potential_energy = electrical_energy / (1 + (1 - efficiency/100)) # J = J * Scaler
|
potential_energy = electrical_energy * (efficiency/100) # J = J * Scaler
|
||||||
|
|
||||||
water_mass = potential_energy / (WATER_DENSITY * elevation) # kg = J / (m/s^2 * m)
|
water_mass = potential_energy / (GRAVITY_ACC * elevation) # kg = J / (m/s^2 * m)
|
||||||
|
|
||||||
return water_mass
|
return water_mass
|
||||||
|
|
||||||
def main():
|
# Task 3
|
||||||
print("Hello World!")
|
|
||||||
|
|
||||||
|
|
||||||
# See if I get what the task sheet wants
|
# See if I get what the task sheet wants
|
||||||
def sheet_tasks():
|
def sheet_tasks():
|
||||||
|
import numpy as np
|
||||||
TASKS = (
|
TASKS = (
|
||||||
(determine_power_used, (5e6, 250, 8, 85), 500.9191176470588),
|
(determine_power_used, (5e6, 250, 8, 85), 500.9191176470588),
|
||||||
(determine_water_released, (300, 250, 8, 85), 2994495.4128440367)
|
(determine_water_released, (300, 250, 8, 85), 2994495.4128440367)
|
||||||
@ -78,12 +78,23 @@ def sheet_tasks():
|
|||||||
for i, (task, args, expected) in enumerate(TASKS):
|
for i, (task, args, expected) in enumerate(TASKS):
|
||||||
print(f'Task {i+1}')
|
print(f'Task {i+1}')
|
||||||
result = task(*args)
|
result = task(*args)
|
||||||
if expected is not None:
|
|
||||||
|
# Number comparison
|
||||||
|
if isinstance(expected, (float, int)):
|
||||||
|
foo = np.isclose(result, expected, 0.001)
|
||||||
|
print(f'{task.__qualname__}{args} -> {result} {"~=" if foo else "!="} {expected}')
|
||||||
|
print(f'Task is{"" if foo else " NOT"} close enough to expected result.')
|
||||||
|
|
||||||
|
# Literal Comparison
|
||||||
|
elif expected is not None:
|
||||||
print(f'{task.__qualname__}{args} -> {result} {"==" if result == expected else "!="} {expected}')
|
print(f'{task.__qualname__}{args} -> {result} {"==" if result == expected else "!="} {expected}')
|
||||||
print(f'Task{"" if result == expected else " NOT"} equal to expected result.')
|
print(f'Task{"" if result == expected else " NOT"} equal to expected result.')
|
||||||
|
|
||||||
|
# Just run the task
|
||||||
else:
|
else:
|
||||||
print(f'{task.__qualname__}{args} -> {result}')
|
print(f'{task.__qualname__}{args} -> {result}')
|
||||||
|
|
||||||
|
# Newline
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user