XPMaster commited on
Commit
a02b03c
·
1 Parent(s): a35ed6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -191,6 +191,7 @@ def col_to_ints(df,columns_to_convert):
191
  return df
192
 
193
  def fill_missing_quarters(df, lob, acc, transaction):
 
194
  print('accident',acc,'transaction',transaction)
195
  columns_to_convert = [acc,transaction] # Only affect acc and transaction
196
 
@@ -201,9 +202,10 @@ def fill_missing_quarters(df, lob, acc, transaction):
201
 
202
  quarters = []
203
  start_year = 2017
 
204
  # df_temp = df.copy(deep=True)
205
  # df_temp = df_temp.dropna()
206
- end_year = min(int(df[acc].max()[:4]), 2025)
207
  print("the end year", end_year)
208
  print("safe and sound")
209
  for year in range(start_year, end_year+1):
@@ -227,7 +229,10 @@ def fill_missing_quarters(df, lob, acc, transaction):
227
  l_missing_df[col] = 0.1
228
 
229
  if len(l_quarters) > 0 :
230
- print(l,'was filled with the dates',l_quarters)
 
 
 
231
  l_missing_df[lob] = l
232
  missing_quarters.append(l_missing_df)
233
 
@@ -250,13 +255,14 @@ def fill_missing_quarters(df, lob, acc, transaction):
250
  # Print the filled quarters or a message if there are no missing quarters
251
  filled_quarters = filled_df[acc].unique()
252
  #filtered_quarters = [q for q in filled_quarters if q[:4] in [str(year1) for year1 in range(start_year, end_year + 1)]]
253
- if False:#len(filtered_quarters) == 0:
254
- print("No missing quarters between 2017-2022")
 
255
  else:
256
  pass#print(filtered_quarters)
257
 
258
  #filled_df = filled_df[[acc, transaction] + [col for col in filled_df.columns if col not in [acc, transaction]]]
259
- return filled_df
260
 
261
  def drop_missing_rows(df, columns):
262
  #import sys
@@ -311,7 +317,7 @@ def filter_claims(df):
311
  print("Sum of Null beginning: ",df.isnull().sum())
312
  print("Sum of Null beginning 2: ",(df == '').sum())
313
  print(df.dtypes)
314
-
315
  global warnings
316
  warnings = []
317
  columns = []
@@ -334,7 +340,7 @@ def filter_claims(df):
334
  #temp.to_csv("gayassshit1.csv")
335
  #df.to_csv("before_filling.csv")
336
  #print("\n"*10,columns[0],min_col,max_col,"\n"*10)
337
- df = fill_missing_quarters(df,columns[0],min_col,max_col)
338
  #df.to_csv("after_filling.csv")
339
  #print(columns[0],min_col,max_col)
340
  #temp = fill_missing_quarters(temp,columns[0],min_col,max_col)
@@ -371,12 +377,13 @@ def filter_claims(df):
371
 
372
  df = df.replace('nan',0)
373
  df = df.fillna({col: 0 for col in df.columns if col not in sublist})
374
- return df,columns,temp
375
 
376
  def filter_premiums(df):
377
  global warnings
378
  warnings = []
379
  columns = []
 
380
  # Find lob
381
  columns.append(get_lob(df))
382
  is_found(columns,"lob")
@@ -384,7 +391,7 @@ def filter_premiums(df):
384
  return None,None
385
  # Find quarter bracket
386
  columns.append(get_quarter_bracket(df))
387
- df = fill_missing_quarters(df,columns[0],columns[-1],columns[-1])
388
  is_found(columns,"quarter")
389
  # Find premium earned
390
  columns.append(get_earned(df))
@@ -395,7 +402,7 @@ def filter_premiums(df):
395
  # Warn
396
  for i,w in enumerate(warnings):
397
  print(str(i+1)+'-',w)
398
- return df,columns
399
 
400
  css_code='body{background-image:url("https://picsum.photos/seed/picsum/200/300");}'
401
 
@@ -469,6 +476,7 @@ def process(files,button):
469
  # return zip_files([files.name]),'Success'+passe
470
  temp = None
471
  columns = []
 
472
  replacens = dict()
473
  print("Processing:", name)
474
 
@@ -484,7 +492,7 @@ def process(files,button):
484
 
485
  if "summ" in name:
486
  print("Summary:")
487
- df,columns = filter_premiums(df)
488
  if columns == None:
489
  print(name,'has no LOB column')
490
  print("--"*50)
@@ -493,7 +501,7 @@ def process(files,button):
493
  altnames = get_alts('summ')
494
  else:
495
  print("Claims:")
496
- df,columns,temp = filter_claims(df)
497
  if columns == None:
498
  print(name,'has no LOB column')
499
  print("--"*50)
