Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #5

Merged
merged 8 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,15 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs/ or
* `BASAL_RENDER` (`none`) - Possible values are `none`, `default`, or `icicle` (inverted)

##### `bridge` (Share2Nightscout bridge)
Glucose reading directly from the Share service, uses these extended settings:
* `BRIDGE_USER_NAME` - Your user name for the Share service.
Glucose reading directly from the Dexcom Share service, uses these extended settings:
* `BRIDGE_USER_NAME` - Your username for the Share service.
* `BRIDGE_PASSWORD` - Your password for the Share service.
* `BRIDGE_INTERVAL` (`150000` *2.5 minutes*) - The time to wait between each update.
* `BRIDGE_INTERVAL` (`150000` *2.5 minutes*) - The time (in milliseconds) to wait between each update.
* `BRIDGE_MAX_COUNT` (`1`) - The number of records to attempt to fetch per update.
* `BRIDGE_FIRST_FETCH_COUNT` (`3`) - Changes max count during the very first update only.
* `BRIDGE_MAX_FAILURES` (`3`) - How many failures before giving up.
* `BRIDGE_MINUTES` (`1400`) - The time window to search for new data per update (default is one day in minutes).
* `BRIDGE_MINUTES` (`1400`) - The time window to search for new data per update (the default value is one day in minutes).
* `BRIDGE_SERVER` (``) - The default blank value is used to fetch data from Dexcom servers in the US. Set to (`EU`) to fetch from European servers instead.

