-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,725 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,7 @@ | ||
const shell = require('shelljs') | ||
const moment = require('moment') | ||
const currentWifiName = require('wifi-name') | ||
const speedTestNet = require('speedtest-net') | ||
const speedTest = require('./src/speed-test') | ||
const generateCharts = require('./src/charts') | ||
|
||
const { ShellString, mkdir } = shell | ||
|
||
module.exports = ({ wifiName, recordLocation }) => { | ||
currentWifiName().then(name => { | ||
if (name === wifiName) { | ||
speedTest() | ||
} | ||
}) | ||
|
||
const speedTest = () => { | ||
const test = speedTestNet({maxTime: 5000}) | ||
|
||
test.on('data', data => { | ||
const now = moment() | ||
const day = now.format('DD/MM/YYYY') | ||
const time = now.format('HH:mm') | ||
|
||
const record = { | ||
ping: data.server.ping, | ||
download: data.speeds.download, | ||
upload: data.speeds.upload, | ||
day, | ||
time, | ||
} | ||
|
||
writeRecord(record) | ||
}) | ||
|
||
test.on('error', error => { | ||
console.error(`Failed to get the results of the speed test\n${error}`) | ||
}) | ||
} | ||
|
||
const writeRecord = (record) => { | ||
const output = `${JSON.stringify(record)}\n` | ||
|
||
// If the recordLocation doesn't already exist, create it's directory | ||
mkdir('-p', `${recordLocation}/..`) | ||
|
||
ShellString(output).toEnd(recordLocation) | ||
} | ||
module.exports = { | ||
speedTest, | ||
generateCharts, | ||
} |
Oops, something went wrong.