create_contours_for_station()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 18
rs 9.2
1
#!/usr/bin/env python3
2
3
import sys
4
import os
5
6
import numpy
7
8
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9
sys.path.append(parentdir)
10
11
import nsmaps
12
from nsmaps.logger import logger
13
14
15
DATA_DIR = './website/nsmaps-data'
16
17
18
def test():
19
    stations = nsmaps.station.Stations(DATA_DIR)
20
21
    departure_station_name = 'Utrecht Centraal'
22
    departure_station = stations.find_station(departure_station_name)
23
    assert os.path.exists(os.path.join(DATA_DIR, 'contours/'))
24
25
    # test_config = nsmaps.contourmap.ContourPlotConfig()
26
    test_config = nsmaps.contourmap.TestConfig()
27
    test_config.print_bounding_box()
28
29
    create_contours_for_station(departure_station, stations, test_config, overwrite_existing=True)
30
31
32
def create_contours_for_station(departure_station, stations, config, overwrite_existing=False, use_saved_data=False):
33
    logger.info(departure_station)
34
    max_level = 180
35
    filepaths = []
36
    contourmap = nsmaps.contourmap.Contour(departure_station, stations, config)
37
38
    filepath_geojson = os.path.join(DATA_DIR, 'contours/' + departure_station.get_code() + '.geojson')
39
    if not overwrite_existing and os.path.exists(filepath_geojson):
40
        print('WARNING: skipping station ' + departure_station.get_code() + ', files already exist.')
41
        return
42
    filepaths.append(filepath_geojson)
43
    if use_saved_data:
44
        contourmap.load()
45
    else:
46
        contourmap.create_contour_data()
47
        contourmap.save()
48
    levels_minor = numpy.linspace(0, max_level, num=37)
49
    contourmap.create_geojson(filepath_geojson, stroke_width=4, levels=levels_minor, overwrite=overwrite_existing)
50
51
52
def create_all():
53
    stations = nsmaps.station.Stations(DATA_DIR)
54
55
    # config = nsmaps.contourmap.TestConfig()
56
    config = nsmaps.contourmap.ContourPlotConfig()
57
58
    for departure_station in stations:
59
        if departure_station.has_travel_time_data():
60
            # if departure_station.get_type() == 'megastation':
61
            create_contours_for_station(departure_station, stations, config, overwrite_existing=False, use_saved_data=False)
62
63
64
if __name__ == "__main__":
65
    # test()
66
    create_all()