From 12c89a87ebf341c832c20ceab1970539806dfe4f Mon Sep 17 00:00:00 2001 From: Alberto Rodriguez Sanchez Date: Aug 07 2020 02:17:39 +0000 Subject: Migrating the plot_world2 method to the new Plotty API --- diff --git a/.gitignore b/.gitignore index ac1b38a..809835e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.csv +*.html *.cfg *.svg __pycache__ .vscode/ -myconfig.cfg \ No newline at end of file +myconfig.cfg diff --git a/fedora_all_example.py b/fedora_all_example.py new file mode 100755 index 0000000..fcfe6d4 --- /dev/null +++ b/fedora_all_example.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# A simple test +# Alberto Rodriguez Sanchez bt0dotninja@fedoraproject.org +# Renato Silva resilva87@fedoraproject.org + + + +import pandas +from geofp import geofp +from datetime import datetime, timezone + +if __name__=='__main__': + #constructor load the config file (Mandatory) + gp=geofp('myconfig.cfg') + # get all the members active since June, 01 + mydate=datetime(2020,1,1,tzinfo=timezone.utc) + print(mydate) + df=gp.all_fedorians(mydate) + # save as csv (actually is pandas dataframe) + df.to_csv('Fedora_Community.csv') + print(gp.plot_world2(title='Fedora Community',label='Active members by country',filename='Fedora_Community.html', notebook=False)) diff --git a/fedora_join_example.py b/fedora_join_example.py index 1ae75c7..7b26754 100755 --- a/fedora_join_example.py +++ b/fedora_join_example.py @@ -7,12 +7,15 @@ import pandas from geofp import geofp -from datetime import datetime +from datetime import datetime, timezone if __name__=='__main__': #constructor load the config file (Mandatory) gp=geofp('myconfig.cfg') # get all the members active since June, 01 - df=gp.by_group('fedora-join',datetime(2018,7,1)) + mydate=datetime(2020,1,1,tzinfo=timezone.utc) + print(mydate) + df=gp.by_group('fedora-join',mydate) # save as csv (actually is pandas dataframe) df.to_csv('Fedora_join.csv') + print(gp.plot_world2(title='Fedora Join Team',label='Members by country',filename='Fedora Join.html', notebook=False)) diff --git a/geofp.py b/geofp.py index 2637a1c..de0e807 100755 --- a/geofp.py +++ b/geofp.py @@ -62,7 +62,7 @@ class geofp(object): return self.members def ask_byCountry(self,since=None): - + ''' Depreciated''' print("Go for coffee...") #get all the msg since "since variable" to today baseurl = "https://apps.fedoraproject.org/datagrepper/raw?topic=org.fedoraproject.prod.askbot.post.edit" @@ -113,8 +113,11 @@ class geofp(object): def plot_world2(self,title='Map', label='# Elements', filename='base_file', notebook=False): '''plot a fancy map with heat information ''' - import plotly.plotly as py + import plotly.graph_objs as gobj + import pandas as pd from iso3166 import countries + from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot + init_notebook_mode(connected=notebook) ct = Counter(self.members.country_code.values.tolist()) del ct[None] @@ -154,15 +157,17 @@ class geofp(object): showcountries = True, showcoastlines = False, projection = dict( - type = 'Mercator' + type = 'natural earth' ) ) ) - fig = dict( data=data, layout=layout ) + + fig = gobj.Figure(data = data,layout = layout) + if notebook: - return py.iplot(fig,filename=filename ) + return iplot(fig,filename=filename ) else: - return py.plot(fig,filename=filename ) + return plot(fig,filename=filename )