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}")
def generate_data(): iso140_08 = Material( name="ISO 140-0.8", max_temp=1400, coeff_400=0.27, coeff_800=0.31, coeff_1000=0.33, coeff_1200=0.36, ) iso125_05 = Material( name="ISO 125-0.5", max_temp=1250, coeff_400=0.14, coeff_600=0.16, coeff_800=0.18, coeff_1000=0.2, ) iso85_06 = Material(name="ISO 185-0.6", max_temp=850, coeff_400=0.14, coeff_600=0.16, coeff_800=0.19) microporus_1000 = Material( name="Microporous ISO 1000", max_temp=1000, coeff_200=0.022, coeff_400=0.025, coeff_600=0.035, coeff_800=0.044, ) microporus_1200 = Material( name="Microporous ISO 1200", max_temp=1200, coeff_200=0.029, coeff_400=0.033, coeff_600=0.039, coeff_800=0.044, ) materials = [ iso140_08, iso125_05, iso85_06, microporus_1000, microporus_1200 ] for material in materials: x = [] y = [] for temp in range(200, 1601, 200): value = getattr(material, f"coeff_{temp}", None) if value is not None: x.append(temp) y.append(value) deg = 2 k = np.polyfit(x, y, deg) print(k) curve = np.poly1d(k) print(f"Materiał {material.name} ma krzywą:\n{curve}") material.coeff_a = k[0] material.coeff_b = k[1] material.coeff_c = k[2]
def addRecipe(): res=input('Introduce: nombre " || " descripcion ,de la nueva receta\n') try: name, desc= res.split(' || ', maxsplit=1) except ValueError: print('Introduce una cadena separada por " || " sin comillas') return #conseguimos los materiales que conforman la receta listMaterials() res=input('Selecciona separando por "," los materiales de la receta\n \ Ejemplo: azufre x 2, acido x 1, 2(<--tbn indexa por id) x 3\n ') #lista de "punteros(nombres o ids) a los materiales" lMatPointers= res.split(',') #conseguimos los materiales lR_MAsocs=[] for pointer in lMatPointers: pointer,num=pointer.split(' x ') print(pointer,num) mat=getMaterial(pointer) lR_MAsocs.append(Re_MatAssociation(mat,num)) r=Recipe(name, desc, lR_MAsocs) m=Material(name,desc) #añadimos la receta a la base de datos(no hasta el commit) session.add(m) session.add(r) try: session.commit() #es en el commit donde puede dar errores de integridad except IntegrityError: session.rollback() print('Ha habido un problema con la nueva receta')
def set_project_cart(self, projectId, cart): project = self.session.query(Project).get(projectId) project.materials = [] #Flush to get the cascade delete from deassociation to happen self.session.flush() cartMaterials = [ Material(api_id=cartApiId, quantity=quantity) for cartApiId, quantity in cart.items() ] project.materials = cartMaterials
def create_example_input_file(): if Material.exists(): data = (m.to_dict(only=headers) for m in Material.select()) else: data = [{ "name": "Microporous ISO 1200", "max_temp": 1200.0, "coeff_200": 0.029, "coeff_400": 0.033, "coeff_600": 0.039, "coeff_800": 0.044, "coeff_1000": None, "coeff_1200": None, "coeff_1400": None, "coeff_1600": None, "price": None, }] with open("example.csv", "w") as csvfile: writer = csv.DictWriter(csvfile, fieldnames=headers) writer.writeheader() writer.writerows(data)
def addMaterial(): res=input('Introduce: nombre " || " descripcion ,del nuevo material\n') try: name, desc= res.split(' || ', maxsplit=1) except ValueError: print('ERRROR: Introduce una cadena separada por " || " sin comillas') return #creamos el nuevo material m= Material(name, desc) session.add(m) try: session.commit() #es en el commit donde puede sar errores de integridad except IntegrityError: session.rollback() print('Material ya existente')
def reply_text(xml_recv): """回复函数,""" toUserName = xml_recv.find("ToUserName").text fromUserName = xml_recv.find("FromUserName").text content = xml_recv.find("Content").text msgtype = xml_recv.find("MsgType").text # print(content) # 此处wechatid有待修改为微信号 user = User.query.filter(User.openid == fromUserName).first() if user == None: return regist_wx(fromUserName, toUserName, content) if content == "帮助": reply_content = "帮助信息\n\n1.微信端功能需要注册方可使用\n2.输入“帮助”可查看帮助信息\n3.输入“历史”可以查看最近保存的一条素材\n4.保存素材信息格式:#标签#内容\n5.所有用作格式识别的标点符号均为英文标点" elif content == "历史": #此处有待增加内容 material_last = Material.query.filter( Material.user_id == user.user_id).order_by(desc( Material.edit_time)).first() reply_content = f"#{material_last.tag}#{material_last.content}" else: # print(content) tag_re = re.compile(f"#(?P<tag>.+)#", re.DOTALL) tag_match = tag_re.match(content) if tag_match == None: tag = '无标签' else: tag = tag_match.group('tag') content = content.replace(tag_match.group(0), '') user_id = user.user_id edit_time = datetime.utcnow() new_material = Material(content=content, user_id=user_id, tag=tag, edit_time=edit_time) db.session.add(new_material) db.session.commit() reply_content = "素材保存成功" xlm_reply = reply_patten(fromUserName, toUserName, reply_content) # print(xlm_reply) return xlm_reply
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}")
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]
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.")
def material_edit(): if request.method == 'GET': mater_id = request.args.get('mater_id') if mater_id: material = Material.query.filter(Material.mater_id==int(mater_id),Material.user_id==session['user_id']).first() return render_template('material_edit.html', material=material) else: return render_template('material_edit.html') else: mater_id = request.form['mater_id'] content = request.form['content'] tag_re = re.compile(f"#(?P<tag>.+)#", re.DOTALL) tag_match = tag_re.match(content) if tag_match == None: tag = '无标签' else: tag = tag_match.group('tag') content = content.replace(tag_match.group(0),'') edit_time = datetime.utcnow() user_id = session['user_id'] # print(mater_id,tag,content,edit_time,user_id) if mater_id: material = Material.query.filter(Material.mater_id==int(mater_id),Material.user_id==session['user_id']).first() material.tag = tag material.content = content material.edit_time = edit_time db.session.add(material) db.session.commit() else: material = Material(tag=tag,content=content,user_id=user_id,edit_time=edit_time) db.session.add(material) db.session.commit() return redirect(url_for('index'))
def firstRun(materials, materialIDs, feedRates, minTemps, maxTemps, recTemps): # Generate the database tables described in app.py db.create_all() # Iterate over factory config lists and add+commit to database session for i in range(len(materials)): db.session.add(Material(name=materials[i])) writeValues(FactoryConfig, materialIDs[i], feedRates[i], minTemps[i], maxTemps[i], recTemps[i] ) writeValues(UserConfig, materialIDs[i], feedRates[i], minTemps[i], maxTemps[i], recTemps[i] ) print() print('Database successfully initialized') print()
def setUp(self): self.steel=Material('Steel', 1.0, 1.0) self.he200a=BeamSection2d('HE200A', self.steel)
def setUp(self): self.steel=Material('Steel', 1.0, 2.0)
def setUp(self): self.node1=Node2d('001',0.0,0.0) self.node2=Node2d('002',10.0,0.0) self.steel=Material('Steel',1.0, 1.0) self.section=BeamSection2d('HE200A', self.steel) self.beam=Beam2d('005', self.node1, self.node2, self.section)
def get_materials(self): self.MATERIAL_LIST = Material.get_all()
def get_material_density(self, material): material = Material.get_material(material) density = material[0].density self.MATERIAL_DENSITY = f'{density}'
def get_mol_weight(self, material): material = Material.get_material(material) mol_weight = material[0].molecular_weight self.MOLECULAR_WEIGHT = f'{mol_weight}'
def setUp(self): node1 = Node2d('001', 0.0, 0.0) node2 = Node2d('001', 1.0, 0.0) steel = Material('Steel', 1.0, 1.0) section = BeamSection2d('HE200A', steel) self.beam = Beam2d('beam001', node1, node2, section)