From 2f9c14152557b493cd0e4c4b70b72109b953618c Mon Sep 17 00:00:00 2001 From: Renato Silva Date: May 05 2017 15:37:00 +0000 Subject: [PATCH 1/3] Ignore visual code studio and .cfg files --- diff --git a/.gitignore b/.gitignore index 3b3aa28..ac1b38a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.cfg *.svg __pycache__ +.vscode/ +myconfig.cfg \ No newline at end of file From ab9bb852e997dc0794719b1d87b8164aa119b0b0 Mon Sep 17 00:00:00 2001 From: Renato Silva Date: May 05 2017 17:45:16 +0000 Subject: [PATCH 2/3] Add plotly heatmap view, not using the y axis --- diff --git a/geofp.py b/geofp.py index c1a82df..a726272 100755 --- a/geofp.py +++ b/geofp.py @@ -73,7 +73,7 @@ class geofp(object): else: params={'page':1,'rows_per_page':100, 'size':'small'} - results= requests.get(baseurl,params=params).json() + results = requests.get(baseurl,params=params).json() for i in range(results['pages']): for msg in results['raw_messages']: if msg['msg']['created']: @@ -166,5 +166,32 @@ class geofp(object): - def plot_heat(self,title): - pass + def plot_heat(self, title='test', filename='base_file', label='label', notebook=False): + '''plot a fancy map with heat information ''' + import plotly.plotly as py + import plotly.graph_objs as go + from iso3166 import countries + + ct = Counter(self.members.country_code.values.tolist()) + del ct[None] + + locations=[] + z=[] + names=[] + for k in ct.keys(): + try: + country=countries.get(k) + locations.append(country[2]) + z.append(ct[k]) + names.append(country[0]) + except: + continue + + z = pd.Series(z) + trace = go.Heatmap(z = [z], x = names) + data = [trace] + + if notebook: + return py.iplot(data,filename=filename ) + else: + return py.plot(data,filename=filename ) diff --git a/geofp_test.py b/geofp_test.py index 89ecab8..b8fa04f 100755 --- a/geofp_test.py +++ b/geofp_test.py @@ -11,7 +11,8 @@ from datetime import datetime if __name__=='__main__': gp=geofp('myconfig.cfg') - df=gp.ask_byCountry(datetime(2017,4,1)) - print("Follow the link") - print(gp.plot_world2(title='Fedora Ask questions by country since 04/01/2017',label='questions by country',filename='Fedora-Ask', notebook=False)) + df=gp.ask_byCountry(datetime(2017,4,15)) + print("Follow the links") + print(gp.plot_world2(title='Fedora Ask questions by country since 04/15/2017',label='questions by country',filename='Fedora-Ask', notebook=False)) df.to_csv('AskFedora.csv') + print(gp.plot_heat(title='Fedora Ask questions by country since 04/15/2017',label='questions by country',filename='Fedora-Ask', notebook=False)) From fc334bdbe8efb2a425873cd55e586e90af6ea390 Mon Sep 17 00:00:00 2001 From: Renato Silva Date: May 05 2017 18:10:13 +0000 Subject: [PATCH 3/3] Correct method comment --- diff --git a/geofp.py b/geofp.py index a726272..2b48a13 100755 --- a/geofp.py +++ b/geofp.py @@ -167,7 +167,7 @@ class geofp(object): def plot_heat(self, title='test', filename='base_file', label='label', notebook=False): - '''plot a fancy map with heat information ''' + '''plots heatmap with location/number of asked questions ''' import plotly.plotly as py import plotly.graph_objs as go from iso3166 import countries