Skip to content

Commit

Permalink
Updated calculations to use settings
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianlinkflink committed Nov 21, 2024
1 parent 757455a commit 4f4789c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Link IO Speckle LCA App
# Link IO SpeckLCA App

This template should help get you started developing with Vue 3 in Vite.

Expand Down
4 changes: 2 additions & 2 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export const standardKeySettings: KeySettings = {
},
speckleConfig: {
serverUrl: "https://app.speckle.systems",
id: null,
secret: null
id: "25477842e5",
secret: "c5a683ccc4"
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ const beforeEachGuard = async (to: RouteLocationNormalized) => {
.then(() => {
// If the route requires authentication and the user is not authenticated, return to the login page.
if (to.meta.requiresAuth && !speckleStore.isAuthenticated) {
if (settingsStore.keySettings.speckleConfig.id === '' || settingsStore.keySettings.speckleConfig.secret === '') {
if (settingsStore.keySettings.speckleConfig.id == undefined || settingsStore.keySettings.speckleConfig.secret == undefined) {
console.log("Speckle credentials are not set, redirecting to project.")
navigationStore.toggleSettingsModal()
return { name: 'Projects' }
} else {
//logMessageToSentry("User is not authenticated, but the route required it.", 'warning')
console.log("User is not authenticated, but the route required it and keys exists.")
speckleStore.login()
}
//logMessageToSentry("User is not authenticated, but the route required it.", 'warning')
console.log("User is not authenticated, but the route required it and keys exists.")
speckleStore.login()
}
});
}
Expand Down
7 changes: 0 additions & 7 deletions src/stores/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ export const useProjectStore = defineStore({
hiddenObjects: [] as GeometryObject[], // GeometryObjects that are currently hidden
}
},
// Save the store to local storage so we dont have to create new settings every time
persist: {
storage: localStorage,
afterHydrate: (ctx) => {
console.log(`just hydrated '${ctx.store.$id}'`)
}
},
actions: {
/**
* Creates a new project.
Expand Down
37 changes: 21 additions & 16 deletions src/utils/emissionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useProjectStore } from '@/stores/main'
import { useSettingsStore } from '@/stores/settings'
import { isAssembly } from '@/utils/EPDUtils'

import type { GeometryObject } from '@/models/geometryObject'
Expand All @@ -10,7 +11,7 @@ import type { Results } from '@/models/project'
*/
export class EmissionCalculator {
private geo: GeometryObject[] = []
private impactCategory: string = 'gwp'
private settingsStore = useSettingsStore()

constructor(geo: GeometryObject[] = []) {
const projectStore = useProjectStore()
Expand Down Expand Up @@ -38,7 +39,7 @@ export class EmissionCalculator {
if (!geo.material) continue

const emissions: Emission = {
[this.impactCategory]: {} as LifeCycleStageEmission }
[this.settingsStore.calculationSettings.standardImpactCategory]: {} as LifeCycleStageEmission }
const material = geo.material

if (isAssembly(material)) {
Expand All @@ -63,7 +64,7 @@ export class EmissionCalculator {
if (!material.materials) return false

for (const mat of material.materials) {
if (mat.emission[this.impactCategory]) {
if (mat.emission[this.settingsStore.calculationSettings.standardImpactCategory]) {
this.calculateMaterialEmissions(mat, emissions, geo)
}
}
Expand All @@ -75,7 +76,7 @@ export class EmissionCalculator {
emissions: Emission,
geo: GeometryObject
): boolean {
if (material.emission[this.impactCategory]) {
if (material.emission[this.settingsStore.calculationSettings.standardImpactCategory]) {
this.calculateMaterialEmissions(material, emissions, geo)
return true
}
Expand All @@ -88,7 +89,7 @@ export class EmissionCalculator {
emissions: Emission,
geo: GeometryObject
) {
const impactCategory = this.impactCategory
const impactCategory = this.settingsStore.calculationSettings.standardImpactCategory
const matEmission = mat.emission[impactCategory]

if (!emissions[impactCategory]) {
Expand All @@ -97,20 +98,24 @@ export class EmissionCalculator {


for (const phase in matEmission) {
let value = matEmission[phase]
if (value === undefined) value = matEmission[phase]
if (value !== null && !isNaN(Number(value))) {
const emissionValue = parseFloat(value as string) * geo.quantity[mat.unit]

if (!emissions[impactCategory][phase]) {
emissions[impactCategory][phase] = 0
// Check if the phase is included in the calculation settings, if not skip it
if (this.settingsStore.calculationSettings.includedStages.relevantStages.some(
(stage) => phase === stage.stage)
){
let value = matEmission[phase]
if (value === undefined) value = matEmission[phase]
if (value !== null && !isNaN(Number(value))) {
const emissionValue = parseFloat(value as string) * geo.quantity[mat.unit]

if (!emissions[impactCategory][phase]) {
emissions[impactCategory][phase] = 0
}

const currentAmount = emissions[impactCategory][phase] || 0
emissions[impactCategory][phase] = currentAmount + emissionValue
}

const currentAmount = emissions[impactCategory][phase] || 0
emissions[impactCategory][phase] = currentAmount + emissionValue
}
}

}

/**
Expand Down

0 comments on commit 4f4789c

Please sign in to comment.