chore(plugins/community): move to community
This commit is contained in:
133
source/plugins/community/nightscout/README.md
Normal file
133
source/plugins/community/nightscout/README.md
Normal file
@@ -0,0 +1,133 @@
|
||||
<!--header-->
|
||||
<table>
|
||||
<tr><th colspan="2"><h3>💉 Nightscout</h3></th></tr>
|
||||
<tr><td colspan="2" align="center"><p>This plugin lets you display blood sugar values from a <a href="http://nightscout.info">Nightscout</a> site.</p>
|
||||
</td></tr>
|
||||
<tr><th>Authors</th><td><a href="https://github.com/legoandmars">@legoandmars</a></td></tr>
|
||||
<tr>
|
||||
<th rowspan="3">Supported features<br><sub><a href="metadata.yml">→ Full specification</a></sub></th>
|
||||
<td><a href="/source/templates/classic"><code>📗 Classic template</code></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>👤 Users</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i>No tokens are required for this plugin</i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" align="center">
|
||||
<img src="https://github.com/legoandmars/legoandmars/blob/master/metrics.plugin.nightscout.svg" alt=""></img>
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--/header-->
|
||||
|
||||
## ➡️ Available options
|
||||
|
||||
<!--options-->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center" nowrap="nowrap">Type</i></td><td align="center" nowrap="nowrap">Description</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_nightscout</code></td>
|
||||
<td rowspan="2"><p>Enable nightscout plugin</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>boolean</code>
|
||||
<br>
|
||||
<b>default:</b> no<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_nightscout_url</code></td>
|
||||
<td rowspan="2"><p>Nightscout URL</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>string</code>
|
||||
<br>
|
||||
<b>default:</b> https://example.herokuapp.com<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_nightscout_datapoints</code></td>
|
||||
<td rowspan="2"><p>Number of datapoints shown the graph</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>number</code>
|
||||
<i>(0 ≤
|
||||
𝑥)</i>
|
||||
<br>
|
||||
<b>zero behaviour:</b> disable</br>
|
||||
<b>default:</b> 12<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_nightscout_lowalert</code></td>
|
||||
<td rowspan="2"><p>Threshold for low blood sugar</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>number</code>
|
||||
<i>(0 ≤
|
||||
𝑥)</i>
|
||||
<br>
|
||||
<b>default:</b> 80<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_nightscout_highalert</code></td>
|
||||
<td rowspan="2"><p>Threshold for high blood sugar</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>number</code>
|
||||
<i>(0 ≤
|
||||
𝑥)</i>
|
||||
<br>
|
||||
<b>default:</b> 180<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_nightscout_urgentlowalert</code></td>
|
||||
<td rowspan="2"><p>Threshold for urgently low blood sugar</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>number</code>
|
||||
<i>(0 ≤
|
||||
𝑥)</i>
|
||||
<br>
|
||||
<b>default:</b> 50<br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><code>plugin_nightscout_urgenthighalert</code></td>
|
||||
<td rowspan="2"><p>Threshold for urgently high blood sugar</p>
|
||||
<img width="900" height="1" alt=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td nowrap="nowrap"><b>type:</b> <code>number</code>
|
||||
<i>(0 ≤
|
||||
𝑥)</i>
|
||||
<br>
|
||||
<b>default:</b> 250<br></td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--/options-->
|
||||
|
||||
## 🌐 Setup a Nightscout instance
|
||||
|
||||
The [nightscout website](http://www.nightscout.info/) details how to self-host a nightscout site.
|
||||
Check out the instructions there.
|
||||
|
||||
## ℹ️ Examples workflows
|
||||
|
||||
<!--examples-->
|
||||
```yaml
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: ${{ secrets.METRICS_TOKEN }}
|
||||
plugin_nightscout: yes
|
||||
plugin_nightscout_url: ${{ secrets.NIGHTSCOUT_URL }}
|
||||
|
||||
```
|
||||
<!--/examples-->
|
||||
7
source/plugins/community/nightscout/examples.yml
Normal file
7
source/plugins/community/nightscout/examples.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: ${{ secrets.METRICS_TOKEN }}
|
||||
plugin_nightscout: yes
|
||||
plugin_nightscout_url: ${{ secrets.NIGHTSCOUT_URL }}
|
||||
prod:
|
||||
skip: true
|
||||
90
source/plugins/community/nightscout/index.mjs
Normal file
90
source/plugins/community/nightscout/index.mjs
Normal file
@@ -0,0 +1,90 @@
|
||||
//Setup
|
||||
export default async function({q, imports, data, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.nightscout))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {url, datapoints, lowalert, highalert, urgentlowalert, urgenthighalert} = imports.metadata.plugins.nightscout.inputs({data, account, q})
|
||||
|
||||
if (!url || url === "https://example.herokuapp.com")
|
||||
throw {error:{message:"Nightscout site URL isn't set!"}}
|
||||
if (url.substring(url.length - 1) !== "/")
|
||||
url += "/"
|
||||
if (url.substring(0, 7) === "http://")
|
||||
url = `https://${url.substring(7)}`
|
||||
if (url.substring(0, 8) !== "https://")
|
||||
url = `https://${url}`
|
||||
if (datapoints <= 0)
|
||||
datapoints = 1
|
||||
//Get nightscout data from axios
|
||||
const resp = await imports.axios.get(`${url}api/v1/entries.json?count=${datapoints}`)
|
||||
for (let i = 0; i < resp.data.length; i++) {
|
||||
const {sgv} = resp.data[i]
|
||||
//Add human readable timestamps and arrows
|
||||
const date = new Date(resp.data[i].dateString)
|
||||
resp.data[i].arrowHumanReadable = directionArrow(resp.data[i].direction)
|
||||
resp.data[i].timeUTCHumanReadable = `${addZero(date.getUTCHours())}:${addZero(date.getUTCMinutes())}`
|
||||
/*
|
||||
* Add colors and alert names
|
||||
* TODO: Maybe make colors better themed instead of just the "github style" - red and yellow could fit better than darker shades of green
|
||||
*/
|
||||
let color = "#40c463"
|
||||
let alertName = "Normal"
|
||||
if (sgv >= urgenthighalert || sgv <= urgentlowalert) {
|
||||
color = "#216e39"
|
||||
alertName = sgv >= urgenthighalert ? "Urgent High" : "Urgent Low"
|
||||
}
|
||||
else if (sgv >= highalert || sgv <= lowalert) {
|
||||
color = "#30a14e"
|
||||
alertName = sgv >= highalert ? "High" : "Low"
|
||||
}
|
||||
resp.data[i].color = color
|
||||
resp.data[i].alert = alertName
|
||||
}
|
||||
return {data:resp.data.reverse()}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
|
||||
function addZero(i) {
|
||||
if (i < 10)
|
||||
i = `0${i}`
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
function directionArrow(direction) {
|
||||
const dir = direction.toUpperCase()
|
||||
switch (dir) {
|
||||
case "NONE":
|
||||
return ""
|
||||
case "DOUBLEUP":
|
||||
return "↑↑"
|
||||
case "SINGLEUP":
|
||||
return "↑"
|
||||
case "FORTYFIVEUP":
|
||||
return "↗"
|
||||
case "FLAT":
|
||||
return "→"
|
||||
case "FORTYFIVEDOWN":
|
||||
return "↘"
|
||||
case "SINGLEDOWN":
|
||||
return "↓"
|
||||
case "DOUBLEDOWN":
|
||||
return "↓↓"
|
||||
case "NOT COMPUTABLE":
|
||||
return ""
|
||||
case "RATE OUT OF RANGE":
|
||||
return ""
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
52
source/plugins/community/nightscout/metadata.yml
Normal file
52
source/plugins/community/nightscout/metadata.yml
Normal file
@@ -0,0 +1,52 @@
|
||||
name: "💉 Nightscout"
|
||||
category: community
|
||||
description: This plugin lets you display blood sugar values from a [Nightscout](http://nightscout.info) site.
|
||||
examples:
|
||||
default: https://github.com/legoandmars/legoandmars/blob/master/metrics.plugin.nightscout.svg
|
||||
authors:
|
||||
- legoandmars
|
||||
supports:
|
||||
- user
|
||||
scopes: []
|
||||
inputs:
|
||||
|
||||
plugin_nightscout:
|
||||
description: Enable nightscout plugin
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
plugin_nightscout_url:
|
||||
description: Nightscout URL
|
||||
type: string
|
||||
default: https://example.herokuapp.com
|
||||
|
||||
plugin_nightscout_datapoints:
|
||||
description: Number of datapoints shown the graph
|
||||
type: number
|
||||
default: 12
|
||||
min: 0
|
||||
zero: disable
|
||||
|
||||
plugin_nightscout_lowalert:
|
||||
description: Threshold for low blood sugar
|
||||
type: number
|
||||
default: 80
|
||||
min: 0
|
||||
|
||||
plugin_nightscout_highalert:
|
||||
description: Threshold for high blood sugar
|
||||
type: number
|
||||
default: 180
|
||||
min: 0
|
||||
|
||||
plugin_nightscout_urgentlowalert:
|
||||
description: Threshold for urgently low blood sugar
|
||||
type: number
|
||||
default: 50
|
||||
min: 0
|
||||
|
||||
plugin_nightscout_urgenthighalert:
|
||||
description: Threshold for urgently high blood sugar
|
||||
type: number
|
||||
default: 250
|
||||
min: 0
|
||||
Reference in New Issue
Block a user