def insert_in_alert_definition_notification_time(
        notification_id, alert_definition_id, notification_datetime: datetime):
    query = insert_query_construction(
        compo=ALERT_DEFINITION_NOTIFICATION_TIME_COMPO,
        name=ALERT_DEFINITION_NOTIFICATION_TIME)
    params = [notification_id, alert_definition_id, notification_datetime]
    return my_sql.execute_and_close(query=query, params=params, return_id=True)
def insert_random_data_in_BI_COMPTAGE_DONNEE_table():
    insert_base = insert_query_construction(compo=COMPTAGE_COMPO,
                                            name=HandleDataFromDB.table_name)

    def get_comptage(comptage):
        if comptage > 100:
            return comptage - comptage / 10
        elif comptage > 20:
            return comptage + comptage - comptage / 2
        else:
            return 20 + comptage % 3

    def __generate_values():
        start_day = datetime.today() - timedelta(days=10)
        meters_id = [1, 2, 3]
        values = list()
        comptage = 20
        while len(values) < 10:
            comptage = get_comptage(comptage)
            start_day += timedelta(days=1)

            values.append((comptage, random.choice(meters_id), start_day))

        return values

    values = __generate_values()

    for value in values:
        my_sql.execute_and_close(query=insert_base, params=value)
def insert_in_alert_definition(name, category, description, level, status,
                               notification_id, calculator_id):
    query = insert_query_construction(compo=DEFINITION_COMPO,
                                      name=DEFINITION_TABLE_NAME)
    params = [
        name, category, description, level, status, notification_id,
        calculator_id
    ]
    return my_sql.execute_and_close(query=query, params=params, return_id=True)
def insert_in_calculator(operator, comparator, data_period_type,
                         data_period_quantity, data_period_unit, value_type,
                         value_number, value_period_type, hour_start, hour_end,
                         acceptable_diff):
    query = insert_query_construction(compo=CALCULATOR_COMPO,
                                      name=CALCULATOR_NAME)
    params = [
        operator, comparator, data_period_type, data_period_quantity,
        data_period_unit, value_type, value_number, value_period_type,
        hour_start, hour_end, acceptable_diff
    ]
    return my_sql.execute_and_close(query=query, params=params, return_id=True)
def insert_in_notification(period_unit: str, period_quantity: int, email: str,
                           days_flags: int, hours_flags: int):
    query = insert_query_construction(compo=NOTIFICATION_COMPO,
                                      name=NOTIFICATION_NAME)
    params = [
        period_unit,
        period_quantity,
        email,
        days_flags,
        hours_flags,
    ]
    return my_sql.execute_and_close(query=query, params=params, return_id=True)
Пример #6
0
    def add_notification_in_db(self, time: datetime):
        query = utils.insert_query_construction(
            name=ALERT_DEFINITION_NOTIFICATION_TIME,
            compo=ALERT_DEFINITION_NOTIFICATION_TIME_COMPO)
        params = [self.notification.id, self.id, time]

        print("query", query)
        print("params", params)

        cursor = my_sql.generate_cursor()
        cursor.execute(operation=query, params=params)
        my_sql.commit()
def insert_data_to_test_in_BI_COMPTAGE_DONNEE_table():
    insert_base = insert_query_construction(compo=COMPTAGE_COMPO,
                                            name=HandleDataFromDB.table_name)
    meter_id = 4
    values = list()
    comptage_list = [3, 2, 5, 1, 4]
    start_day = datetime.today() - timedelta(days=1)

    for comtage in comptage_list:
        start_day += timedelta(hours=1)
        values.append((comtage, meter_id, start_day))

    for value in values:
        my_sql.execute_and_close(query=insert_base, params=value)
def insert_in_bi_compteurs_data():
    select_base = insert_query_construction(compo=METER_TABLE_COMPO,
                                            name=METER_TABLE_NAME)
    print(select_base)

    def __generate_values():
        values = list()
        my_bool = [0, 1]
        i = 1
        while len(values) < 10:
            values.append(("name_{}".format(i), random.choice(my_bool)))
            i += 1

        return values

    values = __generate_values()

    for value in values:
        print(value)
        insert_in_bi_compteurs(name=value[0], is_index=value[1])
def insert_in_bi_comptage_donnees(donnee_comptage_value, meter_id, time):
    query = insert_query_construction(compo=COMPTAGE_COMPO,
                                      name=HandleDataFromDB.table_name)
    params = [donnee_comptage_value, meter_id, time]
    my_sql.execute_and_close(query=query, params=params)
def insert_in_alert_manager(launch_datetime: datetime):
    query = insert_query_construction(compo=ALERT_MANAGER_TABLE_COMPO,
                                      name=ALERT_MANAGER_TABLE_NAME)
    params = [launch_datetime]
    return my_sql.execute_and_close(query=query, params=params, return_id=True)
def insert_in_bi_objectifs(objectif_value: float, time_unit: str, meter_id):
    query = insert_query_construction(compo=OBJECTIF_TABLE_COMPO,
                                      name=OBJECTIF_TABLE_NAME)
    params = [objectif_value, time_unit, meter_id]
    return my_sql.execute_and_close(query=query, params=params, return_id=True)
def insert_in_bi_compteurs(name, is_index: bool):
    query = insert_query_construction(compo=METER_TABLE_COMPO,
                                      name=METER_TABLE_NAME)
    params = [name, is_index]
    print("params", params)
    return my_sql.execute_and_close(query=query, params=params, return_id=True)