コード例 #1
0
def main(t_current):
    # Call the police API
    api = PoliceAPI()

    # Define tables
    crime_categories = pd.DataFrame({'id': [], 'description': []})
    outcome_categories = pd.DataFrame({'id': [], 'description': []})
    streets = pd.DataFrame({'id': [], 'name': []})
    crimes = pd.DataFrame({
        'persistent_id': [],
        'category': [],
        'street': [],
        'city': [],
        'latitude': [],
        'longitude': [],
        'date': [],
        'context': []
    })
    outcomes = pd.DataFrame({
        'crime': [],
        'category': [],
        'date': [],
        'person_id': []
    })

    # Transform dates into pandas Series for better manipulation
    dates = pd.Series(api.get_dates())

    # Get Forces
    forces = api.get_forces()
    # Get neighbourhoods
    neighbourhoods = [f.neighbourhoods for f in forces]
    nb_flat = [n for sublist in neighbourhoods for n in sublist]
    s_nb_flat = pd.Series(nb_flat).unique()

    first_job(api, dates, t_current)

    t_last_update = api.get_latest_date()
    second_job(api, dates, t_last_update, t_current)

    last_job(api, t_current)
コード例 #2
0
    'Drugs': 'Blue',
    'Bicycle theft': 'Green',
    'Criminal damage and arson': 'light yellow',
    'Other theft': 'light green',
    'Possession of weapons': 'cyan',
    'Public order': 'white',
    'Shoplifting': 'grey',
    'Theft from the person': 'light orange',
    'Vehicle crime': 'brown',
    'Other crime': 'light blue',
    'Robbery': 'Yellow'
}

police = PoliceAPI()
# Get the date range of data
dt_range = police.get_dates()


def format_date_range(date_range):
    month_dict = {
        1: 'Jan',
        2: 'Feb',
        3: 'Mar',
        4: 'Apr',
        5: 'May',
        6: 'Jun',
        7: 'Jul',
        8: 'Aug',
        9: 'Sep',
        10: 'Oct',
        11: 'Nov',