import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from sklearn.externals import joblib
import numpy as np
dev_list = ['AMP', 'ETH', 'ETH10G', 'ETHN', 'ETTP', 'OPTMON', 'OSC', 'OTM', 'OTM2', 'OTUTTP', 'PTP']

alarm_list = [None, 'Excessive Error Ratio',  # 1
              'Frequency Out Of Range',  # 2
              'GCC0 Link Failure', 'Gauge Threshold Crossing Alert Summary',  # 4
              'Link Down', 'Local Fault', 'Loss Of Clock', 'Loss Of Frame', 'Loss Of Signal',  # 9
              'OSC OSPF Adjacency Loss', 'OTU Signal Degrade',  # 11
              'Rx Power Out Of Range']  # 12

state_list = ['IS', 'n/a', 'IS-ANR']


# # May dataset
# data = pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/Europe_Network_Data_May13.parquet')
# data.drop('LASTOCCURRENCE', axis=1, inplace=True)


# # May 23 dataset
# data = pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/v2_Europe_network_data_pivoted.parquet')
# labels = pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/v2_Europe_network_labels.parquet')
#
# # remove PEC for join
# tmp, _ = data['meta_NHP_ID'].str.rsplit(':',1).str
# data['ID'] = tmp
#
# labels['ID'] = labels['fk']
#
# # floor to nearest day
# data['TIME'] = pd.to_datetime(data['pk_timestamp'], infer_datetime_format=True).dt.floor('1D')
# labels['TIME'] = pd.to_datetime(labels['time'], infer_datetime_format=True).dt.floor('1D')
#
# data = pd.merge(data, labels, on=['ID', 'TIME'])
# data = data.drop(['pk_id', 'pk_timestamp', 'meta_NHP_ID', 'meta_PEC', 'meta_TID', 'meta_AID', 'meta_SHELF', 'meta_SLOT', 'meta_PORT', 'meta_CHANNEL',
#             'createdAt', 'description', 'extraAttributes', 'fk', 'time', 'timestamp'], axis=1)
# rep_list = {'meta_FACILITY': 'GROUPBYKEY',
#             'meta_STATUS': 'LABEL',
#             'category': 'ALARM'
#             }
# # rename the columns
# data = data.rename(columns=rep_list)
# sup_list = ['OPTAVG-OCH', 'OPTMAX-OCH_OPTMIN-OCH_-']
# data[sup_list] = np.nan

# # March data
data= pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/Europe_Network_data.parquet')
index = data.columns
# scaler = joblib.load('standard_scaler.pkl')

# filter data
devices = data[data['GROUPBYKEY'].isin(dev_list)]
devices = devices[devices['ALARM'].isin(alarm_list)]  # filter out devices with alarm out of the list
devices = devices.set_index(['ID', 'TIME']).sort_index().reset_index()
devices = devices.drop_duplicates(subset=['ID', 'TIME'])

# drop data that has less than 100 days
dev_count = devices['ID'].value_counts()
dev_count = dev_count.drop(dev_count[dev_count < 30].index).index.tolist()
devices = devices[devices['ID'].isin(dev_count)]  # filter out devices that has less data than the time window

# devices.iloc[:, 4:49] = scaler.transform(devices.iloc[:, 4:49].values)


anomalies = devices.loc[devices['ALARM'].notna()]


# devices = df.groupby(['meta_facility'])['ID'].value_counts().index.to_frame()
# devices['meta_facility'].value_counts()
## Count anomaly devices
# devices = anomaly.groupby(['category', 'meta_facility']).nunique()['ID']

