Skip to content

Commit

Permalink
feat(GoTransitStops, Monitoring): Continue work on getting all Go Tra…
Browse files Browse the repository at this point in the history
…nsit API docs up, and start the base work for queueing and tracking platform allocation and other transit related shitz
  • Loading branch information
EntraptaJ committed Mar 13, 2023
1 parent 4916f8e commit 952271e
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- name: Start Redis Stack
init: docker compose --file ./docker-compose-dev.yaml up -d

- init: npm install && npm run build
command: npm run dev

Expand Down
8 changes: 8 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.9'

services:
redis:
container_name: redis
image: redis:latest
ports:
- 6379:6379
9 changes: 9 additions & 0 deletions src/Library/PlatformNotifyLab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// src/Library/PlatformNotifyLab.ts
/**
* This is just temp until I work out the actual design of the main system
*/
import { logger, LogMode } from "./Logger";

export async function monitorRoute(routeName: string): Promise<void> {
logger.log(LogMode.DEBUG, `Starting route monitoring system`);
}
20 changes: 18 additions & 2 deletions src/Modules/GoTransit/Stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@
import { Type } from 'class-transformer';
import { IsString } from 'class-validator';

export enum GoTransitStopType {
BUS = 'Bus Stop',
TRAIN = 'Train Station',
TRAINBUS = 'Train & Bus Station',
BUSTERMINAL = 'Bus Terminal',
PARKNRIDE = 'Park & Ride'
}

export class GoTransitStop {
@Type(() => String)
@IsString()
public Name: string;
public LocationCode: string;

@Type(() => String)
@IsString()
public LocationName: string;

@Type(() => String)
@IsString()
public PublicStopId: string;

public Code: string | null;
public LocationType: GoTransitStopType;
}
13 changes: 10 additions & 3 deletions src/Modules/GoTransit/UnionDeparture.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// src/Modules/GoTransit/Trips.ts
import { IsDate, IsNumber, IsString } from 'class-validator';
import { Type } from 'class-transformer';
import { GoTransitStop } from './Stop';

export class GoTransitUnionDepartureStop {
@Type(() => String)
@IsString()
public Name: string;

public Code: string | null;
}

export class GoTransitUnionDepartureTrip {
@Type(() => String)
Expand All @@ -28,6 +35,6 @@ export class GoTransitUnionDepartureTrip {
@IsDate()
public Time: Date;

@Type(() => GoTransitStop)
public Stops: GoTransitStop[];
@Type(() => GoTransitUnionDepartureStop)
public Stops: GoTransitUnionDepartureStop[];
}
28 changes: 28 additions & 0 deletions src/Modules/GoTransit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { plainToInstance } from 'class-transformer';
import got, { OptionsOfJSONResponseBody } from 'got';
import { CONFIG } from '../../Library/Config';
import { logger, LogMode } from '../../Library/Logger';
import { GoTransitStop, GoTransitStopType } from './Stop';
import { GoTransitTrainTrip } from './TrainTrip';
import { GoTransitUnionDepartureTrip } from './UnionDeparture';

Expand All @@ -19,6 +20,7 @@ interface APIMetadata {

ErrorMessage: string;
}

interface APIResponse {
Metadata: APIMetadata;
}
Expand Down Expand Up @@ -61,6 +63,12 @@ export class GoTransit {
return request.body;
}

/**
* Gets all the trains soon arriving at Union and the platform allocation
* if provided/same as the departure board/go tracker.
*
* @returns array of GoTransitUnionDepartureTrip
*/
public async unionDepartures(): Promise<GoTransitUnionDepartureTrip[]> {
const response = await this.makeRequest<
APIResponse & { AllDepartures: { Trip: GoTransitUnionDepartureTrip[] } }
Expand All @@ -72,11 +80,31 @@ export class GoTransit {
);
}


/**
* Function to get all active trains within the Go Transit network.
*
* @returns All active trains in Go Network
*/
public async getAllTrains(): Promise<GoTransitTrainTrip[]> {
const response = await this.makeRequest<
APIResponse & { Trips: { Trip: GoTransitUnionDepartureTrip[] } }
>('ServiceataGlance/Trains/All');

return plainToInstance(GoTransitTrainTrip, response.Trips.Trip);
}

/**
* Get all Go Transit Stops within the network
*
* @returns Array of all Go Transit Bus Stops,
* Bus Terminals, Bus & Train Stations, and Park & Ride Stops
*/
public async getAllStops(): Promise<GoTransitStop[]> {
const response = await this.makeRequest<
APIResponse & { Stations: { Station: GoTransitStop[] } }
>('Stop/All');

return plainToInstance(GoTransitStop, response.Stations.Station);
}
}
21 changes: 10 additions & 11 deletions src/Modules/User/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// src/Modules/User/index.ts
import { iCloudAPI, sendAlert } from "../../Library/iCloud";
import { logger, LogMode } from "../../Library/Logger";
import { iCloudAPI, sendAlert } from '../../Library/iCloud';
import { logger, LogMode } from '../../Library/Logger';

export class User {
public name: string;

public deviceID: string;


public async findUserNotifyDevice(deviceName: string): Promise<void> {
const findMyAPI = iCloudAPI.getService('findme');

await findMyAPI.refresh()
await findMyAPI.refresh();

for (const [deviceID, device] of findMyAPI.devices) {
logger.log(LogMode.DEBUG, `Looping over user Devices`, deviceID, device);

if (device.deviceInfo.name === deviceName) {
logger.log(LogMode.DEBUG, `Found device ${deviceName} with the ID of ${deviceID}`);
logger.log(
LogMode.DEBUG,
`Found device ${deviceName} with the ID of ${deviceID}`,
);

this.deviceID = deviceID;
}
Expand All @@ -27,10 +29,7 @@ export class User {
/**
* Sends notification to user via her Apple Watch Ultra
*/
public async notifyUser(options: {
subject?: string,
text?: string
}) {
await sendAlert(this.deviceID, options)
public async notifyUser(options: { subject?: string; text?: string }) {
await sendAlert(this.deviceID, options);
}
}
}
23 changes: 9 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
// src/index.ts
import 'reflect-metadata';
import { CONFIG } from './Library/Config';
import { initiCloud } from './Library/iCloud';
import { logger, LogMode } from './Library/Logger';
import { GoTransit } from './Modules/GoTransit';
import { User } from './Modules/User';
import { sayHello } from './Utils/sayHello';



logger.log(LogMode.INFO, `Starting TransitRouting`);

// logger.log(LogMode.INFO, `Init iCloud Library`);
// await initiCloud();

logger.log(LogMode.INFO, `Init iCloud Library`);
await initiCloud();

logger.log(LogMode.INFO, `Creating Kristine Entity`);
// logger.log(LogMode.INFO, `Creating Kristine Entity`);

const kristine = new User();
// const kristine = new User();

await kristine.findUserNotifyDevice(`Kristine’s Apple Watch`);
// await kristine.findUserNotifyDevice(`Kristine’s Apple Watch`);

await kristine.notifyUser({
subject: 'Platform Assignment',
text: 'Platform 6 & 7'
})
// await kristine.notifyUser({
// subject: 'Platform Assignment',
// text: 'Platform 6 & 7'
// })

const goAPI = new GoTransit({
apiURL: CONFIG.apiURL,
Expand Down

0 comments on commit 952271e

Please sign in to comment.