1111REPORT_STEP_SECONDS = 3600 # Example1
1212
1313
14- def cdd (t , r ):
14+ def _correct_decimal_digits (t , r ):
15+ """
16+ Correct Decimal Digits (CDD) is computed as a bounded form of
17+ ``-log10(abs(test_value - ref_value))``, which approximates how many
18+ decimal digits of ``test_value`` agree with ``ref_value``.
19+ """
1520 import math
1621
1722 if t == r :
@@ -29,9 +34,30 @@ def cdd(t, r):
2934
3035 return tmp
3136
37+
3238def check_cdd_float (test : list [float ], ref : list [float ], cdd_tol : int ) -> bool :
3339 """
34- Checks minimum correct decimal digits between two float sequences. Fails if lengths differ.
40+ Check the minimum number of correct decimal digits (CDD) between two
41+ float sequences. This function finds the minimum CDD over all element
42+ pairs in ``test`` and ``ref``, then checks whether ``floor(min_cdd)``
43+ is greater than or equal to ``cdd_tol``.
44+
45+ Parameters
46+ ----------
47+ test : list[float]
48+ Sequence of test values to be compared.
49+ ref : list[float]
50+ Sequence of reference values used as the expected results.
51+ cdd_tol : int
52+ Required minimum number of correct decimal digits (integer threshold)
53+ that the minimum CDD over all pairs must meet or exceed.
54+
55+ Returns
56+ -------
57+ bool
58+ ``True`` if ``test`` and ``ref`` have the same length and
59+ ``floor(min_cdd) >= cdd_tol``; ``False`` otherwise (including if the
60+ sequences differ in length).
3561 """
3662 import math
3763
@@ -41,15 +67,15 @@ def check_cdd_float(test: list[float], ref: list[float], cdd_tol: int) -> bool:
4167 min_cdd = 10.0
4268
4369 for t , r in zip (test , ref ):
44- tmp = cdd (t , r )
70+ tmp = _correct_decimal_digits (t , r )
4571
4672 if tmp < min_cdd :
4773 min_cdd = tmp
4874
4975 return math .floor (min_cdd ) >= cdd_tol
5076
5177
52- def _curr_dt ():
78+ def _get_current_datetime ():
5379 y , m , d , hh , mm , ss = solver .simulation_get_current_datetime ()
5480 return datetime (y , m , d , hh , mm , ss )
5581
@@ -59,7 +85,7 @@ def build_link_flow_solver_tuples_aligned():
5985 try :
6086 solver .swmm_start (0 )
6187 # After start callback
62- # period_end = _curr_dt()
88+ # period_end = _get_current_datetime
6389 # value = solver.link_get_result(0, shared_enum.LinkResult.FLOW)
6490 # tuples.append((period_end, value))
6591
@@ -72,12 +98,12 @@ def build_link_flow_solver_tuples_aligned():
7298 if time_left == 0 :
7399 break
74100 # Value for the interval that just ended; align to its period-end timestamp
75- period_end = _curr_dt () - timedelta (seconds = REPORT_STEP_SECONDS )
101+ period_end = _get_current_datetime () - timedelta (seconds = REPORT_STEP_SECONDS )
76102 value = solver .link_get_result (0 , shared_enum .LinkResult .FLOW )
77103 tuples .append ((period_end , value ))
78104
79105 # Before end callback
80- period_end = _curr_dt () - timedelta (seconds = REPORT_STEP_SECONDS )
106+ period_end = _get_current_datetime () - timedelta (seconds = REPORT_STEP_SECONDS )
81107 value = solver .link_get_result (0 , shared_enum .LinkResult .FLOW )
82108 tuples .append ((period_end , value ))
83109
0 commit comments