mam taki kod i chce zeby wyrzucalo mi sklepy z critical_overhea_alarm innym niż 0 - aplikacja uruchamia się we flasku # import pandas as pd
# from datetime import datetime, timedelta, date
# from api.services.detectors.detector import Detector


# class RPRVValveJamsDetector(Detector):

#     @property
#     def scope_key(self):
#         return "report_configuration"


#     @property
#     def config(self):
#         return {
#             "device_type": "agregat",
#             "parameter_keys": [
#                 "Receiver_Press",
#                 "RPRV_Open",
#                 "HPV_Open",
#                 "Power_Percent_Cmps_L1",
#                 "External_Temp"  # zakładam, że tak nazywa się temperatura zewnętrzna w danych
#             ],
#             "drop_na_parameter_keys": [
#                 "Receiver_Press",
#                 "RPRV_Open",
#                 "HPV_Open",
#                 "Power_Percent_Cmps_L1",
#                 "External_Temp"
#             ]
#         }

#     def __init__(self, app, mpks=None, start_date=None, end_date=None, params=None):
#         # zamiana kolejności start date w przeszłości, end_date dzisiaj
#         if start_date is None:
#             start_date = date.today() - timedelta(days=14)
#         if end_date is None:
#             end_date = date.today()

#         super().__init__(app, mpks, start_date, end_date, params)

#         # Sprawdzenie, czy start_date jest przed end_date
#         if self.start_date > self.end_date:
#             self.logger.warning(f"[RPRV] Change data: start={self.start_date}, end={self.end_date}")
#             self.start_date, self.end_date = self.end_date, self.start_date
#         self.logger.info(f"[RPRV] Data from: {self.start_date} to {self.end_date}")
#         self.logger.info("Initializing RPRVValveJamsDetector")


#     def get_run_info(self, shops_data):
#         return f"{super().get_run_info(shops_data)} (period: {self.start_date} to {self.end_date})"

#     # zmienione zwracanie
#     def get_data(self, shop_data):
#         self.logger.info(f'Getting Data - Shop MPK: {shop_data[1]}')
#         self.logger.info(f"[RPRV] Fetching data in range: {self.start_date} to {self.end_date}")

#         return self.data_service.get_compose_and_clear_device_parameters_values_df(
#             shop_data,
#             self.config["device_type"],
#             self.config["parameter_keys"],
#             self.config["drop_na_parameter_keys"],
#             None,
#             self.start_date,
#             self.end_date
#         )

#     # tu poprawilam i rozbudowalam o regułę 1
#     def compute_valve_jam_alerts(self, data_df):
#         if data_df is None or data_df.empty:
#             return {
#                 'Valve_jam_alarm': {
#                     "status": "error",
#                     "value": pd.NA,
#                     "info": "No data found"
#                 },
#                 'Critical_overheat_alarm': {
#                     "status": "error",
#                     "value": pd.NA,
#                     "info": "No data found"
#                 }
#             }

#         df = data_df.copy()
#         df['Value_timestamp'] = df.index
#         df.sort_index(inplace=True)

#         # Reguła 0: wykrywanie zacięcia zaworu RPRV

#         df['Value_timestamp_next'] = df['Value_timestamp'].shift(-1)
#         df['Receiver_Press_next'] = df['Receiver_Press'].shift(-1)
#         df['RPRV_Open_next'] = df['RPRV_Open'].shift(-1)

#         def compute_alarm(row):
#             required_fields = [
#                 row['Value_timestamp'], row['Value_timestamp_next'],
#                 row['Receiver_Press'], row['Receiver_Press_next'],
#                 row['RPRV_Open'], row['RPRV_Open_next']
#             ]
#             if pd.isna(required_fields).any():
#                 return 0

#             time_diff = row['Value_timestamp_next'] - row['Value_timestamp']
#             if time_diff == timedelta(minutes=30):
#                 avg_pressure = (row['Receiver_Press'] + row['Receiver_Press_next']) / 2
#                 avg_open = (row['RPRV_Open'] + row['RPRV_Open_next']) / 2
#                 return int(avg_pressure >= 40 and avg_open >= 90)
#             return 0

#         df['Valve_jam_alarm'] = df.apply(compute_alarm, axis=1)
#         jam_score = df['Valve_jam_alarm'].mean()

#         # Reguła 1: Krytyczne przegrzanie + otwarty RPRV

#         # Dwa pomiary z rzędu (1h) → przesunięcia o 1 i 2 wiersze (zakładam 30 min odstępu między pomiarami)
#         df['Value_timestamp_next_2'] = df['Value_timestamp'].shift(-2)
#         df['Receiver_Press_next_1'] = df['Receiver_Press'].shift(-1)
#         df['Receiver_Press_next_2'] = df['Receiver_Press'].shift(-2)
#         df['RPRV_Open_next_1'] = df['RPRV_Open'].shift(-1)
#         df['RPRV_Open_next_2'] = df['RPRV_Open'].shift(-2)
#         df['External_Temp_next_1'] = df['External_Temp'].shift(-1)
#         df['External_Temp_next_2'] = df['External_Temp'].shift(-2)

#         def compute_critical_overheat(row):
#             required_fields = [
#                 row['Value_timestamp'], row['Value_timestamp_next_2'],
#                 row['Receiver_Press'], row['Receiver_Press_next_1'], row['Receiver_Press_next_2'],
#                 row['RPRV_Open'], row['RPRV_Open_next_1'], row['RPRV_Open_next_2'],
#                 row['External_Temp'], row['External_Temp_next_1'], row['External_Temp_next_2']
#             ]
#             if pd.isna(required_fields).any():
#                 return 0

#             # Sprawdzenie, czy dwa kolejne pomiary (razem 1h) spełniają warunki
#             time_diff_1 = row['Value_timestamp_next_2'] - row['Value_timestamp']
#             if time_diff_1 == timedelta(minutes=60):
#                 cond_pressure = (row['Receiver_Press'] > 40 and row['Receiver_Press_next_1'] > 40 and row['Receiver_Press_next_2'] > 40)
#                 cond_rprv = (row['RPRV_Open'] == 100 and row['RPRV_Open_next_1'] == 100 and row['RPRV_Open_next_2'] == 100)
#                 cond_temp = (row['External_Temp'] > 34 and row['External_Temp_next_1'] > 34 and row['External_Temp_next_2'] > 34)

#                 if cond_pressure and cond_rprv and cond_temp:
#                     return 1
#             return 0

#         df['Critical_overheat_alarm'] = df.apply(compute_critical_overheat, axis=1)
#         critical_overheat_score = df['Critical_overheat_alarm'].mean()

#         return {
#             'Valve_jam_alarm': {
#                 "status": "success",
#                 "value": float(jam_score),
#                 "info": None
#             },
#             'Critical_overheat_alarm': {
#                 "status": "success",
#                 "value": float(critical_overheat_score),
#                 "info": None
#             }
#         }

#     def check_state(self, data_df):
#         return self.compute_valve_jam_alerts(data_df)