Skip to content

Commit

Permalink
Accounting for missing columns
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaragomes committed Aug 30, 2023
1 parent 819c57e commit de831e5
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions v6_healthai_dashboard_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def master(
info('Master algorithm complete')
final_results = []
for name, result in zip(names, results):
if not result['organisation']:
result['organisation'] = name
result['organisation'] = name
final_results.append(result)

return final_results
Expand All @@ -107,27 +106,41 @@ def RPC_statistics_partial(data, cutoff, delta):
results
Dictionary with the partial result
"""
# Initialising results dictionary
results = {'logs': ''}

info('Counting number of unique ids')
if 'centre' in data.columns:
organisation = data['centre'].unique()[0]
column = 'id'
if column in data.columns:
nids = data[column].nunique()
results['nids'] = nids
else:
organisation = None
nids = data['id'].nunique()
results['logs'] += f'Column {column} not found in the data\n'

info('Counting number of unique ids per stage')
data['stage'] = data['stage'].str.upper()
stages = data.groupby(['stage'])['id'].nunique().reset_index()
column = 'stage'
if column in data.columns:
data[column] = data[column].str.upper()
stages = data.groupby([column])['id'].nunique().reset_index()
results[column] = stages.to_dict()
else:
results['logs'] += f'Column {column} not found in the data'

info('Counting number of unique ids per vital status')
vital_status = data.groupby(['vital_status'])['id'].nunique().reset_index()
column = 'vital_status'
if column in data.columns:
vital_status = data.groupby([column])['id'].nunique().reset_index()
results[column] = vital_status.to_dict()
else:
results['logs'] += f'Column {column} not found in the data'

info('Getting survival rates')
survival = survival_rate(data, cutoff, delta)

return {
'organisation': organisation,
'nids': nids,
'stages': stages.to_dict(),
'vital_status': vital_status.to_dict(),
'survival': survival
}
columns = ['date_of_diagnosis', 'date_of_fu']
if (columns[0] in data.columns) and (columns[1] in data.columns):
survival = survival_rate(data, cutoff, delta)
results['survival'] = survival
else:
results['logs'] += \
f'Columns {columns[0]} and/or {columns[1]} not found in the data'

return results

0 comments on commit de831e5

Please sign in to comment.