""" This module provide the functionality to create geomaps from given DataFrames
"""
import plotly.express as px
[docs]def get_map_stats_by_country(df, type="tweets"):
"""
Given a df it creates a figure with the tweet activity of the users stored in the database.
:param df: The DataFrame generated from dash_utils.get_map_df().
:param type: The type of activity (tweets or followers)
:return: The figure representing the activity.
"""
result = df.groupby(["iso_3", "continent", "country"])[type].sum().reset_index(name=type)
print(result)
fig = px.scatter_geo(result, locations="iso_3", width=1500, height=768,
color="continent",
hover_name="country",
size_max=50,
size=type # size of markers, "pop" is one of the columns of gapminder
)
print("crea figura")
return fig
[docs]def get_map_locations(df):
"""
Given a df it creates a figure with the tweet activity of the users stored in the database.
:param df: The DataFrame generated from dash_utils.get_map_df().
:return: The figure with the location of the users.
"""
test = df
test["country"] = test["country"].fillna(55)
fig = px.scatter_geo(df, lat="lat", lon="lon", width=1500, height=768,
color="country",
)
return fig