From f63dc14cb9f8fb61893e27265980d35527bdc9d9 Mon Sep 17 00:00:00 2001 From: nicholasyfu1 Date: Thu, 3 Oct 2024 18:27:10 -0400 Subject: [PATCH 1/2] Added BG12 and expected csv file --- .../test/web/readingsBarGroupQuantity.js | 63 +++++++++++++++ ...20_mu_kWh_gu_kgCO2_st_-inf_et_inf_bd_1.csv | 76 +++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kgCO2_st_-inf_et_inf_bd_1.csv diff --git a/src/server/test/web/readingsBarGroupQuantity.js b/src/server/test/web/readingsBarGroupQuantity.js index bfe6cc59b..944e6786f 100644 --- a/src/server/test/web/readingsBarGroupQuantity.js +++ b/src/server/test/web/readingsBarGroupQuantity.js @@ -204,6 +204,69 @@ mocha.describe('readings API', () => { // Add BG11 here // Add BG12 here + mocha.it('BG12: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kg of CO2', async () =>{ + const unitData = unitDatakWh.concat([ + { + // 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' + }, + { + // 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 conversionData = conversionDatakWh.concat([ + { + //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' + } + ]); + //load data into database + await prepareTest(unitData, conversionData, meterDatakWhGroups, groupDatakWh); + // Get unit ID for 'kg CO₂' + const unitId = await getUnitId('kg of CO₂'); + // Load expected response data from the corresponding CSV file + const expected = await parseExpectedCsv('src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kgCO2_st_-inf_et_inf_bd_1.csv'); + // Create a request to the API for unbounded reading times and save the response + const res = await chai.request(app).get(`/api/unitReadings/bar/groups/${GROUP_ID}`) + .query({ + timeInterval: ETERNITY.toString(), + barWidthDays: '1', + graphicUnitId: unitId + }); + // Check that the API reading is equal to what it is expected to equal + expectReadingToEqualExpected(res, expected, GROUP_ID); + }); // Add BG13 here diff --git a/src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kgCO2_st_-inf_et_inf_bd_1.csv b/src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kgCO2_st_-inf_et_inf_bd_1.csv new file mode 100644 index 000000000..383511541 --- /dev/null +++ b/src/server/test/web/readingsData/expected_bar_group_ri_15-20_mu_kWh_gu_kgCO2_st_-inf_et_inf_bd_1.csv @@ -0,0 +1,76 @@ +reading,start time,end time +6069.41157428824,2022-08-18 00:00:00,2022-08-19 00:00:00 +5360.0950529087,2022-08-19 00:00:00,2022-08-20 00:00:00 +6136.3385888459,2022-08-20 00:00:00,2022-08-21 00:00:00 +6020.31237213475,2022-08-21 00:00:00,2022-08-22 00:00:00 +5824.75240869586,2022-08-22 00:00:00,2022-08-23 00:00:00 +5984.82849114233,2022-08-23 00:00:00,2022-08-24 00:00:00 +6044.53672566359,2022-08-24 00:00:00,2022-08-25 00:00:00 +5935.08743516999,2022-08-25 00:00:00,2022-08-26 00:00:00 +5535.90866257469,2022-08-26 00:00:00,2022-08-27 00:00:00 +5969.96595764567,2022-08-27 00:00:00,2022-08-28 00:00:00 +5896.94043288837,2022-08-28 00:00:00,2022-08-29 00:00:00 +5573.61231080648,2022-08-29 00:00:00,2022-08-30 00:00:00 +6088.81494914974,2022-08-30 00:00:00,2022-08-31 00:00:00 +5850.42840472852,2022-08-31 00:00:00,2022-09-01 00:00:00 +5716.40890876994,2022-09-01 00:00:00,2022-09-02 00:00:00 +6170.27951065381,2022-09-02 00:00:00,2022-09-03 00:00:00 +6186.65565793557,2022-09-03 00:00:00,2022-09-04 00:00:00 +5916.29487489138,2022-09-04 00:00:00,2022-09-05 00:00:00 +5517.26940948484,2022-09-05 00:00:00,2022-09-06 00:00:00 +6014.97656889892,2022-09-06 00:00:00,2022-09-07 00:00:00 +6039.05132316679,2022-09-07 00:00:00,2022-09-08 00:00:00 +5803.8829685348,2022-09-08 00:00:00,2022-09-09 00:00:00 +5980.44656658293,2022-09-09 00:00:00,2022-09-10 00:00:00 +5893.79958529856,2022-09-10 00:00:00,2022-09-11 00:00:00 +6378.403817572,2022-09-11 00:00:00,2022-09-12 00:00:00 +5916.58257205527,2022-09-12 00:00:00,2022-09-13 00:00:00 +6084.77823786232,2022-09-13 00:00:00,2022-09-14 00:00:00 +5728.84584182247,2022-09-14 00:00:00,2022-09-15 00:00:00 +6030.88102504494,2022-09-15 00:00:00,2022-09-16 00:00:00 +5787.568676668,2022-09-16 00:00:00,2022-09-17 00:00:00 +6111.36424880746,2022-09-17 00:00:00,2022-09-18 00:00:00 +6151.65276828447,2022-09-18 00:00:00,2022-09-19 00:00:00 +5850.24709482304,2022-09-19 00:00:00,2022-09-20 00:00:00 +6473.47539581256,2022-09-20 00:00:00,2022-09-21 00:00:00 +5748.84600295891,2022-09-21 00:00:00,2022-09-22 00:00:00 +6191.25412974175,2022-09-22 00:00:00,2022-09-23 00:00:00 +5685.22305173247,2022-09-23 00:00:00,2022-09-24 00:00:00 +5674.99127718854,2022-09-24 00:00:00,2022-09-25 00:00:00 +6045.79861756136,2022-09-25 00:00:00,2022-09-26 00:00:00 +5761.38007323321,2022-09-26 00:00:00,2022-09-27 00:00:00 +5716.08943844792,2022-09-27 00:00:00,2022-09-28 00:00:00 +5954.37349494221,2022-09-28 00:00:00,2022-09-29 00:00:00 +6148.2098568215,2022-09-29 00:00:00,2022-09-30 00:00:00 +5971.53246571957,2022-09-30 00:00:00,2022-10-01 00:00:00 +5843.91057900997,2022-10-01 00:00:00,2022-10-02 00:00:00 +5977.13386582796,2022-10-02 00:00:00,2022-10-03 00:00:00 +5740.81516105115,2022-10-03 00:00:00,2022-10-04 00:00:00 +5970.9702794199,2022-10-04 00:00:00,2022-10-05 00:00:00 +5877.46271918843,2022-10-05 00:00:00,2022-10-06 00:00:00 +6011.36345934627,2022-10-06 00:00:00,2022-10-07 00:00:00 +6150.41087042478,2022-10-07 00:00:00,2022-10-08 00:00:00 +5843.6561977355,2022-10-08 00:00:00,2022-10-09 00:00:00 +5502.29449289721,2022-10-09 00:00:00,2022-10-10 00:00:00 +5891.96020736497,2022-10-10 00:00:00,2022-10-11 00:00:00 +5823.6261696142,2022-10-11 00:00:00,2022-10-12 00:00:00 +6155.16409969168,2022-10-12 00:00:00,2022-10-13 00:00:00 +6029.05248499971,2022-10-13 00:00:00,2022-10-14 00:00:00 +5930.80658096196,2022-10-14 00:00:00,2022-10-15 00:00:00 +5735.21780405837,2022-10-15 00:00:00,2022-10-16 00:00:00 +5858.50805873689,2022-10-16 00:00:00,2022-10-17 00:00:00 +5996.44774260275,2022-10-17 00:00:00,2022-10-18 00:00:00 +5849.9833166756,2022-10-18 00:00:00,2022-10-19 00:00:00 +5648.7842460619,2022-10-19 00:00:00,2022-10-20 00:00:00 +5974.56052728109,2022-10-20 00:00:00,2022-10-21 00:00:00 +6087.89481690719,2022-10-21 00:00:00,2022-10-22 00:00:00 +5767.23572718058,2022-10-22 00:00:00,2022-10-23 00:00:00 +5972.45731067561,2022-10-23 00:00:00,2022-10-24 00:00:00 +6276.45009086608,2022-10-24 00:00:00,2022-10-25 00:00:00 +6479.29053423768,2022-10-25 00:00:00,2022-10-26 00:00:00 +5669.79546444366,2022-10-26 00:00:00,2022-10-27 00:00:00 +5717.84802537126,2022-10-27 00:00:00,2022-10-28 00:00:00 +5990.23531580915,2022-10-28 00:00:00,2022-10-29 00:00:00 +6379.73868466838,2022-10-29 00:00:00,2022-10-30 00:00:00 +5920.95200034458,2022-10-30 00:00:00,2022-10-31 00:00:00 +5544.67726481774,2022-10-31 00:00:00,2022-11-01 00:00:00 From b0cadd680980218b4b083cec9f1a0a820662774e Mon Sep 17 00:00:00 2001 From: nicholasyfu1 <62448453+nicholasyfu1@users.noreply.github.com> Date: Thu, 3 Oct 2024 20:22:55 -0400 Subject: [PATCH 2/2] Update readingsBarGroupQuantity.js --- src/server/test/web/readingsBarGroupQuantity.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/test/web/readingsBarGroupQuantity.js b/src/server/test/web/readingsBarGroupQuantity.js index 944e6786f..4cc4f45e7 100644 --- a/src/server/test/web/readingsBarGroupQuantity.js +++ b/src/server/test/web/readingsBarGroupQuantity.js @@ -203,7 +203,6 @@ mocha.describe('readings API', () => { // Add BG11 here - // Add BG12 here mocha.it('BG12: 1 day bars for 15 + 20 minute reading intervals and quantity units with +-inf start/end time & kWh as kg of CO2', async () =>{ const unitData = unitDatakWh.concat([ {