Skip to content

Commit

Permalink
Generate charts from speed data
Browse files Browse the repository at this point in the history
  • Loading branch information
sievins committed Jul 4, 2019
1 parent 53fa5b9 commit 8f9a7e6
Show file tree
Hide file tree
Showing 22 changed files with 1,725 additions and 353 deletions.
54 changes: 39 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

Think your Wi-Fi connection is slow and want a record to show your internet provider? Look no further :smiley:.

Each time the application is run, the wifi speed is recorded and appended to a results file.
Each time you record the WiFi's speed the results are appended to a `records.txt` file in JSON format. A set of charts can then be generated from this data.

```
{"ping":38,"download":21.2,"upload":18,"day":"24/06/2019","time":"16:50"}
{"ping":39,"download":22,"upload":17.6,"day":"24/06/2019","time":"17:50"}
{"ping":54,"download":22.8,"upload":18,"day":"24/06/2019","time":"18:50"}
[
{"ping":38,"download":21.2,"upload":18,"day":"24/06/2019","time":"16:50"},
{"ping":39,"download":22,"upload":17.6,"day":"24/06/2019","time":"17:50"},
{"ping":54,"download":22.8,"upload":18,"day":"24/06/2019","time":"18:50"},
...
]
```
![Download chart](./download.png)

## Install
```
Expand All @@ -19,31 +23,51 @@ npm install --global record-wifi-speed

#### Arguments
- wifiName: The name of the Wi-Fi network you wish to record the speed of. For example `PLUSNET-1234`.
- recordLocation: The location of the file which will contain a record of the results. For example `C:\Users\Bob\wifi-speed-results.txt`.
- resultsDirectory: The directory which will contain the results of the speed tests and the generated charts. The directory will have the following structure:

```bash
resultsDirectory/
├── records.txt
└── charts
├── download.html
├── download.png
├── download.svg
├── ping.html
├── ping.png
├── ping.svg
├── upload.html
├── upload.png
└── upload.svg
```

### Node
```js
const recordWifiSpeed = require('record-wifi-speed')
const { speedTest, generateCharts } = require('record-wifi-speed')

recordWifiSpeed({
wifiName: '...',
recordLocation: '...',
})
const wifiName = '...'
const resultsDirectory = '...'

speedTest({ wifiName, resultsDirectory })
generateCharts({ resultsDirectory })
```

### CLI
> You must have installed record-wifi-speed globally to run it on the CLI.
```
record-wifi-speed <wifiName> <recordLocation>
rws-run <wifiName> <resultsDirectory>
rws-charts <resultsDirectory>
```

### Executable
> You must have installed record-wifi-speed globally to run the executable.
The command `package-record-wifi-speed` creates an executable called `record-wifi-speed.exe` in your current directory.
The command `rws/package` creates an executable called `record-wifi-speed.exe` in your current directory.
```
package-record-wifi-speed
./record-wifi-speed.exe <wifiName> <recordLocation>
rws-package
./record-wifi-speed.exe <wifiName> <resultsDirectory>
```

You might want to create a scheduled task which runs this executable periodically (for example with Windows Task Scheduler). It would then record your Wi-Fi speed in the background every period.
You might want to create a scheduled task which runs this executable periodically (for example with Windows Task Scheduler). It would then record your Wi-Fi speed in the background every period.

## Updating from v1 to v2
See [release notes](https://github.com/sievins/record-wifi-speed/releases/tag/v2.0.0)
Binary file added download.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 5 additions & 45 deletions index.js
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,
}
Loading

0 comments on commit 8f9a7e6

Please sign in to comment.