Skip to content

Commit

Permalink
Simplify function
Browse files Browse the repository at this point in the history
  • Loading branch information
petya-vasileva committed Nov 5, 2023
1 parent 3c3ef48 commit 8c0b5c4
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions ps-packetloss.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,8 @@ def findRatio(row, total_minutes):

@timer
def markPairs(dateFrom, dateTo):
df = pd.DataFrame()

tempdf = loadPacketLossData(dateFrom, dateTo)
grouped = tempdf.groupby(['src', 'dest', 'pair', 'src_host', 'dest_host', 'src_site', 'dest_site']).agg(
{'value': lambda x: x.mean(skipna=False)}, axis=1).reset_index()

# calculate the percentage of measures based on the assumption that ideally measures are done once every minute
grouped = getPercentageMeasuresDone(grouped, tempdf)

dataDf = loadPacketLossData(dateFrom, dateTo)
df = getPercentageMeasuresDone(dataDf, dateFrom, dateTo)
# set value to 0 - we consider there is no issue bellow 2% loss
# set value to 1 - the pair is marked problematic between 2% and 100% loss
# set value to 2 - the pair shows 100% loss
Expand All @@ -173,11 +166,9 @@ def setFlag(x):
return 1
elif x == 1:
return 2
return 'something is wrong'

grouped['flag'] = grouped['value'].apply(lambda val: setFlag(val))
return 'Value is not in range [0,1]'

df = pd.concat([df, grouped], ignore_index=True)
df['flag'] = df['value'].apply(lambda val: setFlag(val))
df.rename(columns={'value': 'avg_value'}, inplace=True)
df = df.round({'avg_value': 3})

Expand Down

0 comments on commit 8c0b5c4

Please sign in to comment.