Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Jul 7, 2024
2 parents 700d772 + b7591b2 commit 7d69ed7
Show file tree
Hide file tree
Showing 51 changed files with 707 additions and 65 deletions.
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,41 @@ The folder for audio files can be found at `audio/`.
the National Rail Journey Planner.
- _For example, Brighton should be `BTN.mp3`._

### Website contributions
### Running the website locally

This site is created with the React Framework using Gatsby. If you're not familiar with React or Gatsby, you may want to research them before
contributing.
You'll need to install [Node.js](https://nodejs.org/en) and the [Yarn package manager](https://yarnpkg.com/getting-started/install) as
prerequisites.

**Set up dev environment:**
When you've cloned the repository, install the required dependencies with Yarn:

```
git clone https://github.com/davwheat/rail-announcements
```bash
yarn install
yarn start
```

**Before committing your changes, format your code:**
Then you can start the three (yes, three) development services:

```bash
# In one terminal, run (for the website):
yarn run develop

# When this says "You can now view rail-announcements in the browser.", open a new terminal and run (for the live trains API):
yarn run develop:workers

# Finally, open a new terminal and run (to serve the audio files):
yarn run serve-audio
```

You'll be able to access the website at [http://local.davw.network:8787](http://local.davw.network:8787). `local.davw.network` is a domain that
will always resolve to your local machine, and is used to ensure that the website works correctly with the audio files and backend API during
local development.

### Website contributions

This site is created with the React Framework using Gatsby. If you're not familiar with React or Gatsby, you may want to research them before
contributing.

**Before committing your changes, format your code:**

```bash
yarn run format
```
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
],
"scripts": {
"develop": "gatsby develop",
"develop:workers": "wrangler pages dev --proxy 8000",
"develop:workers": "wrangler pages dev --proxy 8000 --port 8787",
"start": "gatsby develop",
"build": "gatsby build",
"build:ci": "cross-env NODE_ENV=production gatsby build --verbose && (yarn run sentry:sourcemaps || true)",
"serve": "yarn wrangler pages dev public/",
"clean": "gatsby clean",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,less,mdx}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md,less,mdx}\"",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org davw-network --project rail-announcements-web ./public && sentry-cli --url https://sentry.service.davw.network sourcemaps upload --org davw-network --project rail-announcements-web ./public"
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org davw-network --project rail-announcements-web ./public && sentry-cli --url https://sentry.service.davw.network sourcemaps upload --org davw-network --project rail-announcements-web ./public",
"serve-audio": "http-server ./audio/ -c-1 --port 8088 --cors"
},
"dependencies": {
"@cfworker/json-schema": "^1.12.8",
Expand Down Expand Up @@ -74,6 +75,7 @@
"@types/uuid": "^9.0.8",
"cross-env": "^7.0.3",
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.32",
"http-server": "^14.1.1",
"prettier": "^3.3.2",
"typescript": "^5.4.5",
"wrangler": "^3.60.3"
Expand Down
6 changes: 5 additions & 1 deletion src/announcement-data/AnnouncementSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ export interface CustomAnnouncementTab<OptionIds extends string> {
| 'getPersonalPresets'
| 'deletePersonalPreset'
| 'system'
| 'defaultState'
>
| ICustomButtonPaneProps
defaultState: Record<OptionIds, any>
}

export type CustomAnnouncementButton = {
Expand Down Expand Up @@ -147,11 +149,13 @@ export default abstract class AnnouncementSystem {
return null
}

private readonly AUDIO_CDN = process.env.NODE_ENV === 'development' ? 'http://local.davw.network:8088' : 'https://cdn.railannouncements.co.uk'

/**
* Generates a URL for the provided audio file ID.
*/
generateAudioFileUrl(fileId: string, customPrefix?: string): string {
return `https://cdn.railannouncements.co.uk/${customPrefix || this.FILE_PREFIX}/${this.processAudioFileId(fileId).replace(/\./g, '/')}.mp3`
return `${this.AUDIO_CDN}/${customPrefix || this.FILE_PREFIX}/${this.processAudioFileId(fileId).replace(/\./g, '/')}.mp3`
}

