-
Notifications
You must be signed in to change notification settings - Fork 1
/
speedLevelGenerators.mjs
95 lines (84 loc) · 2.46 KB
/
speedLevelGenerators.mjs
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
export async function generateDaySpeedLevels(lowPollution, highPollution) {
let levels = [];
let pollutionRange = (highPollution - lowPollution);
let low = {
range: pollutionRange * (35 / 100),
levels: 5,
lowLevel: 0,
maxLevel: function () {
return low.lowLevel + low.levels;
},
low: lowPollution,
high: function () {
return low.low + low.range;
},
speed: function () {
return low.range / low.levels;
},
};
let mid = {
range: pollutionRange * (50 / 100),
levels: 6,
lowLevel: low.maxLevel(),
maxLevel: function () {
return mid.lowLevel + mid.levels;
},
low: low.high(),
high: function () {
return mid.low + mid.range;
},
speed: function () {
return mid.range / mid.levels;
},
};
let high = {
range: pollutionRange * (15 / 100),
levels: 3,
lowLevel: mid.maxLevel(),
maxLevel: function () {
return high.lowLevel + high.levels;
},
low: mid.high(),
high: function () {
return high.low + high.range;
},
speed: function () {
return high.range / high.levels;
},
};
for (let i = 0; i <= low.levels; ++i) {
levels.push({pm25: (i * low.speed()) + low.low, level: i + low.lowLevel});
}
for (let i = 1; i <= mid.levels; ++i) {
levels.push({pm25: (i * mid.speed()) + mid.low, level: i + mid.lowLevel})
}
for (let i = 1; i <= high.levels; ++i) {
levels.push({pm25: (i * high.speed()) + high.low, level: i + high.lowLevel})
}
levels.reverse();
return levels;
}
export async function generateNightSpeedLevels(lowPollution, highPollution) {
let levels = [];
let pollutionRange = (highPollution - lowPollution);
let low = {
range: pollutionRange,
levels: 8, //maxSpeed - minSpeed
lowLevel: 0,
maxLevel: function () {
return low.lowLevel + low.levels;
},
low: lowPollution,
high: function () {
return low.low + low.range;
},
speed: function () {
return low.range / low.levels;
},
};
for (let i = 0; i <= low.levels; ++i) {
levels.push({pm25: (i * low.speed()) + low.low, level: i + low.lowLevel});
}
levels.reverse();
return levels;
}