Skip to content

Commit

Permalink
Add pacific power meters (#302)
Browse files Browse the repository at this point in the history
* Upload for PPM working

* Pacific Power meter download fixed

* add timezone offset for pacificpower

---------

Co-authored-by: solderq35 <solderq35@gmail.com>
  • Loading branch information
s-egge and solderq35 authored Feb 25, 2024
1 parent 72def0f commit ddfe96d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
9 changes: 8 additions & 1 deletion backend/app/meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ exports.upload = async (event, context) => {
const pwd = payload['pwd']
const meter_id = payload['id']
const meter_data = payload['body']
const meter_type = payload['type']

if (pwd !== process.env.ACQUISUITE_PASS) {
response.statusCode = 400
Expand All @@ -105,7 +106,13 @@ exports.upload = async (event, context) => {
return response
}

let query_string = `INSERT INTO Solar_Meters (\`time\`, \`time_seconds\`, \`energy_change\`, \`MeterID\`, \`MeterName\`) VALUES ('${meter_data.time}', '${meter_data.time_seconds}', '${meter_data.totalYieldYesterday}', '${meter_data.meterID}', '${meter_data.meterName}');`
let query_string = ''

if (meter_type === 'solar') {
query_string = `INSERT INTO Solar_Meters (\`time\`, \`time_seconds\`, \`energy_change\`, \`MeterID\`, \`MeterName\`) VALUES ('${meter_data.time}', '${meter_data.time_seconds}', '${meter_data.totalYieldYesterday}', '${meter_data.meterID}', '${meter_data.meterName}');`
} else if (meter_type === 'pacific_power') {
query_string = `INSERT INTO pacific_power_data (\`time\`, \`time_seconds\`, \`accumulated_real\`, \`pacific_power_meter_id\`) VALUES ('${meter_data.time}', '${meter_data.time_seconds}', '${meter_data.usage_kwh}', '${meter_data.pp_meter_id}');`
}

try {
await DB.query(query_string)
Expand Down
18 changes: 14 additions & 4 deletions backend/dependencies/nodejs/models/meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ class Meter {
' WHERE time_seconds >= ? AND time_seconds <= ?',
[startTime, endTime]
)
}

// may have to modify the below to be else-if, if we are going to have multiple custom webscraper tables (Solar_Meters, etc)
else {
} else if (meter_table_name === 'Solar_Meters') {
return DB.query(
'SELECT ' +
point +
Expand All @@ -165,6 +162,19 @@ class Meter {
[startTime, endTime, this.id]
)
}

// pacific power meters, may need to change to else-if if there are going to be more custom classes starting with 999
else {
let [{ pacific_power_id: pp_id }] = await DB.query('SELECT pacific_power_id FROM meters WHERE id = ?', [
this.id
])
return DB.query(
'SELECT ' +
point +
', time_seconds AS time FROM pacific_power_data WHERE time_seconds >= ? AND time_seconds <= ? AND pacific_power_meter_id = ?',
[startTime, endTime, pp_id]
)
}
}
// Aquisuites
return DB.query(
Expand Down
4 changes: 3 additions & 1 deletion src/store/block.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ const actions = {
let moduleSpace = store.getters.path + '/' + chartSpace
this.registerModule(moduleSpace.split('/'), Chart)
let utilityType = ''
let blockClassInt = ''
if (this.getters[payload.group.path + '/meters'].length > 0) {
await this.getters[payload.group.path + '/meters'][0].promise
utilityType = this.getters[this.getters[payload.group.path + '/meters'][0].path + '/type']
blockClassInt = this.getters[this.getters[payload.group.path + '/meters'][0].path + '/classInt']
}
// this defines the "default chart", "Total Electricity"
store.commit(chartSpace + '/name', 'Total ' + utilityType)
Expand Down Expand Up @@ -257,7 +259,7 @@ const actions = {
// change default interval for solar panels
// Note: this parameter is often modified elsewhere in the dashboard
// E.g. Building list component changes it via a Vue router parameter
if (utilityType === 'Solar Panel') {
if (utilityType === 'Solar Panel' || blockClassInt === 9990002) {
// Solar panel webscraper uploads time_seconds in UTC
// so we're gonna need to add the offset for the correct time
// in pacific standard time.
Expand Down
16 changes: 15 additions & 1 deletion src/store/chart.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ const actions = {
...store.getters.modifierData
}

const chartModifier = ChartModifiers(payload.graphType, reqPayload.point)
let point = reqPayload.point

const isPacificPowerMeter = this.getters[store.getters.meterGroupPath + '/meters'][0].classInt === 9990002

// PacificPower meters only collect data daily and need to use the same chart modifier as solar arrays
if (isPacificPowerMeter) {
point = 'energy_change'
}

const chartModifier = ChartModifiers(payload.graphType, point)
await chartModifier.preGetData(reqPayload, this, store)

let data = await this.dispatch(store.getters.meterGroupPath + '/getData', reqPayload)
Expand All @@ -66,6 +75,11 @@ const actions = {

await chartModifier.postGetData(chartData, reqPayload, this, store)

// fix PacificPower meters chart being filled by the energy_change chart modifier
if (isPacificPowerMeter) {
chartData.fill = false
}

return chartData
},

Expand Down

0 comments on commit ddfe96d

Please sign in to comment.