mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Change properties to match GraphQL input and query result
This commit is contained in:
@@ -110,10 +110,10 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository
|
|||||||
options: ParkingStructureCountOptions
|
options: ParkingStructureCountOptions
|
||||||
): HistoricalParkingAverageQueryResult[] => {
|
): HistoricalParkingAverageQueryResult[] => {
|
||||||
const results: HistoricalParkingAverageQueryResult[] = [];
|
const results: HistoricalParkingAverageQueryResult[] = [];
|
||||||
const { startUnixEpochMs, endUnixEpochMs, intervalMs } = options;
|
const { from, to, intervalMs } = options;
|
||||||
|
|
||||||
let currentIntervalStart = startUnixEpochMs.getTime();
|
let currentIntervalStart = from.getTime();
|
||||||
const endTime = endUnixEpochMs.getTime();
|
const endTime = to.getTime();
|
||||||
|
|
||||||
while (currentIntervalStart < endTime) {
|
while (currentIntervalStart < endTime) {
|
||||||
const currentIntervalEnd = Math.min(currentIntervalStart + intervalMs, endTime);
|
const currentIntervalEnd = Math.min(currentIntervalStart + intervalMs, endTime);
|
||||||
@@ -149,8 +149,8 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository
|
|||||||
const averageSpotsAvailable = totalSpotsAvailable / records.length;
|
const averageSpotsAvailable = totalSpotsAvailable / records.length;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fromUnixEpochMs: new Date(fromMs),
|
from: new Date(fromMs),
|
||||||
toUnixEpochMs: new Date(toMs),
|
to: new Date(toMs),
|
||||||
averageSpotsAvailable
|
averageSpotsAvailable
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { IParkingStructure } from "../../entities/ParkingRepositoryEntities";
|
import { IParkingStructure } from "../../entities/ParkingRepositoryEntities";
|
||||||
|
|
||||||
export interface ParkingStructureCountOptions {
|
export interface ParkingStructureCountOptions {
|
||||||
startUnixEpochMs: Date;
|
from: Date;
|
||||||
endUnixEpochMs: Date;
|
to: Date;
|
||||||
intervalMs: number;
|
intervalMs: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HistoricalParkingAverageQueryResult {
|
export interface HistoricalParkingAverageQueryResult {
|
||||||
fromUnixEpochMs: Date;
|
from: Date;
|
||||||
toUnixEpochMs: Date;
|
to: Date;
|
||||||
averageSpotsAvailable: number;
|
averageSpotsAvailable: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,11 +160,11 @@ export class RedisParkingRepository extends BaseRedisRepository implements Parki
|
|||||||
options: ParkingStructureCountOptions
|
options: ParkingStructureCountOptions
|
||||||
): Promise<HistoricalParkingAverageQueryResult[]> => {
|
): Promise<HistoricalParkingAverageQueryResult[]> => {
|
||||||
const keys = this.createRedisKeys(id);
|
const keys = this.createRedisKeys(id);
|
||||||
const { startUnixEpochMs, endUnixEpochMs, intervalMs } = options;
|
const { from, to, intervalMs } = options;
|
||||||
const results: HistoricalParkingAverageQueryResult[] = [];
|
const results: HistoricalParkingAverageQueryResult[] = [];
|
||||||
|
|
||||||
let currentIntervalStart = startUnixEpochMs.getTime();
|
let currentIntervalStart = from.getTime();
|
||||||
const endTime = endUnixEpochMs.getTime();
|
const endTime = to.getTime();
|
||||||
|
|
||||||
while (currentIntervalStart < endTime) {
|
while (currentIntervalStart < endTime) {
|
||||||
const currentIntervalEnd = Math.min(currentIntervalStart + intervalMs, endTime);
|
const currentIntervalEnd = Math.min(currentIntervalStart + intervalMs, endTime);
|
||||||
@@ -183,8 +183,8 @@ export class RedisParkingRepository extends BaseRedisRepository implements Parki
|
|||||||
if (aggregationResult && aggregationResult.length > 0) {
|
if (aggregationResult && aggregationResult.length > 0) {
|
||||||
const [, averageValue] = aggregationResult[0];
|
const [, averageValue] = aggregationResult[0];
|
||||||
results.push({
|
results.push({
|
||||||
fromUnixEpochMs: new Date(currentIntervalStart),
|
from: new Date(currentIntervalStart),
|
||||||
toUnixEpochMs: new Date(currentIntervalEnd),
|
to: new Date(currentIntervalEnd),
|
||||||
averageSpotsAvailable: parseFloat(averageValue)
|
averageSpotsAvailable: parseFloat(averageValue)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,8 +152,8 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
|||||||
describe("getHistoricalAveragesOfParkingStructureCounts", () => {
|
describe("getHistoricalAveragesOfParkingStructureCounts", () => {
|
||||||
it("should return empty array for non-existent structure or no data", async () => {
|
it("should return empty array for non-existent structure or no data", async () => {
|
||||||
const options: ParkingStructureCountOptions = {
|
const options: ParkingStructureCountOptions = {
|
||||||
startUnixEpochMs: new Date(1000),
|
from: new Date(1000),
|
||||||
endUnixEpochMs: new Date(2000),
|
to: new Date(2000),
|
||||||
intervalMs: 500
|
intervalMs: 500
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -183,8 +183,8 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
|||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const options: ParkingStructureCountOptions = {
|
const options: ParkingStructureCountOptions = {
|
||||||
startUnixEpochMs: new Date(now - 10000), // Look back 10 seconds
|
from: new Date(now - 10000), // Look back 10 seconds
|
||||||
endUnixEpochMs: new Date(now + 10000), // Look forward 10 seconds
|
to: new Date(now + 10000), // Look forward 10 seconds
|
||||||
intervalMs: 20000 // Single large interval
|
intervalMs: 20000 // Single large interval
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -193,10 +193,10 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
|||||||
// Should have at least some historical data
|
// Should have at least some historical data
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
expect(result[0]).toHaveProperty('fromUnixEpochMs');
|
expect(result[0]).toHaveProperty('from');
|
||||||
expect(result[0]).toHaveProperty('toUnixEpochMs');
|
expect(result[0]).toHaveProperty('to');
|
||||||
expect(result[0].fromUnixEpochMs).toBeInstanceOf(Date);
|
expect(result[0].from).toBeInstanceOf(Date);
|
||||||
expect(result[0].toUnixEpochMs).toBeInstanceOf(Date);
|
expect(result[0].to).toBeInstanceOf(Date);
|
||||||
expect(result[0]).toHaveProperty('averageSpotsAvailable');
|
expect(result[0]).toHaveProperty('averageSpotsAvailable');
|
||||||
expect(result[0].averageSpotsAvailable).toBeCloseTo(52.5);
|
expect(result[0].averageSpotsAvailable).toBeCloseTo(52.5);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user