def plot_per_device(data, device_id):

    plt.rcParams['figure.figsize']=[8,6]
    plt.rcParams['figure.dpi'] = 200
    # get data by device id
    per_device = data[data.ID == device_id]
    anomaly = per_device.loc[per_device['ALARM'].notna()]
    oos = per_device[~per_device['LABEL'].isin(state_list)]
    # get device type
    device_type = per_device['GROUPBYKEY'].values[0]
    # drop NaN columns
    per_device.dropna('columns', inplace=True)
    # set `TIME` column as index and convert the format to '%y-%mm-%dd'
    per_device.set_index('TIME', inplace=True)
    per_device.index = pd.to_datetime(per_device.index, format='%y-%mm-%dd', unit='s')
    # data from 2018-11-18 to 2019-03-19, frequency: day
    days = pd.date_range('20181118', end='20190319', freq='D')
    # reindex the data and fill the gaps with NaN
    per_device = per_device.reindex(days)
    # set `TIME` column as index and convert the format to '%y-%mm-%dd'
    anomaly.set_index('TIME', inplace=True)
    anomaly.index = pd.to_datetime(anomaly.index, format='%y-%mm-%dd', unit='s')
    # alarm_type = anomaly['ALARM']
    print(anomaly['ALARM'])
    oos.set_index('TIME', inplace=True)
    oos.index = pd.to_datetime(oos.index, format='%y-%mm-%dd', unit='s')
    oos = oos[per_device.columns]

    plt.figure()
    # plot a subplot for each PM value
    axs = per_device.plot(subplots=True, grid=True, marker='o', markersize=2)
    # plot scatter for not-in-service data
    try:
        axs = oos.plot(ax = axs.flatten()[:], legend = False, subplots=True, grid=True, style='yx', markersize=5)
    except:
        print('All data in-service')
    # # plot a vline for each anomaly in each ax
    for ax in axs:
        ax.legend(loc=2, prop={'size': 5})
        try:
            for vline in anomaly.index.to_list():
                ax.axvline(vline, color='r', lw=1, ls='dashed', label='anomaly')
                # print(anomaly.loc[vline, ['TIME', 'ALARM']])
        except:
            print('No anomaly exsists')

    plt.xlabel('ID: ' + device_id + '   Device Type: '+device_type)

    plt.show()

devs = anomalies[anomalies['GROUPBYKEY']==dev_list[0]]['ID'].value_counts().index.to_list()
for dev in devs:
    plot_per_device(devices, dev)


# ALARM                                   GROUPBYKEY
# Excessive Error Ratio                   ETH10G          2
#                                         ETTP           13
# Frequency Out Of Range                  ETTP            3
# GCC0 Link Failure                       OTM            35
#                                         OTM2            2
#                                         OTUTTP          1
# Gauge Threshold Crossing Alert Summary  AMP            17
#                                         OPTMON         25
# Link Down                               ETH10G          2
# Local Fault                             ETH10G        109
#                                         ETHN            8
#                                         ETTP           14
# Loss Of Clock                           ETH10G          9
#                                         ETHN           26
#                                         ETTP            1
#                                         OTM             1
#                                         OTUTTP          3
# Loss Of Frame                           ETH10G         17
#                                         ETHN            2
#                                         ETTP            3
# Loss Of Signal                          ETH10G        208
#                                         ETHN           15
#                                         OPTMON         75
#                                         OTM             1
#                                         OTM2            2
#                                         PTP             3
# OSC OSPF Adjacency Loss                 OSC            18
# OTU Signal Degrade                      OTM2            1
# Rx Power Out Of Range                   ETH10G          6
#                                         ETHN            1
#                                         OTM             1

eer = anomalies[anomalies['ALARM'] == 'Excessive Error Ratio']['ID'].value_counts()
670d4e41f1251cc4051cf6daa6f9396656a4a617
<mask token>


def plot_per_device(data, device_id):
    plt.rcParams['figure.figsize'] = [8, 6]
    plt.rcParams['figure.dpi'] = 200
    per_device = data[data.ID == device_id]
    anomaly = per_device.loc[per_device['ALARM'].notna()]
    oos = per_device[~per_device['LABEL'].isin(state_list)]
    device_type = per_device['GROUPBYKEY'].values[0]
    per_device.dropna('columns', inplace=True)
    per_device.set_index('TIME', inplace=True)
    per_device.index = pd.to_datetime(per_device.index, format='%y-%mm-%dd',
        unit='s')
    days = pd.date_range('20181118', end='20190319', freq='D')
    per_device = per_device.reindex(days)
    anomaly.set_index('TIME', inplace=True)
    anomaly.index = pd.to_datetime(anomaly.index, format='%y-%mm-%dd', unit='s'
        )
    print(anomaly['ALARM'])
    oos.set_index('TIME', inplace=True)
    oos.index = pd.to_datetime(oos.index, format='%y-%mm-%dd', unit='s')
    oos = oos[per_device.columns]
    plt.figure()
    axs = per_device.plot(subplots=True, grid=True, marker='o', markersize=2)
    try:
        axs = oos.plot(ax=axs.flatten()[:], legend=False, subplots=True,
            grid=True, style='yx', markersize=5)
    except:
        print('All data in-service')
    for ax in axs:
        ax.legend(loc=2, prop={'size': 5})
        try:
            for vline in anomaly.index.to_list():
                ax.axvline(vline, color='r', lw=1, ls='dashed', label='anomaly'
                    )
        except:
            print('No anomaly exsists')
    plt.xlabel('ID: ' + device_id + '   Device Type: ' + device_type)
    plt.show()


