-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateData.py
114 lines (93 loc) · 2.72 KB
/
generateData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
---------------------------------
Author: gilbertorgit
Date: 03/2023
---------------------------------
"""
import sys
sys.path.append('/')
import pandas as pd
import json
import numpy as np
import openpyxl
class GenerateData:
def __init__(self):
# lab1_device_info.xlsx TABs
self._VMX = {}
self._VROUTER = {}
self._SRX = {}
self._VEX = {}
self._VEVO = {}
self._APSTRA = {}
self._LINUX = {}
self._merged_data = {}
def generate_data_info(self, excel_file: str, *args):
"""
Read Excel file
"""
for tab_name in args:
try:
df = pd.read_excel(excel_file, sheet_name=tab_name)
except ValueError as e:
print(f"Error reading the sheet '{tab_name}': {e}")
continue
df['name'] = df['name'].replace({0: np.nan}).fillna(method='ffill')
df = df.replace({None: np.nan})
df = df.dropna(thresh=2)
df = df.fillna('None')
results = {}
for name, g in df.groupby(by='name'):
g = g.drop('name', axis=1)
data = json.loads(g.to_json(orient='table'))['data']
for d in data:
__ = d.pop('index')
results[name] = {
'data': data
}
attribute_map = {
'VMX': '_VMX',
'VROUTER': '_VROUTER',
'SRX': '_SRX',
'VEX': '_VEX',
'VEVO': '_VEVO',
'APSTRA': '_APSTRA',
'LINUX': '_LINUX'
}
attribute_name = attribute_map.get(tab_name)
if attribute_name:
setattr(self, attribute_name, results)
@property
def get_vmx(self):
return self._VMX
@property
def get_vrouter(self):
return self._VROUTER
@property
def get_srx(self):
return self._SRX
@property
def get_vex(self):
return self._VEX
@property
def get_vevo(self):
return self._VEVO
@property
def get_apstra(self):
return self._APSTRA
@property
def get_linux(self):
return self._LINUX
@property
def get_merged_data(self):
"""
Creates a merged data list based on the TABS
:return:
"""
self._merged_data = self.get_vmx
self._merged_data.update(self.get_vrouter)
self._merged_data.update(self.get_srx)
self._merged_data.update(self.get_vex)
self._merged_data.update(self.get_vevo)
self._merged_data.update(self.get_apstra)
self._merged_data.update(self.get_linux)
return self._merged_data