|
| 1 | +"""Functions to prevent a nuclear meltdown.""" |
| 2 | + |
| 3 | + |
| 4 | +def is_criticality_balanced(temperature, neutrons_emitted) -> bool: |
| 5 | + """Verify criticality is balanced. |
| 6 | +
|
| 7 | + :param temperature: int or float - temperature value in kelvin. |
| 8 | + :param neutrons_emitted: int or float - number of neutrons emitted per second. |
| 9 | + :return: bool - is criticality balanced? |
| 10 | +
|
| 11 | + A reactor is said to be critical if it satisfies the following conditions: |
| 12 | + - The temperature is less than 800 K. |
| 13 | + - The number of neutrons emitted per second is greater than 500. |
| 14 | + - The product of temperature and neutrons emitted per second is less than 500000. |
| 15 | + """ |
| 16 | + return temperature < 800 and neutrons_emitted > 500 and (temperature * neutrons_emitted) < 500000 |
| 17 | + |
| 18 | + |
| 19 | +def reactor_efficiency(voltage, current, theoretical_max_power) -> str: |
| 20 | + """Assess reactor efficiency zone. |
| 21 | +
|
| 22 | + :param voltage: int or float - voltage value. |
| 23 | + :param current: int or float - current value. |
| 24 | + :param theoretical_max_power: int or float - power that corresponds to a 100% efficiency. |
| 25 | + :return: str - one of ('green', 'orange', 'red', or 'black'). |
| 26 | +
|
| 27 | + Efficiency can be grouped into 4 bands: |
| 28 | +
|
| 29 | + 1. green -> efficiency of 80% or more, |
| 30 | + 2. orange -> efficiency of less than 80% but at least 60%, |
| 31 | + 3. red -> efficiency below 60%, but still 30% or more, |
| 32 | + 4. black -> less than 30% efficient. |
| 33 | +
|
| 34 | + The percentage value is calculated as |
| 35 | + (generated power/ theoretical max power)*100 |
| 36 | + where generated power = voltage * current |
| 37 | + """ |
| 38 | + generated_power = voltage * current |
| 39 | + efficiency = (generated_power/theoretical_max_power)*100 |
| 40 | + |
| 41 | + if efficiency < 30: |
| 42 | + return 'black' |
| 43 | + elif 30 <= efficiency < 60: |
| 44 | + return 'red' |
| 45 | + elif 60 <= efficiency < 80: |
| 46 | + return 'orange' |
| 47 | + |
| 48 | + return 'green' |
| 49 | + |
| 50 | + |
| 51 | +def fail_safe(temperature, neutrons_produced_per_second, threshold) -> str: |
| 52 | + """Assess and return status code for the reactor. |
| 53 | +
|
| 54 | + :param temperature: int or float - value of the temperature in kelvin. |
| 55 | + :param neutrons_produced_per_second: int or float - neutron flux. |
| 56 | + :param threshold: int or float - threshold for category. |
| 57 | + :return: str - one of ('LOW', 'NORMAL', 'DANGER'). |
| 58 | +
|
| 59 | + 1. 'LOW' -> `temperature * neutrons per second` < 90% of `threshold` |
| 60 | + 2. 'NORMAL' -> `temperature * neutrons per second` +/- 10% of `threshold` |
| 61 | + 3. 'DANGER' -> `temperature * neutrons per second` is not in the above-stated ranges |
| 62 | + """ |
| 63 | + current_state = (temperature * neutrons_produced_per_second) / 100 |
| 64 | + thr_percent = threshold / 100 |
| 65 | + |
| 66 | + if thr_percent - 10 <= current_state <= thr_percent + 10: |
| 67 | + return 'NORMAL' |
| 68 | + elif current_state < thr_percent - 10: |
| 69 | + return 'LOW' |
| 70 | + |
| 71 | + return 'DANGER' |
0 commit comments