hongaik commited on
Commit
b4fc692
1 Parent(s): bfa3476

initial test

Browse files
Files changed (1) hide show
  1. app.py +201 -13
app.py CHANGED
@@ -50,43 +50,231 @@ uploaded_files = st.file_uploader("Upload multiple files", accept_multiple_files
50
  if uploaded_files is not None:
51
 
52
  # with st.spinner('Generating report...'):
53
- # results = get_multiple_predictions(uploaded_file)
54
  for uploaded_file in uploaded_files:
55
  if uploaded_file.name == 'Flip_accum.xlsx':
56
  flip_accum1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
57
  flip_accum2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:N")
58
- st.write('flip_accum1: ' + str(flip_accum1.shape))
59
 
60
  elif uploaded_file.name == 'Fold_accum.xlsx':
61
  fold_accum1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
62
  fold_accum2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:N")
63
- st.write('fold_accum1: ' + str(fold_accum1.shape))
64
 
65
  elif uploaded_file.name == 'Flip_today.xlsx':
66
  flip_today1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
67
  flip_today2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:M")
68
- st.write('flip_today1: ' + str(flip_today1.shape))
69
 
70
  elif uploaded_file.name == 'Fold_today.xlsx':
71
  fold_today1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
72
  fold_today2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:M")
73
- st.write('fold_today1: ' + str(fold_today1.shape))
74
 
75
  elif uploaded_file.name == 'FlipFold4_accum.xlsx':
76
  flipfold_accum = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
77
  flipfold_accum2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:N")
78
- st.write('flipfold_accum: ' + str(flipfold_accum.shape))
79
 
80
  elif uploaded_file.name == 'FlipFold4_analysis.xlsx':
81
  flipfold = pd.read_excel(uploaded_file, skiprows=9)
82
- st.write('flipfold: ' + str(flipfold.shape))
 
 
 
 
 
 
 
 
 
 
 
 
83
 
 
 
 
 
84
 
85
- # st.download_button(
86
- # label="Download report here",
87
- # data=results,
88
- # file_name='results.csv',
89
- # mime='text/csv',
90
- # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
 
 
50
  if uploaded_files is not None:
51
 
52
  # with st.spinner('Generating report...'):
53
+
54
  for uploaded_file in uploaded_files:
55
  if uploaded_file.name == 'Flip_accum.xlsx':
56
  flip_accum1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
57
  flip_accum2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:N")
58
+ #st.write('flip_accum1: ' + str(flip_accum1.shape))
59
 
60
  elif uploaded_file.name == 'Fold_accum.xlsx':
61
  fold_accum1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
62
  fold_accum2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:N")
63
+ #st.write('fold_accum1: ' + str(fold_accum1.shape))
64
 
65
  elif uploaded_file.name == 'Flip_today.xlsx':
66
  flip_today1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
67
  flip_today2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:M")
68
+ #st.write('flip_today1: ' + str(flip_today1.shape))
69
 
70
  elif uploaded_file.name == 'Fold_today.xlsx':
71
  fold_today1 = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
72
  fold_today2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:M")
73
+ #st.write('fold_today1: ' + str(fold_today1.shape))
74
 
75
  elif uploaded_file.name == 'FlipFold4_accum.xlsx':
76
  flipfold_accum = pd.read_excel(uploaded_file, skiprows=8, nrows=11, usecols="A:D")
77
  flipfold_accum2 = pd.read_excel(uploaded_file, skiprows=24, nrows=5, usecols="A:N")
78
+ #st.write('flipfold_accum: ' + str(flipfold_accum.shape))
79
 
80
  elif uploaded_file.name == 'FlipFold4_analysis.xlsx':
81
  flipfold = pd.read_excel(uploaded_file, skiprows=9)
82
+ #st.write('flipfold: ' + str(flipfold.shape))
83
+
84
+ elif uploaded_file.name == 'flipfold4_report_template.docx':
85
+ doc = DocxTemplate(uploaded_file)
86
+
87
+ if datetime.datetime.now().day == 1:
88
+ day_suffix = "st"
89
+ elif datetime.datetime.now().day == 2:
90
+ day_suffix = "nd"
91
+ elif datetime.datetime.now().day == 3:
92
+ day_suffix = "rd"
93
+ else:
94
+ day_suffix = "th"
95
 
96
+ if round(((flipfold_accum2.iloc[2, 4] - flipfold_accum2.iloc[2, 13])/flipfold_accum2.iloc[2, 13]) * 100) < 0:
97
+ increase_decrease = "Decrease"
98
+ else:
99
+ increase_decrease = "Increase"
100
 
101
+ flipfold = flipfold[['Symptom\nGroup 1', 'Subsidiary', 'Marketing Name']]
102
+ flipfold.columns = ['symptom', 'subsidiary', 'Marketing Name']
103
+
104
+ display = ['Display', 'Touch', 'OCTA/Backglass Broken', 'Sensor']
105
+ quick_discharge = ['Quick Discharge', 'Charging', 'Discharging']
106
+ appearance = ['Appearance', 'Case', 'Button']
107
+ others = ['In Process', 'WIFI', 'Connection', 'S pen', 'Fault Operation', 'Bluetooth']
108
+
109
+ flipfold['symptom'] = flipfold['symptom'].apply(lambda x:
110
+ 'Display' if x in display else
111
+ 'Quick Discharge' if x in quick_discharge else
112
+ 'Appearance' if x in appearance else
113
+ 'Others' if x in others else
114
+ 'Sound/Call Audio' if x == 'Sound/Call audio' else
115
+ x
116
+ )
117
+
118
+ template = pd.DataFrame({
119
+ 'symptom': ['Total', 'Heat', 'Display', 'Camera', 'Quick Discharge', 'Power', 'Rebooting', 'App/SW', 'Sound/Call Audio', 'Appearance', 'Others'],
120
+ 'SEAO Total': [0]*11,
121
+ 'SAVINA': [0]*11,
122
+ 'SEAU': [0]*11,
123
+ 'SEIN': [0]*11,
124
+ 'SENZ': [0]*11,
125
+ 'SEPCO': [0]*11,
126
+ 'SESP': [0]*11,
127
+ 'SME': [0]*11,
128
+ 'TSE': [0]*11
129
+ }).set_index('symptom')
130
+
131
+ flip4 = flipfold[flipfold['Marketing Name'] == 'Galaxy Z Flip4']
132
+
133
+ flip4_groupby = pd.DataFrame(flip4.groupby(['symptom', 'subsidiary'])['subsidiary'].count())
134
+ flip4_groupby.columns=['count']
135
+ flip4_groupby.reset_index(inplace=True)
136
+ flip4_groupby = flip4_groupby.pivot(index='symptom', columns='subsidiary', values='count').fillna(0)
137
+
138
+ fold4 = flipfold[flipfold['Marketing Name'] == 'Galaxy Z Fold4']
139
+
140
+ fold4_groupby = pd.DataFrame(fold4.groupby(['symptom', 'subsidiary'])['subsidiary'].count())
141
+ fold4_groupby.columns=['count']
142
+ fold4_groupby.reset_index(inplace=True)
143
+ fold4_groupby = fold4_groupby.pivot(index='symptom', columns='subsidiary', values='count').fillna(0)
144
+
145
+ template_flip4 = template.copy()
146
+ template_fold4 = template.copy()
147
+
148
+ for col in template.columns:
149
+ for row in template.index:
150
+ try:
151
+ template_flip4.loc[row, col] = flip4_groupby.loc[row, col]
152
+ except:
153
+ continue
154
+
155
+ for col in template.columns:
156
+ for row in template.index:
157
+ try:
158
+ template_fold4.loc[row, col] = fold4_groupby.loc[row, col]
159
+ except:
160
+ continue
161
+
162
+ # Account for SEPCO data entry error
163
+ template_flip4.loc['Display', 'SEPCO'] = template_flip4.loc['Display', 'SEPCO'] - 4
164
+ template_flip4.loc['App/SW', 'SEPCO'] = template_flip4.loc['App/SW', 'SEPCO'] - 2
165
+ template_flip4.loc['Others', 'SEPCO'] = template_flip4.loc['Others', 'SEPCO'] + 6
166
+
167
+ # Account for SEVT into SAVINA count
168
+ template_fold4.loc['Display', 'SAVINA'] = template_fold4.loc['Display', 'SAVINA'] + 5
169
+ template_fold4.loc['Others', 'SAVINA'] = template_fold4.loc['Others', 'SAVINA'] + 2
170
+ template_fold4.loc['Rebooting', 'SAVINA'] = template_fold4.loc['Rebooting', 'SAVINA'] + 1
171
+ template_fold4.loc['Appearance', 'SAVINA'] = template_fold4.loc['Appearance', 'SAVINA'] + 1
172
+
173
+ template_flip4.loc['Appearance', 'SAVINA'] = template_flip4.loc['Appearance', 'SAVINA'] + 1
174
+ template_flip4.loc['Others', 'SAVINA'] = template_flip4.loc['Others', 'SAVINA'] + 2
175
+
176
+ template_flip4['SEAO Total'] = template_flip4[['SAVINA', 'SEAU', 'SEIN', 'SENZ', 'SEPCO', 'SESP', 'SME', 'TSE']].sum(axis=1)
177
+ template_flip4.loc['Total'] = template_flip4[['SEAO Total', 'SAVINA', 'SEAU', 'SEIN', 'SENZ', 'SEPCO', 'SESP', 'SME', 'TSE']].sum(axis=0)
178
+ template_flip4 = template_flip4.astype(int)
179
+
180
+ template_fold4['SEAO Total'] = template_fold4[['SEAO Total', 'SAVINA', 'SEAU', 'SEIN', 'SENZ', 'SEPCO', 'SESP', 'SME', 'TSE']].sum(axis=1)
181
+ template_fold4.loc['Total'] = template_fold4[['SEAO Total', 'SAVINA', 'SEAU', 'SEIN', 'SENZ', 'SEPCO', 'SESP', 'SME', 'TSE']].sum(axis=0)
182
+ template_fold4 = template_fold4.astype(int)
183
+
184
+ flip4_dict = {'a' + str(i): template_flip4.values.flatten()[i-1] for i in range(1,100)}
185
+ fold4_dict = {'b' + str(i): template_fold4.values.flatten()[i-1] for i in range(1,100)}
186
+
187
+ context = {
188
+
189
+ #"topleft": topleft,
190
+ #"topright": topright,
191
+ #"bottomleft": bottomleft,
192
+ #"bottomright": bottomright,
193
+
194
+ "date0" : int((datetime.date.today() - date(2022, 9, 2))/ timedelta(days=1) + 1),
195
+ "date1" : datetime.datetime.now().strftime("%#d.%#m.%Y"),
196
+ "date2" : (datetime.datetime.now() - timedelta(days=1)).strftime("%#d/%#m"),
197
+ "date3": datetime.datetime.now().strftime("%b.%#d"),
198
+ "day_suffix": day_suffix,
199
+ "v2": "{:>6}".format(f'{flip_today1.iloc[5, 2] + fold_today1.iloc[5, 2]:,}'),
200
+ "v3": f'{int(flip_accum1.iloc[3, 2]):,}',
201
+ "v4": f'{int(flip_accum1.iloc[5, 2]):,}',
202
+ "v5": f'{int(flip_accum1.iloc[7, 2]):,}',
203
+
204
+ "v6": f'{int(flip_accum2.iloc[1, 12]):,}',
205
+ "v7": f'{int(flip_accum2.iloc[1, 5]):,}',
206
+ "v8": f'{int(flip_accum2.iloc[1, 6]):,}',
207
+
208
+ "v9": f'{int(fold_accum1.iloc[3, 2]):,}',
209
+ "v10": f'{int(fold_accum1.iloc[5, 2]):,}',
210
+ "v11": f'{int(fold_accum1.iloc[7, 2]):,}',
211
+
212
+ "v12": f'{int(fold_accum2.iloc[1, 12]):,}',
213
+ "v13": f'{int(fold_accum2.iloc[1, 5]):,}',
214
+ "v14": f'{int(fold_accum2.iloc[1, 6]):,}',
215
+
216
+ # "v21": f'{int(flip_today1.iloc[3, 2]):,}', # changed on 5 Sep 2022
217
+ # "v22": f'{int(flip_today1.iloc[5, 2]):,}',
218
+ # "v23": f'{int(flip_today1.iloc[7, 2]):,}',
219
+
220
+ "v21": f'{int(flip_today2.iloc[1, 12]):,}',
221
+ "v22": f'{int(flip_today2.iloc[1, 5]):,}',
222
+ "v23": f'{int(flip_today2.iloc[1, 6]):,}',
223
+
224
+ "v24": f'{int(fold_today2.iloc[1, 12]):,}',
225
+ "v25": f'{int(fold_today2.iloc[1, 5]):,}',
226
+ "v26": f'{int(fold_today2.iloc[1, 6]):,}',
227
+
228
+ # Table 1 Subtotals
229
+ "v16": f'{int(flip_accum1.iloc[7, 2] + fold_accum1.iloc[7, 2]):,}',
230
+ "v17": f'{int(flip_accum1.iloc[3, 2] + fold_accum1.iloc[3, 2]):,}',
231
+ "v18": f'{int(flip_accum2.iloc[1, 12] + fold_accum2.iloc[1, 12]):,}',
232
+ "v19": f'{int(flip_accum2.iloc[1, 5] + fold_accum2.iloc[1, 5]):,}',
233
+ "v20": f'{int(flip_accum2.iloc[1, 6] + fold_accum2.iloc[1, 6]):,}',
234
+ "v27": f'{int(flip_today2.iloc[1, 12]) + int(fold_today2.iloc[1, 12]):,}',
235
+ "v28": f'{int(flip_today2.iloc[1, 5]) + int(fold_today2.iloc[1, 5]):,}',
236
+ "v29": f'{int(flip_today2.iloc[1, 6]) + int(fold_today2.iloc[1, 6]):,}',
237
+ "v30": f'{int(flip_today2.iloc[1, 4]):,}',
238
+ "v31": f'{int(fold_today2.iloc[1, 4]):,}',
239
+ "v15": f'{int(flip_today2.iloc[1, 4]) + int(fold_today2.iloc[1, 4]):,}',
240
+ "v1": f'{int(flip_accum1.iloc[5, 2] + fold_accum1.iloc[5, 2]):,}',
241
+
242
+ "v32": f'{int(flipfold_accum2.iloc[2, 4]):,}',
243
+ "v33": f'{int(flip_accum2.iloc[2, 4]):,}',
244
+ "v34": f'{int(fold_accum2.iloc[2, 4]):,}',
245
+
246
+ "v35": f'{int(flipfold_accum2.iloc[2, 13]):,}',
247
+ "v36": f'{int(fold_accum2.iloc[2, 13]):,}',
248
+ "v37": f'{int(flip_accum2.iloc[2, 13]):,}',
249
+ "v38": abs(round(((flipfold_accum2.iloc[2, 4] - flipfold_accum2.iloc[2, 13])/flipfold_accum2.iloc[2, 13]) * 100)),
250
+ "increase_decrease": increase_decrease,
251
+
252
+ "c12": int(template_flip4.loc[['Heat', 'Quick Discharge', 'Power', 'Rebooting'], 'SEAO Total'].sum()),
253
+ "c19": int(template_fold4.loc[['Heat', 'Quick Discharge', 'Power', 'Rebooting'], 'SEAO Total'].sum()),
254
+ "c14": int(template_flip4.loc[['Camera', 'Others'], 'SEAO Total'].sum()),
255
+ "c21": int(template_fold4.loc[['Camera', 'Others'], 'SEAO Total'].sum()),
256
+ "c1": int(flip4_dict["a1"] + fold4_dict["b1"]),
257
+ "c2": int(flip4_dict["a19"] + fold4_dict["b19"]),
258
+ "c3": int(flip4_dict["a64"] + fold4_dict["b64"]),
259
+ "c4": int(flip4_dict["a82"] + fold4_dict["b82"]),
260
+ "c5": int(template_flip4.loc[['Heat', 'Quick Discharge', 'Power', 'Rebooting'], 'SEAO Total'].sum() + template_fold4.loc[['Heat', 'Quick Discharge', 'Power', 'Rebooting'], 'SEAO Total'].sum()),
261
+ "c6": int(flip4_dict["a73"] + fold4_dict["b73"]),
262
+ "c7": int(template_flip4.loc[['Camera', 'Others'], 'SEAO Total'].sum() + template_fold4.loc[['Camera', 'Others'], 'SEAO Total'].sum()),
263
+
264
+ "d1": round(100*(flip4_dict["a19"] + fold4_dict["b19"])/(flip4_dict["a1"] + fold4_dict["b1"])),
265
+ "d2": round(100*(flip4_dict["a64"] + fold4_dict["b64"])/(flip4_dict["a1"] + fold4_dict["b1"])),
266
+ "d3": round(100*(template_flip4.loc[['Heat', 'Quick Discharge', 'Power', 'Rebooting'], 'SEAO Total'].sum() + template_fold4.loc[['Heat', 'Quick Discharge', 'Power', 'Rebooting'], 'SEAO Total'].sum())/(flip4_dict["a1"] + fold4_dict["b1"]))
267
+ }
268
+
269
+ context2 = {**context, **flip4_dict, **fold4_dict}
270
+ doc.render(context2)
271
+ results = doc.save()
272
+
273
+ st.download_button(
274
+ label="Download report here",
275
+ data=results,
276
+ file_name="SEAO Fold 4_Flip 4 Quality Monitoring (" + datetime.datetime.now().strftime("%#d %b") + ").docx",
277
+ mime='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
278
+ )
279
 
280