/**
Expand Down
60 changes: 54 additions & 6 deletions src/announcement-data/systems/stations/AmeyCelia.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICustomAnnouncementPreset } from '@components/PanelPanes/CustomAnnouncementPane'
import AmeyPhil, { ChimeType, INextTrainAnnouncementOptions } from './AmeyPhil'
import AmeyPhil, { ChimeType } from './AmeyPhil'
import DelayCodeMapping from './DarwinDelayCodes_Female1.json'
import NamedServices from './named-services.json'

import type { CustomAnnouncementButton } from '@announcement-data/AnnouncementSystem'

Expand Down Expand Up @@ -37,6 +37,10 @@ export default class AmeyCelia extends AmeyPhil {
nowStandingAtId: 's.the train now standing at platform',
}

protected readonly shortPlatformOptions = {
unknownLocation: 'w.please listen for further on train announcements',
}

get DEFAULT_CHIME(): ChimeType {
return 'three'
}
Expand Down Expand Up @@ -219,6 +223,27 @@ export default class AmeyCelia extends AmeyPhil {
'Eurostar',
'Govia',
'Great North Eastern Railway',
'Great Western Railway Atlantic Coast Express',
'Great Western Railway Bristolian',
'Great Western Railway Cathedrals Express',
'Great Western Railway Cheltenham Flier',
'Great Western Railway Cheltenham Spa Express',
'Great Western Railway Cornish Riviera',
'Great Western Railway Devon Belle',
'Great Western Railway Devon Express',
'Great Western Railway Golden Hind',
'Great Western Railway Hibernian',
'Great Western Railway High Speed',
'Great Western Railway Intercity',
'Great Western Railway Mayflower',
'Great Western Railway Merchant Venturer',
'Great Western Railway Night Riviera',
'Great Western Railway Pembroke Coast Express',
'Great Western Railway Red Dragon',
'Great Western Railway Royal Duchy',
'Great Western Railway Royal Wessex',
'Great Western Railway St David',
'Great Western Railway Torbay Express',
'Island Line',
'LTS Rail',
'Merseyside Electrics',
Expand Down Expand Up @@ -3120,7 +3145,14 @@ export default class AmeyCelia extends AmeyPhil {
thisStationAudio: 'e.this station',
}

processTocForLiveTrains(tocName: string, tocCode: string, originCrs: string, destinationCrs: string, useLegacy: boolean): string {
processTocForLiveTrains(
tocName: string,
tocCode: string,
originCrs: string,
destinationCrs: string,
useLegacy: boolean,
trainUid: string,
): string {
if (useLegacy) {
switch (tocCode.toUpperCase()) {
case 'AW':
Expand All @@ -3142,6 +3174,12 @@ export default class AmeyCelia extends AmeyPhil {
case 'GR':
return 'national express east coast'
case 'GW':
const namedMatch = Object.entries(NamedServices.GW.services)
.find(([_, uids]) => uids.includes(trainUid))?.[0]
?.toLowerCase()

if (namedMatch && this.ALL_AVAILABLE_TOCS.includes(`first great western ${namedMatch}`)) return `first great western ${namedMatch}`

return 'first great western'
case 'GX':
return 'gatwick express'
Expand Down Expand Up @@ -3194,13 +3232,20 @@ export default class AmeyCelia extends AmeyPhil {
}

switch (tocCode.toUpperCase()) {
default:
return this.ALL_AVAILABLE_TOCS.find(t => t?.toLowerCase() === tocName?.toLowerCase()) ?? ''

// LNER has different filename compared to TOC name
case 'GR':
return 'london north eastern railway'

// Handle named GWR services
case 'GW':
const namedMatch = Object.entries(NamedServices.GW.services)
.find(([_, uids]) => uids.includes(trainUid))?.[0]
?.toLowerCase()

if (namedMatch && this.ALL_AVAILABLE_TOCS.includes(`first great western ${namedMatch}`)) return `first great western ${namedMatch}`

return 'great western railway'

// West Midlands Trains
case 'LM':
// https://www.westmidlandsrailway.co.uk/media/3657/download?inline
Expand All @@ -3210,6 +3255,9 @@ export default class AmeyCelia extends AmeyPhil {
} else {
return 'west midlands railway'
}

default:
return this.ALL_AVAILABLE_TOCS.find(t => t?.toLowerCase() === tocName?.toLowerCase()) ?? ''
}
}

Expand Down
Loading

0 comments on commit 7d69ed7

Please sign in to comment.