-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsuppression.py
More file actions
48 lines (42 loc) · 1.37 KB
/
suppression.py
File metadata and controls
48 lines (42 loc) · 1.37 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
def suppress_value(valuein: int, rc: str = "*", upper: int = 100000000) -> str:
"""
Suppress values less than or equal to 7, round all non-national values.
This function suppresses value if it is less than or equal to 7.
If value is 0 then it will remain as 0.
If value is at national level it will remain unsuppressed.
All other values will be rounded to the nearest 5.
Parameters
----------
valuein : int
Metric value
rc : str
Replacement character if value needs suppressing
upper : int
Upper limit for suppression of numbers
Returns
-------
out : str
Suppressed value (*), 0 or valuein if greater than 7 or national
Examples
--------
>>> suppress_value(3)
'*'
>>> suppress_value(24)
'25'
>>> suppress_value(0)
'0'
"""
base = 5
if not isinstance(valuein, int):
raise ValueError("The input: {} is not an integer.".format(valuein))
if valuein < 0:
raise ValueError("The input: {} is less than 0.".format(valuein))
elif valuein == 0:
valueout = str(valuein)
elif valuein >= 1 and valuein <= 7:
valueout = rc
elif valuein > 7 and valuein <= upper:
valueout = str(base * round(valuein / base))
else:
raise ValueError("The input: {} is greater than: {}.".format(valuein, upper))
return valueout