-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from rl-institut/release/v0.7.0
Release/v0.7.0
- Loading branch information
Showing
59 changed files
with
1,804 additions
and
1,673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.,,,,,,,,,,,,,,,,,,,,,,,,,,,, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |
Oops, something went wrong.