diff --git a/src/server/test/web/readingsBarMeterFlow.js b/src/server/test/web/readingsBarMeterFlow.js index 786cfce7d..303d6d424 100644 --- a/src/server/test/web/readingsBarMeterFlow.js +++ b/src/server/test/web/readingsBarMeterFlow.js @@ -12,7 +12,7 @@ const Unit = require("../../models/Unit"); const { prepareTest, parseExpectedCsv, - //createTimeString, + createTimeString, expectReadingToEqualExpected, getUnitId, ETERNITY, @@ -103,7 +103,6 @@ mocha.describe("readings API", () => { expectReadingToEqualExpected(res, expected); } ); - mocha.it( "B16: 13 day bars for 15 minute reading intervals and flow units with +-inf start/end time & thing as thing where rate is 36", async () => { @@ -179,7 +178,81 @@ mocha.describe("readings API", () => { expectReadingToEqualExpected(res, expected); } ); - // Add B17 here + mocha.it( + "B17: 1 day bars for 15 minute reading intervals and flow units with +-inf start/end time & kW as kW", + async () => { + const unitData = [ + { + // u4 + name: "kW", + identifier: "", + unitRepresent: Unit.unitRepresentType.FLOW, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: "", + displayable: Unit.displayableType.ALL, + preferredDisplay: true, + note: "kilowatts", + }, + { + // u5 + name: "Electric", + identifier: "", + unitRepresent: Unit.unitRepresentType.FLOW, + secInRate: 3600, + typeOfUnit: Unit.unitType.METER, + suffix: "", + displayable: Unit.displayableType.NONE, + preferredDisplay: false, + note: "special unit", + }, + ]; + const conversionData = [ + { + // c4 + sourceName: "Electric", + destinationName: "kW", + bidirectional: false, + slope: 1, + intercept: 0, + note: "Electric → kW", + }, + ]; + const meterData = [ + { + name: "Electric kW", + unit: "Electric", + defaultGraphicUnit: "kW", + 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, + }, + ]; + // Load the data into the database + await prepareTest(unitData, conversionData, meterData); + // Get the unit ID since the DB could use any value. + const unitId = await getUnitId("kW"); + // Load the expected response data from the corresponding csv file + const expected = await parseExpectedCsv( + "src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_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/meters/${METER_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); + } + ); // Add B18 here @@ -264,7 +337,87 @@ mocha.describe("readings API", () => { } ); - // Add B22 here + mocha.it( + "B22: 13 day bars for 15 minute reading intervals and quantity units with reduced, partial days & kWh as kWh", + async () => { + const unitData = [ + { + // u4 + name: "kW", + identifier: "", + unitRepresent: Unit.unitRepresentType.FLOW, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: "", + displayable: Unit.displayableType.ALL, + preferredDisplay: true, + note: "kilowatts", + }, + { + // u5 + name: "Electric", + identifier: "", + unitRepresent: Unit.unitRepresentType.FLOW, + secInRate: 3600, + typeOfUnit: Unit.unitType.METER, + suffix: "", + displayable: Unit.displayableType.NONE, + preferredDisplay: false, + note: "special unit", + }, + ]; + const conversionData = [ + { + // c4 + sourceName: "Electric", + destinationName: "kW", + bidirectional: false, + slope: 1, + intercept: 0, + note: "Electric → kW", + }, + ]; + const meterData = [ + { + name: "Electric kW", + unit: "Electric", + defaultGraphicUnit: "kW", + 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, + }, + ]; + // Load the data into the database + await prepareTest(unitData, conversionData, meterData); + // Get the unit ID since the DB could use any value. + const unitId = await getUnitId("kW"); + // Load the expected response data from the corresponding csv file + const expected = await parseExpectedCsv( + "src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.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/meters/${METER_ID}`) + .query({ + timeInterval: createTimeString( + "2022-08-20", + "07:25:35", + "2022-10-28", + "13:18:28" + ), + barWidthDays: 13, + graphicUnitId: unitId, + }); + + // Check that the API reading is equal to what it is expected to equal + expectReadingToEqualExpected(res, expected); + } + ); }); }); } diff --git a/src/server/test/web/readingsCompareMeterQuantity.js b/src/server/test/web/readingsCompareMeterQuantity.js index 720324b5b..d5652eb20 100644 --- a/src/server/test/web/readingsCompareMeterQuantity.js +++ b/src/server/test/web/readingsCompareMeterQuantity.js @@ -154,12 +154,191 @@ mocha.describe('readings API', () => { expectCompareToEqualExpected(res, expected); }); - // Add C9 here + mocha.it('C9: 1 day shift end 2022-10-31 17:00:00 for 15 minute reading intervals and quantity units & kWh as MJ reverse conversion', async () => { + // add u3 to existing unitData + 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 c2 to existing conversionData + const conversionData = conversionDatakWh.concat([ + { + sourceName: 'MJ', + destinationName: 'kWh', + bidirectional: true, + slope: 1 / 3.6, + intercept: 0, + note: 'MJ → kWh' + } + ]); + await prepareTest(unitData, conversionData, meterDatakWh); + // Get the unit ID since the DB could use any value. + const unitId = await getUnitId('MJ'); + const expected = [11232.0660730344, 12123.0051081528]; + // for compare, need the unitID, currentStart, currentEnd, shift + const res = await chai.request(app).get(`/api/compareReadings/meters/${METER_ID}`) + .query({ + curr_start: '2022-10-31 00:00:00', + curr_end: '2022-10-31 17:00:00', + shift: 'P1D', + graphicUnitId: unitId + }); + expectCompareToEqualExpected(res, expected); + }); - // Add C10 here - // Add C11 here + mocha.it('C10: 1 day shift end 2022-10-31 17:00:00 for 15 minute reading intervals and quantity units & kWh as BTU', async () => { + // Use predefined unit and conversion data + const unitData = unitDatakWh.concat([ + //adding u3, u16 + { + // u3 + name: 'MJ', + identifier: 'megaJoules', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: false, + note: 'MJ' + }, + { + // u16 + name: 'BTU', + identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', + displayable: Unit.displayableType.ALL, + preferredDisplay: true, + note: 'OED created standard unit' + } + ]); + const conversionData = conversionDatakWh.concat([ + // adding c2, c3 + { + // c2 + sourceName: 'kWh', + destinationName: 'MJ', + bidirectional: true, + slope: 3.6, + intercept: 0, + note: 'MJ → BTU' + }, + { + // c3 + sourceName: 'MJ', + destinationName: 'BTU', + bidirectional: true, + slope: 947.8, + intercept: 0, + note: 'MJ → BTU' + } + ]); + + // load data into database + await prepareTest(unitData, conversionData, meterDatakWh); + + // Get the unit ID since the DB could use any value + const unitId = await getUnitId('BTU'); + const expected = [10645752.224022, 11490184.2415072]; + // for compare, need the unitID, currentStart, currentEnd, shift + const res = await chai.request(app).get(`/api/compareReadings/meters/${METER_ID}`) + .query({ + curr_start: '2022-10-31 00:00:00', + curr_end: '2022-10-31 17:00:00', + shift: 'P1D', + graphicUnitId: unitId + }); + expectCompareToEqualExpected(res, expected); + }); + mocha.it('C11: 1 day shift end 2022-10-31 17:00:00 for 15 minute reading intervals and quantity units & kWh as BTU reverse conversion', async () => { + const unitData = unitDatakWh.concat([ + // adding units u3, u16 + { + // u3 + name: 'MJ', + identifier: 'megaJoules', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, typeOfUnit: Unit.unitType.UNIT, + suffix: '', displayable: Unit.displayableType.ALL, + preferredDisplay: false, + note: 'MJ' + }, + { + // u16 + name: 'BTU', identifier: '', + unitRepresent: Unit.unitRepresentType.QUANTITY, + secInRate: 3600, + typeOfUnit: Unit.unitType.UNIT, + suffix: '', displayable: Unit.displayableType.ALL, + preferredDisplay: true, + note: 'OED created standard unit' + }, + ]); + const conversionData = conversionDatakWh.concat([ + // adding conversions c6, c3 + { + // c6 + sourceName: 'MJ', + destinationName: 'kWh', + bidirectional: true, + slope: 1 / 3.6, + intercept: 0, + note: 'MJ → KWh' + }, + { + // c3 + sourceName: 'MJ', + destinationName: 'BTU', + bidirectional: true, + slope: 947.8, + intercept: 0, + note: 'MJ → BTU' + }, + + ]); + // redefining the meterData as the unit is different + const meterData = [ + { + name: 'Electric Utility BTU', + 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 + } + ]; + // load data into database + await prepareTest(unitData, conversionData, meterData); + // Get the unit ID since the DB could use any value + const unitId = await getUnitId('BTU'); + const expected = [10645752.224022, 11490184.2415072]; + // for compare, need the unitID, currentStart, currentEnd, shift + const res = await chai.request(app).get(`/api/compareReadings/meters/${METER_ID}`) + .query({ + curr_start: '2022-10-31 00:00:00', + curr_end: '2022-10-31 17:00:00', + shift: 'P1D', + graphicUnitId: unitId + }); + expectCompareToEqualExpected(res, expected); + }); mocha.it('C12: 1 day shift end 2022-10-31 17:00:00 for 15 minute reading intervals and quantity units & kWh as kg of CO2', async () => { const unitData = [ // adding units u2, u10, u12 diff --git a/src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_st_-inf_et_inf_bd_1.csv b/src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_st_-inf_et_inf_bd_1.csv new file mode 100644 index 000000000..cbf8834e3 --- /dev/null +++ b/src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_st_-inf_et_inf_bd_1.csv @@ -0,0 +1,76 @@ +reading,start time,end time +1244.4732821245,2022-08-18 00:00:00,2022-08-19 00:00:00 +988.315804920483,2022-08-19 00:00:00,2022-08-20 00:00:00 +1229.16913704567,2022-08-20 00:00:00,2022-08-21 00:00:00 +1214.90679769041,2022-08-21 00:00:00,2022-08-22 00:00:00 +1141.42617179595,2022-08-22 00:00:00,2022-08-23 00:00:00 +1173.22097628136,2022-08-23 00:00:00,2022-08-24 00:00:00 +1172.76622813581,2022-08-24 00:00:00,2022-08-25 00:00:00 +1217.29080157992,2022-08-25 00:00:00,2022-08-26 00:00:00 +1078.14650822547,2022-08-26 00:00:00,2022-08-27 00:00:00 +1195.102845216,2022-08-27 00:00:00,2022-08-28 00:00:00 +1156.49973049494,2022-08-28 00:00:00,2022-08-29 00:00:00 +1112.47501131559,2022-08-29 00:00:00,2022-08-30 00:00:00 +1192.86644903414,2022-08-30 00:00:00,2022-08-31 00:00:00 +1161.02765232201,2022-08-31 00:00:00,2022-09-01 00:00:00 +1152.18197026441,2022-09-01 00:00:00,2022-09-02 00:00:00 +1272.45260726068,2022-09-02 00:00:00,2022-09-03 00:00:00 +1217.82966175226,2022-09-03 00:00:00,2022-09-04 00:00:00 +1176.84658742283,2022-09-04 00:00:00,2022-09-05 00:00:00 +1125.57284174782,2022-09-05 00:00:00,2022-09-06 00:00:00 +1194.22329876519,2022-09-06 00:00:00,2022-09-07 00:00:00 +1171.71190809283,2022-09-07 00:00:00,2022-09-08 00:00:00 +1130.54158593037,2022-09-08 00:00:00,2022-09-09 00:00:00 +1236.92056317258,2022-09-09 00:00:00,2022-09-10 00:00:00 +1142.10449794792,2022-09-10 00:00:00,2022-09-11 00:00:00 +1340.16170552738,2022-09-11 00:00:00,2022-09-12 00:00:00 +1182.05404123472,2022-09-12 00:00:00,2022-09-13 00:00:00 +1248.84451712363,2022-09-13 00:00:00,2022-09-14 00:00:00 +1137.33538285512,2022-09-14 00:00:00,2022-09-15 00:00:00 +1221.31552272137,2022-09-15 00:00:00,2022-09-16 00:00:00 +1143.33626142129,2022-09-16 00:00:00,2022-09-17 00:00:00 +1225.3967032627,2022-09-17 00:00:00,2022-09-18 00:00:00 +1286.93091007234,2022-09-18 00:00:00,2022-09-19 00:00:00 +1110.56503545471,2022-09-19 00:00:00,2022-09-20 00:00:00 +1340.33530846461,2022-09-20 00:00:00,2022-09-21 00:00:00 +1123.21972183704,2022-09-21 00:00:00,2022-09-22 00:00:00 +1249.65113803395,2022-09-22 00:00:00,2022-09-23 00:00:00 +1131.23559326555,2022-09-23 00:00:00,2022-09-24 00:00:00 +1142.76238111977,2022-09-24 00:00:00,2022-09-25 00:00:00 +1210.92514071449,2022-09-25 00:00:00,2022-09-26 00:00:00 +1150.76698467275,2022-09-26 00:00:00,2022-09-27 00:00:00 +1152.78225650689,2022-09-27 00:00:00,2022-09-28 00:00:00 +1215.20127016486,2022-09-28 00:00:00,2022-09-29 00:00:00 +1273.79854318597,2022-09-29 00:00:00,2022-09-30 00:00:00 +1198.53270778934,2022-09-30 00:00:00,2022-10-01 00:00:00 +1165.80837300627,2022-10-01 00:00:00,2022-10-02 00:00:00 +1180.22585254585,2022-10-02 00:00:00,2022-10-03 00:00:00 +1112.62184179863,2022-10-03 00:00:00,2022-10-04 00:00:00 +1217.71687161273,2022-10-04 00:00:00,2022-10-05 00:00:00 +1199.38826568772,2022-10-05 00:00:00,2022-10-06 00:00:00 +1160.1762157385,2022-10-06 00:00:00,2022-10-07 00:00:00 +1269.25906753997,2022-10-07 00:00:00,2022-10-08 00:00:00 +1167.40579266569,2022-10-08 00:00:00,2022-10-09 00:00:00 +1058.18319043406,2022-10-09 00:00:00,2022-10-10 00:00:00 +1211.93520880573,2022-10-10 00:00:00,2022-10-11 00:00:00 +1152.7344011911,2022-10-11 00:00:00,2022-10-12 00:00:00 +1259.0249731428,2022-10-12 00:00:00,2022-10-13 00:00:00 +1192.12826970549,2022-10-13 00:00:00,2022-10-14 00:00:00 +1208.21671287911,2022-10-14 00:00:00,2022-10-15 00:00:00 +1155.22102759493,2022-10-15 00:00:00,2022-10-16 00:00:00 +1178.49984441914,2022-10-16 00:00:00,2022-10-17 00:00:00 +1221.29509976931,2022-10-17 00:00:00,2022-10-18 00:00:00 +1162.54298706786,2022-10-18 00:00:00,2022-10-19 00:00:00 +1128.36869126957,2022-10-19 00:00:00,2022-10-20 00:00:00 +1162.34721422175,2022-10-20 00:00:00,2022-10-21 00:00:00 +1243.61079923689,2022-10-21 00:00:00,2022-10-22 00:00:00 +1187.32006552077,2022-10-22 00:00:00,2022-10-23 00:00:00 +1203.7441556701,2022-10-23 00:00:00,2022-10-24 00:00:00 +1223.62767515703,2022-10-24 00:00:00,2022-10-25 00:00:00 +1347.85241257491,2022-10-25 00:00:00,2022-10-26 00:00:00 +1135.57752734976,2022-10-26 00:00:00,2022-10-27 00:00:00 +1091.91787954098,2022-10-27 00:00:00,2022-10-28 00:00:00 +1203.63545481652,2022-10-28 00:00:00,2022-10-29 00:00:00 +1349.13987250313,2022-10-29 00:00:00,2022-10-30 00:00:00 +1210.55315436926,2022-10-30 00:00:00,2022-10-31 00:00:00 +1072.65000056083,2022-10-31 00:00:00,2022-11-01 00:00:00 diff --git a/src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.csv b/src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.csv new file mode 100644 index 000000000..9659118af --- /dev/null +++ b/src/server/test/web/readingsData/expected_bar_ri_15_mu_kW_gu_kW_st_2022-08-20%07#25#35_et_2022-10-28%13#18#28_bd_13.csv @@ -0,0 +1,6 @@ +reading,start time,end time +15231.0588947719,2022-08-24 00:00:00,2022-09-06 00:00:00 +15660.8768981274,2022-09-06 00:00:00,2022-09-19 00:00:00 +15465.5844542162,2022-09-19 00:00:00,2022-10-02 00:00:00 +15389.0166637474,2022-10-02 00:00:00,2022-10-15 00:00:00 +15441.925379393,2022-10-15 00:00:00,2022-10-28 00:00:00