Skip to content

Commit

Permalink
Tracker selector
Browse files Browse the repository at this point in the history
- Fixing a few bugs
  • Loading branch information
brandoncorbin committed Jul 31, 2019
1 parent 33f7c7c commit 9e9de21
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ npm install
npm run dev
```

## Running tests

```
npm run cypress
```

Deploy straight to Netlify to test it out quickly.

[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://app.netlify.com/start/deploy?repository=https://github.com/open-nomie/nomie)
Expand Down
9 changes: 0 additions & 9 deletions cypress/integration/store/board.js

This file was deleted.

49 changes: 49 additions & 0 deletions cypress/integration/utils/math.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math from '../../../src/utils/math/math';
import NomieUOM from '../../../src/utils/nomie-uom/nomie-uom';

describe('utils/math', function() {
it('math.sum', () => {
Expand All @@ -7,6 +8,54 @@ describe('utils/math', function() {
it('math.average', () => {
expect(math.average([30, 344, 21, 23])).to.equal(104.5);
});

it('math.average sleeo', () => {
let avg = math.average([
29400,
25980,
24720,
27420,
1860,
24900,
5400,
21540,
18960,
18060,
11340,
60,
21180,
3600,
17760,
28140,
26940,
23580,
24000,
28260,
22500,
6000,
4020,
3840,
15660,
17340,
10800,
25440,
32400,
24000,
29820,
22500,
27660,
23760,
5340,
22320,
28620,
20580,
22860,
21840,
25560,
]);
expect(avg).to.equal(19413.66);
});

it('math.round - default', () => {
expect(math.round(10.12345)).to.equal(10.12);
});
Expand Down
36 changes: 27 additions & 9 deletions src/containers/tracker/selector/selector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,36 @@
// State
let data = {
selected: {},
trackers: [],
alphaGroup: {}
trackers: []
};
// Holder of the alphabet for the list
let alphaGroup = {};
// When tracker store loads. Turn trackers into array sorted by label
$: data.trackers = Object.keys($TrackerStore || {})
.map(tag => {
return $TrackerStore[tag];
})
.sort((a, b) => {
return a.label < b.label ? -1 : 1;
return a.label.substr(0, 1).toLowerCase() >=
b.label.substr(0, 1).toLowerCase()
? 1
: -1;
});
// When selected, auto create an array of selected trackers
$: data.selectedArray = Object.keys(data.selected).map(tag => {
alphaGroup = {};
return data.selected[tag];
});
// If show changes, set selected to notihng
$: if (show) {
data.selected = {};
alphaGroup = {};
}
// Methods
const methods = {
toggle(tracker) {
Expand All @@ -47,17 +61,21 @@
data.selected[tracker.tag] = tracker;
}
},
// Check if a letter has been shown
alphaGroupExists(tracker) {
if (data.trackers.length > 10) {
// get first letter
let alpha = tracker.label.substr(0, 1).toLowerCase();
if (data.alphaGroup.hasOwnProperty(alpha)) {
// If it has value - return true...
if (alphaGroup.hasOwnProperty(alpha)) {
return true;
} else {
data.alphaGroup[alpha] = true;
// Else - populate the alphaGroup, then return false
alphaGroup[alpha] = true;
return false;
}
} else {
// if it's less than 10 trackers - just show them without the letters
return true;
}
}
Expand All @@ -71,12 +89,12 @@
{#if show}
<NModal title="Tracker Selector" allowClose={true}>
<div class="list">
{#each data.trackers as tracker (tracker.tag)}
<!-- {#if !methods.alphaGroupExists(tracker)}
{#each data.trackers as tracker}
{#if !methods.alphaGroupExists(tracker)}
<NItem
className="bg-light text-faded"
title={tracker.label.substr(0, 1).toUpperCase()} />
{/if} -->
{/if}
<NItem
borderBottom
className={data.selected.hasOwnProperty(tracker.tag) ? 'bg-selected' : ''}
Expand Down
1 change: 1 addition & 0 deletions src/modules/stats/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default class StatsProcessor {
});

newMap.sum = math.sum(allValues);
console.log('Averaging the following values', allValues);
newMap.avg = math.average(allValues);

return newMap;
Expand Down

0 comments on commit 9e9de21

Please sign in to comment.