##### `mmconnect` (MiniMed Connect bridge)
Transfer real-time MiniMed Connect data from the Medtronic CareLink server into Nightscout ([read more](https://github.com/mddub/minimed-connect-to-nightscout))
Expand Down Expand Up @@ -524,6 +525,25 @@ For remote overrides, the following extended settings must be configured:
Enabled [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) so other websites can make request to your Nightscout site, uses these extended settings:
* `CORS_ALLOW_ORIGIN` (`*`) - The list of sites that are allow to make requests

##### `dbsize` (Database Size)
Show size of Nightscout Database, as a percentage of declared available space or in MiB.

Many deployments of Nightscout use free tier of MongoDB on Heroku, which is limited in size. After some time, as volume of stored data grows, it may happen that this limit is reached and system is unable to store new data. This plugin provides pill that indicates size of Database and shows (when configured) alarms regarding reaching space limit.

**IMPORTANT:** This plugin can only check how much space database already takes, _but cannot infer_ max size available on server for it. To have correct alarms and realistic percentage, `DBSIZE_MAX` need to be properly set - according to your mongoDB hosting configuration.

**NOTE:** It may happen that new data cannot be saved to database (due to size limits) even when this plugin reports that storage is not 100% full. MongoDB pre-allocate data in advance, and database file is always made bigger than total real data size. To avoid premature alarms, this plugin refers to data size instead of file size, but sets warning thresholds low. It may happen, that file size of database will take 100% of allowed space but there will be plenty of place inside to store the data. But it may also happen, with file size is at its max, that data size will be ~70% of file size, and there will be no place left. That may happen because data inside file is fragmented and free space _holes_ are too small for new entries. In such case calling `db.repairDatabase()` on mongoDB is recommended to compact and repack data (currently only doable with third-party mongoDB tools, but action is planned to be added in _Admin Tools_ section in future releases).

All sizes are expressed as integers, in _Mebibytes_ `1 MiB == 1024 KiB == 1024*1024 B`

* `DBSIZE_MAX` (`496`) - Maximal allowed size of database on your mongoDB server, in MiB. You need to adjust that value to match your database hosting limits - default value is for standard Heroku mongoDB free tier.
* `DBSIZE_WARN_PERCENTAGE` (`60`) - Threshold to show first warning about database size. When database reach this percentage of `DBSIZE_MAX` size - pill will show size in yellow.
* `DBSIZE_URGENT_PERCENTAGE` (`75`) - Threshold to show urgent warning about database size. When database reach this percentage of `DBSIZE_MAX` size, it is urgent to do backup and clean up old data. At this percentage info pill turns red.
* `DBSIZE_ENABLE_ALERTS` (`false`) - Set to `true` to enable notifications about database size.
* `DBSIZE_IN_MIB` (`false`) - Set to `true` to display size of database in MiB-s instead of default percentage.

This plugin should be enabled by default, if needed can be diasabled by adding `dbsize` to the list of disabled plugins, for example: `DISABLE="dbsize"`.

#### Extended Settings
Some plugins support additional configuration using extra environment variables. These are prefixed with the name of the plugin and a `_`. For example setting `MYPLUGIN_EXAMPLE_VALUE=1234` would make `extendedSettings.exampleValue` available to the `MYPLUGIN` plugin.

Expand Down
16 changes: 10 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const bodyParser = require('body-parser');

const path = require('path');
const fs = require('fs');
const ejs = require('ejs');

function create (env, ctx) {
var app = express();
Expand Down Expand Up @@ -92,6 +93,15 @@ function create (env, ctx) {
}
app.locals.cachebuster = cacheBuster;

app.get("/sw.js", (req, res) => {
res.setHeader('Content-Type', 'application/javascript');
res.send(ejs.render(fs.readFileSync(
require.resolve(`${__dirname}/views/service-worker.js`),
{ encoding: 'utf-8' }),
{ locals: app.locals}
));
});

if (ctx.bootErrors && ctx.bootErrors.length > 0) {
app.get('*', require('./lib/server/booterror')(ctx));
return app;
Expand Down Expand Up @@ -178,12 +188,6 @@ function create (env, ctx) {

app.use("/clock", clockviews);

app.get("/appcache/*", (req, res) => {
res.render("nightscout.appcache", {
locals: app.locals
});
});

app.use('/api', bodyParser({
limit: 1048576 * 50
}), apiRoot);
Expand Down
87 changes: 87 additions & 0 deletions assets/fonts/Nightscout Plugin Icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"metadata": {
"name": "Nightscout Plugin Icons",
"lastOpened": 0,
"created": 1580075608590
},
"iconSets": [
{
"selection": [
{
"order": 2,
"id": 0,
"name": "database",
"prevSize": 32,
"code": 59649,
"tempChar": ""
}
],
"id": 2,
"metadata": {
"name": "Plugin Icons",
"importSize": {
"width": 16,
"height": 18
}
},
"height": 1024,
"prevSize": 32,
"icons": [
{
"id": 0,
"paths": [
"M455.111 0c-251.449 0-455.111 101.831-455.111 227.556s203.662 227.556 455.111 227.556 455.111-101.831 455.111-227.556-203.662-227.556-455.111-227.556zM0 341.333v170.667c0 125.724 203.662 227.556 455.111 227.556s455.111-101.831 455.111-227.556v-170.667c0 125.724-203.662 227.556-455.111 227.556s-455.111-101.831-455.111-227.556zM0 625.778v170.667c0 125.724 203.662 227.556 455.111 227.556s455.111-101.831 455.111-227.556v-170.667c0 125.724-203.662 227.556-455.111 227.556s-455.111-101.831-455.111-227.556z"
],
"attrs": [
{}
],
"width": 910,
"isMulticolor": false,
"isMulticolor2": false,
"grid": 0,
"tags": [
"plugins"
]
}
],
"invisible": false,
"colorThemes": []
}
],
"preferences": {
"showGlyphs": true,
"showQuickUse": true,
"showQuickUse2": true,
"showSVGs": true,
"fontPref": {
"prefix": "plugicon-",
"metadata": {
"fontFamily": "pluginicons",
"majorVersion": 1,
"minorVersion": 0
},
"metrics": {
"emSize": 1024,
"baseline": 6.25,
"whitespace": 50
},
"embed": false,
"showSelector": false,
"showMetrics": false,
"showMetadata": false,
"showVersion": false
},
"imagePref": {
"prefix": "icon-",
"png": true,
"useClassSelector": true,
"color": 0,
"bgColor": 16777215,
"classSelector": ".icon"
},
"historySize": 50,
"showCodes": true,
"gridSize": 16
},
"uid": -1
}
29 changes: 29 additions & 0 deletions assets/fonts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
How to upgrade icons in icon-fonts on Nightscout
================================================

This guide is fol developers regarding how to add new icon to Nightscout.

Nightscout use icon fonts to render icons. Each icon is glyph (like - letter, or more like emoji character) inside custom made font file.
That way we have nice, vector icons, that are small, scalable, looks good on each platform, and are easy to embed inside CSS.

To extend existing icon set.:

1. Prepare minimalist, black & white icon in SVG tool of choice, and optimize it (you can use Inkscape) to be small in size and render good at small sizes.
2. Use https://icomoon.io/app and import accompanied JSON project file (`Nightscout Plugin Icons.json`)
3. Add SVG as new glyph. Remember to take care to set proper character code and CSS name
4. Save new version of JSON project file and store in this folder
5. Generate font, download zip file and unpack it to get `fonts/pluginicons.svg` and `fonts/pluginicons.woff`
6. Update `statc/css/main.css` file
* In section of `@font-face` with `font-family: 'pluginicons'`
* update part after `data:application/font-woff;charset=utf-8;base64,` with Base64-encoded content of just generated `pluginicons.woff` font
* update part after `data:application/font-svg;charset=utf-8;base64,` with Base64-encoded content of just generated `pluginicons.svg` font
* copy/update all entries `.plugicon-****:before { content: "****"; }` from generated font `style.css` into `statc/css/main.css`
7. Do not forget to update `Nightscout Plugin Icons.json` in this repo (´download updated project from icomoon.io)

Hints
-----

* You can find many useful online tools to encode file into Base64, like: https://base64.guru/converter/encode/file
* Do not split Base64 output - it should be one LONG line
* Since update process is **manual** and generated fonts & updated CSS sections are **binary** - try to avoid **git merge conflicts** by speaking with other developers if you plan to add new icon
* When in doubt - check `git log` and reach last contributor for guidelines :)
4 changes: 2 additions & 2 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,6 @@ function init (client, d3, $) {
};

function scrollUpdate () {
scrolling = false;

var nowDate = scrollNow;

var currentBrushExtent = scrollBrushExtent;
Expand Down Expand Up @@ -669,6 +667,8 @@ function init (client, d3, $) {
// console.log('Redrawing brush due to update: ', currentBrushExtent);

chart.theBrush.call(chart.brush.move, currentBrushExtent.map(chart.xScale2));

scrolling = false;
}

chart.scroll = function scroll (nowDate) {
Expand Down
3 changes: 3 additions & 0 deletions lib/client/receiveddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ function receiveDData (received, ddata, settings) {
}
}

if (received.dbstats && received.dbstats.fileSize) {
ddata.dbstats = received.dbstats;
}
}

//expose for tests
Expand Down
18 changes: 18 additions & 0 deletions lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function init(env, ctx) {

// clear treatments, we're going to merge from more queries
ddata.treatments = [];
ddata.dbstats = {};

async.parallel([
loadEntries.bind(null, ddata, ctx)
Expand All @@ -79,6 +80,7 @@ function init(env, ctx) {
, loadFood.bind(null, ddata, ctx)
, loadDeviceStatus.bind(null, ddata, env, ctx)
, loadActivity.bind(null, ddata, ctx)
, loadDatabaseStats.bind(null, ddata, ctx)
], loadComplete);

};
Expand Down Expand Up @@ -399,5 +401,21 @@ function loadDeviceStatus(ddata, env, ctx, callback) {
});
}

function loadDatabaseStats(ddata, ctx, callback) {
ctx.store.db.stats(function mongoDone (err, result) {
if (err) {
console.log("Problem loading database stats");
}
if (!err && result) {
ddata.dbstats = {
dataSize: result.dataSize
, indexSize: result.indexSize
, fileSize: result.fileSize
};
}
callback();
});
}

module.exports = init;

2 changes: 2 additions & 0 deletions lib/data/ddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function init () {
, devicestatus: []
, food: []
, activity: []
, dbstats: {}
, lastUpdated: 0
};

Expand Down Expand Up @@ -51,6 +52,7 @@ function init () {
results.mbgs = ddata.mbgs;
results.food = ddata.food;
results.treatments = ddata.treatments;
results.dbstats = ddata.dbstats;

return results;

Expand Down
2 changes: 1 addition & 1 deletion lib/data/treatmenttocurve.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function fitTreatmentsToBGCurve (ddata, env, ctx) {
calcedBG = mgdlAfter;
}

return calcedBG || 180;
return Math.round(calcedBG) || 180;
}

function mgdlValue (entry) {
Expand Down
28 changes: 27 additions & 1 deletion lib/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -15100,7 +15100,33 @@ function init() {
, pl: 'Tłuszcz ogółem'
,ru: 'Всего жиров'
,he: 'כל שומנים'
}
},
'Database Size': {
pl: 'Rozmiar Bazy Danych'
},
'Database Size near its limits!': {
pl: 'Rozmiar bazy danych zbliża się do limitu!'
},
'Database size is %1 MiB out of %2 MiB. Please backup and clean up database!': {
pl: 'Baza danych zajmuje %1 MiB z dozwolonych %2 MiB. Proszę zrób kopię zapasową i oczyść bazę danych!'
},
'Database file size': {
pl: 'Rozmiar pliku bazy danych'
},
'%1 MiB of %2 MiB (%3%)': {
pl: '%1 MiB z %2 MiB (%3%)'
},
'Data size': {
pl: 'Rozmiar danych'
},
'virtAsstDatabaseSize': {
en: '%1 MiB that is %2% of available database space'
,pl: '%1 MiB co stanowi %2% przestrzeni dostępnej dla bazy danych'
},
'virtAsstTitleDatabaseSize': {
en: 'Database file size'
,pl: 'Rozmiar pliku bazy danych'
}
};

language.translations = translations;
Expand Down
Loading