-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculations.js
122 lines (98 loc) · 3.78 KB
/
calculations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// calculations.js
// calculations.js
const pi = Math.PI;
function calculateArea(diameter) {
return pi * Math.pow(diameter / 2, 2);
}
function calculateRatio(mcArea, totalPistonArea) {
return totalPistonArea / mcArea;
}
function calculateOverallLeverage(mcToCaliperRatio, interaxisRatio, pumpType) {
return mcToCaliperRatio * interaxisRatio;
}
function calculatePercentageDifference(newValue, originalValue) {
return ((newValue - originalValue) / originalValue) * 100;
}
function calculateMcToCaliperRatio(mcBore, pistonDiameter, pistonsPerCaliper, numberOfCalipers) {
const mcArea = calculateArea(mcBore);
const pistonArea = calculateArea(pistonDiameter);
const totalPistonArea = pistonsPerCaliper * numberOfCalipers * pistonArea;
return calculateRatio(mcArea, totalPistonArea);
}
function calculateInteraxisRatio(pivotToHand, pivotToPiston) {
return pivotToHand / pivotToPiston;
}
function calculateZScore(mcToCaliperRatio, overallLeverageRatio, pistonArea, minPower, maxPower, powerWeight) {
// Coefficienti delle rette per Ratio Min e Ratio Max
const m1 = (22 - 10) / (14000 - 2000); // Coefficiente angolare per Ratio Min
const b1 = 10 - m1 * 2000; // Intercetta per Ratio Min
const m2 = (28 - 12) / (14000 - 2000); // Coefficiente angolare per Ratio Max
const b2 = 12 - m2 * 2000; // Intercetta per Ratio Max
// Calcolo del minModularity e maxModularity basati sull'area dei pistoni
const minModularity = m1 * pistonArea + b1;
const maxModularity = m2 * pistonArea + b2;
// Calcolo della modularità come l'inverso del MC-to-Caliper Ratio
const modularity = 1 / mcToCaliperRatio;
// Normalizzazione della modularità rispetto agli intervalli calcolati
let normalizedModularity;
if (mcToCaliperRatio < minModularity) {
normalizedModularity = -Math.pow((minModularity - mcToCaliperRatio) / minModularity, 2);
} else if (mcToCaliperRatio > maxModularity) {
normalizedModularity = -Math.pow((mcToCaliperRatio - maxModularity) / maxModularity, 2);
} else {
normalizedModularity = 1; // All'interno dell'intervallo ottimale
}
// Normalizzazione della potenza rispetto agli intervalli minPower e maxPower
const normalizedPower = Math.pow((overallLeverageRatio - minPower) / (maxPower - minPower), 2);
// Calcolo finale dello Z-Score, premiando le configurazioni all'interno del range ottimale
const zScore = (normalizedModularity * (1 - Math.pow(powerWeight, 2)) + normalizedPower * Math.pow(powerWeight, 2));
return zScore;
}
function validateInputs(...inputs) {
return inputs.every(input => input > 0);
}
// Export the functions if using modules
// Uncomment the following line if you're using ES6 modules
/*
export {
calculateArea,
calculateRatio,
calculateOverallLeverage,
calculatePercentageDifference,
calculateMcToCaliperRatio,
calculateInteraxisRatio,
calculateZScore,
validateInputs
};
*/
// Export the functions if using modules
// Uncomment the following line if you're using ES6 modules
/*
export {
calculateArea,
calculateRatio,
calculateOverallLeverage,
calculatePercentageDifference,
calculateMcToCaliperRatio,
calculateInteraxisRatio,
calculateZScore,
validateInputs
};
*/
//function validateInputs(...inputs) {
// return inputs.every(input => input > 0);
//}
// Export the functions if using modules
// Uncomment the following line if you're using ES6 modules
/*
export {
calculateArea,
calculateRatio,
calculateOverallLeverage,
calculatePercentageDifference,
calculateMcToCaliperRatio,
calculateInteraxisRatio,
calculateZScore,
validateInputs
};
*/