From 2b02ee6c9a727437c7423f31e04611f4764f6b34 Mon Sep 17 00:00:00 2001 From: Ellis Lempriere Date: Mon, 19 Feb 2024 17:16:19 -0800 Subject: [PATCH 1/2] Add test LG19 --- ...15-20_mu_kWh_gu_MTonCO2_st_-inf_et_inf.csv | 76 ++++++++++ .../test/web/readingsLineGroupQuantity.js | 132 +++++++++++++++++- 2 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MTonCO2_st_-inf_et_inf.csv diff --git a/src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MTonCO2_st_-inf_et_inf.csv b/src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MTonCO2_st_-inf_et_inf.csv new file mode 100644 index 000000000..a5480f03e --- /dev/null +++ b/src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MTonCO2_st_-inf_et_inf.csv @@ -0,0 +1,76 @@ +reading,start time,end time +0.252892148928677,2022-08-18 00:00:00,2022-08-19 00:00:00 +0.223337293871196,2022-08-19 00:00:00,2022-08-20 00:00:00 +0.255680774535246,2022-08-20 00:00:00,2022-08-21 00:00:00 +0.250846348838948,2022-08-21 00:00:00,2022-08-22 00:00:00 +0.242698017028994,2022-08-22 00:00:00,2022-08-23 00:00:00 +0.249367853797597,2022-08-23 00:00:00,2022-08-24 00:00:00 +0.25185569690265,2022-08-24 00:00:00,2022-08-25 00:00:00 +0.247295309798749,2022-08-25 00:00:00,2022-08-26 00:00:00 +0.230662860940612,2022-08-26 00:00:00,2022-08-27 00:00:00 +0.24874858156857,2022-08-27 00:00:00,2022-08-28 00:00:00 +0.245705851370349,2022-08-28 00:00:00,2022-08-29 00:00:00 +0.232233846283603,2022-08-29 00:00:00,2022-08-30 00:00:00 +0.253700622881239,2022-08-30 00:00:00,2022-08-31 00:00:00 +0.243767850197022,2022-08-31 00:00:00,2022-09-01 00:00:00 +0.238183704532081,2022-09-01 00:00:00,2022-09-02 00:00:00 +0.257094979610576,2022-09-02 00:00:00,2022-09-03 00:00:00 +0.257777319080649,2022-09-03 00:00:00,2022-09-04 00:00:00 +0.246512286453807,2022-09-04 00:00:00,2022-09-05 00:00:00 +0.229886225395202,2022-09-05 00:00:00,2022-09-06 00:00:00 +0.250624023704122,2022-09-06 00:00:00,2022-09-07 00:00:00 +0.251627138465283,2022-09-07 00:00:00,2022-09-08 00:00:00 +0.241828457022283,2022-09-08 00:00:00,2022-09-09 00:00:00 +0.249185273607622,2022-09-09 00:00:00,2022-09-10 00:00:00 +0.245574982720773,2022-09-10 00:00:00,2022-09-11 00:00:00 +0.265766825732167,2022-09-11 00:00:00,2022-09-12 00:00:00 +0.246524273835636,2022-09-12 00:00:00,2022-09-13 00:00:00 +0.253532426577597,2022-09-13 00:00:00,2022-09-14 00:00:00 +0.238701910075936,2022-09-14 00:00:00,2022-09-15 00:00:00 +0.251286709376873,2022-09-15 00:00:00,2022-09-16 00:00:00 +0.241148694861167,2022-09-16 00:00:00,2022-09-17 00:00:00 +0.254640177033644,2022-09-17 00:00:00,2022-09-18 00:00:00 +0.256318865345186,2022-09-18 00:00:00,2022-09-19 00:00:00 +0.243760295617627,2022-09-19 00:00:00,2022-09-20 00:00:00 +0.26972814149219,2022-09-20 00:00:00,2022-09-21 00:00:00 +0.239535250123288,2022-09-21 00:00:00,2022-09-22 00:00:00 +0.257968922072573,2022-09-22 00:00:00,2022-09-23 00:00:00 +0.236884293822186,2022-09-23 00:00:00,2022-09-24 00:00:00 +0.236457969882856,2022-09-24 00:00:00,2022-09-25 00:00:00 +0.251908275731724,2022-09-25 00:00:00,2022-09-26 00:00:00 +0.240057503051384,2022-09-26 00:00:00,2022-09-27 00:00:00 +0.238170393268664,2022-09-27 00:00:00,2022-09-28 00:00:00 +0.248098895622592,2022-09-28 00:00:00,2022-09-29 00:00:00 +0.256175410700896,2022-09-29 00:00:00,2022-09-30 00:00:00 +0.248813852738315,2022-09-30 00:00:00,2022-10-01 00:00:00 +0.243496274125415,2022-10-01 00:00:00,2022-10-02 00:00:00 +0.249047244409498,2022-10-02 00:00:00,2022-10-03 00:00:00 +0.239200631710465,2022-10-03 00:00:00,2022-10-04 00:00:00 +0.248790428309162,2022-10-04 00:00:00,2022-10-05 00:00:00 +0.244894279966184,2022-10-05 00:00:00,2022-10-06 00:00:00 +0.250473477472761,2022-10-06 00:00:00,2022-10-07 00:00:00 +0.256267119601032,2022-10-07 00:00:00,2022-10-08 00:00:00 +0.243485674905646,2022-10-08 00:00:00,2022-10-09 00:00:00 +0.229262270537384,2022-10-09 00:00:00,2022-10-10 00:00:00 +0.24549834197354,2022-10-10 00:00:00,2022-10-11 00:00:00 +0.242651090400592,2022-10-11 00:00:00,2022-10-12 00:00:00 +0.256465170820487,2022-10-12 00:00:00,2022-10-13 00:00:00 +0.251210520208321,2022-10-13 00:00:00,2022-10-14 00:00:00 +0.247116940873415,2022-10-14 00:00:00,2022-10-15 00:00:00 +0.238967408502432,2022-10-15 00:00:00,2022-10-16 00:00:00 +0.244104502447371,2022-10-16 00:00:00,2022-10-17 00:00:00 +0.249851989275115,2022-10-17 00:00:00,2022-10-18 00:00:00 +0.243749304861483,2022-10-18 00:00:00,2022-10-19 00:00:00 +0.235366010252579,2022-10-19 00:00:00,2022-10-20 00:00:00 +0.248940021970046,2022-10-20 00:00:00,2022-10-21 00:00:00 +0.2536622840378,2022-10-21 00:00:00,2022-10-22 00:00:00 +0.240301488632524,2022-10-22 00:00:00,2022-10-23 00:00:00 +0.248852387944817,2022-10-23 00:00:00,2022-10-24 00:00:00 +0.261518753786087,2022-10-24 00:00:00,2022-10-25 00:00:00 +0.26997043892657,2022-10-25 00:00:00,2022-10-26 00:00:00 +0.236241477685152,2022-10-26 00:00:00,2022-10-27 00:00:00 +0.238243667723802,2022-10-27 00:00:00,2022-10-28 00:00:00 +0.249593138158715,2022-10-28 00:00:00,2022-10-29 00:00:00 +0.265822445194516,2022-10-29 00:00:00,2022-10-30 00:00:00 +0.246706333347691,2022-10-30 00:00:00,2022-10-31 00:00:00 +0.231028219367406,2022-10-31 00:00:00,2022-11-01 00:00:00 diff --git a/src/server/test/web/readingsLineGroupQuantity.js b/src/server/test/web/readingsLineGroupQuantity.js index e54b2a1d8..dfeede9cc 100644 --- a/src/server/test/web/readingsLineGroupQuantity.js +++ b/src/server/test/web/readingsLineGroupQuantity.js @@ -106,18 +106,18 @@ mocha.describe('readings API', () => { typeOfUnit: Unit.unitType.UNIT, suffix: '', displayable: Unit.displayableType.ALL, preferredDisplay: false, - note: 'MJ' + note: 'MJ' } ]); // Add kWh -> MJ conversion to our conversionData list const conversionData = conversionDatakWh.concat([ - { + { sourceName: 'kWh', destinationName: 'MJ', bidirectional: true, slope: 3.6, intercept: 0, - note: 'kWh → MJ' + note: 'kWh → MJ' } ]); // Converts meters from kWh to MJ @@ -183,6 +183,132 @@ mocha.describe('readings API', () => { // Add LG18 here // Add LG19 here + mocha.it('LG19: should have daily points for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as metric ton of CO2 & chained', async () => { + const unitDatakWh = [ + { + // u2 + name: 'Electric_Utility', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.METER, + suffix: '', + displayable: Unit.displayableType.NONE, + preferredDisplay: false, + note: 'special unit' + }, + { + // u10 + name: 'kg', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: false, + note: 'OED created standard unit' + }, + { + // u11 + name: 'metric ton', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: false, + note: 'OED created standard unit' + }, + { + // u12 + name: 'kg CO₂', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: 'CO₂', + displayable: Unit.displayableType.ALL, + preferredDisplay: false, + note: 'special unit' + } + ]; + const conversionDatakWh = [ + { + // c11 + sourceName: 'Electric_Utility', + destinationName: 'kg CO₂', + bidirectional: false, + slope: 0.709, + intercept: 0, + note: 'Electric_Utility → kg CO₂' + }, + { + // c12 + sourceName: 'kg CO₂', + destinationName: 'kg', + bidirectional: false, + slope: 1, + intercept: 0, + note: 'CO₂ → kg' + }, + { + // c13 + sourceName: 'kg', + destinationName: 'metric ton', + bidirectional: true, + slope: 1e-3, + intercept: 0, + note: 'kg → Metric ton' + } + ]; + const meterDatakWhGroups = [ + { + name: 'Electric_Utility metric ton of CO₂', + unit: 'Electric_Utility', + displayable: true, + gps: undefined, + note: 'special meter', + file: 'test/web/readingsData/readings_ri_15_days_75.csv', + deleteFile: false, + readingFrequency: '15 minutes', + id: METER_ID + }, + { + name: 'Electric Utility metric ton of CO₂ Other', + unit: 'Electric_Utility', + displayable: true, + gps: undefined, + note: 'special meter', + file: 'test/web/readingsData/readings_ri_20_days_75.csv', + deleteFile: false, + readingFrequency: '20 minutes', + id: (METER_ID + 1) + } + ]; + const groupDatakWh = [ + { + id: GROUP_ID, + name: 'Electric Utility kWh + Other', + displayable: true, + note: 'special group', + childMeters: ['Electric_Utility metric ton of CO₂', 'Electric Utility metric ton of CO₂ Other'], + childGroups: [], + } + ]; + // Load the data into the database + await prepareTest(unitDatakWh, conversionDatakWh, meterDatakWhGroups, groupDatakWh); + // Get the unit ID since the DB could use any value. + const unitId = await getUnitId('metric ton of CO₂'); + // Load the expected response data from the corresponding csv file + const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MTonCO2_st_-inf_et_inf.csv'); + // Create a request to the API for unbounded reading times and save the response + const res = await chai.request(app).get(`/api/unitReadings/line/groups/${GROUP_ID}`) + .query({ timeInterval: ETERNITY.toString(), graphicUnitId: unitId }); + // Check that the API reading is equal to what it is expected to equal + expectReadingToEqualExpected(res, expected, GROUP_ID); + }); // Add LG20 here From baf62dea243da008eeb69fbc3f27bee6045fed77 Mon Sep 17 00:00:00 2001 From: Steven Huss-Lederman Date: Tue, 20 Feb 2024 07:02:30 -0600 Subject: [PATCH 2/2] remove project comment --- src/server/test/web/readingsLineGroupQuantity.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/test/web/readingsLineGroupQuantity.js b/src/server/test/web/readingsLineGroupQuantity.js index dfeede9cc..48f4dcaa9 100644 --- a/src/server/test/web/readingsLineGroupQuantity.js +++ b/src/server/test/web/readingsLineGroupQuantity.js @@ -182,7 +182,6 @@ mocha.describe('readings API', () => { // Add LG18 here - // Add LG19 here mocha.it('LG19: should have daily points for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as metric ton of CO2 & chained', async () => { const unitDatakWh = [ {