def create_groups(group_db: sm.Group, catalog: cat_.Catalog):

    item_group = cat_.ItemGroup(group_db.id, group_db.name, group_db.code, group_db.parent_id)
    catalog.add_item_group(item_group)

    x = session.query(func.count(sm.Composition.id)).scalar()
    for composition in group_db.compositions:
        print(f'{count[0]} / {x}')
        count[0] += 1
        create_full_composition(composition, catalog)
def create_composition(composition_db: sm.Composition, catalog: cat_.Catalog) -> cat_.Item:
    item = cat_.Item(
        composition_db.id,
        composition_db.name,
        composition_db.code,
        composition_db.group_id,
        description=composition_db.name)
    primary_quantity = item.get_variable('PrimaryQuantity')
    primary_quantity.formula = '=' + units_convert[composition_db.units]['formula']
    primary_quantity.units = units_convert[composition_db.units]['units']

    catalog.add_item(item)

    for attribution in composition_db.grouped_attributions:
        create_attribution(attribution.Attribution, item, catalog, attribution.sum_coefficient)

    return item
Beispiel #3
0
def create_full_composition(composition_db: sm.Composition,
                            catalog: cat_.Catalog) -> cat_.Item:
    item = cat_.Item(composition_db.id,
                     composition_db.name,
                     composition_db.code,
                     composition_db.group_id,
                     description=composition_db.name)
    primary_quantity = item.get_variable('PrimaryQuantity')
    primary_quantity.formula = '=' + units_convert[
        composition_db.units]['formula']
    primary_quantity.units = units_convert[composition_db.units]['units']

    catalog.add_item(item)

    for step in composition_db.steps:
        step: sm.Step = step

        if len(step.attributions):
            s = cat_.Step(step.id, step.name, step.composition_id)
            c = s.get_variable('Coefficient')
            c.formula = f"={step.coefficient}"
            item.append(s)

            for attribution in step.attributions:
                attribution: sm.Attribution = attribution

                step_resource = cat_.StepResource(attribution.id,
                                                  attribution.step_id,
                                                  attribution.resource_id)
                s.append(step_resource)

                coef = cat_.Variable('Coefficient', formula='=0')
                step_resource.add_variable(coef)

                primary_quantity = cat_.Variable('PrimaryQuantity')
                primary_quantity.units = units_convert[
                    attribution.resource.units]['units']
                primary_quantity.formula = f'{item.get_variable("PrimaryQuantity").formula}*{coef.name}'
                step_resource.add_variable(primary_quantity)

                coef = step_resource.get_variable('Coefficient')
                coef.formula = f"={step.coefficient * attribution.coefficient * units_convert[attribution.resource.units]['Coefficient']}"

    return item
Beispiel #4
0
def create_resources(resource_db: sm.Resource,
                     catalog: cat_.Catalog) -> cat_.Resource:
    resource = cat_.Resource(resource_db.id,
                             resource_db.name,
                             resource_db.code,
                             description=resource_db.name)
    catalog.add_resource(resource)

    cost = resource.get_variable('UnitCost')
    cost.formula = f"={resource_db.cost / units_convert[resource_db.units]['Coefficient']}"

    primary_quantity = resource.get_variable('PrimaryQuantity')
    primary_quantity.units = units_convert[resource_db.units]['units']

    if resource_db.process is not None:
        flow = resource.get_variable("Flow")
        flow.formula = f"{resource_db.process.flow}"

        category = resource.get_variable("Category")
        category.formula = f"{resource_db.process.category}"

        uncertainty = resource.get_variable("Uncertainty")
        uncertainty.formula = f"{resource_db.process.uncertainty}"

        avoided_waste = resource.get_variable("AvoidedWaste")
        avoided_waste.formula = f"{resource_db.process.avoided_waste}"

        provider = resource.get_variable("Provider")
        provider.formula = f"{resource_db.process.provider}"

        data_quality_entry = resource.get_variable("DataQualityEntry")
        data_quality_entry.formula = f"{resource_db.process.data_quality_entry}"

        description = resource.get_variable("Description")
        description.formula = f"{resource_db.process.description}"

    return resource
