From baa1f9cd8e5ebc3259082ba07f60576aa043fee0 Mon Sep 17 00:00:00 2001 From: Daria Kolokolnikova <72koda1bif@hft-stuttgart.de> Date: Thu, 13 Jan 2022 03:19:53 +0100 Subject: [PATCH] Implemented Normalization functions for ranges of PV-values --- public/js/pvPotentialNormalization.js | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/public/js/pvPotentialNormalization.js b/public/js/pvPotentialNormalization.js index b9244ba..8c1702d 100644 --- a/public/js/pvPotentialNormalization.js +++ b/public/js/pvPotentialNormalization.js @@ -1,4 +1,31 @@ /* TODO: issue #128 write a function which normalizes each value from the pvPotential array and -*/ \ No newline at end of file +*/ +var minAndMaxPvPotentials = []; + + +function setMinAndMax(pvPotentialValue) { + let pvPotentials = []; + pvPotentialSurfaces.forEach(t => { + for (const [key, value] of Object.entries(t.attributes.pvPotential)) { + if (key === pvPotentialValue) { + pvPotentials.push(value); + } + } + }); + pvPotentials = pvPotentials.sort(function(a, b) { return a - b; }); + minAndMaxPvPotentials.push(pvPotentials[0]); + minAndMaxPvPotentials.push(pvPotentials[pvPotentials.length - 1]); +} + +function getNormalizedValue(selectedPvPotentialValue) { + var normalizedValue; + if(minAndMaxPvPotentials[1]-minAndMaxPvPotentials[0]!==0){ + normalizedValue = (selectedPvPotentialValue-minAndMaxPvPotentials[0])/(minAndMaxPvPotentials[1]-minAndMaxPvPotentials[0]); + } + else{ + normalizedValue=1; + } + return normalizedValue; +} -- GitLab