<mask token>

<mask token>


def plot_per_device(data, device_id):
    plt.rcParams['figure.figsize'] = [8, 6]
    plt.rcParams['figure.dpi'] = 200
    per_device = data[data.ID == device_id]
    anomaly = per_device.loc[per_device['ALARM'].notna()]
    oos = per_device[~per_device['LABEL'].isin(state_list)]
    device_type = per_device['GROUPBYKEY'].values[0]
    per_device.dropna('columns', inplace=True)
    per_device.set_index('TIME', inplace=True)
    per_device.index = pd.to_datetime(per_device.index, format='%y-%mm-%dd',
        unit='s')
    days = pd.date_range('20181118', end='20190319', freq='D')
    per_device = per_device.reindex(days)
    anomaly.set_index('TIME', inplace=True)
    anomaly.index = pd.to_datetime(anomaly.index, format='%y-%mm-%dd', unit='s'
        )
    print(anomaly['ALARM'])
    oos.set_index('TIME', inplace=True)
    oos.index = pd.to_datetime(oos.index, format='%y-%mm-%dd', unit='s')
    oos = oos[per_device.columns]
    plt.figure()
    axs = per_device.plot(subplots=True, grid=True, marker='o', markersize=2)
    try:
        axs = oos.plot(ax=axs.flatten()[:], legend=False, subplots=True,
            grid=True, style='yx', markersize=5)
    except:
        print('All data in-service')
    for ax in axs:
        ax.legend(loc=2, prop={'size': 5})
        try:
            for vline in anomaly.index.to_list():
                ax.axvline(vline, color='r', lw=1, ls='dashed', label='anomaly'
                    )
        except:
            print('No anomaly exsists')
    plt.xlabel('ID: ' + device_id + '   Device Type: ' + device_type)
    plt.show()


<mask token>
for dev in devs:
    plot_per_device(devices, dev)
<mask token>

<mask token>
dev_list = ['AMP', 'ETH', 'ETH10G', 'ETHN', 'ETTP', 'OPTMON', 'OSC', 'OTM',
    'OTM2', 'OTUTTP', 'PTP']
alarm_list = [None, 'Excessive Error Ratio', 'Frequency Out Of Range',
    'GCC0 Link Failure', 'Gauge Threshold Crossing Alert Summary',
    'Link Down', 'Local Fault', 'Loss Of Clock', 'Loss Of Frame',
    'Loss Of Signal', 'OSC OSPF Adjacency Loss', 'OTU Signal Degrade',
    'Rx Power Out Of Range']
state_list = ['IS', 'n/a', 'IS-ANR']
data = pd.read_parquet(
    '/home/oem/Projects/NetDeviceAbnormalDetection/data/Europe_Network_data.parquet'
    )
index = data.columns
devices = data[data['GROUPBYKEY'].isin(dev_list)]
devices = devices[devices['ALARM'].isin(alarm_list)]
devices = devices.set_index(['ID', 'TIME']).sort_index().reset_index()
devices = devices.drop_duplicates(subset=['ID', 'TIME'])
dev_count = devices['ID'].value_counts()
dev_count = dev_count.drop(dev_count[dev_count < 30].index).index.tolist()
devices = devices[devices['ID'].isin(dev_count)]
anomalies = devices.loc[devices['ALARM'].notna()]


