Skip to content

Commit

Permalink
Remove occupancy from output
Browse files Browse the repository at this point in the history
The occupancy isn't provided anymore by the API since 2017:
OpendataCH/Transport#163

Since we now have more space available, I renamed the "Chg." column to
"Changes".
  • Loading branch information
dbrgn committed Oct 17, 2024
1 parent 251c7be commit 84e4b87
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 24 deletions.
21 changes: 1 addition & 20 deletions fahrplan/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
import sys
from .helpers import perror

occupancies = {
None: '',
-1: '',
0: 'Low', # todo check
1: 'Low',
2: 'Medium',
3: 'High',
}
API_URL = 'http://transport.opendata.ch/v1'


Expand Down Expand Up @@ -68,15 +60,6 @@ def _parse_section(con_section, connection):
section['arrival'] = dateutil.parser.parse(arrival['arrival'])
section['platform_from'] = "" if walk else departure['platform']
section['platform_to'] = arrival['platform']
if walk:
section['occupancy1st'] = ''
section['occupancy2nd'] = ''
elif journey:
section['occupancy1st'] = occupancies.get(con_section['journey']['capacity1st'], '')
section['occupancy2nd'] = occupancies.get(con_section['journey']['capacity2nd'], '')
else:
section['occupancy1st'] = occupancies.get(connection['capacity1st'], '')
section['occupancy2nd'] = occupancies.get(connection['capacity2nd'], '')
return section


Expand Down Expand Up @@ -107,8 +90,6 @@ def keyfunc(s):
in connection['sections']
if section['journey'] is not None
)
data['occupancy1st'] = occupancies.get(connection['capacity1st'], '')
data['occupancy2nd'] = occupancies.get(connection['capacity2nd'], '')

# Sections
con_sections = sorted(connection['sections'], key=keyfunc)
Expand All @@ -127,7 +108,7 @@ def keyfunc(s):
for p in ["station_to", "arrival"]:
section[p] = to[p]
# Get information from connection
for p in ["occupancy2nd", "occupancy1st", "travelwith", "change_count"]:
for p in ["travelwith", "change_count"]:
section[p] = data[p]
data['sections'] = [section]

Expand Down
4 changes: 1 addition & 3 deletions fahrplan/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def _get_connection_row(i, connection):
lambda x: [str((x['arrival'] - x['departure'])).rsplit(':', 1)[0], ' '], # Duration
None,
lambda x: [x['travelwith'], ' '], # With
lambda x: ['1: ' + x['occupancy1st'], '2: ' + x['occupancy2nd']] # Occupancy
]:
if p is None:
row.append(connection['change_count'])
Expand All @@ -46,9 +45,8 @@ def connectionsTable(connections, output_format):
table.add_column("Date", justify="left", vertical="top")
table.add_column("Time", justify="left", vertical="top")
table.add_column("Duration", justify="center", vertical="top")
table.add_column("Chg.", justify="center", vertical="middle")
table.add_column("Changes", justify="center", vertical="middle")
table.add_column("With", justify="left", vertical="top")
table.add_column("Occupancy", justify="left", vertical="top")
# Connection rows
for i, connection in enumerate(connections):
table.add_row(*_get_connection_row(i, connection))
Expand Down
2 changes: 1 addition & 1 deletion fahrplan/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def testRowCount(self):
def testHeadline(self):
"""Test the headline items."""
headline_items = ['Station', 'Platform', 'Date', 'Time',
'Duration', 'Chg.', 'With', 'Occupancy']
'Duration', 'Changes', 'With']
for item in headline_items:
self.assertIn(item, self.rows[1])

Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 84e4b87

Please sign in to comment.