-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdc
271 lines (170 loc) · 9.29 KB
/
dc
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
Sub main()
Dim EEJSON_folder As String
EEJSON_folder = "C:\JSON\"
csvFilename = Dir(EEJSON_folder & "*.txt")
Dim c As New Collection
Debug.Print "fetch all files", "start", Now
Do While csvFilename <> ""
c.Add csvFilename
csvFilename = Dir()
Loop
Debug.Print "fetch all files", "end", Now
For i = 1 To c.Count
If c(i) <> "wall.txt" Then
timethen = Now
'Debug.Print c(i), GetFileSizeKB(EEJSON_folder & c(i)) & "kb", "start", Now
'Call ff(EEJSON_folder, c(i))
Call functiontest(EEJSON_folder, c(i))
'Debug.Print c(i), "end", Now
Debug.Print c(i), "cpu usage: " & GetCPUUsage(), "Memory usage: " & GetMemoryUsagePercentage(), "filesize: " & GetFileSizeKB(EEJSON_folder & c(i)) & "kb", "Time: " & Format(Now - timethen, "hh:mm:ss")
End If
Next i
End Sub
Function GetMemoryUsagePercentage() As String
Dim objWMIService As Object
Dim colOS As Object
Dim objOS As Object
Dim usedMemoryPercentage As Double
' Connect to the WMI service
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
' Query operating system properties
Set colOS = objWMIService.ExecQuery("Select TotalVisibleMemorySize, FreePhysicalMemory from Win32_OperatingSystem", , 48)
For Each objOS In colOS
' Calculate the used memory percentage
usedMemoryPercentage = ((objOS.TotalVisibleMemorySize - objOS.FreePhysicalMemory) / objOS.TotalVisibleMemorySize) * 100
Next
GetMemoryUsagePercentage = Format(usedMemoryPercentage, "0.00") & "%"
End Function
Function GetCPUUsage() As String
Dim objWMIService As Object
Dim colItems As Object
Dim objItem As Object
Dim strReturn As String
' Connect to the WMI service
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
' Query CPU load
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor", , 48)
For Each objItem In colItems
strReturn = strReturn & "CPU " & objItem.DeviceID & " Usage: " & objItem.LoadPercentage & "%"
Next
GetCPUUsage = strReturn
End Function
Function GetFileSizeKB(filePath As String) As Double
Dim fileSize As Long
fileSize = FileLen(filePath)
If Err.Number <> 0 Then
GetFileSizeKB = -1 ' Return -1 if there's an error (e.g., file not found)
Else
GetFileSizeKB = Round(fileSize / 1024, 2) ' Convert bytes to KB and round to 2 decimal places
End If
End Function
Sub functiontest(EEJSON_folder, eeJsonFile)
'empid = ""
eeJsonFile = EEJSON_folder & eeJsonFile
' Set reference to the worksheet where data will be populated
Dim st As Worksheet
Set st = Workbooks("Data Capture Template v2 0808 1520(1).xlsm").Sheets("DC")
' Delete existing data in Column B and shift cells left
st.Cells.Delete Shift:=xlToLeft
' Read JSON file content into a string
eeJson = F_util.ReadTextFileToString(eeJsonFile)
' Parse the JSON string into a dictionary object
Dim eeJson_obj As Object
Set eeJson_obj = JsonConverter.ParseJson(eeJson)
' Retrieve keys from the parsed JSON object
json_k = eeJson_obj.Keys
' Iterate through each key in the JSON object
For u = 0 To UBound(json_k)
start_r = st.Cells(st.Rows.Count, "a").End(xlUp).row
Section_name = "Section: " & json_k(u)
st.Cells(start_r + 2, 1).Value = Section_name
'Debug.Print json_k(u), TypeName(eeJson_obj(json_k(u)))
' Check if the current item is a collection
If TypeName(eeJson_obj(json_k(u))) = "Collection" Then
start_r = st.Cells(st.Rows.Count, "a").End(xlUp).row
For i = 1 To eeJson_obj(json_k(u)).Count
If TypeName(eeJson_obj(json_k(u))(i)) = "Collection" Then
For o = 1 To eeJson_obj(json_k(u))(i).Count
'Debug.Print TypeName(eeJson_obj(json_k(u))(i)(o))
st.Cells(start_r + o, 1).Value = eeJson_obj(json_k(u))(i)(o)
Next o
ElseIf TypeName(eeJson_obj(json_k(u))(i)) = "Dictionary" Then
Set layer2_dic = eeJson_obj(json_k(u))(i)
layer2_keys = layer2_dic.Keys
For i_layer2 = 0 To UBound(layer2_keys)
If i = 1 Then
st.Cells(start_r + i_layer2 + 1, 1).Value = layer2_keys(i_layer2)
End If
st.Cells(start_r + i_layer2 + 1, i + 1).Value = layer2_dic(layer2_keys(i_layer2))
Next i_layer2
ElseIf TypeName(eeJson_obj(json_k(u))(i)) = "String" Then
st.Cells(start_r + 1, 1).Value = "Value"
st.Cells(start_r + 1, i + 1).Value = eeJson_obj(json_k(u))(i)
End If
Next i
' Check if the current item is a Dictionary
ElseIf TypeName(eeJson_obj(json_k(u))) = "Dictionary" Then
If (json_k(u)) = "Plans" Then
start_r = st.Cells(st.Rows.Count, "a").End(xlUp).row
st.Cells(start_r + 1, 1).Value = "Plan Name"
st.Cells(start_r + 2, 1).Value = "Carrier"
Set layer1_dic = eeJson_obj(json_k(u))
layer1_keys = eeJson_obj(json_k(u)).Keys
For i = 0 To UBound(layer1_keys)
st.Cells(start_r + 1, i + 2).Value = layer1_keys(i)
st.Cells(start_r + 2, i + 2).Value = layer1_dic(layer1_keys(i))
Next i
Else
Set layer1_dic = eeJson_obj(json_k(u))
layer1_keys = eeJson_obj(json_k(u)).Keys
For i = 0 To UBound(layer1_keys)
'Debug.Print layer1_keys(i), TypeName(layer1_keys(i))
start_r = st.Cells(st.Rows.Count, "a").End(xlUp).row
If TypeName(layer1_dic(layer1_keys(i))) = "String" Then
st.Cells(start_r + 1, 1).Value = layer1_keys(i)
st.Cells(start_r + 1, 2).Value = layer1_dic(layer1_keys(i))
ElseIf TypeName(layer1_dic(layer1_keys(i))) = Null Then
st.Cells(start_r + 1, 1).Value = layer1_keys(i)
ElseIf TypeName(layer1_dic(layer1_keys(i))) = "Collection" Then
Subsection_name = "Subsection: " & layer1_keys(i)
st.Cells(start_r + 1, "a").Value = Subsection_name
start_r = st.Cells(st.Rows.Count, "a").End(xlUp).row
Set layer2_col = layer1_dic(layer1_keys(i))
For c = 1 To layer2_col.Count
Set layer2_dic = layer2_col(c)
layer2_keys = layer2_dic.Keys
For o = 0 To UBound(layer2_keys)
layer2_key = layer2_keys(o)
layer2_v = ""
st.Cells(start_r + o + 1, 1).Value = layer2_key
If TypeName(layer2_dic(layer2_keys(o))) = "Collection" Then
Set layer3_col = layer2_dic(layer2_keys(o))
For p = 1 To layer3_col.Count
layer2_v = layer2_v & "," & layer3_col(p)
Next p
Else
layer2_v = layer2_dic(layer2_keys(o))
End If
st.Cells(start_r + o + 1, c + 1).Value = layer2_v
Next o
Next c
End If
Next i
End If
End If
Next u
Set res = get_pcp(EEJSON_folder, eeJsonFile)
If res.Count > 0 Then
start_r = st.Cells(st.Rows.Count, "a").End(xlUp).row
st.Cells(start_r + 2, "a").Value = "Section: Reports_PrimaryCarePhysicians"
cell_r = st.Cells(st.Rows.Count, "a").End(xlUp).row
For i = 1 To res.Count
Set res_dic = res(i)
res_dic_k = res_dic.Keys
For o = 0 To UBound(res_dic_k)
st.Cells(cell_r + o + 1, 1).Value = res_dic_k(o)
st.Cells(cell_r + o + 1, 1 + i).Value = res_dic(res_dic_k(o))
Next o
Next i
End If
End Sub