Exemplo n.º 1
0
def calc_temps(start_temp, end_temp):
    """
    Oblicza zmianę temperatur
    """
    TEMP_START = start_temp  # inner wall temp [C]
    TEMP_END = end_temp  # outer wall temp [C]
    Q = 750  # initial heat flux
    # Q = calculate_Q()

    read_wall_config = pd.read_excel("wall_config.xlsx")
    wall_config_material = read_wall_config["material"].tolist()
    wall_config_thickness = read_wall_config["thickness"].tolist()
    wall_config = dict(zip(wall_config_material, wall_config_thickness))

    # główna funkcja programu
    with db_session:
        query = Material.select(lambda m: m.name in wall_config_material)
        if set(wall_config_material) - set(m.name for m in query):
            raise ValueError("Nie wszystkie materiały znajdują się w bazie!")

        temp = TEMP_START
        for name, thickness in wall_config:
            material = Material.get(name=name)
            if temp > material.max_temp:
                raise TooHighTempException(temp, name)

            layer_coeff = (material.coeff_a * (temp**2) +
                           material.coeff_b * temp + material.coeff_c)
            print(f"Temperatura na warstwie {name} jest rowna {temp}")
            temp = temp - ((thickness * Q) / layer_coeff)
    if temp > end_temp:
        print("Wszystko okej, obliczenia wykonane poprawnie")
    raise ValueError(
        f"Niepoprawnie przepriwadzone obliczenia temp koncowa {temp}")
Exemplo n.º 2
0
def update_database(input_data):  # type: (List[Dict]) -> None
    """
    Format danych przyjmowanych przez tę funkcję:
    [
        {
            "name": "Nazwa materiału",
            "max_temp": 1200,
            "price": 15.0,
            "coeff_200": 3.4,
            "coeff_400": 3.6,
            "coeff_600": 3.6,
            "coeff_800": 3.6,
            "coeff_1000": 3.4,
            "coeff_1200": None,
            "coeff_1400": None,
            "coeff_1600": None,
        },
        {...}

    ]

    """

    for entry in input_data:
        name = entry["name"]
        # zabezpieczyć przed brakiem elementu
        db_obj = Material.get(name=name)
        if db_obj:
            db_obj.set(**entry)
        else:
            db_obj = Material(**entry)

        # tutaj możemy operować na db_obj, żeby wyliczyć współczynniki
        # kod napisany na jednym z poprzednich spotkań:
        x = []
        y = []
        missing_temps = []
        max_temp = db_obj.max_temp or 2000
        for temp in range(200, 1601, 200):
            value = getattr(db_obj, f"coeff_{temp}", None)
            if value is not None:
                x.append(temp)
                y.append(value)
            elif temp < max_temp:
                missing_temps.append(temp)
        deg = 2
        k = np.polyfit(x, y, deg)
        db_obj.coeff_a = k[0]
        db_obj.coeff_b = k[1]
        db_obj.coeff_c = k[2]
Exemplo n.º 3
0
def calc_temps(start_temp, end_temp):
    """
    Oblicza zmianę temperatur
    """
    TEMP_START = start_temp  # inner wall temp [C]
    TEMP_END = end_temp  # outer wall temp [C]
    Q = 750  # initial heat flux
    # Q = calculate_Q()
    '''wall_config = [
        # material name, thickness
        ("ISO 140-0.8", 0.065),
        ("ISO 125-0.5", 0.065),
        ("Microporous ISO 1200", 0.06),
    ]'''
    # TODO: Wczytać te parametry z pliku!
    read_wall_config = pd.read_excel('wall_config.xlsx')
    wall_config_material = read_wall_config['material'].tolist()
    wall_config_thickness = read_wall_config['thickness'].tolist()
    wall_config = dict(zip(wall_config_material, wall_config_thickness))

    # główna funkcja programu
    with db_session:
        mat_testowy = select(m for m in Material).first()
        if mat_testowy is None:
            raise ValueError("Pusta baza danych!")

        # TODO: Sprawdzić, czy wszystkie nazwy materiałów z konfiguracji ściany znajdują się w bazie!
        # tutaj proszę o pomoc w napisaniu tego

        temp = TEMP_START
        for name, thickness in wall_config:
            material = Material.get(name=name)
            if temp > material.max_temp:
                raise TooHighTempException(temp, name)

            layer_coeff = (material.coeff_a * (temp**2) +
                           material.coeff_b * temp + material.coeff_c)
            print(f"Temperatura na warstwie {name} jest rowna {temp}")
            temp = temp - ((thickness * Q) / layer_coeff)
    # TODO: Sprawdzić, czy osiągnięta została temp. końcowa - jesli nie, to błąd itd.
    if temp > end_temp:
        print('Wszystko okej, obliczenia wykonane poprawnie')
    raise ValueError(
        f"Niepoprawnie przepriwadzone obliczenia temp koncowa {temp}")
Exemplo n.º 4
0
def main():
    TEMP_START = 1360  # inner wall temp [C]
    TEMP_END = 70  # outer wall temp [C]
    Q = 750  # initial heat flux
    # Q = calculate_Q()

    wall_config = [
        # material name, thickness
        ("ISO 140-0.8", 0.065),
        ("ISO 125-0.5", 0.065),
        ("Microporous ISO 1200", 0.06),
    ]

    # główna funkcja programu
    with db_session:
        # 1. jeśli w bazie nie ma materiałów -> wczytaj i wygeneruj dane
        mat_testowy = select(m for m in Material).first()
        if mat_testowy is None:
            generate_data()
            commit()
        else:
            print("Dane już są w bazie!")

        temp = TEMP_START
        for name, thickness in wall_config:
            material = Material.get(name=name)
            if temp > material.max_temp:
                raise TooHighTempException(temp, name)
            # print("temp", temp)
            # print("a", material.coeff_a, "b", material.coeff_b, "c", material.coeff_c)
            layer_coeff = (material.coeff_a * (temp**2) +
                           material.coeff_b * temp + material.coeff_c)
            print(f"Temperatura na warstwie {name} jest rowna {temp}")
            temp = temp - ((thickness * Q) / layer_coeff)

    if temp > TEMP_END:
        print(
            f"Mamy problem, temp końcowa: {round(temp, 2)}*C jest większa niż zakładana {TEMP_END}*C"
        )
    else:
        print(f"Wszystko dobrze, końcowa temperatura jest mniejsza niż 70*C.")