@@ -532,6 +540,7 @@ def process(files,button):
532
  sheet_data[name] = {
533
  "Before columns": [old_olds],
534
  "After columns": [columns, '00FF00'],
 
535
  #"Warnings": [sheetwarnings]
536
  }
537
 
 
191
  return df
192
 
193
  def fill_missing_quarters(df, lob, acc, transaction):
194
+ filled = []
195
  print('accident',acc,'transaction',transaction)
196
  columns_to_convert = [acc,transaction] # Only affect acc and transaction
197
 
 
202
 
203
  quarters = []
204
  start_year = 2017
205
+ end_year = 2022
206
  # df_temp = df.copy(deep=True)
207
  # df_temp = df_temp.dropna()
208
+ end_year = min(int(df[acc].max()[:4]), 2022)
209
  print("the end year", end_year)
210
  print("safe and sound")
211
  for year in range(start_year, end_year+1):
 
229
  l_missing_df[col] = 0.1
230
 
231
  if len(l_quarters) > 0 :
232
+ filled_warn = str(l)+' was filled with the dates '+str(l_quarters)
233
+ print(filled_warn)
234
+ filled.append(filled_warn)
235
+
236
  l_missing_df[lob] = l
237
  missing_quarters.append(l_missing_df)
238
 
 
255
  # Print the filled quarters or a message if there are no missing quarters
256
  filled_quarters = filled_df[acc].unique()
257
  #filtered_quarters = [q for q in filled_quarters if q[:4] in [str(year1) for year1 in range(start_year, end_year + 1)]]
258
+ if len(filtered_quarters) == 0:
259
+ print("No missing quarters between 2017-"+str(end_year))
260
+ filled.append("No missing quarters between 2017-"+str(end_year))
261
  else:
262
  pass#print(filtered_quarters)
263
 
264
  #filled_df = filled_df[[acc, transaction] + [col for col in filled_df.columns if col not in [acc, transaction]]]
265
+ return filled_df,filled
266
 
267
  def drop_missing_rows(df, columns):
268
  #import sys
 
317
  print("Sum of Null beginning: ",df.isnull().sum())
318
  print("Sum of Null beginning 2: ",(df == '').sum())
319
  print(df.dtypes)
320
+ filled_warn = []
321
  global warnings
322
  warnings = []
323
  columns = []
 
340
  #temp.to_csv("gayassshit1.csv")
341
  #df.to_csv("before_filling.csv")
342
  #print("\n"*10,columns[0],min_col,max_col,"\n"*10)
343
+ df, filled_warn = fill_missing_quarters(df,columns[0],min_col,max_col)
344
  #df.to_csv("after_filling.csv")
345
  #print(columns[0],min_col,max_col)
346
  #temp = fill_missing_quarters(temp,columns[0],min_col,max_col)
 
377
 
378
  df = df.replace('nan',0)
379
  df = df.fillna({col: 0 for col in df.columns if col not in sublist})
380
+ return df,columns,temp,filled_warn
381
 
382
  def filter_premiums(df):
383
  global warnings
384
  warnings = []
385
  columns = []
386
+ filled_warn = []
387
  # Find lob
388
  columns.append(get_lob(df))
389
  is_found(columns,"lob")
 
391
  return None,None
392
  # Find quarter bracket
393
  columns.append(get_quarter_bracket(df))
394
+ df,filled_warn = fill_missing_quarters(df,columns[0],columns[-1],columns[-1])
395
  is_found(columns,"quarter")
396
  # Find premium earned
397
  columns.append(get_earned(df))
 
402
  # Warn
403
  for i,w in enumerate(warnings):
404
  print(str(i+1)+'-',w)
405
+ return df,columns,filled_warn
406
 
407
  css_code='body{background-image:url("https://picsum.photos/seed/picsum/200/300");}'
408
 
 
476
  # return zip_files([files.name]),'Success'+passe
477
  temp = None
478
  columns = []
479
+ filled_warn = []
480
  replacens = dict()
481
  print("Processing:", name)
482
 
 
492
 
493
  if "summ" in name:
494
  print("Summary:")
495
+ df,columns,filled_warn = filter_premiums(df)
496
  if columns == None:
497
  print(name,'has no LOB column')
498
  print("--"*50)
 
501
  altnames = get_alts('summ')
502
  else:
503
  print("Claims:")
504
+ df,columns,temp,filled_warn = filter_claims(df)
505
  if columns == None:
506
  print(name,'has no LOB column')
507
  print("--"*50)
 
540
  sheet_data[name] = {
541
  "Before columns": [old_olds],
542
  "After columns": [columns, '00FF00'],
543
+ 'Filled quarters':[filled_warn]
544
  #"Warnings": [sheetwarnings]
545
  }
546