From 8201f067a14a9564d6ddae3d8d7e65f95e7c05b3 Mon Sep 17 00:00:00 2001 From: Sergio Zavala Date: Mon, 19 Feb 2024 05:19:52 +0000 Subject: [PATCH] LG10 Testcase final Co-authored-by: Jean-luc Martel Co-authored-by: Ruxue Jin --- ...p_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf.csv | 76 +++++++++++++++++ .../test/web/readingsLineGroupQuantity.js | 84 ++++++++++++++++++- 2 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf.csv diff --git a/src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf.csv b/src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf.csv new file mode 100644 index 000000000..dffa8e807 --- /dev/null +++ b/src/server/test/web/readingsData/expected_line_group_ri_15-20_mu_kWh_gu_MJ_st_-inf_et_inf.csv @@ -0,0 +1,76 @@ +reading,start time,end time +1284.07861233179,2022-08-18 00:00:00,2022-08-19 00:00:00 +1134.01164730085,2022-08-19 00:00:00,2022-08-20 00:00:00 +1298.23806534116,2022-08-20 00:00:00,2022-08-21 00:00:00 +1273.69091088887,2022-08-21 00:00:00,2022-08-22 00:00:00 +1232.31715275653,2022-08-22 00:00:00,2022-08-23 00:00:00 +1266.18374283688,2022-08-23 00:00:00,2022-08-24 00:00:00 +1278.81595042248,2022-08-24 00:00:00,2022-08-25 00:00:00 +1255.66024721509,2022-08-25 00:00:00,2022-08-26 00:00:00 +1171.20775653907,2022-08-26 00:00:00,2022-08-27 00:00:00 +1263.03934223815,2022-08-27 00:00:00,2022-08-28 00:00:00 +1247.58965434874,2022-08-28 00:00:00,2022-08-29 00:00:00 +1179.18455094636,2022-08-29 00:00:00,2022-08-30 00:00:00 +1288.18369869176,2022-08-30 00:00:00,2022-08-31 00:00:00 +1237.74930988615,2022-08-31 00:00:00,2022-09-01 00:00:00 +1209.39539677784,2022-09-01 00:00:00,2022-09-02 00:00:00 +1305.41879633014,2022-09-02 00:00:00,2022-09-03 00:00:00 +1308.88342551528,2022-09-03 00:00:00,2022-09-04 00:00:00 +1251.68438819987,2022-09-04 00:00:00,2022-09-05 00:00:00 +1167.26433204898,2022-09-05 00:00:00,2022-09-06 00:00:00 +1272.56203855407,2022-09-06 00:00:00,2022-09-07 00:00:00 +1277.65542803247,2022-09-07 00:00:00,2022-09-08 00:00:00 +1227.90189743332,2022-09-08 00:00:00,2022-09-09 00:00:00 +1265.2566784026,2022-09-09 00:00:00,2022-09-10 00:00:00 +1246.92515908996,2022-09-10 00:00:00,2022-09-11 00:00:00 +1349.45073714499,2022-09-11 00:00:00,2022-09-12 00:00:00 +1251.74525501875,2022-09-12 00:00:00,2022-09-13 00:00:00 +1287.32966950543,2022-09-13 00:00:00,2022-09-14 00:00:00 +1212.02662379883,2022-09-14 00:00:00,2022-09-15 00:00:00 +1275.92687412799,2022-09-15 00:00:00,2022-09-16 00:00:00 +1224.45035472525,2022-09-16 00:00:00,2022-09-17 00:00:00 +1292.95435447266,2022-09-17 00:00:00,2022-09-18 00:00:00 +1301.47801867796,2022-09-18 00:00:00,2022-09-19 00:00:00 +1237.71095094987,2022-09-19 00:00:00,2022-09-20 00:00:00 +1369.56461124384,2022-09-20 00:00:00,2022-09-21 00:00:00 +1216.25796959638,2022-09-21 00:00:00,2022-09-22 00:00:00 +1309.85630389459,2022-09-22 00:00:00,2022-09-23 00:00:00 +1202.79754267965,2022-09-23 00:00:00,2022-09-24 00:00:00 +1200.63285130928,2022-09-24 00:00:00,2022-09-25 00:00:00 +1279.08292332046,2022-09-25 00:00:00,2022-09-26 00:00:00 +1218.90974751055,2022-09-26 00:00:00,2022-09-27 00:00:00 +1209.32780785217,2022-09-27 00:00:00,2022-09-28 00:00:00 +1259.74051373954,2022-09-28 00:00:00,2022-09-29 00:00:00 +1300.74961709905,2022-09-29 00:00:00,2022-09-30 00:00:00 +1263.37076143573,2022-09-30 00:00:00,2022-10-01 00:00:00 +1236.37036227291,2022-10-01 00:00:00,2022-10-02 00:00:00 +1264.55582492834,2022-10-02 00:00:00,2022-10-03 00:00:00 +1214.55891982747,2022-10-03 00:00:00,2022-10-04 00:00:00 +1263.25182216218,2022-10-04 00:00:00,2022-10-05 00:00:00 +1243.46884044889,2022-10-05 00:00:00,2022-10-06 00:00:00 +1271.7976289167,2022-10-06 00:00:00,2022-10-07 00:00:00 +1301.21527583035,2022-10-07 00:00:00,2022-10-08 00:00:00 +1236.31654394968,2022-10-08 00:00:00,2022-10-09 00:00:00 +1164.09615505583,2022-10-09 00:00:00,2022-10-10 00:00:00 +1246.5360100208,2022-10-10 00:00:00,2022-10-11 00:00:00 +1232.07887932599,2022-10-11 00:00:00,2022-10-12 00:00:00 +1302.22089556241,2022-10-12 00:00:00,2022-10-13 00:00:00 +1275.54001798301,2022-10-13 00:00:00,2022-10-14 00:00:00 +1254.75456578885,2022-10-14 00:00:00,2022-10-15 00:00:00 +1213.37471171898,2022-10-15 00:00:00,2022-10-16 00:00:00 +1239.4586866157,2022-10-16 00:00:00,2022-10-17 00:00:00 +1268.64197657322,2022-10-17 00:00:00,2022-10-18 00:00:00 +1237.65514457171,2022-10-18 00:00:00,2022-10-19 00:00:00 +1195.08834542917,2022-10-19 00:00:00,2022-10-20 00:00:00 +1264.01139505242,2022-10-20 00:00:00,2022-10-21 00:00:00 +1287.98903037529,2022-10-21 00:00:00,2022-10-22 00:00:00 +1220.14860236543,2022-10-22 00:00:00,2022-10-23 00:00:00 +1263.5664268002,2022-10-23 00:00:00,2022-10-24 00:00:00 +1327.88083727773,2022-10-24 00:00:00,2022-10-25 00:00:00 +1370.79489440854,2022-10-25 00:00:00,2022-10-26 00:00:00 +1199.53359614464,2022-10-26 00:00:00,2022-10-27 00:00:00 +1209.69986432396,2022-10-27 00:00:00,2022-10-28 00:00:00 +1267.3276408623,2022-10-28 00:00:00,2022-10-29 00:00:00 +1349.73314908358,2022-10-29 00:00:00,2022-10-30 00:00:00 +1252.66967567234,2022-10-30 00:00:00,2022-10-31 00:00:00 +1173.06289100516,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 61f03020d..e6b97178f 100644 --- a/src/server/test/web/readingsLineGroupQuantity.js +++ b/src/server/test/web/readingsLineGroupQuantity.js @@ -12,10 +12,10 @@ const Unit = require('../../models/Unit'); const { prepareTest, parseExpectedCsv, expectReadingToEqualExpected, - // createTimeString, + createTimeString, getUnitId, ETERNITY, - // METER_ID, + METER_ID, GROUP_ID, unitDatakWh, conversionDatakWh, @@ -53,7 +53,85 @@ mocha.describe('readings API', () => { // Add LG7 here - // Add LG10 here + // Test using a data range of infinity, which should return as days + mocha.it('LG10: should have daily points for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as MJ', async () => { + // Add MegaJoules unit to our unitData list + const unitData = unitDatakWh.concat([ + { + name: 'MJ', + identifier: 'megaJoules', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: false, + 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' + } + ]); + // Converts meters from kWh to MJ + const meterData = [ + { + name: 'Electric Utility MJ', + unit: 'Electric_Utility', + defaultGraphicUnit: 'MJ', + displayable: true, + gps: undefined, + note: 'special meter', + file: 'test/web/readingsData/readings_ri_15_days_75.csv', + deleteFile: false, + // Test 15 minutes + readingFrequency: '15 minutes', + id: METER_ID + }, + { + name: 'Electric Utility Other', + unit: 'Electric_Utility', + defaultGraphicUnit: 'MJ', + displayable: true, + gps: undefined, + note: 'special meter', + file: 'test/web/readingsData/readings_ri_20_days_75.csv', + deleteFile: false, + // Test 20 minutes + readingFrequency: '20 minutes', + id: (METER_ID + 1) + } + ]; + // Group data as MegaJoules instead of kWh. + const groupData = [ + { + id: GROUP_ID, + name: 'Electric Utility MJ + Other', + displayable: true, + note: 'special group', + defaultGraphicUnit: 'MJ', + childMeters: ['Electric Utility MJ', 'Electric Utility Other'], + childGroups: [], + } + ] + // Load the data into the database + await prepareTest(unitData, conversionData, meterData, groupData); + //Get the unit ID since the DB could use any value. + const unitId = await getUnitId('MJ'); + // 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_MJ_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 LG11 here