Skip to content

Commit

Permalink
Refactor status table generation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
petya-vasileva committed Dec 14, 2023
1 parent 8d09190 commit 588cf90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
12 changes: 7 additions & 5 deletions src/model/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,14 @@ def getSubcategories():
# catdf = pd.DataFrame(subcategories)

description = {
'Infrastructure': ['bad owd measurements','large clock correction', 'path changed between sites',
'Infrastructure': ['bad owd measurements','large clock correction',
'destination cannot be reached from multiple', 'destination cannot be reached from any',
'source cannot reach any', 'firewall issue'],
'Network': ['bandwidth decreased from/to multiple sites', 'bandwidth decreased'],
'Other': ['bandwidth increased from/to multiple sites', 'bandwidth increased',
'high packet loss', 'high packet loss on multiple links', 'complete packet loss']
'source cannot reach any', 'firewall issue', 'complete packet loss'],

'Network': ['bandwidth decreased from/to multiple sites', 'path changed between sites'],

'Other': ['bandwidth increased from/to multiple sites', 'bandwidth increased', 'bandwidth decreased',
'high packet loss', 'high packet loss on multiple links']
}

subcategories = []
Expand Down
27 changes: 19 additions & 8 deletions src/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def builMap(mapDf):

@timer
def generate_status_table(alarmCnt):

red_sites = alarmCnt[(alarmCnt['event']=='bandwidth decreased from/to multiple sites')
& alarmCnt['cnt']>0]['site'].unique().tolist()

yellow_sites = alarmCnt[(alarmCnt['event']=='path changed between sites')
& alarmCnt['cnt']>0]['site'].unique().tolist()

grey_sites = alarmCnt[(alarmCnt['event'].isin(['firewall issue', 'source cannot reach any', 'complete packet loss']))
& (alarmCnt['cnt']>0)]['site'].unique().tolist()

catdf = qrs.getSubcategories()
catdf = pd.merge(alarmCnt, catdf, on='event', how='left')

Expand All @@ -93,19 +103,20 @@ def generate_status_table(alarmCnt):

df_pivot.sort_values(by=['Network', 'Infrastructure', 'Other'], ascending=False, inplace=True)

def give_status(row):
if row['Network'] > 0:

if row['Infrastructure'] > 0:
return '⚪'
def give_status(site):
if site in red_sites:
return '🔴'

elif row['Infrastructure'] == 0 and row['Network'] == 0:
return '🟢'
elif site in yellow_sites:
return '🟡'

else: return '🟡'
elif site in grey_sites:
return '⚪'
return '🟢'

df_pivot['Status'] = df_pivot['site'].apply(give_status)

df_pivot['Status'] = df_pivot.apply(give_status, axis=1)
df_pivot = df_pivot[['site', 'Status', 'Network', 'Infrastructure', 'Other']]

url = f'{request.host_url}site'
Expand Down

0 comments on commit 588cf90

Please sign in to comment.