Rename query interface for historical data

This commit is contained in:
2025-07-19 13:14:39 -04:00
parent 52a0133107
commit ee7b5eefda
4 changed files with 11 additions and 11 deletions

View File

@@ -3,7 +3,7 @@ import {
IParkingStructure, IParkingStructure,
IParkingStructureTimestampRecord IParkingStructureTimestampRecord
} from "../../entities/ParkingRepositoryEntities"; } from "../../entities/ParkingRepositoryEntities";
import { HistoricalParkingAverageQueryResult, ParkingStructureCountOptions } from "./ParkingGetterRepository"; import { HistoricalParkingAverageQueryResult, HistoricalParkingAverageQueryArguments } from "./ParkingGetterRepository";
import { CircularQueue } from "../../types/CircularQueue"; import { CircularQueue } from "../../types/CircularQueue";
import { PARKING_LOGGING_INTERVAL_MS } from "./ParkingRepositoryConstants"; import { PARKING_LOGGING_INTERVAL_MS } from "./ParkingRepositoryConstants";
@@ -63,7 +63,7 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository
return null; return null;
}; };
getHistoricalAveragesOfParkingStructureCounts = async (id: string, options: ParkingStructureCountOptions): Promise<HistoricalParkingAverageQueryResult[]> => { getHistoricalAveragesOfParkingStructureCounts = async (id: string, options: HistoricalParkingAverageQueryArguments): Promise<HistoricalParkingAverageQueryResult[]> => {
const queue = this.historicalData.get(id); const queue = this.historicalData.get(id);
if (!queue || queue.size() === 0) { if (!queue || queue.size() === 0) {
return []; return [];
@@ -107,7 +107,7 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository
private calculateAveragesFromRecords = ( private calculateAveragesFromRecords = (
records: IParkingStructureTimestampRecord[], records: IParkingStructureTimestampRecord[],
options: ParkingStructureCountOptions options: HistoricalParkingAverageQueryArguments
): HistoricalParkingAverageQueryResult[] => { ): HistoricalParkingAverageQueryResult[] => {
const results: HistoricalParkingAverageQueryResult[] = []; const results: HistoricalParkingAverageQueryResult[] = [];
const { from, to, intervalMs } = options; const { from, to, intervalMs } = options;

View File

@@ -1,6 +1,6 @@
import { IParkingStructure } from "../../entities/ParkingRepositoryEntities"; import { IParkingStructure } from "../../entities/ParkingRepositoryEntities";
export interface ParkingStructureCountOptions { export interface HistoricalParkingAverageQueryArguments {
from: Date; from: Date;
to: Date; to: Date;
intervalMs: number; intervalMs: number;
@@ -22,5 +22,5 @@ export interface ParkingGetterRepository {
* @param id * @param id
* @param options * @param options
*/ */
getHistoricalAveragesOfParkingStructureCounts(id: string, options: ParkingStructureCountOptions): Promise<HistoricalParkingAverageQueryResult[]>; getHistoricalAveragesOfParkingStructureCounts(id: string, options: HistoricalParkingAverageQueryArguments): Promise<HistoricalParkingAverageQueryResult[]>;
} }

View File

@@ -1,6 +1,6 @@
import { ParkingGetterSetterRepository } from "./ParkingGetterSetterRepository"; import { ParkingGetterSetterRepository } from "./ParkingGetterSetterRepository";
import { IParkingStructure } from "../../entities/ParkingRepositoryEntities"; import { IParkingStructure } from "../../entities/ParkingRepositoryEntities";
import { HistoricalParkingAverageQueryResult, ParkingStructureCountOptions } from "./ParkingGetterRepository"; import { HistoricalParkingAverageQueryResult, HistoricalParkingAverageQueryArguments } from "./ParkingGetterRepository";
import { BaseRedisRepository } from "../BaseRedisRepository"; import { BaseRedisRepository } from "../BaseRedisRepository";
import { PARKING_LOGGING_INTERVAL_MS } from "./ParkingRepositoryConstants"; import { PARKING_LOGGING_INTERVAL_MS } from "./ParkingRepositoryConstants";
@@ -75,7 +75,7 @@ export class RedisParkingRepository extends BaseRedisRepository implements Parki
return null; return null;
}; };
getHistoricalAveragesOfParkingStructureCounts = async (id: string, options: ParkingStructureCountOptions): Promise<HistoricalParkingAverageQueryResult[]> => { getHistoricalAveragesOfParkingStructureCounts = async (id: string, options: HistoricalParkingAverageQueryArguments): Promise<HistoricalParkingAverageQueryResult[]> => {
return this.calculateAveragesFromRecords(id, options); return this.calculateAveragesFromRecords(id, options);
}; };
@@ -157,7 +157,7 @@ export class RedisParkingRepository extends BaseRedisRepository implements Parki
private calculateAveragesFromRecords = async ( private calculateAveragesFromRecords = async (
id: string, id: string,
options: ParkingStructureCountOptions options: HistoricalParkingAverageQueryArguments
): Promise<HistoricalParkingAverageQueryResult[]> => { ): Promise<HistoricalParkingAverageQueryResult[]> => {
const keys = this.createRedisKeys(id); const keys = this.createRedisKeys(id);
const { from, to, intervalMs } = options; const { from, to, intervalMs } = options;

View File

@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals"; import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { InMemoryParkingRepository, } from "../../src/repositories/parking/InMemoryParkingRepository"; import { InMemoryParkingRepository, } from "../../src/repositories/parking/InMemoryParkingRepository";
import { IParkingStructure } from "../../src/entities/ParkingRepositoryEntities"; import { IParkingStructure } from "../../src/entities/ParkingRepositoryEntities";
import { ParkingStructureCountOptions } from "../../src/repositories/parking/ParkingGetterRepository"; import { HistoricalParkingAverageQueryArguments } from "../../src/repositories/parking/ParkingGetterRepository";
import { ParkingGetterSetterRepository } from "../../src/repositories/parking/ParkingGetterSetterRepository"; import { ParkingGetterSetterRepository } from "../../src/repositories/parking/ParkingGetterSetterRepository";
import { RedisParkingRepository } from "../../src/repositories/parking/RedisParkingRepository"; import { RedisParkingRepository } from "../../src/repositories/parking/RedisParkingRepository";
@@ -151,7 +151,7 @@ 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: HistoricalParkingAverageQueryArguments = {
from: new Date(1000), from: new Date(1000),
to: new Date(2000), to: new Date(2000),
intervalMs: 500 intervalMs: 500
@@ -182,7 +182,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
} }
const now = Date.now(); const now = Date.now();
const options: ParkingStructureCountOptions = { const options: HistoricalParkingAverageQueryArguments = {
from: new Date(now - 10000), // Look back 10 seconds from: new Date(now - 10000), // Look back 10 seconds
to: 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