Skip to content

Commit 952271e

Browse files
committed
feat(GoTransitStops, Monitoring): Continue work on getting all Go Transit API docs up, and start the base work for queueing and tracking platform allocation and other transit related shitz
1 parent 4916f8e commit 952271e

8 files changed

Lines changed: 95 additions & 30 deletions

File tree

.gitpod.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart
66

77
tasks:
8+
- name: Start Redis Stack
9+
init: docker compose --file ./docker-compose-dev.yaml up -d
10+
811
- init: npm install && npm run build
912
command: npm run dev
1013

docker-compose-dev.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '3.9'
2+
3+
services:
4+
redis:
5+
container_name: redis
6+
image: redis:latest
7+
ports:
8+
- 6379:6379

src/Library/PlatformNotifyLab.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// src/Library/PlatformNotifyLab.ts
2+
/**
3+
* This is just temp until I work out the actual design of the main system
4+
*/
5+
import { logger, LogMode } from "./Logger";
6+
7+
export async function monitorRoute(routeName: string): Promise<void> {
8+
logger.log(LogMode.DEBUG, `Starting route monitoring system`);
9+
}

src/Modules/GoTransit/Stop.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22
import { Type } from 'class-transformer';
33
import { IsString } from 'class-validator';
44

5+
export enum GoTransitStopType {
6+
BUS = 'Bus Stop',
7+
TRAIN = 'Train Station',
8+
TRAINBUS = 'Train & Bus Station',
9+
BUSTERMINAL = 'Bus Terminal',
10+
PARKNRIDE = 'Park & Ride'
11+
}
12+
513
export class GoTransitStop {
614
@Type(() => String)
715
@IsString()
8-
public Name: string;
16+
public LocationCode: string;
17+
18+
@Type(() => String)
19+
@IsString()
20+
public LocationName: string;
21+
22+
@Type(() => String)
23+
@IsString()
24+
public PublicStopId: string;
925

10-
public Code: string | null;
26+
public LocationType: GoTransitStopType;
1127
}

src/Modules/GoTransit/UnionDeparture.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// src/Modules/GoTransit/Trips.ts
22
import { IsDate, IsNumber, IsString } from 'class-validator';
33
import { Type } from 'class-transformer';
4-
import { GoTransitStop } from './Stop';
4+
5+
export class GoTransitUnionDepartureStop {
6+
@Type(() => String)
7+
@IsString()
8+
public Name: string;
9+
10+
public Code: string | null;
11+
}
512

613
export class GoTransitUnionDepartureTrip {
714
@Type(() => String)
@@ -28,6 +35,6 @@ export class GoTransitUnionDepartureTrip {
2835
@IsDate()
2936
public Time: Date;
3037

31-
@Type(() => GoTransitStop)
32-
public Stops: GoTransitStop[];
38+
@Type(() => GoTransitUnionDepartureStop)
39+
public Stops: GoTransitUnionDepartureStop[];
3340
}

src/Modules/GoTransit/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { plainToInstance } from 'class-transformer';
33
import got, { OptionsOfJSONResponseBody } from 'got';
44
import { CONFIG } from '../../Library/Config';
55
import { logger, LogMode } from '../../Library/Logger';
6+
import { GoTransitStop, GoTransitStopType } from './Stop';
67
import { GoTransitTrainTrip } from './TrainTrip';
78
import { GoTransitUnionDepartureTrip } from './UnionDeparture';
89

@@ -19,6 +20,7 @@ interface APIMetadata {
1920

2021
ErrorMessage: string;
2122
}
23+
2224
interface APIResponse {
2325
Metadata: APIMetadata;
2426
}
@@ -61,6 +63,12 @@ export class GoTransit {
6163
return request.body;
6264
}
6365

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

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

8094
return plainToInstance(GoTransitTrainTrip, response.Trips.Trip);
8195
}
96+
97+
/**
98+
* Get all Go Transit Stops within the network
99+
*
100+
* @returns Array of all Go Transit Bus Stops,
101+
* Bus Terminals, Bus & Train Stations, and Park & Ride Stops
102+
*/
103+
public async getAllStops(): Promise<GoTransitStop[]> {
104+
const response = await this.makeRequest<
105+
APIResponse & { Stations: { Station: GoTransitStop[] } }
106+
>('Stop/All');
107+
108+
return plainToInstance(GoTransitStop, response.Stations.Station);
109+
}
82110
}

src/Modules/User/index.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
// src/Modules/User/index.ts
2-
import { iCloudAPI, sendAlert } from "../../Library/iCloud";
3-
import { logger, LogMode } from "../../Library/Logger";
2+
import { iCloudAPI, sendAlert } from '../../Library/iCloud';
3+
import { logger, LogMode } from '../../Library/Logger';
44

55
export class User {
66
public name: string;
77

88
public deviceID: string;
99

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

14-
await findMyAPI.refresh()
13+
await findMyAPI.refresh();
1514

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

1918
if (device.deviceInfo.name === deviceName) {
20-
logger.log(LogMode.DEBUG, `Found device ${deviceName} with the ID of ${deviceID}`);
19+
logger.log(
20+
LogMode.DEBUG,
21+
`Found device ${deviceName} with the ID of ${deviceID}`,
22+
);
2123

2224
this.deviceID = deviceID;
2325
}
@@ -27,10 +29,7 @@ export class User {
2729
/**
2830
* Sends notification to user via her Apple Watch Ultra
2931
*/
30-
public async notifyUser(options: {
31-
subject?: string,
32-
text?: string
33-
}) {
34-
await sendAlert(this.deviceID, options)
32+
public async notifyUser(options: { subject?: string; text?: string }) {
33+
await sendAlert(this.deviceID, options);
3534
}
36-
}
35+
}

src/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
// src/index.ts
22
import 'reflect-metadata';
33
import { CONFIG } from './Library/Config';
4-
import { initiCloud } from './Library/iCloud';
54
import { logger, LogMode } from './Library/Logger';
65
import { GoTransit } from './Modules/GoTransit';
7-
import { User } from './Modules/User';
86
import { sayHello } from './Utils/sayHello';
97

10-
11-
128
logger.log(LogMode.INFO, `Starting TransitRouting`);
139

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

15-
logger.log(LogMode.INFO, `Init iCloud Library`);
16-
await initiCloud();
17-
18-
logger.log(LogMode.INFO, `Creating Kristine Entity`);
13+
// logger.log(LogMode.INFO, `Creating Kristine Entity`);
1914

20-
const kristine = new User();
15+
// const kristine = new User();
2116

22-
await kristine.findUserNotifyDevice(`Kristine’s Apple Watch`);
17+
// await kristine.findUserNotifyDevice(`Kristine’s Apple Watch`);
2318

24-
await kristine.notifyUser({
25-
subject: 'Platform Assignment',
26-
text: 'Platform 6 & 7'
27-
})
19+
// await kristine.notifyUser({
20+
// subject: 'Platform Assignment',
21+
// text: 'Platform 6 & 7'
22+
// })
2823

2924
const goAPI = new GoTransit({
3025
apiURL: CONFIG.apiURL,

0 commit comments

Comments
 (0)