pvPotentialNormalization.js 1.19 KB
Newer Older
1
2
3
4
/** Documentation:
 * Function is used to calculate normalized pvPotential data
 * it normalizes every value from the array
 */
5

6
var minAndMaxPvPotentials = [];
7

8
//getting the min and max for each attributes 
9
10
11
12
13
14
15
16
17
18
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; });
19
    minAndMaxPvPotentials = [];
20
21
    minAndMaxPvPotentials.push(pvPotentials[0]);
    minAndMaxPvPotentials.push(pvPotentials[pvPotentials.length - 1]);
22
    console.log("setMinAndMax calculated");
23
24
}

25
//calculating the normalized value for the selected pvPotential value
26
27
function getNormalizedValue(selectedPvPotentialValue) {
    var normalizedValue;
28
29
30
31
    if (minAndMaxPvPotentials[1] - minAndMaxPvPotentials[0] !== 0) {
        normalizedValue = (selectedPvPotentialValue - minAndMaxPvPotentials[0]) / (minAndMaxPvPotentials[1] - minAndMaxPvPotentials[0]);
    } else {
        normalizedValue = 1;
32
33
34
    }
    return normalizedValue;
}