-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from DSSD-Madison/panels
Filtering for graphs
- Loading branch information
Showing
5 changed files
with
111 additions
and
16 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
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
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
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
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,28 +1,38 @@ | ||
import { readable, derived } from 'svelte/store'; | ||
import { readable, derived, writable, get } from 'svelte/store'; | ||
|
||
import getData from './getData'; | ||
import { type PanelData } from './getData'; | ||
|
||
export const dbData = readable(getData()); | ||
|
||
export const selectedPanelStore = writable(null); | ||
|
||
const LBS_CO2_PER_KWH = 1.52; | ||
const DOLLARS_SAVED_PER_KWH = 0.10; | ||
|
||
const TOTALS_PANEL_WHITELIST = null; | ||
|
||
function calcTotal(data: { [key: string]: PanelData }) { | ||
function calcTotal(data: { [key: string]: PanelData }, panelFilter: string) { | ||
let total = 0; | ||
for (const [panelName, xy] of Object.entries(data)) { | ||
if (TOTALS_PANEL_WHITELIST !== null) { | ||
if (!TOTALS_PANEL_WHITELIST.includes(panelName)) { | ||
continue; | ||
} | ||
} | ||
for (const output of xy.y) { | ||
total += +output; | ||
if(!panelFilter || panelFilter == panelName) { | ||
for (const output of xy.y) { | ||
total += +output; | ||
} | ||
} | ||
} | ||
return total; | ||
} | ||
|
||
export const totalData = derived(dbData, promise => promise.then(calcTotal)); | ||
//export const totalData = derived(dbData, promise => promise.then(data => calcTotal(data, get(selectedPanelStore)))); | ||
export const totalData = derived( | ||
[dbData, selectedPanelStore], | ||
async ([$dbData, $selectedPanelStore]) => { | ||
return calcTotal(await $dbData, $selectedPanelStore); | ||
} | ||
); |