Skip to content

Commit

Permalink
Merge pull request #148 from rl-institut/release/v0.7.0
Browse files Browse the repository at this point in the history
Release/v0.7.0
  • Loading branch information
henhuy authored Apr 9, 2020
2 parents 95fc739 + 48416d5 commit 6ce7642
Show file tree
Hide file tree
Showing 59 changed files with 1,804 additions and 1,673 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project tries to adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.0] - 2020-04-09
### Added
- real station data
- icons and images to landing page

### Changed
- timed display route to carousel
- Departure station can be changed
- category icons to filled and line icons
- Answer animation can be skipped

### Fixed
- First dashboard popup layout

## [0.6.0] - 2020-02-19
### Added
- Environment page.
Expand Down
4 changes: 4 additions & 0 deletions compose/local/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ RUN apk update \
# libsass dependencies
&& apk add g++

RUN pip install --no-cache-dir numpy
RUN pip install --no-cache-dir pandas
RUN pip install --no-cache-dir django-libsass==0.7

# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install -r /requirements/local.txt
Expand Down
4 changes: 4 additions & 0 deletions compose/production/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ RUN apk update \
RUN addgroup -S django \
&& adduser -S -G django django

RUN pip install --no-cache-dir numpy
RUN pip install --no-cache-dir pandas
RUN pip install --no-cache-dir django-libsass==0.7

# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install --no-cache-dir -r /requirements/production.txt \
Expand Down
27 changes: 22 additions & 5 deletions e_metrobus/navigation/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
TEXTSIZE = 5
TROPHY_OFFSET = 20

DEFAULT_COLOR = "Gainsboro"
E_BUS_COLOR = "black"

Sizes = namedtuple("Sizes", ["margin", "offset", "size", "textsize"])


Expand All @@ -36,8 +39,8 @@ def get_sizes(max_value):


def get_mobility_figure(values):
colors = ["Gainsboro"] * 5
colors[2] = "black"
colors = [DEFAULT_COLOR] * 5
colors[2] = E_BUS_COLOR
mobiles = ["Zu Fuß", "Fahrrad", "E-Bus", "Dieselbus", "PKW"]

max_value = max(values)
Expand All @@ -52,6 +55,7 @@ def get_mobility_figure(values):
width=0.6,
)
bar.textfont.size = 15
bar.textfont.color = E_BUS_COLOR
fig = go.Figure([bar])
fig.layout.margin.t = 0
fig.layout.margin.b = 0
Expand All @@ -61,14 +65,24 @@ def get_mobility_figure(values):
fig.layout.plot_bgcolor = "#fff"
fig.layout.xaxis.tickangle = -45
fig.layout.xaxis.tickfont.size = 15
fig.layout.font.family = "Roboto"
fig.layout.font.color = E_BUS_COLOR
fig.layout.yaxis.visible = False
fig.layout.yaxis.range = [-sizes.margin, max_value + sizes.margin]
fig.add_annotation(
x=0.5,
y=max_value,
text="CO2 Emissionen<br>nach Verkehrsmittel",
font={"size": 15, "color": E_BUS_COLOR},
align="left",
showarrow=False,
)

