-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatters.js
165 lines (137 loc) · 3.77 KB
/
formatters.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
'use strict';
let chalk = require('chalk')
//const MAX_SIGNAL = -35
//const MIN_SIGNAL = -90
//const MAX_SNR = 40
//const MIN_SNR = 10
// level should be a negative number
//function signalLevelMarkers(level) {
//level = Math.min(MAX_SIGNAL, level)
//level = Math.max(MIN_SIGNAL, level)
//let range = Math.abs(MAX_SIGNAL - MIN_SIGNAL)
//let shiftedLevel = (-level + MAX_SIGNAL)
//let pp = (range - shiftedLevel) / range
//let p = Math.round(pp * 10)
//var q = 10 - p;
//return "|".repeat(p) + "-".repeat(q)
//}
//function snrMarkers(snr) {
//snr = Math.min(MAX_SNR, snr)
//snr = Math.max(MIN_SNR, snr)
//let range = Math.abs(MAX_SNR - MIN_SNR)
//let shiftedLevel = (snr - MIN_SNR)
//let pp = shiftedLevel / range
//let p = Math.round(pp * 10)
//let q = 10 - p;
//return "|".repeat(p) + "-".repeat(q)
//}
//function signalLevelDescription(level) {
//if (level >= -50)
//return 'Excelent'
//else if (level >= -60)
//return 'Good'
//else if (level >= -70)
//return 'Fair'
//return 'Bad'
//}
// snr Status, description and Markers (levels) are calculated according to the following resources
// http://www.wireless-nets.com/resources/tutorials/define_SNR_values.html
//http://www.enterprisenetworkingplanet.com/netsp/article.php/3747656/WiFi-Define-Minimum-SNR-Values-for-Signal-Coverage.htm
//function snrDescription(snr) {
//if (snr >= 40)
//return 'Excelent'
//else if (snr >= 25)
//return 'Good'
//else if (snr >= 15)
//return 'Low'
//else if (snr >= 10)
//return 'Very Low'
//return 'No Signal'
//}
//function snrColor(snr) {
//if (snr >= 40)
//return chalk.blue
//else if (snr >= 25)
//return chalk.green
//else if (snr >= 15)
//return chalk.yellow
//else if (snr >= 10)
//return chalk.red
//return chalk.red
//}
//exports.snrStatus = function snrStatus(snr) {
//if (snr >= 40)
//return 'always associated, lightening fast.'
//else if (snr >= 25)
//return 'always associated, very fast'
//else if (snr >= 15)
//return 'always associated, usually fast'
//else if (snr >= 10)
//return 'mostly associated, mostly slow'
//return 'not associated, no go'
//}
function signalLevelColor(level) {
if (level >= -50)
return chalk.blue
else if (level >= -60)
return chalk.green
else if (level >= -70)
return chalk.yellow
return chalk.red
}
function signalLevelStatus(level) {
if (level >= -50)
return 'Perfect!'
else if (level >= -60)
return 'Every application should work correctly'
else if (level >= -70)
return 'You might experience some troubles with Voip and streaming'
else if (level >= -80)
return 'Expect difficulties to surf the web'
return 'Expect no internet access'
}
exports.getPercentage = function getPercentage(value, min, max) {
if (min == null) {
min = 0
}
if (max == null) {
max = 100
}
value = Math.min(max, value)
value = Math.max(min, value)
let range = Math.abs(max - min)
let shiftedValue = (value - min)
return shiftedValue / range
}
exports.getMarkers = function getMarkers(percentage) {
let p = Math.round(percentage * 10)
var q = 10 - p;
return "|".repeat(p) + "-".repeat(q)
}
exports.getColor = function getColor(percentage) {
let value = percentage * 100
if (value >= 75)
return chalk.blue
else if (value >= 50)
return chalk.green
else if (value >= 25)
return chalk.yellow
return chalk.red
}
//module.exports = {
//MAX_SIGNAL,
//MIN_SIGNAL,
//signalLevelMarkers,
//MAX_SNR,
//MIN_SNR,
//snrMarkers,
//signalLevelDescription,
//signalLevelColor,
//signalLevelStatus,
//snrColor,
//snrDescription,
//snrStatus,
//getMarkers,
//getColor,
//getPercentage
//}