コード例 #1
0
def get_county_choropleth(start_datetime, end_datetime, output='json'):
    data = d.get_traffic_accident_by_date(start_datetime, end_datetime)['countyId']
    county_names = d.get_county()
    data = data.value_counts()
    data.index = data.index.map(lambda p: county_names.loc[p]['name'])
    zeroes = pd.Series(data=0, index=county_names.name)
    data = data + zeroes
    data = data.fillna(0)
    data = data.sort_values()
    df = pd.DataFrame(dict(county=data.index, count=data.values))
    
    geojson_file = os.path.join(os.path.dirname(__file__), 'regions_epsg_4326.geojson.txt')
    with open(geojson_file, encoding='utf-8') as file:
        geo_counties = json.loads(file.read())
    fig = px.choropleth(data_frame=df, geojson=geo_counties, featureidkey='properties.NM4', locations='county', color='count',
                           color_continuous_scale='tealrose',
                           range_color=(0, df['count'].mean()*2),
                           projection='sinusoidal', 
                           labels={'count':'Počet nehôd'},
                           hover_data={'county':False},
                           hover_name=df['county'])
    fig.update_geos(fitbounds="locations", visible=False)
    fig.update_layout(
            margin={"r":0,"t":0,"l":0,"b":0},
            paper_bgcolor='rgba(0,0,0,0)',
            plot_bgcolor='rgba(0,0,0,0)',
            geo=dict(bgcolor= 'rgba(0,0,0,0)'),
            coloraxis_showscale=False,
    )
    return plots.encode_plot(fig, output)
コード例 #2
0
def get_accident_scatter_map(data, output, zoom, center, size_max = None):
    if size_max is None:
        size_max = 50
    fig = px.scatter_mapbox(data, lat='latitude', lon='longitude',
                  mapbox_style="open-street-map", size='marker_size', size_max=size_max, opacity=0.8,
                  hover_data={'latitude':False, 'longitude':False, 'marker_size':False}, zoom=zoom, center = center)
    fig.update_layout(
            margin={"r":0,"t":0,"l":0,"b":0},
            paper_bgcolor='rgba(0,0,0,0)',
            plot_bgcolor='rgba(0,0,0,0)',
    )
    return plots.encode_plot(fig, output)
コード例 #3
0
def get_map_with_most_frequent_accidents_for_road(road_number, max_number_accidents_returned, start_datetime, end_datetime, start_km=0, end_km=999999999, output='json'):
    data = d.get_traffic_accident_by_date(start_datetime, end_datetime)
    data = data.loc[data.roadNumber == road_number]
    data = data.loc[(data.roadPosition >= start_km) & (data.roadPosition <= end_km)]
    fig = get_map_with_most_frequent_accidents(max_number_accidents_returned, data, 8)
    if data.size > 0:
        shape = d.get_road_shape(road_number)
        if shape is not None:
            shape_list = parse_shape_string(shape)
            shape_list = filter_shape(shape_list, start_km, end_km)
            for s in shape_list:
                fig.add_trace(go.Scattermapbox(
                    mode = 'lines',
                    line=dict(width=4, color="#006699"),
                    showlegend=False,
                    lon = s[1],
                    lat = s[0],
                    hoverinfo='skip'))
    return plots.encode_plot(fig, output)
コード例 #4
0
def get_map_with_most_frequent_accidents_for_country(max_number_accidents_returned, start_datetime, end_datetime, output='json'):
    data = d.get_traffic_accident_by_date(start_datetime, end_datetime)
    fig = get_map_with_most_frequent_accidents(max_number_accidents_returned, data, 6, center = {'lat':48.663863, 'lon':19.502998})
    return plots.encode_plot(fig, output)
コード例 #5
0
def get_map_with_most_frequent_accidents_for_district(district_id, max_number_accidents_returned, start_datetime, end_datetime, output='json'):
    data = d.get_traffic_accident_by_date(start_datetime, end_datetime)
    data = data.loc[data.districtId == district_id]
    fig = get_map_with_most_frequent_accidents(max_number_accidents_returned, data, 9.5)
    return plots.encode_plot(fig, output)