def plot_per_device(data, device_id):
    plt.rcParams['figure.figsize'] = [8, 6]
    plt.rcParams['figure.dpi'] = 200
    per_device = data[data.ID == device_id]
    anomaly = per_device.loc[per_device['ALARM'].notna()]
    oos = per_device[~per_device['LABEL'].isin(state_list)]
    device_type = per_device['GROUPBYKEY'].values[0]
    per_device.dropna('columns', inplace=True)
    per_device.set_index('TIME', inplace=True)
    per_device.index = pd.to_datetime(per_device.index, format='%y-%mm-%dd',
        unit='s')
    days = pd.date_range('20181118', end='20190319', freq='D')
    per_device = per_device.reindex(days)
    anomaly.set_index('TIME', inplace=True)
    anomaly.index = pd.to_datetime(anomaly.index, format='%y-%mm-%dd', unit='s'
        )
    print(anomaly['ALARM'])
    oos.set_index('TIME', inplace=True)
    oos.index = pd.to_datetime(oos.index, format='%y-%mm-%dd', unit='s')
    oos = oos[per_device.columns]
    plt.figure()
    axs = per_device.plot(subplots=True, grid=True, marker='o', markersize=2)
    try:
        axs = oos.plot(ax=axs.flatten()[:], legend=False, subplots=True,
            grid=True, style='yx', markersize=5)
    except:
        print('All data in-service')
    for ax in axs:
        ax.legend(loc=2, prop={'size': 5})
        try:
            for vline in anomaly.index.to_list():
                ax.axvline(vline, color='r', lw=1, ls='dashed', label='anomaly'
                    )
        except:
            print('No anomaly exsists')
    plt.xlabel('ID: ' + device_id + '   Device Type: ' + device_type)
    plt.show()


devs = anomalies[anomalies['GROUPBYKEY'] == dev_list[0]]['ID'].value_counts(
    ).index.to_list()
for dev in devs:
    plot_per_device(devices, dev)
eer = anomalies[anomalies['ALARM'] == 'Excessive Error Ratio']['ID'
    ].value_counts()

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from sklearn.externals import joblib
import numpy as np
dev_list = ['AMP', 'ETH', 'ETH10G', 'ETHN', 'ETTP', 'OPTMON', 'OSC', 'OTM',
    'OTM2', 'OTUTTP', 'PTP']
alarm_list = [None, 'Excessive Error Ratio', 'Frequency Out Of Range',
    'GCC0 Link Failure', 'Gauge Threshold Crossing Alert Summary',
    'Link Down', 'Local Fault', 'Loss Of Clock', 'Loss Of Frame',
    'Loss Of Signal', 'OSC OSPF Adjacency Loss', 'OTU Signal Degrade',
    'Rx Power Out Of Range']
state_list = ['IS', 'n/a', 'IS-ANR']
data = pd.read_parquet(
    '/home/oem/Projects/NetDeviceAbnormalDetection/data/Europe_Network_data.parquet'
    )
index = data.columns
devices = data[data['GROUPBYKEY'].isin(dev_list)]
devices = devices[devices['ALARM'].isin(alarm_list)]
devices = devices.set_index(['ID', 'TIME']).sort_index().reset_index()
devices = devices.drop_duplicates(subset=['ID', 'TIME'])
dev_count = devices['ID'].value_counts()
dev_count = dev_count.drop(dev_count[dev_count < 30].index).index.tolist()
devices = devices[devices['ID'].isin(dev_count)]
anomalies = devices.loc[devices['ALARM'].notna()]


def plot_per_device(data, device_id):
    plt.rcParams['figure.figsize'] = [8, 6]
    plt.rcParams['figure.dpi'] = 200
    per_device = data[data.ID == device_id]
    anomaly = per_device.loc[per_device['ALARM'].notna()]
    oos = per_device[~per_device['LABEL'].isin(state_list)]
    device_type = per_device['GROUPBYKEY'].values[0]
    per_device.dropna('columns', inplace=True)
    per_device.set_index('TIME', inplace=True)
    per_device.index = pd.to_datetime(per_device.index, format='%y-%mm-%dd',
        unit='s')
    days = pd.date_range('20181118', end='20190319', freq='D')
    per_device = per_device.reindex(days)
    anomaly.set_index('TIME', inplace=True)
    anomaly.index = pd.to_datetime(anomaly.index, format='%y-%mm-%dd', unit='s'
        )
    print(anomaly['ALARM'])
    oos.set_index('TIME', inplace=True)
    oos.index = pd.to_datetime(oos.index, format='%y-%mm-%dd', unit='s')
    oos = oos[per_device.columns]
    plt.figure()
    axs = per_device.plot(subplots=True, grid=True, marker='o', markersize=2)
    try:
        axs = oos.plot(ax=axs.flatten()[:], legend=False, subplots=True,
            grid=True, style='yx', markersize=5)
    except:
        print('All data in-service')
    for ax in axs:
        ax.legend(loc=2, prop={'size': 5})
        try:
            for vline in anomaly.index.to_list():
                ax.axvline(vline, color='r', lw=1, ls='dashed', label='anomaly'
                    )
        except:
            print('No anomaly exsists')
    plt.xlabel('ID: ' + device_id + '   Device Type: ' + device_type)
    plt.show()


