Add script for ex3
This commit is contained in:
parent
38a2eb523e
commit
4c05f0ccd7
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
data
|
data
|
||||||
venv
|
venv
|
||||||
.idea
|
.idea
|
||||||
|
|||||||
43
ex3/exercise3.py
Normal file
43
ex3/exercise3.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.dates as mdate
|
||||||
|
from datetime import datetime
|
||||||
|
from statistics import median
|
||||||
|
|
||||||
|
'''
|
||||||
|
IMPORTANT: Remove leading space from column '# Bytes' in csv file or pandas
|
||||||
|
won't read it correctly.
|
||||||
|
'''
|
||||||
|
|
||||||
|
dataset = pd.read_csv('./global_last10years.csv', index_col=0).dropna()
|
||||||
|
|
||||||
|
# Convert unix timestamps to dates
|
||||||
|
timestamps = mdate.epoch2num(dataset.index)
|
||||||
|
date_formatter = mdate.DateFormatter('%y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
# List of packet counts per hour (daily avg)
|
||||||
|
ts_packets = dataset.iloc[:,1]
|
||||||
|
|
||||||
|
# List of bytes per hour (daily avg)
|
||||||
|
ts_bytes = dataset.iloc[:,0]
|
||||||
|
|
||||||
|
# List of unique source IPs per hour (daily avg)
|
||||||
|
ts_uIPs = dataset.iloc[:,2]
|
||||||
|
|
||||||
|
# List of unique destination IPs per hour (daily avg)
|
||||||
|
ts_uIPd = dataset.iloc[:,3]
|
||||||
|
|
||||||
|
### rep-14: Signals correlation ###
|
||||||
|
|
||||||
|
print('Correlations between different columns (NaNs filtered):')
|
||||||
|
print(dataset.corr(method='pearson').round(decimals=2))
|
||||||
|
|
||||||
|
### rep-15: Destinations/Sources ratio ###
|
||||||
|
|
||||||
|
ratio_uIPd_uIPs = median(ts_uIPd) / median(ts_uIPs)
|
||||||
|
print('Ratio between median IP destinations and median IP sources: ', ratio_uIPd_uIPs)
|
||||||
|
|
||||||
|
### rep-16: Peak in unique sources ###
|
||||||
|
|
||||||
|
date = datetime.fromtimestamp(ts_uIPs.idxmax())
|
||||||
|
print('Peak in unique sources: ', date)
|
||||||
3686
ex3/global_last10years.csv
Normal file
3686
ex3/global_last10years.csv
Normal file
File diff suppressed because it is too large
Load Diff
2
ex3/requirements.txt
Normal file
2
ex3/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pandas
|
||||||
|
matplotlib
|
||||||
Loading…
x
Reference in New Issue
Block a user