module velib.data_jcdecaux

Inheritance diagram of manydataapi.velib.data_jcdecaux

Short summary

module manydataapi.velib.data_jcdecaux

The file contains a class which collects data coming from :epkg:`Velib`.

source on GitHub

Classes

class

truncated documentation

DataCollectJCDecaux

This class automates data collecting from JCDecaux. The service is provided at JCDecaux developer. …

Static Methods

staticmethod

truncated documentation

animation

Displays a javascript animation, see animation.FuncAnimation. …

distance_haversine

Computes the haversine distance.

draw

Draws a graph using four columns: lng, lat, available_bike_stands, available_bikes.

run_collection

Runs the collection of the data for velib, data are stored using json format. The function creates a file …

simulate

Simulates velibs on a set of stations given by df.

to_df

Reads all files in a folder (assuming there were produced by this class) and returns a dataframe with it.

Methods

method

truncated documentation

__init__

collecting_data

Collects data for a period of time.

get_contracts

Returns the list of contracts.

get_json

Returns the data associated to a contract.

Documentation

The file contains a class which collects data coming from :epkg:`Velib`.

source on GitHub

class manydataapi.velib.data_jcdecaux.DataCollectJCDecaux(apiKey, fetch_contracts=False)

Bases: object

This class automates data collecting from JCDecaux. The service is provided at JCDecaux developer.

See also notebook on Velib The list of contracts for JCDecaux can be obtained at: Données statiques. The API provided by JCDecaux is described here.

Simple code to fetch velib data

private_key = 'your_key'

from manydataapi.velib import DataCollectJCDecaux
DataCollectJCDecaux.run_collection(private_key, contract="besancon",
            delayms=30000, single_file=False, stop_datetime=None,
            log_every=1)

source on GitHub

Parameters:
  • apiKey – api key

  • fetch_contracts – if True, it uses a short list of known contracts, otherwise, it will updated through the website API

source on GitHub

__init__(apiKey, fetch_contracts=False)
Parameters:
  • apiKey – api key

  • fetch_contracts – if True, it uses a short list of known contracts, otherwise, it will updated through the website API

source on GitHub

_contracts_static = {'arcueil': 1, 'besancon': 1, 'lyon': 1, 'nancy': 1}

list of available cities = contract (subset)

_url_api = 'https://api.jcdecaux.com/vls/v1/stations?contract=%s&apiKey=%s'
_url_apic = 'https://api.jcdecaux.com/vls/v1/contracts?apiKey=%s'
static animation(df, interval=20, module='matplotlib', **args)

Displays a javascript animation, see animation.FuncAnimation.

Parameters:
  • df – dataframe

  • interval

    see animation.FuncAnimation

  • module – module to build the animation

  • args – other parameters to give method plt.figure

Returns:

animation

Available modules for animation:

Additional arguments:

  • size: size of scatter plots

  • duration: if module is ‘moviepy’, duration of the animation

source on GitHub

collecting_data(contract, delayms=1000, outfile='velib_data.txt', single_file=True, stop_datetime=None, log_every=10, fLOG=<built-in function print>)

Collects data for a period of time.

Parameters:
  • contract – contract name, _contracts

  • delayms – delay between two collections (in ms)

  • outfile – write data in this file (json), if single_file is True, outfile is used as a prefix

  • single_file – if True, one file, else, many files with timestamp as a suffix

  • stop_datetime – if None, never stops, else stops when the date is reached

  • log_every – print something every <log_every> times data were collected

  • fLOG – logging function (None to disable)

Returns:

list of created file

source on GitHub

static distance_haversine(lat1, lon1, lat2, lon2)

Computes the haversine distance.

Returns:

double

source on GitHub

static draw(df, use_folium=False, **args)

Draws a graph using four columns: lng, lat, available_bike_stands, available_bikes.

Parameters:
  • df – dataframe

  • args – other parameters to give method plt.subplots or :epkg:`folium`

  • use_folium – use folium to create the map

Returns:

fig, ax, plt, (fig,ax) comes plt.subplot, plt is matplotlib.pyplot

Additional parameters:

  • size: change the size of points

source on GitHub

get_contracts()

Returns the list of contracts.

Returns:

dictionary, something like {'station': 1}

source on GitHub

get_json(contract)

Returns the data associated to a contract.

Parameters:

contract – contract name, _contracts

Returns:

json string

source on GitHub

static run_collection(key=None, contract='Paris', delayms=60000, folder_file='velib_data', stop_datetime=None, single_file=False, log_every=1, fLOG=<built-in function print>)

Runs the collection of the data for velib, data are stored using json format. The function creates a file every time a new status is downloaded.

Parameters:
  • key – (str|None), not implemented if None

  • contract – a city

  • delayms – gets a status every delayms milliseconds

  • folder_file – prefix used to create one file or several, it depends on single_file) where to place downloaded files)

  • stop_datetime – (datetime) stop when this datetime is reached or None for never stops

  • single_file – if True, every json status will be stored in a single file, if False, it will be a different file each time, if True, then folder_file is a file

  • log_every – log some information every 1 (minutes)

  • fLOG – logging function (None to disable)

collect Velib data

The following example produces a file every minute in json format about the status of all Velib stations in Paris. They will be put in a folder call velib_data.

from manydataapi.velib.data_jcdecaux import DataCollectJCDecaux
DataCollectJCDecaux.run_collection(private_key, contract="Paris",
            delayms=60000, single_file=False, stop_datetime=None,
            log_every=1)

source on GitHub

static simulate(df, nbbike, speed, period=datetime.timedelta(seconds=60), iteration=500, min_min=10, delta_speed=2.5, fLOG=<built-in function print>)

Simulates velibs on a set of stations given by df.

Parameters:
  • df – dataframe with station information

  • nbbike – number of bicycles

  • period – period

  • speed – average speed (in km/h)

  • iteration – number of iterations

  • min_min – minimum duration of a trip

  • delta_speed – allowed speed difference

  • fLOG – logging function

Returns:

simulated paths, data (as DataFrame)

source on GitHub

static to_df(folder, regex='velib_data.*[.]txt')

Reads all files in a folder (assuming there were produced by this class) and returns a dataframe with it.

Parameters:
  • folder – folder where to find the files

  • regex – regular expression which filter the files

Returns:

pandas DataFrame

Each file is a status of all stations, a row per station will be added to the file. It produces a table with the following columns:

  • address

  • available_bike_stands

  • available_bikes

  • banking

  • bike_stands

  • bonus

  • collect_date

  • contract_name

  • last_update

  • lat

  • lng

  • name

  • number

  • status

  • file

source on GitHub