devs = anomalies[anomalies['GROUPBYKEY'] == dev_list[0]]['ID'].value_counts(
    ).index.to_list()
for dev in devs:
    plot_per_device(devices, dev)
eer = anomalies[anomalies['ALARM'] == 'Excessive Error Ratio']['ID'
    ].value_counts()

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from sklearn.externals import joblib
import numpy as np
dev_list = ['AMP', 'ETH', 'ETH10G', 'ETHN', 'ETTP', 'OPTMON', 'OSC', 'OTM', 'OTM2', 'OTUTTP', 'PTP']

alarm_list = [None, 'Excessive Error Ratio',  # 1
              'Frequency Out Of Range',  # 2
              'GCC0 Link Failure', 'Gauge Threshold Crossing Alert Summary',  # 4
              'Link Down', 'Local Fault', 'Loss Of Clock', 'Loss Of Frame', 'Loss Of Signal',  # 9
              'OSC OSPF Adjacency Loss', 'OTU Signal Degrade',  # 11
              'Rx Power Out Of Range']  # 12

state_list = ['IS', 'n/a', 'IS-ANR']


# # May dataset
# data = pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/Europe_Network_Data_May13.parquet')
# data.drop('LASTOCCURRENCE', axis=1, inplace=True)


# # May 23 dataset
# data = pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/v2_Europe_network_data_pivoted.parquet')
# labels = pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/v2_Europe_network_labels.parquet')
#
# # remove PEC for join
# tmp, _ = data['meta_NHP_ID'].str.rsplit(':',1).str
# data['ID'] = tmp
#
# labels['ID'] = labels['fk']
#
# # floor to nearest day
# data['TIME'] = pd.to_datetime(data['pk_timestamp'], infer_datetime_format=True).dt.floor('1D')
# labels['TIME'] = pd.to_datetime(labels['time'], infer_datetime_format=True).dt.floor('1D')
#
# data = pd.merge(data, labels, on=['ID', 'TIME'])
# data = data.drop(['pk_id', 'pk_timestamp', 'meta_NHP_ID', 'meta_PEC', 'meta_TID', 'meta_AID', 'meta_SHELF', 'meta_SLOT', 'meta_PORT', 'meta_CHANNEL',
#             'createdAt', 'description', 'extraAttributes', 'fk', 'time', 'timestamp'], axis=1)
# rep_list = {'meta_FACILITY': 'GROUPBYKEY',
#             'meta_STATUS': 'LABEL',
#             'category': 'ALARM'
#             }
# # rename the columns
# data = data.rename(columns=rep_list)
# sup_list = ['OPTAVG-OCH', 'OPTMAX-OCH_OPTMIN-OCH_-']
# data[sup_list] = np.nan

# # March data
data= pd.read_parquet('/home/oem/Projects/NetDeviceAbnormalDetection/data/Europe_Network_data.parquet')
index = data.columns
# scaler = joblib.load('standard_scaler.pkl')

# filter data
devices = data[data['GROUPBYKEY'].isin(dev_list)]
devices = devices[devices['ALARM'].isin(alarm_list)]  # filter out devices with alarm out of the list
devices = devices.set_index(['ID', 'TIME']).sort_index().reset_index()
devices = devices.drop_duplicates(subset=['ID', 'TIME'])

# drop data that has less than 100 days
dev_count = devices['ID'].value_counts()
dev_count = dev_count.drop(dev_count[dev_count < 30].index).index.tolist()
devices = devices[devices['ID'].isin(dev_count)]  # filter out devices that has less data than the time window

