-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionals.py
More file actions
80 lines (63 loc) · 2.67 KB
/
conditionals.py
File metadata and controls
80 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
""" Meltdown Mitigation exercise """
# is_criticality_balanced
CRIT_TEMP = 800
CRIT_NEUTRONS = 500
CRIT_TN = 500000
# reactor_efficiency
GREEN = 0.8
ORANGE = 0.6
RED = 0.3
# fail_safe
LOW = 0.9
NORMAL = 1.1
def is_criticality_balanced(temperature, neutrons_emitted):
"""Verify criticality is balanced.
:param temperature: temperature value (integer or float)
:param neutrons_emitted: number of neutrons emitted per second (integer or float)
:return: boolean True if conditions met, False if not
A reactor is said to be critical if it satisfies the following conditions:
- The temperature is less than 800.
- The number of neutrons emitted per second is greater than 500.
- The product of temperature and neutrons emitted per second is less than 500000.
"""
temp_neutrons = temperature * neutrons_emitted
return temperature < CRIT_TEMP and neutrons_emitted > CRIT_NEUTRONS and temp_neutrons < CRIT_TN
def reactor_efficiency(voltage, current, theoretical_max_power):
"""Assess reactor efficiency zone.
:param voltage: voltage value (integer or float)
:param current: current value (integer or float)
:param theoretical_max_power: power that corresponds to a 100% efficiency (integer or float)
:return: str one of 'green', 'orange', 'red', or 'black'
Efficiency can be grouped into 4 bands:
1. green -> efficiency of 80% or more,
2. orange -> efficiency of less than 80% but at least 60%,
3. red -> efficiency below 60%, but still 30% or more,
4. black -> less than 30% efficient.
The percentage value is calculated as
(generated power/ theoretical max power)*100
where generated power = voltage * current
"""
percent = (voltage * current) / theoretical_max_power
if percent >= GREEN:
return 'green'
if percent >= ORANGE:
return 'orange'
if percent >= RED:
return 'red'
return 'black'
def fail_safe(temperature, neutrons_produced_per_second, threshold):
"""Assess and return status code for the reactor.
:param temperature: value of the temperature (integer or float)
:param neutrons_produced_per_second: neutron flux (integer or float)
:param threshold: threshold (integer or float)
:return: str one of: 'LOW', 'NORMAL', 'DANGER'
- `temperature * neutrons per second` < 90% of `threshold` == 'LOW'
- `temperature * neutrons per second` +/- 10% of `threshold` == 'NORMAL'
- `temperature * neutrons per second` is not in the above-stated ranges == 'DANGER'
"""
status = (temperature * neutrons_produced_per_second) / threshold
if status < LOW:
return 'LOW'
if status < NORMAL:
return 'NORMAL'
return 'DANGER'