-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHamilton Method Manager Build script.py
More file actions
201 lines (167 loc) · 6.93 KB
/
Hamilton Method Manager Build script.py
File metadata and controls
201 lines (167 loc) · 6.93 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import pandas as pd
import json
#defining excel filepaths
excel_filepath = "C:/Users/Festo Muhire/Desktop/Method Manager Python/Method Manager Masterlist.xlsx"
#defining JSON Config files
Groupsjson_filepath = "C:/Users/Festo Muhire/Desktop/Method Manager Python/Method Manager 2/db/groups.json"
Treesjson_filepath = "C:/Users/Festo Muhire/Desktop/Method Manager Python/Method Manager 2/db/tree.json"
Linksjson_filepath = "C:/Users/Festo Muhire/Desktop/Method Manager Python/Method Manager 2/db/links.json"
# Replace 'Sheet2' with the name of your desired worksheet
worksheet_name = 'Sheet1'
# Read the specific worksheet into a pandas DataFrame
df= pd.read_excel(excel_filepath, sheet_name=worksheet_name)
# Reading the :
with open(Groupsjson_filepath,'r') as groups:
group_data_load = json.load(groups)
with open(Treesjson_filepath,'r') as trees:
tree_data_load = json.load(trees)
with open(Linksjson_filepath, 'r') as links:
link_data_load = json.load(links)
# Replace 'your_column_name' with the actual name of the column you want to analyze
column_groupIDs = list(df['groups'].unique())
column_links = list(df['links'])
column_paths = list(df['paths'])
column_attachments = list(df['attachments'])
#print(column_paths)
for group in column_groupIDs:
found = False
tree_found = False
for item in group_data_load:
if item["name"] == group:
found = True
break # The GroupID was found; then break
# If the Group was not found, create a new dictionary entry
if not found:
group_data = {}
group_data['name'] = group
group_data['icon-class'] = 'fa-dna'
group_data['default'] = False
group_data['navbar'] = 'left'
group_data['favorite'] = True
group_data['_id'] = group
group_data_load.append(group_data)
# Save the updated JSON data back to the file
with open(Groupsjson_filepath, "w") as g:
json.dump(group_data_load, g)
for item in tree_data_load:
if item["group-id"] == group:
tree_found = True
break # The GroupID was found; then break
if not tree_found:
tree_data = {}
tree_data['group-id'] = group
tree_data['method-ids'] = []
tree_data['locked'] = False
tree_data['_id'] = ""
tree_data_load.append(tree_data)
# Save the updated JSON data back to the file
with open(Treesjson_filepath, "w") as t:
json.dump(tree_data_load, t)
#checking if the link is present in the links JSON file:
for link in column_links:
#corresponding_attachments = (df.loc[df['links'] == link, 'attachments'].values)
#print(corresponding_attachments)
found = False
for item in link_data_load:
if item["name"] == link:
found = True
break # The GroupID was found; then break
# If the link was not found, create a new dictionary entry
if not found:
link_data = {}
link_data['name'] = link
link_data['description'] = ""
link_data['icon-customImage'] = ""
link_data['icon-class'] = "fa-dna"
link_data['icon-color'] = "color-dark"
link_data['path'] = ""
link_data['type'] = "method"
link_data['attachments'] = []
link_data['default'] = False
link_data['favorite'] = True
link_data['last-started'] = ""
link_data['last-startedUTC'] = ""
link_data['_id'] = link
link_data_load.append(link_data)
# Save the updated JSON data back to the file
with open(Linksjson_filepath, "w") as l:
json.dump(link_data_load, l)
# Check if the link is associated to the right group in the tree JSON file:
for link in column_links:
corresponding_group = (df.loc[df['links'] == link, 'groups'].values)
found = False
for item in tree_data_load:
for entry in item['method-ids']:
if entry == link:
if item['group-id'] == corresponding_group:
found = True
break
else:
item['method-ids'].remove(link)
if not found:
for item in tree_data_load:
if item['group-id'] == corresponding_group:
# locate which group the link belongs to, and append it to the Method-ids key:
item['method-ids'].append(link)
# Save the updated JSON data back to the file
with open(Treesjson_filepath, "w") as l:
json.dump(tree_data_load, l)
# Check if the path is present in the link JSON file, and if not, add to the JSON file:
for path in column_paths:
corresponding_link = df.loc[df['paths'] == path, 'links'].values
#print(corresponding_link)
found = False
for item in link_data_load:
if item ['name'] == corresponding_link:
if item['path'] == path:
found = True
break
if not found:
for item in link_data_load:
if item['name'] == corresponding_link:
# locate which group the link belongs to, and append it to the Method-ids key:
item['path'] = path
# Save the updated JSON data back to the file
with open(Linksjson_filepath, "w") as j:
json.dump(link_data_load, j)
# Check if the attachment(s) is present in the link JSON file, and if not, add to the JSON file:
for attachment in column_attachments:
corresponding_link = df.loc[df['attachments'] == attachment, 'links'].values
print(corresponding_link)
found = False
for item in link_data_load:
if item ['name'] == corresponding_link:
if item['attachments'] == [attachment]:
found = True
break
elif item['attachments'] == []:
found = True
break
if not found:
for item in link_data_load:
if item['name'] == corresponding_link:
# locate which group the link belongs to, and append it to the Method-ids key:
item['attachments'].append(attachment)
# Save the updated JSON data back to the file
with open(Linksjson_filepath, "w") as a:
json.dump(link_data_load, a)
# Check if the link is associated with the right path in the link JSON file:
for link in column_links:
corresponding_path = (df.loc[df['links'] == link, 'paths'].values)
found = False
for item in link_data_load:
for entry in item['name']:
if entry == link:
if item['group-id'] == corresponding_group:
found = True
break
else:
item['method-ids'].remove(link)
if not found:
for item in tree_data_load:
if item['group-id'] == corresponding_group:
# locate which group the link belongs to, and append it to the Method-ids key:
item['method-ids'].append(link)
# Save the updated JSON data back to the file
with open(Treesjson_filepath, "w") as l:
json.dump(tree_data_load, l)