Upload results_utils.py
Browse files- results_utils.py +120 -0
results_utils.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def ReadPDFFile(doc, PageNum, searchtext, BreakText):
|
4 |
+
Read = False
|
5 |
+
found = False
|
6 |
+
Extracttext = []
|
7 |
+
#
|
8 |
+
page = doc.loadPage(PageNum)
|
9 |
+
pagetext = page.getText("text")
|
10 |
+
#
|
11 |
+
text_instances = page.searchFor(searchtext)
|
12 |
+
#
|
13 |
+
if (text_instances):
|
14 |
+
page_display = page.getDisplayList()
|
15 |
+
dictionary_elements = page_display.getTextPage().extractDICT()
|
16 |
+
for block in dictionary_elements['blocks']:
|
17 |
+
for line in block['lines']:
|
18 |
+
for span in line['spans']:
|
19 |
+
Line = span['text']
|
20 |
+
if (Line.strip() == searchtext):
|
21 |
+
Read = True
|
22 |
+
if (BreakText != "" and BreakText in Line.strip() and Read == True):
|
23 |
+
Extracttext.append(Line)
|
24 |
+
found = True
|
25 |
+
break
|
26 |
+
if (Read):
|
27 |
+
if (len(Line) > 1):
|
28 |
+
Extracttext.append(Line)
|
29 |
+
if (found): break
|
30 |
+
if (found): break
|
31 |
+
#
|
32 |
+
return Extracttext
|
33 |
+
|
34 |
+
|
35 |
+
def PopulateDict(Extracttext, DictText):
|
36 |
+
Extractedtext = []
|
37 |
+
# DictText = {}
|
38 |
+
ShareAmts = []
|
39 |
+
Key = ""
|
40 |
+
Extractedtext = Extracttext[4:len(Extracttext) - 1]
|
41 |
+
for readtext in Extractedtext:
|
42 |
+
if (not any(map(str.isdigit, readtext)) and "(" in readtext):
|
43 |
+
Key = Key + readtext
|
44 |
+
else:
|
45 |
+
if (not any(map(str.isdigit, readtext))):
|
46 |
+
if (ShareAmts):
|
47 |
+
DictText[Key] = ShareAmts
|
48 |
+
Key = readtext # String data
|
49 |
+
else:
|
50 |
+
Key = readtext
|
51 |
+
ShareAmts = []
|
52 |
+
else:
|
53 |
+
ShareAmts.append(readtext.strip())
|
54 |
+
#
|
55 |
+
if (ShareAmts):
|
56 |
+
DictText[Key] = ShareAmts
|
57 |
+
#
|
58 |
+
return DictText
|
59 |
+
|
60 |
+
|
61 |
+
def get_brief(DictText):
|
62 |
+
for Key in DictText:
|
63 |
+
Values = DictText[Key]
|
64 |
+
if (len(Values) == 3):
|
65 |
+
Val0 = Values[0].replace(",", ".")
|
66 |
+
Val1 = Values[1].replace(",", ".")
|
67 |
+
Val0 = Val0.replace("%", "")
|
68 |
+
Val1 = Val1.replace("%", "")
|
69 |
+
Val2 = Values[2]
|
70 |
+
Val2 = Val2.replace("(", "")
|
71 |
+
Val2 = Val2.replace(")", "")
|
72 |
+
Val2 = Val2.replace("]", "")
|
73 |
+
Val2 = Val2.replace("[", "")
|
74 |
+
Val2 = Val2.replace("pt", "%")
|
75 |
+
Val2 = Val2.replace(" %", "%")
|
76 |
+
#
|
77 |
+
if (float(Val0) > float(Val1)):
|
78 |
+
st.markdown('* {} ${}B, <font color="green">**up**</font> {} YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), Val2,
|
79 |
+
round(float(Val1), 2)),unsafe_allow_html=True)
|
80 |
+
else:
|
81 |
+
st.markdown('* {} ${}B, <font color="red">**down**</font> {} YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), Val2,
|
82 |
+
round(float(Val1), 2)),unsafe_allow_html=True)
|
83 |
+
if (len(Values) == 2):
|
84 |
+
Val0 = Values[0].replace(",", ".")
|
85 |
+
Val1 = Values[1].replace(",", ".")
|
86 |
+
Val0 = Val0.replace("%", "")
|
87 |
+
Val1 = Val1.replace("%", "")
|
88 |
+
Val0 = Val0.replace("(", "")
|
89 |
+
Val0 = Val0.replace(")", "")
|
90 |
+
Val1 = Val1.replace("(", "")
|
91 |
+
Val1 = Val1.replace(")", "")
|
92 |
+
#
|
93 |
+
if (float(Val0) > float(Val1)):
|
94 |
+
diffVal = (float(Val0) - float(Val1))
|
95 |
+
Res = (100 * diffVal) / (float(Val1))
|
96 |
+
st.markdown('* {} ${}B, <font color="green">**up**</font> {}% YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), round(Res, 2),
|
97 |
+
round(float(Val1), 2)),unsafe_allow_html=True)
|
98 |
+
else:
|
99 |
+
diffVal = (float(Val1) - float(Val0))
|
100 |
+
Res = (100 * diffVal) / (float(Val0))
|
101 |
+
st.markdown('* {} ${}B, <font color="red">**down**</font> {}% YoY vs ${}B in 1Q21.'.format(Key, round(float(Val0), 2), round(Res, 2),
|
102 |
+
round(float(Val1), 2)),unsafe_allow_html=True)
|
103 |
+
if (len(Values) == 1):
|
104 |
+
Values = str(Values)
|
105 |
+
Values = Values.replace("]", "")
|
106 |
+
Values = Values.replace("[", "")
|
107 |
+
Values = Values.replace(" %", "%")
|
108 |
+
if ("Impact" in Key):
|
109 |
+
if ("(" in Values):
|
110 |
+
Values = Values.replace("(", "")
|
111 |
+
Values = Values.replace(")", "")
|
112 |
+
st.markdown('* {} on revenue growth, <font color="red">**negative**</font> {}.'.format(Key, Values),unsafe_allow_html=True)
|
113 |
+
else:
|
114 |
+
st.markdown('* {} on revenue growth, {}.'.format(Key, Values),unsafe_allow_html=True)
|
115 |
+
else:
|
116 |
+
if ("Organic" in Key):
|
117 |
+
st.write('* {}, {}.'.format(Key, Values))
|
118 |
+
else:
|
119 |
+
st.write('* {}, {}.'.format(Key, Values))
|
120 |
+
|