Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slamd update 3 dichtebasierte angaben beim blending #125

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cypress/e2e/test_base_materials.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe("Test creating base materials", () => {
cy.findByText("Structural composition").should("exist");
cy.fillForm({
"Fine modules (m²/kg)": "123.45",
"Specific gravity": "67.890",
});

// Fill out additional properties
Expand Down
1 change: 0 additions & 1 deletion cypress/fixtures/example_aggregates_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"delivery_time": "10",
"fine_aggregates": "10",
"coarse_aggregates": "",
"gravity": "10",
"fineness_modulus": "",
"water_absorption": "",
"additional_properties-0-property_name": "Example shared property",
Expand Down
1 change: 0 additions & 1 deletion cypress/fixtures/example_aggregates_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"delivery_time": "5",
"fine_aggregates": "",
"coarse_aggregates": "5",
"gravity": "10",
"fineness_modulus": "",
"water_absorption": "",
"additional_properties-0-property_name": "Example shared property",
Expand Down
1 change: 0 additions & 1 deletion cypress/fixtures/example_powder_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
"mn2_o3": "10",
"loi": "10",
"fine": "10",
"gravity": "10",
"submit": "6 - Save material"
}
1 change: 0 additions & 1 deletion cypress/fixtures/example_powder_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
"mn2_o3": "10",
"loi": "10",
"fine": "10",
"gravity": "10",
"submit": "6 - Save material"
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def _populate_create_powder_composition_fields_with_session_value(cls, form, pow
@classmethod
def _populate_create_powder_structure_fields_with_session_value(cls, form, powder_structure):
form.new_project_form.create_powder_form.fines_modulus.data = powder_structure.fine
form.new_project_form.create_powder_form.specific_gravity.data = powder_structure.gravity

@classmethod
def _populate_create_liquid_name_field_with_session_value(cls, form, liquid_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ class CreateAggregateForm(Form):
]
)

gravity = DecimalField(
label='Specific gravity',
validators=[
validators.Optional()
]
)

fineness_modulus = DecimalField(
label='Fineness modulus (m³/kg)',
validators=[
Expand Down
2 changes: 1 addition & 1 deletion slamd/design_assistant/processing/llm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _generate_design_knowledge_prompt(cls):
instruction_excerpt = cls._generate_design_knowledge_instruction_excerpt(zero_shot_learner_session)
# combine user excerpt with system excerpt and instruction excerpt to build final design knowledge prompt
design_knowledge_prompt = instruction_excerpt + user_input_excerpt
#print(design_knowledge_prompt)

return design_knowledge_prompt

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function handleSubmittingAggregateComposition(event){
"delivery_time" : aggregate_cost_inputs[2].value,
"recyclingrate" : aggregate_cost_inputs[3].value,
"fine_aggregates" : aggregate_composition_inputs[0].value,
"coarse_aggregates" : aggregate_composition_inputs[1].value,
"gravity" : aggregate_composition_inputs[2].value,
"coarse_aggregates" : aggregate_composition_inputs[1].value,
"fineness_modulus" : aggregate_composition_inputs[3].value,
"water_absorption" : aggregate_composition_inputs[4].value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function handleSubmittingPowderStructuralComposition(event){
"si_o2" : powder_oxide_composition_inputs[2].value,
"fe3_o2" : powder_oxide_composition_inputs[3].value,
"fine" : powder_structural_composition_inputs[0].value,
"gravity" : powder_structural_composition_inputs[1].value
}
powder_structural_composition_inputs.forEach((powder_structural_composition_input) => {
powder_structural_composition_input.disabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<div>{{ form.new_project_form.create_aggregate_form.coarse_aggregates.label.text}}</div>
<input class="aggregate_composition_input w-auto form-control text-end" name="aggregate_composition_coarse_aggregates" {% if form.new_project_form.create_aggregate_form.coarse_aggregates.data %} value="{{ form.new_project_form.create_aggregate_form.coarse_aggregates.data }}" {% endif %} type="number" {% if progress >= 12 %} disabled {% endif %}/>
</div>
<div class="d-flex w-100 justify-content-end align-items-center gap-3">
<div>{{ form.new_project_form.create_aggregate_form.gravity.label.text}}</div>
<input class="aggregate_composition_input w-auto form-control text-end" name="aggregate_composition_gravity" {% if form.new_project_form.create_aggregate_form.gravity.data %} value="{{ form.new_project_form.create_aggregate_form.gravity.data }}" {% endif %} type="number" {% if progress >= 12 %} disabled {% endif %}/>
</div>
<div class="d-flex w-100 justify-content-end align-items-center gap-3">
<div>{{ form.new_project_form.create_aggregate_form.fineness_modulus.label.text}}</div>
<input class="aggregate_composition_input w-auto form-control text-end" name="aggregate_composition_fineness_modulus" {% if form.new_project_form.create_aggregate_form.fineness_modulus.data %} value="{{ form.new_project_form.create_aggregate_form.fineness_modulus.data }}" {% endif %} type="number" {% if progress >= 12 %} disabled {% endif %}/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<div>{{ form.new_project_form.create_powder_form.fines_modulus.label.text}}</div>
<input class="powder_structural_composition_input w-auto form-control text-end" name="powder_structural_composition_fines_modulus" {% if form.new_project_form.create_powder_form.fines_modulus.data %} value="{{ form.new_project_form.create_powder_form.fines_modulus.data }}" {% endif %} type="number" {% if progress >= 6 %} disabled {% endif %}/>
</div>
<div class="d-flex w-100 justify-content-end align-items-center gap-3">
<div>{{ form.new_project_form.create_powder_form.specific_gravity.label.text}}</div>
<input class="powder_structural_composition_input w-auto form-control text-end" name="powder_oxide_composition_specific_gravity" {% if form.new_project_form.create_powder_form.specific_gravity.data %} value="{{ form.new_project_form.create_powder_form.specific_gravity.data }}" {% endif %} type="number" {% if progress >= 6 %} disabled {% endif %}/>
</div>
</div>
<div class="text-end mt-2"><button class="powder_structural_composition_button btn btn-primary" id="powder_structural_composition_button" {% if progress >= 6 %} disabled {% endif %}>Save</button></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion slamd/materials/processing/blended_materials_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def submit_blending():
def add_min_max_entry(material_type, count):
data = json.loads(request.data)
min_max_form, complete = BlendedMaterialsService.create_min_max_form(material_type, count, data)
body = {'template': render_template('min_max_form.html', min_max_form=min_max_form, complete=complete)}
body = {'template': render_template('min_max_form.html', material_type=material_type, count=count, min_max_form=min_max_form, complete=complete)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verständnisfrage: Wo werden material_type und count im min_max_form template verwendet?

return make_response(jsonify(body), 200)


Expand Down
15 changes: 9 additions & 6 deletions slamd/materials/processing/blended_materials_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ def create_min_max_form(cls, material_type, count, base_material_uuids):
for _ in range(count):
min_max_form.all_min_max_entries.append_entry()

# Min/Max of the last entry are calculated from the previous entries, and the labels need to be switched
min_max_form.all_min_max_entries[-1].min.label.text = 'Max (%)'
min_max_form.all_min_max_entries[-1].max.label.text = 'Min (%)'

return min_max_form, complete

@classmethod
Expand Down Expand Up @@ -99,24 +95,31 @@ def save_blended_materials(cls, submitted_blending_configuration):

base_materials_as_dict = []
base_type = submitted_blending_configuration['base_type']
blending_strategy = submitted_blending_configuration['blending_strategy']
base_materials_as_string = ''

for base_material_uuid in base_material_uuids:
base_material = MaterialsPersistence.query_by_type_and_uuid(base_type, base_material_uuid)
if base_material is None:
raise MaterialNotFoundException('The requested base materials do no longer exist!')
base_materials_as_dict.append(base_material.__dict__)
base_materials_as_string += base_material.name + '/'

list_of_normalized_ratios_lists = RatioParser.create_list_of_normalized_ratio_lists(all_ratios_as_string,
RATIO_DELIMITER)

print(list_of_normalized_ratios_lists)
print(base_materials_as_dict)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements können raus

if blending_strategy == 'Volume-based':
list_of_normalized_ratios_lists = RatioParser.weight_to_density_ratios(list_of_normalized_ratios_lists,
base_materials_as_dict)
strategy = MaterialFactory.create_strategy(base_type.lower())

for ratio_list in list_of_normalized_ratios_lists:
if len(ratio_list) != len(base_materials_as_dict):
raise ValueNotSupportedException('Ratios cannot be matched with base materials!')

blend_name = submitted_blending_configuration['blended_material_name']
blended_material_name = f'{blend_name}-{RatioParser.ratio_list_to_ratio_string(ratio_list)}'
blended_material_name = f'{blend_name}-{blending_strategy}-{base_materials_as_string[:-1]}-{RatioParser.ratio_list_to_ratio_string(ratio_list)}'
blended_material = strategy.create_blended_material(blended_material_name, ratio_list,
base_materials_as_dict)
strategy.save_model(blended_material)
Expand Down
8 changes: 4 additions & 4 deletions slamd/materials/processing/constants/material_constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
POWDER_DEFAULT_DENSITY = 1.40
LIQUID_DEFAULT_DENSITY = 1.00
AGGREGATE_DEFAULT_DENSITY = 2.40
ADMIXTURE_DEFAULT_DENSITY = 1.10
POWDER_DEFAULT_DENSITY = 3.15
LIQUID_DEFAULT_DENSITY = 1.05
AGGREGATE_DEFAULT_DENSITY = 2.65
ADMIXTURE_DEFAULT_DENSITY = 1.50
CUSTOM_DEFAULT_DENSITY = 1.00
6 changes: 3 additions & 3 deletions slamd/materials/processing/forms/admixture_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


from slamd.materials.processing.forms.materials_form import MaterialsForm

from slamd.materials.processing.constants.material_constants import ADMIXTURE_DEFAULT_DENSITY

class AdmixtureForm(MaterialsForm):
density = DecimalField(
label='Admixture density (t/m³)',
default=1.1,
label='Specific Gravity',
default=ADMIXTURE_DEFAULT_DENSITY,
validators=[
validators.DataRequired(message='Material density cannot be empty')
]
Expand Down
12 changes: 3 additions & 9 deletions slamd/materials/processing/forms/aggregates_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from wtforms import DecimalField, validators

from slamd.materials.processing.forms.materials_form import MaterialsForm

from slamd.materials.processing.constants.material_constants import AGGREGATE_DEFAULT_DENSITY

class AggregatesForm(MaterialsForm):
fine_aggregates = DecimalField(
Expand All @@ -18,12 +18,6 @@ class AggregatesForm(MaterialsForm):
]
)

gravity = DecimalField(
label='Specific gravity',
validators=[
validators.Optional()
])

fineness_modulus = DecimalField(
label='Fineness modulus (m³/kg)',
validators=[
Expand All @@ -37,8 +31,8 @@ class AggregatesForm(MaterialsForm):
])

density = DecimalField(
label='Aggregate density (t/m³)',
default=2.4,
label='Specific Gravity',
default=AGGREGATE_DEFAULT_DENSITY,
validators=[
validators.DataRequired(message='Material density cannot be empty')
]
Expand Down
5 changes: 3 additions & 2 deletions slamd/materials/processing/forms/custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@


from slamd.materials.processing.forms.materials_form import MaterialsForm
from slamd.materials.processing.constants.material_constants import CUSTOM_DEFAULT_DENSITY


class CustomForm(MaterialsForm):
density = DecimalField(
label='Density (t/m³)',
default=1.0,
label='Specific Gravity',
default=CUSTOM_DEFAULT_DENSITY,
validators=[
validators.DataRequired(message='Material density cannot be empty')
]
Expand Down
6 changes: 3 additions & 3 deletions slamd/materials/processing/forms/liquid_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from wtforms import DecimalField, validators

from slamd.materials.processing.forms.materials_form import MaterialsForm

from slamd.materials.processing.constants.material_constants import LIQUID_DEFAULT_DENSITY

class LiquidForm(MaterialsForm):
na2_si_o3 = DecimalField(
Expand Down Expand Up @@ -75,8 +75,8 @@ class LiquidForm(MaterialsForm):
)

density = DecimalField(
label='Liquid density (t/m³)',
default=1.0,
label='Liquid Specific Gravity',
default=LIQUID_DEFAULT_DENSITY,
validators=[
validators.DataRequired(message='Material density cannot be empty')
]
Expand Down
11 changes: 7 additions & 4 deletions slamd/materials/processing/forms/min_max_form.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask_wtf import FlaskForm as Form
from wtforms import FieldList, FormField, DecimalField, validators
from wtforms import FieldList, FormField, DecimalField, SelectField, validators
from wtforms import StringField


Expand All @@ -12,12 +12,15 @@ class MinMaxEntriesForm(Form):
validators=[validators.DataRequired(message='Name cannot be empty')]
)

increment = DecimalField('Increment (%)')
increment = DecimalField('Increment (Vol.-%)')

min = DecimalField('Min (%)')
min = DecimalField('Min (Vol.-%)')

max = DecimalField('Max (%)')
max = DecimalField('Max (Vol.-%)')


class MinMaxForm(Form):

blending_strategy = SelectField(label='Blending Strategy', choices=['Volume-based', 'Weight-based'])

all_min_max_entries = FieldList(FormField(MinMaxEntriesForm), min_entries=0)
13 changes: 3 additions & 10 deletions slamd/materials/processing/forms/powder_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from wtforms import DecimalField, validators

from slamd.materials.processing.forms.materials_form import MaterialsForm

from slamd.materials.processing.constants.material_constants import POWDER_DEFAULT_DENSITY

class PowderForm(MaterialsForm):

Expand Down Expand Up @@ -103,16 +103,9 @@ class PowderForm(MaterialsForm):
]
)

gravity = DecimalField(
label='Specific gravity',
validators=[
validators.Optional()
]
)

density = DecimalField(
label='Powder density (t/m³)',
default=1.4,
label='Specific Gravity',
default=POWDER_DEFAULT_DENSITY,
validators=[
validators.DataRequired(message='Material density cannot be empty')
]
Expand Down
1 change: 0 additions & 1 deletion slamd/materials/processing/models/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
class Composition:
fine_aggregates: float = None
coarse_aggregates: float = None
gravity: float = None
fineness_modulus: float = None
water_absorption: float = None

Expand Down
1 change: 0 additions & 1 deletion slamd/materials/processing/models/powder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Composition:
@dataclass
class Structure:
fine: float = None
gravity: float = None


@dataclass
Expand Down
17 changes: 17 additions & 0 deletions slamd/materials/processing/ratio_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ def _to_normalized_ratio_list(cls, ratio, delimiter):
ratio_list = [string_to_number(piece) for piece in pieces]
sum_ratio_list = sum(ratio_list)
return [ratio / sum_ratio_list for ratio in ratio_list]

@classmethod
def weight_to_density_ratios(cls, normalized_ratios, base_materials):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diese Funktion nimmt Volumen-Ratios, wandelt sie durch Multiplikation mit Dichte in Massen-Ratios um, und renormalisiert dann diese, richtig?

Wäre also ein Name wie "volume_to_weight_ratios" nicht passender? (Und ggf. "weight_ratio" als variablenname besser als "density ratio")

densities = [base_material['density'] for base_material in base_materials]
normalized_density_ratios = []

for normalized_ratio in normalized_ratios:
weighted_ratios = [float(density) * float(ratio) for density, ratio in zip(densities, normalized_ratio)]
sum_density_ratios = sum(weighted_ratios)

normalized_density_ratio = [round(weighted / sum_density_ratios, 2) for weighted in weighted_ratios]
normalized_density_ratios.append(normalized_density_ratio)

return normalized_density_ratios



10 changes: 2 additions & 8 deletions slamd/materials/processing/strategies/aggregates_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def create_model(cls, submitted_material):
composition = Composition(
fine_aggregates=float_if_not_empty(submitted_material.get('fine_aggregates', None)),
coarse_aggregates=float_if_not_empty(submitted_material.get('coarse_aggregates', None)),
gravity=float_if_not_empty(submitted_material.get('gravity', None)),
fineness_modulus=float_if_not_empty(submitted_material.get('fineness_modulus', None)),
water_absorption=float_if_not_empty(submitted_material.get('water_absorption', None))
)
Expand All @@ -56,7 +55,6 @@ def create_model(cls, submitted_material):
def gather_composition_information(cls, aggregates):
return [cls.include('Fine Aggregates (m%)', aggregates.composition.fine_aggregates),
cls.include('Coarse Aggregates (m%)', aggregates.composition.coarse_aggregates),
cls.include('Specific Gravity', aggregates.composition.gravity),
cls.include('Fineness modulus (m³/kg)', aggregates.composition.fineness_modulus),
cls.include('Water absorption (m%)', aggregates.composition.water_absorption)]

Expand All @@ -74,11 +72,10 @@ def _check_completeness_of_composition(cls, base_materials_as_dict):

fine_aggregates_complete = pcc.is_complete(base_materials_as_dict, 'composition', 'fine_aggregates')
coarse_aggregates_complete = pcc.is_complete(base_materials_as_dict, 'composition', 'coarse_aggregates')
gravity_complete = pcc.is_complete(base_materials_as_dict, 'composition', 'gravity')
fineness_modulus_complete = pcc.is_complete(base_materials_as_dict, 'composition', 'fineness_modulus')
water_absorption_complete = pcc.is_complete(base_materials_as_dict, 'composition', 'water_absorption')

return (fine_aggregates_complete and coarse_aggregates_complete and gravity_complete and
return (fine_aggregates_complete and coarse_aggregates_complete and
fineness_modulus_complete and water_absorption_complete)

@classmethod
Expand Down Expand Up @@ -115,16 +112,13 @@ def _compute_blended_composition(cls, normalized_ratios, base_aggregates_as_dict
'fine_aggregates')
blended_coarse_aggregates = bpc.compute_mean(normalized_ratios, base_aggregates_as_dict, 'composition',
'coarse_aggregates')
blended_gravity = bpc.compute_mean(normalized_ratios, base_aggregates_as_dict, 'composition', 'gravity')

blended_fineness_modulus = bpc.compute_mean(normalized_ratios, base_aggregates_as_dict, 'composition',
'fineness_modulus')
blended_water_absorption = bpc.compute_mean(normalized_ratios, base_aggregates_as_dict, 'composition',
'water_absorption')

composition = Composition(fine_aggregates=blended_fine_aggregates, coarse_aggregates=blended_coarse_aggregates,
gravity=blended_gravity, fineness_modulus=blended_fineness_modulus,
water_absorption=blended_water_absorption)
fineness_modulus=blended_fineness_modulus, water_absorption=blended_water_absorption)

return composition

Expand Down
Loading