-
Notifications
You must be signed in to change notification settings - Fork 0
/
aqi_buckets.js
76 lines (72 loc) · 1.83 KB
/
aqi_buckets.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
const path = require('path');
const fs = require('fs');
const buckets = [{
min: 0,
max: 50,
level: 'clean',
color_code: 'Green',
title: 'Good',
voice: 'The air is clean. Go outside and play!'
},
{
min: 51,
max: 100,
level: 'acceptable',
color_code: 'Yellow',
title: 'Moderate',
voice: 'The air is OK.'
},
{
min: 101,
max: 150,
level: 'not-perfect',
color_code: 'Orange',
title: 'Unhealthy for Sensitive Groups',
voice: 'This is not very good.'
},
{
min: 151,
max: 200,
level: 'not-good',
color_code: 'Red',
title: 'Unhealthy',
voice: 'The air is unhealthy.'
},
{
min: 201,
max: 300,
level: 'pretty-bad',
color_code: 'Purple',
title: 'Pretty Bad',
voice: 'The air is terrible. Do not go outside!'
},
{
min: 301,
max: 1000,
level: 'hazardous',
color_code: 'Maroon',
title: 'Hazardous',
voice: 'It is atrocious. Get out of there now!'
}
]
const random_background = (level) => {
const folder = path.join(__dirname, 'ui', 'images', level);
if (!fs.existsSync(folder)) {
return {};
}
const items = fs.readdirSync(folder).filter(v => {
return v.endsWith('.jpg');
});
if (!items.length) {
return {};
}
const item = items[Math.floor(Math.random() * items.length)];
return {
background_index: item.substring(0, item.indexOf('.')),
background_path: level + '/' + item
};
}
module.exports.get_bucket = (value) => {
const ret = Object.assign({}, buckets.find(b => value >= b.min && value <= b.max));
return Object.assign(ret, random_background(ret.level));
}