Skip to content

Commit

Permalink
Merge branch 'development' into working_alex_bolshakov
Browse files Browse the repository at this point in the history
  • Loading branch information
Bolshialex committed Mar 4, 2025
2 parents 11dfa61 + 5c2bb73 commit 04dbeeb
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 7 deletions.
161 changes: 157 additions & 4 deletions src/server/test/web/readingsBarMeterFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Unit = require("../../models/Unit");
const {
prepareTest,
parseExpectedCsv,
//createTimeString,
createTimeString,
expectReadingToEqualExpected,
getUnitId,
ETERNITY,
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
}
);
});
});
}
Expand Down
185 changes: 182 additions & 3 deletions src/server/test/web/readingsCompareMeterQuantity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 04dbeeb

Please sign in to comment.