-
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.
- Loading branch information
Showing
7 changed files
with
84 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
interface EnergyDataStatistics { | ||
dataIdCount: number; | ||
assetIdDistinctCount: number; | ||
fileIdDistinctCount: number; | ||
timeSecondsMin: number; | ||
endTimeSecondsMax: number; | ||
} | ||
export declare function getEnergyDataStatistics(): EnergyDataStatistics; | ||
export {}; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import sqlite from 'better-sqlite3'; | ||
import { databasePath } from '../helpers/functions.database.js'; | ||
export function getEnergyDataStatistics() { | ||
const emileDB = sqlite(databasePath, { | ||
readonly: true | ||
}); | ||
const statistics = emileDB | ||
.prepare(`select count(dataId) as dataIdCount, | ||
count(distinct assetId) as assetIdDistinctCount, | ||
count(distinct fileId) as fileIdDistinctCount, | ||
min(timeSeconds) as timeSecondsMin, | ||
max(endTimeSeconds) as endTimeSecondsMax | ||
from EnergyData | ||
where recordDelete_timeMillis is null`) | ||
.get(); | ||
emileDB.close(); | ||
return statistics; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sqlite from 'better-sqlite3' | ||
|
||
import { databasePath } from '../helpers/functions.database.js' | ||
|
||
interface EnergyDataStatistics { | ||
dataIdCount: number | ||
|
||
assetIdDistinctCount: number | ||
|
||
fileIdDistinctCount: number | ||
|
||
timeSecondsMin: number | ||
endTimeSecondsMax: number | ||
} | ||
|
||
export function getEnergyDataStatistics(): EnergyDataStatistics { | ||
const emileDB = sqlite(databasePath, { | ||
readonly: true | ||
}) | ||
|
||
const statistics = emileDB | ||
.prepare( | ||
`select count(dataId) as dataIdCount, | ||
count(distinct assetId) as assetIdDistinctCount, | ||
count(distinct fileId) as fileIdDistinctCount, | ||
min(timeSeconds) as timeSecondsMin, | ||
max(endTimeSeconds) as endTimeSecondsMax | ||
from EnergyData | ||
where recordDelete_timeMillis is null` | ||
) | ||
.get() as EnergyDataStatistics | ||
|
||
emileDB.close() | ||
|
||
return statistics | ||
} |
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,15 +1,18 @@ | ||
import { getAssetGroups } from '../../database/getAssetGroups.js'; | ||
import { getAssets } from '../../database/getAssets.js'; | ||
import { getEnergyDataStatistics } from '../../database/getEnergyDataStatistics.js'; | ||
import { getAssetCategories } from '../../helpers/functions.cache.js'; | ||
export function handler(request, response) { | ||
const assets = getAssets(); | ||
const assetGroups = getAssetGroups(request.session.user); | ||
const assetCategories = getAssetCategories(); | ||
const energyDataStatistics = getEnergyDataStatistics(); | ||
response.render('dashboard', { | ||
headTitle: 'Dashboard', | ||
assets, | ||
assetGroups, | ||
assetCategories | ||
assetCategories, | ||
energyDataStatistics | ||
}); | ||
} | ||
export default handler; |
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