pvPotentialNormalization.js 1.03 KB
Newer Older
1
2
3
/* TODO: issue #128
write a function which normalizes each value from the pvPotential array
and 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
*/
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; });
Kolokolnikova's avatar
Kolokolnikova committed
18
    minAndMaxPvPotentials=[];
19
20
    minAndMaxPvPotentials.push(pvPotentials[0]);
    minAndMaxPvPotentials.push(pvPotentials[pvPotentials.length - 1]);
21
    console.log("setMinAndMax calculated");
22
23
24
25
26
27
28
29
30
31
32
33
}

function getNormalizedValue(selectedPvPotentialValue) {
    var normalizedValue;
    if(minAndMaxPvPotentials[1]-minAndMaxPvPotentials[0]!==0){
    normalizedValue = (selectedPvPotentialValue-minAndMaxPvPotentials[0])/(minAndMaxPvPotentials[1]-minAndMaxPvPotentials[0]);
    }
    else{
    normalizedValue=1;   
    }
    return normalizedValue;
}