%run startup.ipy
def event_places(band_mbid):
df = sql("""
SELECT e.name AS event_name,
p.name AS place_name,
p.coordinates,
to_date(to_char(e.begin_date_year, '9999') ||
to_char(e.begin_date_month, '99') ||
to_char(e.begin_date_day, '99'), 'YYYY MM DD') AS start,
to_date(to_char(e.end_date_year, '9999') ||
to_char(e.end_date_month, '99') ||
to_char(e.end_date_day, '99'), 'YYYY MM DD') AS end,
e.gid AS mbid
FROM event AS e
JOIN l_artist_event AS lae ON e.id = lae.entity1
JOIN artist AS a ON a.id = lae.entity0
JOIN l_event_place AS lep ON e.id = lep.entity0
JOIN place AS p ON p.id = lep.entity1
WHERE a.gid = %(band_mbid)s
AND p.coordinates IS NOT NULL
;""", band_mbid=band_mbid)
df['lat'] = df.coordinates.apply(lambda t: eval(t)[0])
df['lon'] = df.coordinates.apply(lambda t: eval(t)[1])
df.drop('coordinates', axis=1, inplace=True)
return df
band_mbid = 'a74b1b7f-71a5-4011-9441-d0b5e4122711' # Radiohead
events = event_places(band_mbid)
events.head()
iplot({'data': [{'lat': events.lat,
'lon': events.lon,
'text': events.event_name,
'type': 'scattergeo',
}],
'layout': {'geo': {'showland': True,
'showcountries': True,
'projection': {'type': 'stereographic'},
},
'title': 'Radiohead events by place',
}
})