# devices.iloc[:, 4:49] = scaler.transform(devices.iloc[:, 4:49].values)


anomalies = devices.loc[devices['ALARM'].notna()]


# devices = df.groupby(['meta_facility'])['ID'].value_counts().index.to_frame()
# devices['meta_facility'].value_counts()
## Count anomaly devices
# devices = anomaly.groupby(['category', 'meta_facility']).nunique()['ID']

def plot_per_device(data, device_id):

    plt.rcParams['figure.figsize']=[8,6]
    plt.rcParams['figure.dpi'] = 200
    # get data by device id
    per_device = data[data.ID == device_id]
    anomaly = per_device.loc[per_device['ALARM'].notna()]
    oos = per_device[~per_device['LABEL'].isin(state_list)]
    # get device type
    device_type = per_device['GROUPBYKEY'].values[0]
    # drop NaN columns
    per_device.dropna('columns', inplace=True)
    # set `TIME` column as index and convert the format to '%y-%mm-%dd'
    per_device.set_index('TIME', inplace=True)
    per_device.index = pd.to_datetime(per_device.index, format='%y-%mm-%dd', unit='s')
    # data from 2018-11-18 to 2019-03-19, frequency: day
    days = pd.date_range('20181118', end='20190319', freq='D')
    # reindex the data and fill the gaps with NaN
    per_device = per_device.reindex(days)
    # set `TIME` column as index and convert the format to '%y-%mm-%dd'
    anomaly.set_index('TIME', inplace=True)
    anomaly.index = pd.to_datetime(anomaly.index, format='%y-%mm-%dd', unit='s')
    # alarm_type = anomaly['ALARM']
    print(anomaly['ALARM'])
    oos.set_index('TIME', inplace=True)
    oos.index = pd.to_datetime(oos.index, format='%y-%mm-%dd', unit='s')
    oos = oos[per_device.columns]

    plt.figure()
    # plot a subplot for each PM value
    axs = per_device.plot(subplots=True, grid=True, marker='o', markersize=2)
    # plot scatter for not-in-service data
    try:
        axs = oos.plot(ax = axs.flatten()[:], legend = False, subplots=True, grid=True, style='yx', markersize=5)
    except:
        print('All data in-service')
    # # plot a vline for each anomaly in each ax
    for ax in axs:
        ax.legend(loc=2, prop={'size': 5})
        try:
            for vline in anomaly.index.to_list():
                ax.axvline(vline, color='r', lw=1, ls='dashed', label='anomaly')
                # print(anomaly.loc[vline, ['TIME', 'ALARM']])
        except:
            print('No anomaly exsists')

    plt.xlabel('ID: ' + device_id + '   Device Type: '+device_type)

    plt.show()

devs = anomalies[anomalies['GROUPBYKEY']==dev_list[0]]['ID'].value_counts().index.to_list()
for dev in devs:
    plot_per_device(devices, dev)


# ALARM                                   GROUPBYKEY
# Excessive Error Ratio                   ETH10G          2
#                                         ETTP           13
# Frequency Out Of Range                  ETTP            3
# GCC0 Link Failure                       OTM            35
#                                         OTM2            2
#                                         OTUTTP          1
# Gauge Threshold Crossing Alert Summary  AMP            17
#                                         OPTMON         25
# Link Down                               ETH10G          2
# Local Fault                             ETH10G        109
#                                         ETHN            8
#                                         ETTP           14
# Loss Of Clock                           ETH10G          9
#                                         ETHN           26
#                                         ETTP            1
#                                         OTM             1
#                                         OTUTTP          3
# Loss Of Frame                           ETH10G         17
#                                         ETHN            2
#                                         ETTP            3
# Loss Of Signal                          ETH10G        208
#                                         ETHN           15
#                                         OPTMON         75
#                                         OTM             1
#                                         OTM2            2
#                                         PTP             3
# OSC OSPF Adjacency Loss                 OSC            18
# OTU Signal Degrade                      OTM2            1
# Rx Power Out Of Range                   ETH10G          6
#                                         ETHN            1
#                                         OTM             1

eer = anomalies[anomalies['ALARM'] == 'Excessive Error Ratio']['ID'].value_counts()