# Mobility icons:
for i, icon in enumerate(["pedestrian", "bike", "ebus", "bus", "car"]):
color = "gray"
if icon == "ebus":
color = "black"
color = "black_fill"
fig.add_layout_image(
go.layout.Image(
source=f"/static/images/icons/i_{icon}_{color}.svg",
Expand All @@ -82,10 +96,13 @@ def get_mobility_figure(values):
go.layout.Image(
source=f"/static/images/icons/i_trophy_{i+1}_{'black' if i == 2 else 'gray'}.svg",
x=i,
y=values[i] + sizes.textsize + sizes.size + sizes.offset + TROPHY_OFFSET,
y=values[i]
+ sizes.textsize
+ sizes.size
+ sizes.offset
+ TROPHY_OFFSET,
)
)

fig.update_layout_images(
{
"xref": "x",
Expand Down
18 changes: 6 additions & 12 deletions e_metrobus/navigation/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
ELLIPSE_X_OFFSET = 7
ELLIPSE_Y_OFFSET = 7

Consumption = namedtuple(
"Consumption", ["distance", "fuel", "co2", "nitrogen", "fine_dust"]
)

STATIONS = [
"Hertzallee",
"S+U Zoologischer Garten",
"S+U Zoologischer Garten/Jebensstr.",
"Breitscheidplatz",
"Budapester Str.",
]
FLEET_CONSUMPTION = Consumption(
distance=3000, fuel=200000, co2=300000, nitrogen=20000, fine_dust=10000
)


class Ellipse:
Expand All @@ -30,8 +29,3 @@ def __init__(self, share):

def __str__(self):
return f"M {ELLIPSE_RADIUS + ELLIPSE_X_OFFSET} {ELLIPSE_Y_OFFSET} A {ELLIPSE_RADIUS} {ELLIPSE_RADIUS} 0 {self.large} 1 {self.x} {self.y}"


Consumption = namedtuple(
"Consumption", ["distance", "fuel", "co2", "nitrogen", "fine_dust"]
)
12 changes: 8 additions & 4 deletions e_metrobus/navigation/questions.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

[e_metrobus]
label = "E-Metrobus"
icon = "images/icons/i_e_bus_black.svg"
icon = "images/icons/i_ebus_black_line.svg"
small_icon = "images/icons/i_ebus_black_fill.svg"
[[questions]]
[[[loading_time]]]
label = "Ladezeiten"
Expand All @@ -24,7 +25,8 @@

[environment]
label = "Umwelt"
icon = "images/icons/i_earth_black.svg"
icon = "images/icons/i_earth_black_line.svg"
small_icon = "images/icons/i_earth_black_fill.svg"
[[questions]]
[[[co2_reduction]]]
label = "CO2 Reduktion"
Expand All @@ -35,7 +37,8 @@

[politics]
label = "Politk"
icon = "images/icons/i_government_black.svg"
icon = "images/icons/i_government_black_line.svg"
small_icon = "images/icons/i_government_black_fill.svg"
[[questions]]
[[[ebus_time]]]
label = "Zeitplan"
Expand All @@ -46,7 +49,8 @@

[personal]
label = "Ich"
icon = "images/icons/i_person_black.svg"
icon = "images/icons/i_human_black_line.svg"
small_icon = "images/icons/i_human_black_fill.svg"
[[questions]]
[[[advantages]]]
label = "Vorteile"
Expand Down
2 changes: 2 additions & 0 deletions e_metrobus/navigation/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def get_label(self):
class Category:
label: str
icon: str
small_icon: str
questions: Dict[str, Question]

def get_label(self):
Expand All @@ -56,6 +57,7 @@ def get_label(self):
QUESTIONS[cat] = Category(
label=question_config[cat]["label"],
icon=question_config[cat]["icon"],
small_icon=question_config[cat]["small_icon"],
questions=questions,
)

Expand Down
29 changes: 29 additions & 0 deletions e_metrobus/navigation/stations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
,Hertzallee,S+U Zoologischer Garten,Breitscheidplatz,Budapester Str.,Corneliusbrücke,Nord.Botschaften/Adenauer-Stiftg,Tiergartenstr.,Philharmonie,Varian-Fry-Str./Potsdamer Platz,S+U Potsdamer Platz,Leipziger Str./Wilhelmstr.,U Stadtmitte/Leipziger Str.,Jerusalemer Str.,U Spittelmarkt,Fischerinsel,Berliner Rathaus,Spandauer Str./Marienkirche,S+U Alexanderplatz/Memhardstr.,Mollstr./Prenzlauer Allee,Mollstr./Otto-Braun-Str.,Am Friedrichshain,Bötzowstr.,Am Friedrichshain/Hufelandstr.,Kniprodestr./Danziger Str.,Conrad-Blenkle-Str.,Kniprodestr./Storkower Str.,Stedingerweg,Michelangelostr.
Hertzallee,,380,824,1520,1733,2083,2840,3419,3884,4143,4438,4893,5321,5772,6188,6825,7040,7511,8123,8487,8984,9278,9702,10029,10423,10968,11256,11820
S+U Zoologischer Garten,,,444,1140,1353,1703,2460,3039,3504,3763,4058,4513,4941,5392,5808,6445,6660,7131,7743,8107,8604,8898,9322,9649,10043,10588,10876,11440
Breitscheidplatz,,,,696,909,1259,2016,2595,3060,3319,3614,4069,4497,4948,5364,6001,6216,6687,7299,7663,8160,8454,8878,9205,9599,10144,10432,10996
Budapester Str.,,,,,213,563,1320,1899,2364,2623,2918,3373,3801,4252,4668,5305,5520,5991,6603,6967,7464,7758,8182,8509,8903,9448,9736,10300
Corneliusbrücke,,,,,,350,1107,1686,2151,2410,2705,3160,3588,4039,4455,5092,5307,5778,6390,6754,7251,7545,7969,8296,8690,9235,9523,10087
Nord.Botschaften/Adenauer-Stiftg,,,,,,,757,1336,1801,2060,2355,2810,3238,3689,4105,4742,4957,5428,6040,6404,6901,7195,7619,7946,8340,8885,9173,9737
Tiergartenstr.,,,,,,,,579,1044,1303,1598,2053,2481,2932,3348,3985,4200,4671,5283,5647,6144,6438,6862,7189,7583,8128,8416,8980
Philharmonie,,,,,,,,,465,724,1019,1474,1902,2353,2769,3406,3621,4092,4704,5068,5565,5859,6283,6610,7004,7549,7837,8401
Varian-Fry-Str./Potsdamer Platz,,,,,,,,,,259,554,1009,1437,1888,2304,2941,3156,3627,4239,4603,5100,5394,5818,6145,6539,7084,7372,7936
S+U Potsdamer Platz,,,,,,,,,,,295,750,1178,1629,2045,2682,2897,3368,3980,4344,4841,5135,5559,5886,6280,6825,7113,7677
Leipziger Str./Wilhelmstr.,,,,,,,,,,,,455,883,1334,1750,2387,2602,3073,3685,4049,4546,4840,5264,5591,5985,6530,6818,7382
U Stadtmitte/Leipziger Str.,,,,,,,,,,,,,428,879,1295,1932,2147,2618,3230,3594,4091,4385,4809,5136,5530,6075,6363,6927
Jerusalemer Str.,,,,,,,,,,,,,,451,867,1504,1719,2190,2802,3166,3663,3957,4381,4708,5102,5647,5935,6499
U Spittelmarkt,,,,,,,,,,,,,,,416,1053,1268,1739,2351,2715,3212,3506,3930,4257,4651,5196,5484,6048
Fischerinsel,,,,,,,,,,,,,,,,637,852,1323,1935,2299,2796,3090,3514,3841,4235,4780,5068,5632
Berliner Rathaus,,,,,,,,,,,,,,,,,215,686,1298,1662,2159,2453,2877,3204,3598,4143,4431,4995
Spandauer Str./Marienkirche,,,,,,,,,,,,,,,,,,471,1083,1447,1944,2238,2662,2989,3383,3928,4216,4780
S+U Alexanderplatz/Memhardstr.,,,,,,,,,,,,,,,,,,,612,976,1473,1767,2191,2518,2912,3457,3745,4309
Mollstr./Prenzlauer Allee,,,,,,,,,,,,,,,,,,,,364,861,1155,1579,1906,2300,2845,3133,3697
Mollstr./Otto-Braun-Str.,,,,,,,,,,,,,,,,,,,,,497,791,1215,1542,1936,2481,2769,3333
Am Friedrichshain,,,,,,,,,,,,,,,,,,,,,,294,718,1045,1439,1984,2272,2836
Bötzowstr.,,,,,,,,,,,,,,,,,,,,,,,424,751,1145,1690,1978,2542
Am Friedrichshain/Hufelandstr.,,,,,,,,,,,,,,,,,,,,,,,,327,721,1266,1554,2118
Kniprodestr./Danziger Str.,,,,,,,,,,,,,,,,,,,,,,,,,394,939,1227,1791
Conrad-Blenkle-Str.,,,,,,,,,,,,,,,,,,,,,,,,,,545,833,1397
Kniprodestr./Storkower Str.,,,,,,,,,,,,,,,,,,,,,,,,,,,288,852
Stedingerweg,,,,,,,,,,,,,,,,,,,,,,,,,,,,564
Michelangelostr.,,,,,,,,,,,,,,,,,,,,,,,,,,,,
91 changes: 91 additions & 0 deletions e_metrobus/navigation/stations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os
from dataclasses import dataclass, fields
from typing import Dict

import pandas
from django.conf import settings

STATIONS_FILE = os.path.join(settings.APPS_DIR, "navigation", "stations.csv")


@dataclass
class DataPerKilometer:
fuel: float
co2: float
nitrogen: float
fine_dust: float

def __mul__(self, value):
return DataPerKilometer(
*(getattr(self, dim.name) * value for dim in fields(self))
)


@dataclass
class Vehicle:
name: str
passengers: int
data: DataPerKilometer


VEHICLES = [
Vehicle(name="car", passengers=30, data=DataPerKilometer(14 / 100, 322, 34, 54)),
Vehicle(name="bus", passengers=30, data=DataPerKilometer(10 / 100, 200, 22, 40)),
Vehicle(name="e-bus", passengers=30, data=DataPerKilometer(5 / 100, 120, 10, 30)),
Vehicle(name="bicycle", passengers=30, data=DataPerKilometer(0, 0, 0, 0)),
Vehicle(name="pedestrian", passengers=30, data=DataPerKilometer(0, 0, 0, 0)),
]


class Stations:
def __init__(self, filename):
self.stations = pandas.read_csv(filename, index_col=0)
self.__init_stations()

def __init_stations(self):
# Mirror diagonal:
for i, station in enumerate(self.stations):
self.stations[station] = self.stations.iloc[i]

# Distances in meter -> kilometer:
self.stations = self.stations / 1000

@staticmethod
def __calc_route_data(km, vehicle):
return vehicle.data * vehicle.passengers * km

def get_stations(self):
return [station for station in self.stations]

def get_distance(self, from_station: str, to_station: str) -> float:
return self.stations[from_station][to_station]

def get_route_data(
self, from_station: str, to_station: str, vehicle=None
) -> Dict[str, DataPerKilometer]:
passenger_kilometer = self.get_distance(from_station, to_station)
return {
vehicle.name: self.__calc_route_data(passenger_kilometer, vehicle)
for vehicle in VEHICLES
}

def get_route_data_for_vehicle(
self, from_station: str, to_station: str, vehicle: str
) -> DataPerKilometer:
passenger_kilometer = self.get_distance(from_station, to_station)
i = 0
while i < len(VEHICLES):
if VEHICLES[i].name == vehicle:
return VEHICLES[i].data * VEHICLES[i].passengers * passenger_kilometer
i += 1
raise KeyError("Vehicle not found", vehicle)

def __getitem__(self, item):
return self.stations.index[item]


STATIONS = Stations(STATIONS_FILE)


if __name__ == "__main__":
print(STATIONS.get_route_data("Station C", "Station A"))
Loading

0 comments on commit 6ce7642

Please sign in to comment.