From 7a097268b5e70eb41b7adb881ee4eb844c9e929f Mon Sep 17 00:00:00 2001 From: Jeff Huang <82061589+solderq35@users.noreply.github.com> Date: Thu, 19 Oct 2023 23:01:53 -0700 Subject: [PATCH] [PR] Revamp sec scraper backend (#269) * poc done but css needs work * final mobile test then feature done * remove comments, console logs, reset env * update backend for revamped webscraper --- backend/app/meter.js | 2 +- backend/dependencies/nodejs/models/meter.js | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/backend/app/meter.js b/backend/app/meter.js index baa6558a..41fb979d 100644 --- a/backend/app/meter.js +++ b/backend/app/meter.js @@ -105,7 +105,7 @@ exports.upload = async (event, context) => { return response } - let query_string = `INSERT INTO Solar_Meters (\`time\`, \`time_seconds\`, \`energy_change\`, \`tableid\`) VALUES ('${meter_data.time}', '${meter_data.time_seconds}', '${meter_data.totalYieldYesterday}', '${meter_data.tableID}');` + 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}');` try { await DB.query(query_string) diff --git a/backend/dependencies/nodejs/models/meter.js b/backend/dependencies/nodejs/models/meter.js index c98a4913..ebc6818a 100644 --- a/backend/dependencies/nodejs/models/meter.js +++ b/backend/dependencies/nodejs/models/meter.js @@ -144,12 +144,6 @@ class Meter { if (String(meterClass).startsWith('999')) { // get table name from meter table let [{ name: meter_table_name }] = await DB.query('SELECT `name` FROM meters WHERE id = ?', [this.id]) - const meterLookupTable = { - 121: 'SEC_OSU_Op_Lube', - 122: 'SEC_OSU_Op', - 123: 'SEC_Solar', - 124: 'OSU_Operations_Total' - } if (meter_table_name.startsWith('M')) { return DB.query( 'SELECT ' + @@ -161,7 +155,10 @@ class Meter { ' WHERE time_seconds >= ? AND time_seconds <= ?', [startTime, endTime] ) - } else { + } + + // may have to modify the below to be else-if, if we are going to have multiple custom webscraper tables (Solar_Meters, etc) + else { return DB.query( 'SELECT ' + point + @@ -169,8 +166,8 @@ class Meter { this.id + "' as id FROM " + meter_table_name + - ' WHERE time_seconds >= ? AND time_seconds <= ? AND tableID = ?', - [startTime, endTime, meterLookupTable[this.id]] + ' WHERE time_seconds >= ? AND time_seconds <= ? AND MeterID = ?', + [startTime, endTime, this.id] ) } }