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

[PR] Negative Power Fixes (originally for Nash) #296

Merged
merged 9 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion backend/app/meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ exports.put = async (event, context) => {
let response = new Response(event)
let user = new User(event, response)
try {
await Meter(event.body.id).update(event.body.name, event.body.classInt, event.body.negate, user)
await Meter(event.body.id).update(event.body.name, event.body.classInt, user)
} catch (error) {
response.body = error.message
response.status = 400
Expand Down
8 changes: 3 additions & 5 deletions backend/dependencies/nodejs/models/building.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ class Building {
meter_groups.default as meter_group_default,
meters.name as meter_name,
meters.id as meter_id,
meters.class as meter_class,
meter_group_relation.operation as meter_negate
meters.class as meter_class
FROM buildings
LEFT JOIN meter_groups on buildings.id = meter_groups.building_id_2
LEFT JOIN meter_group_relation on meter_groups.id = meter_group_relation.group_id
Expand Down Expand Up @@ -191,8 +190,7 @@ class Building {

queryJson[row.id].meterGroups[row.meter_group_id].meters[row.meter_id] = {
name: row.meter_name,
classInt: row.meter_class,
negate: row.meter_negate === 0
classInt: row.meter_class
}
}

Expand All @@ -204,7 +202,7 @@ class Building {
for (let meterKey of Object.keys(queryJson[key].meterGroups[groupKey].meters)) {
let meterJson = queryJson[key].meterGroups[groupKey].meters[meterKey]
let meter = new Meter(meterKey)
meter.set(meterJson.name, meterJson.classInt, meterJson.negate)
meter.set(meterJson.name, meterJson.classInt)
meters.push(meter)
}

Expand Down
25 changes: 8 additions & 17 deletions backend/dependencies/nodejs/models/meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Meter {
this.name = ''
this.address = address
this.classInt = 0
this.negate = 0
this.type = ''
this.points = []
}
Expand All @@ -42,16 +41,13 @@ class Meter {
this.name = row[0]['name']
this.address = row[0]['address']
this.classInt = row[0]['class']
this.negate = row[0]['negate'] === 1

this.calcProps()
return this
}

set(name, classInt, negate) {
set(name, classInt) {
this.name = name
this.classInt = classInt
this.negate = negate
this.calcProps()
}

Expand All @@ -73,8 +69,8 @@ class Meter {

const map = {
accumulated_real: 'Net Energy Usage (kWh)',
real_power: 'Real Power (W)',
reactive_power: 'Reactive Power (VAR)',
real_power: 'Real Power (kW)',
reactive_power: 'Reactive Power (kVAR)',
apparent_power: 'Apparent Power (VA)',
real_a: 'Real Power, Phase A (kW)',
real_b: 'Real Power, Phase B (kW)',
Expand Down Expand Up @@ -131,7 +127,6 @@ class Meter {
name: this.name,
address: this.address,
classInt: this.classInt,
negate: this.negate,
type: this.type,
points: this.points
}
Expand Down Expand Up @@ -391,30 +386,27 @@ class Meter {
}
}

async update(name, classInt, negate, user) {
async update(name, classInt, user) {
if (user.data.privilege <= 3) {
throw new Error('Need escalated privileges')
}
await DB.connect()
await DB.query('UPDATE meters SET name = ?, class = ?, negate = ? WHERE id = ?', [name, classInt, negate, this.id])
await DB.query('UPDATE meters SET name = ?, class = ? WHERE id = ?', [name, classInt, this.id])
this.name = name
this.classInt = classInt
this.negate = negate
}

static async create(name, address, classInt, negate = 0) {
static async create(name, address, classInt) {
await DB.connect()
let returnRow = await DB.query('INSERT INTO meters (name, address, class, negate) values (?, ?, ?, ?)', [
let returnRow = await DB.query('INSERT INTO meters (name, address, class) values (?, ?, ?)', [
name,
address,
classInt,
negate
classInt
])
let meter = new Meter(returnRow.insertId)
meter.name = name
meter.address = address
meter.class = classInt
meter.negate = negate
return meter
}

Expand All @@ -429,7 +421,6 @@ class Meter {
meter.name = meterQ['name']
meter.address = meterQ['address']
meter.classInt = meterQ['class']
meter.negate = meterQ['negate'] === 1
meter.calcProps()
r.push(meter.data)
}
Expand Down
11 changes: 3 additions & 8 deletions backend/dependencies/nodejs/models/meter_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ class MeterGroup {
this.meters = []
for (let meter of meters) {
// this.meters.push((new Meter(meter)).get())
DB.query('INSERT INTO meter_group_relation (meter_id, group_id, operation) VALUES (?, ?, ?)', [
meter.id,
this.id,
meter.operation
])
DB.query('INSERT INTO meter_group_relation (meter_id, group_id) VALUES (?, ?)', [meter.id, this.id])
}
// this.meters = await Promise.all(this.meters)
return this
Expand Down Expand Up @@ -125,10 +121,9 @@ class MeterGroup {
let meterPromises = []
for (let meter of meters) {
meterPromises.push(
DB.query('INSERT INTO meter_group_relation (meter_id, group_id, operation) VALUES (?, ?, ?)', [
DB.query('INSERT INTO meter_group_relation (meter_id, group_id) VALUES (?, ?)', [
meter.id,
insertRow['insertId'],
meter.operation
insertRow['insertId']
])
)
}
Expand Down
Loading
Loading