Skip to content
Snippets Groups Projects

fix bug calculate find_tps_tm when the end time fall into the last 5 minute of a day

Merged Lan Dam requested to merge i81_tps_second_marker into master
1 file
+ 41
26
Compare changes
  • Side-by-side
  • Inline
@@ -822,14 +822,15 @@ def trim_downsample_wf_chan(chan: Dict, start_tm: float, end_tm: float,
chan['data'] = np.hstack(downsampled_data)
def get_each_day_5_min_list(start_tm: float, end_tm: float) -> np.ndarray:
def get_start_5mins_of_diff_days(start_tm: float, end_tm: float) -> np.ndarray:
"""
Get the list of all five minute for every day start from the day of startTm
and end at the day of endTm.
Get the list of the start time of all five minutes for each day start from
the day of startTm and end at the day of endTm.
:param start_tm: float - start time
:param end_tm: float - end time
:return every_day_5_min_list: [[288 of floats], ] - the list of all start
of five minutes for every day in which each day has 288 of 5 minutes.
:return start_5mins_of_diff_days: [[288 of floats], ] - the list of
start of all five minutes of days specified by start_tm and end_tm in
which each day has 288 of 5 minutes.
"""
exact_day_tm = (start_tm // const.SEC_DAY) * const.SEC_DAY
exact_day_tm_list = []
@@ -841,43 +842,57 @@ def get_each_day_5_min_list(start_tm: float, end_tm: float) -> np.ndarray:
exact_day_tm_list.append(exact_day_tm)
exact_day_tm += const.SEC_DAY
# list of start/end 5m in each day: every_day_5_min_list
# list of start/end 5m in each day: start_5mins_of_diff_days
for idx, start_day_tm in enumerate(exact_day_tm_list):
a_day_5_min = np.arange(start_day_tm,
start_day_tm + const.SEC_DAY,
const.SEC_5M)
start_5mins_of_day = np.arange(start_day_tm,
start_day_tm + const.SEC_DAY,
const.SEC_5M)
if idx == 0:
every_day_5_min_list = np.array([a_day_5_min])
start_5mins_of_diff_days = np.array([start_5mins_of_day])
else:
every_day_5_min_list = np.vstack(
(every_day_5_min_list, a_day_5_min))
return every_day_5_min_list
start_5mins_of_diff_days = np.vstack(
(start_5mins_of_diff_days, start_5mins_of_day))
return start_5mins_of_diff_days
def find_tps_tm(given_tm: float, each_day_5_min_list: List[List[float]]
) -> Tuple[float, float]:
def find_tps_tm_idx(
given_tm: float, start_5mins_of_diff_days: List[List[float]]) \
-> Tuple[float, float]:
"""
Find the position of the given time (given_tm) in time-power-squared plot
:param given_tm: float - given time
:param each_day_5_min_list: [[288 of floats], ] - the list of all start
of five minutes for every day in which each day has 288 of 5 minutes.
:return x_idx: int - index of time in the each_day_5_min_list
:return y_idx: int - index of day plotted
(look in TimePowerSquaredWidget.getZoomData())
:param start_5mins_of_diff_days: [[288 of floats], ] - the list of
start of all five minutes of some specific days in which each day has
288 of 5 minutes.
:return x_idx: int - index of 5m section
:return y_idx: int - index of the day the given time belong to in plotting
"""
x_idx = None
y_idx = None
for day_idx, day in enumerate(each_day_5_min_list):
for tm_idx, tm in enumerate(day):
if tm > given_tm:
for day_idx, a_day_5mins in enumerate(start_5mins_of_diff_days):
for start_5m_idx, start_5m in enumerate(a_day_5mins):
if start_5m > given_tm:
# index of day start from 0 to negative because day is plotted
# from top to bottom
y_idx = - day_idx
x_idx = tm_idx - 1
if x_idx < 0:
x_idx = start_5m_idx - 1
if start_5m_idx == 0:
# if the start_5m_idx == 0, the given time belong to the
# last 5m of the previous day
y_idx = -(day_idx - 1)
x_idx = len(day) - 1
x_idx = const.NO_5M_DAY - 1
break
if x_idx is not None:
break
if x_idx is None:
# x_idx == None happens when the given time fall into the last 5m of
# the last day. Although the time 24:00 of the last day belongs
# to the next days of other cases, but since there is no more days to
# plot it, it is no harm to set it at the last 5m of the last day.
x_idx = const.NO_5M_DAY - 1
y_idx = - (len(start_5mins_of_diff_days) - 1)
return x_idx, y_idx
Loading