Код: Выделить всё
def find_top_consequential_alarms(
ui: frontPage.Application, data: pd.DataFrame, fromAr: bool
):
# Get selected alarm and time window based on the source
selected_alarm = (
ui.select_conc_alarm.currentText()
if not fromAr
else ui.ar_alarm_combo.currentText()
)
selected_time = (
ui.select_conc_time_window.currentText()
if not fromAr
else ui.ar_timewindow_combo.currentText()
)
# Convert selected time to timedelta
time_map = {
"5 Minutes": timedelta(minutes=5),
"10 Minutes": timedelta(minutes=10),
"15 Minutes": timedelta(minutes=15),
"30 Minutes": timedelta(minutes=30),
"1 Hour": timedelta(hours=1),
"5 Hours": timedelta(hours=5),
"24 Hours": timedelta(hours=24),
}
time_window = time_map[selected_time]
# Filter for occurrences of the selected alarm
specific_alarms = data[data["PtName"].str.strip() == selected_alarm].copy()
# Create time intervals for each specific alarm occurrence
specific_alarms["window_start"] = specific_alarms["TimestampUTC"]
specific_alarms["window_end"] = specific_alarms["TimestampUTC"] + time_window
intervals = pd.IntervalIndex.from_arrays(
specific_alarms["window_start"], specific_alarms["window_end"], closed="right"
)
# Filter for other alarms that fall within any of the intervals
other_alarms = data[data["PtName"] != selected_alarm].copy()
in_interval = np.vectorize(lambda x: intervals.contains(x).any(), otypes=[bool])
mask = in_interval(other_alarms["TimestampUTC"])
consequential_alarms = other_alarms[mask]
# Count the occurrences of each alarm within the time windows and get the top 10
consequential_alarm_counts = consequential_alarms["PtName"].value_counts().head(10)
title = f"Top 10 Consequential Alarms for {selected_alarm}\n(Time Window: {time_window})"
return consequential_alarm_counts, title
Код: Выделить всё
# Filter for other alarms that fall within any of the intervals
other_alarms = data[data["PtName"] != selected_alarm].copy()
in_interval = np.vectorize(lambda x: intervals.contains(x).any(), otypes=[bool])
mask = in_interval(other_alarms["TimestampUTC"])
consequential_alarms = other_alarms[mask]
будем очень благодарны за любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/791 ... -in-pandas
Мобильная версия