def create_resources(resource_db: sm.Resource, catalog: cat_.Catalog) -> cat_.Resource:
    resource = cat_.Resource(resource_db.id, resource_db.name, resource_db.code, description=resource_db.name)
    catalog.add_resource(resource)

    cost = resource.get_variable('UnitCost')
    cost.formula = f"={resource_db.cost / units_convert[resource_db.units]['Coefficient']}"

    primary_quantity = resource.get_variable('PrimaryQuantity')
    primary_quantity.units = units_convert[resource_db.units]['units']

    if resource_db.impact is not None:
        ozone_formation_terrestrial_ecosystems = resource.get_variable("OzoneFormationTerrestrialEcosystems")
        ozone_formation_terrestrial_ecosystems.formula = f"={resource_db.impact.ozone_formation_terrestrial_ecosystems:.13f} * Weight"

        water_consumption = resource.get_variable("WaterConsumption")
        water_consumption.formula = f"={resource_db.impact.water_consumption:.13f} * Weight"

        marine_eutrophication = resource.get_variable("MarineEutrophication")
        marine_eutrophication.formula = f"={resource_db.impact.marine_eutrophication:.13f} * Weight"

        marine_ecotoxicity = resource.get_variable("MarineEcotoxicity")
        marine_ecotoxicity.formula = f"={resource_db.impact.marine_ecotoxicity:.13f} * Weight"

        land_use = resource.get_variable("LandUse")
        land_use.formula = f"={resource_db.impact.land_use:.13f} * Weight"

        fine_particulate_matter_formation = resource.get_variable("FineParticulateMatterFormation")
        fine_particulate_matter_formation.formula = f"={resource_db.impact.fine_particulate_matter_formation:.13f} * Weight"

        mineral_resource_scarcity = resource.get_variable("MineralResourceScarcity")
        mineral_resource_scarcity.formula = f"={resource_db.impact.mineral_resource_scarcity:.13f} * Weight"

        ionizing_radiation = resource.get_variable("IonizingRadiation")
        ionizing_radiation.formula = f"={resource_db.impact.ionizing_radiation:.13f} * Weight"

        human_non_carcinogenic_toxicity = resource.get_variable("HumanNonCarcinogenicToxicity")
        human_non_carcinogenic_toxicity.formula = f"={resource_db.impact.human_non_carcinogenic_toxicity:.13f} * Weight"

        freshwater_eutrophication = resource.get_variable("FreshwaterEutrophication")
        freshwater_eutrophication.formula = f"={resource_db.impact.freshwater_eutrophication:.13f} * Weight"

        terrestrial_acidification = resource.get_variable("TerrestrialAcidification")
        terrestrial_acidification.formula = f"={resource_db.impact.terrestrial_acidification:.13f} * Weight"

        fossil_resource_scarcity = resource.get_variable("FossilResourceScarcity")
        fossil_resource_scarcity.formula = f"={resource_db.impact.fossil_resource_scarcity:.13f} * Weight"

        global_warming = resource.get_variable("GlobalWarming")
        global_warming.formula = f"={resource_db.impact.global_warming:.13f} * Weight"

        stratospheric_ozone_depletion = resource.get_variable("StratosphericOzoneDepletion")
        stratospheric_ozone_depletion.formula = f"={resource_db.impact.stratospheric_ozone_depletion:.13f} * Weight"

        terresetrial_ecotoxicity = resource.get_variable("TerresetrialEcotoxicity")
        terresetrial_ecotoxicity.formula = f"={resource_db.impact.terresetrial_ecotoxicity:.13f} * Weight"

        human_carcinogenic_toxicity = resource.get_variable("HumanCarcinogenicToxicity")
        human_carcinogenic_toxicity.formula = f"={resource_db.impact.human_carcinogenic_toxicity:.13f} * Weight"

        freshwater_ecotoxicity = resource.get_variable("FreshwaterEcotoxicity")
        freshwater_ecotoxicity.formula = f"={resource_db.impact.freshwater_ecotoxicity:.13f} * Weight"

        ozone_formation_human_health = resource.get_variable("OzoneFormationHumanHealth")
        ozone_formation_human_health.formula = f"={resource_db.impact.ozone_formation_human_health:.13f} * Weight"

    return resource