-
Notifications
You must be signed in to change notification settings - Fork 6
/
tool_industry_revenue.py
49 lines (36 loc) · 1.57 KB
/
tool_industry_revenue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
""" Tool to visualize industry by revenue.
Inspired from https://www.youtube.com/watch?v=5Zg-C8AAIGg
Author : Manohar Kuse <[email protected]>
Created : 12th Apr, 2017
"""
from pymongo import MongoClient
import pprint
from bokeh.plotting import figure, output_file, show, save
import numpy as np
import matplotlib.pyplot as plt
client = MongoClient()
db = client.universalData.universalData
pprint.pprint( db.find_one({'ticker':'0011.HK', 'type1':'Profile', 'type2':'Company Info', 'type3':'Sales or Revenue' }) )
#cursor = db.find({'industry':'Automotive', 'sector':'Auto & Commercial Vehicle Parts', 'type1':'Profile', 'type2':'Company Info', 'type3':'Sales or Revenue' }, \
# {'industry':1, 'sector':1, 'company':1, 'ticker':1, 'val':1} )
year = 2012
for year in [2012]:
cursor = db.find({'industry':'Automotive', 'type1':'Financial Statements', 'type2':'income_statement', 'type3':'None', 'period':'a', 'type5':'Sales/Revenue', 'type6':'None', 'type7':'None', 'type4':year }, \
{'industry':1, 'sector':1, 'company':1, 'ticker':1, 'val':1} ).sort( 'company', 1 )
revenue = []
labels = []
for json_rev in cursor:
pprint.pprint( json_rev )
try:
v = json_rev['val']
except KeyError:
v = 0
revenue.append( v )
labels.append( json_rev['company'] )
pdf = np.array(revenue)/sum(revenue)
cdf = np.cumsum( pdf )
plt.clf()
plt.pie( pdf*100, autopct='%1.1f%%', shadow=True, labels=labels )
plt.axis( 'equal')
plt.show()
plt.pause(0)