Skip to content

Commit

Permalink
Fix chart showing the data for the wrong case (#1279)
Browse files Browse the repository at this point in the history
* Fix chart showing the data for the wrong case
  • Loading branch information
taustad authored Sep 20, 2024
1 parent efa1d92 commit 8118cad
Showing 1 changed file with 50 additions and 40 deletions.
90 changes: 50 additions & 40 deletions frontend/src/Hooks/useProjectChartData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useProjectChartData = () => {
const { project } = useProjectContext()

const [rowData, setRowData] = useState<TableCompareCase[]>()
const [compareCasesTotals, setCompareCasesTotals] = useState<any>()
const [compareCasesTotals, setCompareCasesTotals] = useState<Components.Schemas.CompareCasesDto[]>()
const [npvChartData, setNpvChartData] = useState<object>()
const [breakEvenChartData, setBreakEvenChartData] = useState<object>()
const [productionProfilesChartData, setProductionProfilesChartData] = useState<object>()
Expand All @@ -35,44 +35,54 @@ export const useProjectChartData = () => {
const [co2IntensityChartData, setCo2IntensityChartData] = useState<object>()

const generateAllCharts = () => {
const npvObject: object[] = []
const breakEvenObject: object[] = []
const productionProfilesObject: object[] = []
const investmentProfilesObject: object[] = []
const totalCo2EmissionsObject: object[] = []
const co2IntensityObject: object[] = []
if (compareCasesTotals !== undefined && project) {
for (let i = 0; i < project.cases.length; i += 1) {
npvObject.push({
cases: project.cases[i].name,
npv: project.cases[i].npv,
})
breakEvenObject.push({
cases: project.cases[i].name,
breakEven: project.cases[i].breakEven,
})
productionProfilesObject.push({
cases: project.cases[i].name,
oilProduction: compareCasesTotals[i]?.totalOilProduction,
gasProduction: compareCasesTotals[i]?.totalGasProduction,
totalExportedVolumes: compareCasesTotals[i]?.totalExportedVolumes,
})
investmentProfilesObject.push({
cases: project.cases[i].name,
offshorePlusOnshoreFacilityCosts: compareCasesTotals[i]?.offshorePlusOnshoreFacilityCosts,
developmentCosts: compareCasesTotals[i]?.developmentWellCosts,
explorationWellCosts: compareCasesTotals[i]?.explorationWellCosts,
})
totalCo2EmissionsObject.push({
cases: project.cases[i].name,
totalCO2Emissions: compareCasesTotals[i]?.totalCo2Emissions,
})
co2IntensityObject.push({
cases: project.cases[i].name,
cO2Intensity: compareCasesTotals[i]?.co2Intensity,
})
if (!compareCasesTotals || !project) { return }

const npvObject = project.cases.map(caseItem => ({
cases: caseItem.name,
npv: caseItem.npv,
}))

const breakEvenObject = project.cases.map(caseItem => ({
cases: caseItem.name,
breakEven: caseItem.breakEven,
}))

const productionProfilesObject = project.cases.map(caseItem => {
const compareCase = compareCasesTotals.find(c => c.caseId === caseItem.id)
return {
cases: caseItem.name,
oilProduction: compareCase?.totalOilProduction,
gasProduction: compareCase?.totalGasProduction,
totalExportedVolumes: compareCase?.totalExportedVolumes,
}
}
})

const investmentProfilesObject = project.cases.map(caseItem => {
const compareCase = compareCasesTotals.find(c => c.caseId === caseItem.id)
return {
cases: caseItem.name,
offshorePlusOnshoreFacilityCosts: compareCase?.offshorePlusOnshoreFacilityCosts,
developmentCosts: compareCase?.developmentWellCosts,
explorationWellCosts: compareCase?.explorationWellCosts,
}
})

const totalCo2EmissionsObject = project.cases.map(caseItem => {
const compareCase = compareCasesTotals.find(c => c.caseId === caseItem.id)
return {
cases: caseItem.name,
totalCO2Emissions: compareCase?.totalCo2Emissions,
}
})

const co2IntensityObject = project.cases.map(caseItem => {
const compareCase = compareCasesTotals.find(c => c.caseId === caseItem.id)
return {
cases: caseItem.name,
cO2Intensity: compareCase?.co2Intensity,
}
})

setNpvChartData(npvObject)
setBreakEvenChartData(breakEvenObject)
setProductionProfilesChartData(productionProfilesObject)
Expand All @@ -93,8 +103,8 @@ export const useProjectChartData = () => {
id: c.id!,
cases: c.name ?? "",
description: c.description ?? "",
npv: Math.round(c.npv ?? 0 * 1) / 1 ?? 0,
breakEven: Math.round(c.breakEven ?? 0 * 1) / 1 ?? 0,
npv: Math.round(c.npv ?? 0 * 1) / 1,
breakEven: Math.round(c.breakEven ?? 0 * 1) / 1,
oilProduction: Math.round(matchingCase.totalOilProduction * 10) / 10,
gasProduction: Math.round(matchingCase.totalGasProduction * 10) / 10,
totalExportedVolumes: Math.round(matchingCase.totalExportedVolumes * 10) / 10,
Expand Down

0 comments on commit 8118cad

Please sign in to comment.