Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework #1

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .gitignore
100644 → 100755
Empty file.
14 changes: 10 additions & 4 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# TransportChamp

----------------
Repo for a very rudimentary website to display current
information about local transport for the hackerspace Port39
Repo for website to display current
information about local transport for the Hackerspace Port39

Using Apache2 for the server itself, planned to run on a
Raspberry Pi
Currently supported methods of transport supported are:
1. RE
2. ICE
3. IC
4. BUS
5. RUF

Major thanks to [Varbin](https://github.com/Varbin) who co-authored a lot of this
2 changes: 1 addition & 1 deletion TODO.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TODO:

- Add Departure from Wasserstraße to Arrivals so you
- Add the departures/arrivals from `locations.txt` so you
can actually get the time you will have to leave for
the bus
- CSS all the things
Expand Down
Empty file modified fonts/DepartureMono-1.346/DepartureMono-Regular.otf
100644 → 100755
Empty file.
Empty file modified fonts/DepartureMono-1.346/DepartureMono-Regular.woff
100644 → 100755
Empty file.
Empty file modified fonts/DepartureMono-1.346/DepartureMono-Regular.woff2
100644 → 100755
Empty file.
Empty file modified fonts/DepartureMono-1.346/LICENSE
100644 → 100755
Empty file.
Empty file modified fonts/DepartureMono-1.346/README.md
100644 → 100755
Empty file.
7 changes: 1 addition & 6 deletions index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
<link href="main.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<h2>Departures</h2>
<table class="information">
<tbody id="departTable"></tbody>
</table>
<h2>Arrivals</h2>
<table class="information">
<tbody id="arriveTable"></tbody>
</table>
<script src="main.js"></script>
<script src="main.mjs" type="module"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions locations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Ozeanum
Wasserstraße
Bahnhof
Bahnhof Rügendamm

70 changes: 61 additions & 9 deletions main.css
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,77 @@
}

:root {
font-family: "Departure Mono";
--lavender-web: #d8d8f6ff;
--rose-quartz: #978897ff;
--davys-gray: #494850ff;
--raisin-black: #2c2c34ff;
font-family: "Departure Mono", serif;

--foreground-color: black;
--background-color: #5e7b6f;
--font-size: 12pt;

color: var(--foreground-color);
background-color: var(--background-color);
font-size: var(--font-size);
}

table {
border-collapse: collapse;
}

.information {
width: 100%;
text-align: left;

tr td, tr th {
vertical-align: top;
line-height: 1.5;
padding: .5em;
}
tr td {
height: calc(2 * 1.5 * 1em);
}
}

.time {
text-align: right;
text-align: left;
width: 1em;

.actual {
font-weight: bold;
}
.planned, .delay {
font-size: 75%;
}
.delay {
color: red;
font-weight: bold;
background-color: var(--foreground-color);
padding: .5ex;
}
.delay::before {
content: "+"
}
}

td.time {
background-color: var(--foreground-color);
color: var(--background-color);
}

.line {
width: 10em;
width: 10ex;
text-align: left;
}

.direction {
width: auto;
text-align: left;
}

.platform {
width: 3em;
text-align: right;
}

.container {
height: 3em;
.cancelled .line, .cancelled .direction {
text-decoration: line-through;
color: red;
}
77 changes: 0 additions & 77 deletions main.js

This file was deleted.

21 changes: 21 additions & 0 deletions main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {formatConnections} from "./transchamp/display.mjs";
import {getDepartingConnections} from "./transchamp/api.mjs";
import {Stations} from "./transchamp/data.mjs";

/**
* Return all departing connections from a single given station
*
* @param {Stations} station
* @return {HTMLElement}
*/
async function getDepartingConnectionsFromStation(station) {
document.querySelector("body").replaceChildren(formatConnections(await getDepartingConnections(
station, {
duration: 600,
results: 10,
linesOfStops: false,
remarks: true,
})));
}

getDepartingConnectionsFromStation(Stations.Stralsund)
69 changes: 69 additions & 0 deletions transchamp/api.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {Connection} from "./data.mjs";

/**
* @typedef StopsParameters
* @type {object}
* @property {number} duration
* @property {number} results
* @property {boolean} linesOfStops
* @property {boolean} remarks
*/



/**
* Returns the departing connections of a station.
*
* @param {number} stationId Bahnhofs-/Haltestellenummer
* @param {StopsParameters} params API parameters to pass to the stations API
* @return {Promise<Connection[]>}
*/
export async function getDepartingConnections(stationId, params) {
const response = await getDepartures(stationId, params);
return response.map((departure) => {
return new Connection(
departure.line.name,
departure.line.productName,
departure.direction || departure.provenance || departure.destination.name,
new Date(departure.when), // Reales-when
new Date(departure.plannedWhen), // Fahrplan-when
departure.delay,
departure.platform,
departure.plannedPlatform,
departure.remarks,
)
})
}

// The following fluff might need major refactoring

/**
*
* @param {number} stationId
* @param {StopsParameters} params
* @returns {Promise<Object>}
*/
async function getDepartures(stationId, params) {
return (await queryStops("departures", stationId, params)).departures
}

/**
*
* @param {string} type
* @param {number} stationId
* @param {StopsParameters} params
* @returns {Promise<Object>}
*/
async function queryStops(type, stationId, params) {
const urlSearchParams = new URLSearchParams(
Object.entries(params).map((e) => {return [e[0].toString(), e[1].toString()]})
)
const url = `https://v6.db.transport.rest/stops/${stationId}/${type}?` + urlSearchParams.toString();
// duration=600&results=20&linesOfStops=false&remarks=true"
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Error: ${response.status}`);
}

return await response.json();
}
80 changes: 80 additions & 0 deletions transchamp/data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* A list of all our known stations
*
* @enum {number}
*/
export const Stations = {
Greifswald: 8010139,
Stralsund: 8010338,
Ruegendamm: 8013062,
Ozeaneum: 325666,
Wasserstrasse: 325719
}

/**
* All known methods of transport available from departing connections
*
* @enum {string}
*/
export const Transport = {
RE: "RE",
BUS: "Bus",
ICE: "ICE",
IC: "IC",
RUF: "RUF"
}

export class Connection {
/**
*
* @param {string} line
* @param {Transport} transportation
* @param {string} direction
* @param {Date} departure
* @param {Date} plannedDeparture
* @param {number} delay
* @param {string|null} platform
* @param {string|null} plannedPlatform
* @param {Remark[]} remarks
*/
constructor(line, transportation, direction, departure, plannedDeparture, delay, platform, plannedPlatform, remarks = []) {
this.line = line;
this.transport = transportation;
this.direction = direction;
this.departure = departure;
this.plannedDeparture = plannedDeparture;
this.delay = delay;
this.platform = platform;
this.plannedPlatform = plannedPlatform;
this.remarks = remarks;
}
}

/**
* All known remark strings that aren't null
*
* @enum {string}
*/
export const RemarkCode = {
Cancelled: "journey-cancelled",
Alternative: "alternative-trip",
}

export class Remark {
/**
* @param {string} type
* @param {RemarkCode|null} code
* @param {string} text
* @param {string|null} summary
*/
constructor(type, code, text, summary = null) {
this.type = type;
this.code = code;
this.text = text;
this.summary = summary;
}

static hasCancelled(remarks) {
return remarks.some((remark) => remark.code === RemarkCode.Cancelled)
}
}
Loading