-
Notifications
You must be signed in to change notification settings - Fork 472
/
QRReader.bas
449 lines (370 loc) · 12.2 KB
/
QRReader.bas
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
Attribute VB_Name = "QRReader"
Sub Save1QR()
saveData (getInput())
ActiveWorkbook.Save
End Sub
Sub processHardCodedData()
saveData ("s=fudd;e=2022carv;l=qm;m=2;r=r2;t=2451;as=[35];asg=[3,4];acc=1;acs=1;am=1;ad=e;tct=[8.3,7.3,6.7,7.1,5.5,5.8,5.4];tsg=[5,6,7,8,9,1,2];tfc=0;wf=0;wd=0;who=;lnk=1;fpu=b;dt=9.9;fs=e;dn=2;ds=v;ls=5;dr=x;sd=1;sr=5;die=0;tip=0;dc=0;all=1;co=PWNAGE")
ActiveWorkbook.Save
End Sub
Sub processQRCodeInput()
saveData (getInput())
saveData (getInput())
saveData (getInput())
saveData (getInput())
saveData (getInput())
saveData (getInput())
ActiveWorkbook.Save
End Sub
Sub Save1PitQR()
savePitData (getInput())
ActiveWorkbook.Save
End Sub
Public Function getInput()
getInput = InputBox("Scan QR Code", "2023 Match Scouting Input")
End Function
Sub test()
saveData ("s=fudd;e=2022carv;l=qm;m=2;r=r2;t=2451;as=[35];asg=[3,4];acc=1;acs=1;am=1;ad=e;tct=[8.3,7.3,6.7,7.1,5.5,5.8,5.4];tsg=[5,6,7,8,9,1,2];tfc=0;wf=0;wd=0;who=;lnk=1;fpu=b;dt=9.9;fs=e;dn=2;ds=v;ls=5;dr=x;sd=1;sr=5;die=0;tip=0;dc=0;all=1;co=PWNAGE")
End Sub
Sub dbm(inp As String)
Dim r
r = MsgBox(inp, vbDefaultButton1 + vbInformation, "Debug", "help.hlp", 1000)
End Sub
Public Function ArrayLen(arr As Variant) As Integer
ArrayLen = UBound(arr) - LBound(arr) + 1
End Function
Sub saveData(inp As String)
Dim fields
Dim par
Dim value
Dim key
Dim table As ListObject
Dim ws As Worksheet
Set ws = ActiveSheet
Dim mapper
Set mapper = CreateObject("Scripting.Dictionary")
Dim data
Set data = CreateObject("Scripting.Dictionary")
Dim tableName As String
tableName = "ScoutingData"
' Set up map
' Fields for every year
mapper.add "s", "scouter"
mapper.add "e", "eventCode"
mapper.add "l", "matchLevel"
mapper.add "m", "matchNumber"
mapper.add "r", "robot"
mapper.add "t", "teamNumber"
' 2023 Fields
' Auto
mapper.add "as", "autoStartingLocation"
mapper.add "asg", "autoScoredGrid"
mapper.add "acc", "autoCrossedCable"
mapper.add "acs", "autoCrossedChargingStation"
mapper.add "am", "autoMobility"
mapper.add "ad", "autoDocked"
mapper.add "aa", "autoAttempted"
' Teleop
mapper.add "tct", "cycleTimes"
mapper.add "tsg", "scoredGrid"
mapper.add "tfc", "feedCount"
mapper.add "wf", "wasFed"
mapper.add "wd", "wasDefended"
mapper.add "who", "whoDefended"
mapper.add "lnk", "smartLinks"
mapper.add "fpu", "floorPickUp"
mapper.add "sub", "substationUsed"
'Endgame
mapper.add "dt", "dockingTime"
mapper.add "fs", "finalState"
mapper.add "dn", "numOfRobotsDocked"
mapper.add "ls", "linksScored"
'Post-game
mapper.add "ds", "driverSkill"
mapper.add "dr", "defenseRating"
mapper.add "sd", "swerveDrive"
mapper.add "sr", "speedRating"
mapper.add "die", "diedOrTipped"
mapper.add "tip", "tippy"
mapper.add "dc", "droppedCones"
mapper.add "all", "goodPartner"
mapper.add "co", "comments"
If inp = "Camera" Then
Exit Sub
End If
If inp = "" Then
Exit Sub
End If
'MsgBox (inp)
fields = Split(inp, ";")
If ArrayLen(fields) > 0 Then
Dim i As Integer
Dim str
i = 0
For Each str In fields
par = Split(str, "=")
key = par(0)
value = par(1)
If mapper.Exists(key) Then
key = mapper(key)
End If
data.add key, value
Next
tableexists = False
Dim tbl As ListObject
Dim sht As Worksheet
'Loop through each sheet and table in the workbook
For Each sht In ThisWorkbook.Worksheets
For Each tbl In sht.ListObjects
If tbl.name = tableName Then
tableexists = True
Set table = tbl
Set ws = sht
End If
Next tbl
Next sht
If tableexists Then
'Set table = ws.ListObjects(tableName)
Else
Dim tablerange As Range
ws.ListObjects.add(xlSrcRange, Range("A1:CZ1"), , xlYes).name = tableName
i = 0
Set table = ws.ListObjects(tableName)
For Each key In data.Keys
table.Range(i + 1) = key
i = i + 1
Next
End If
Dim newrow As ListRow
Set newrow = table.ListRows.add
For Each str In data.Keys
' Specific data manipulation
If str = "autoStartingLocation" Then
data(str) = stripShootingLocation(data(str))
End If
newrow.Range(table.ListColumns(str).Index) = data(str)
Next
End If
End Sub
Sub savePitData(inp As String)
Dim fields
Dim par
Dim value
Dim key
Dim table As ListObject
Dim ws As Worksheet
Set ws = ActiveSheet
Dim mapper
Set mapper = CreateObject("Scripting.Dictionary")
Dim data
Set data = CreateObject("Scripting.Dictionary")
Dim tableName As String
tableName = "PitData"
' Set up map
mapper.add "t", "teamNumber"
mapper.add "wid", "width"
mapper.add "wei", "weight"
mapper.add "drv", "drivetrain"
mapper.add "odt", "otherDrivetrain"
mapper.add "sr", "swerveRatio"
mapper.add "mot", "drivetrainMotor"
mapper.add "nob", "numberOfBatteries"
mapper.add "fco", "floorPickUpCones"
mapper.add "fcu", "floorPickUpCubes"
mapper.add "ccs", "crossCS"
mapper.add "aut", "autos"
mapper.add "sct", "scoutingMethod"
mapper.add "co", "comments"
If inp = "Camera" Then
Exit Sub
End If
If inp = "" Then
Exit Sub
End If
' MsgBox (inp)
fields = Split(inp, ";")
If ArrayLen(fields) > 0 Then
Dim i As Integer
Dim str
i = 0
For Each str In fields
par = Split(str, "=")
key = par(0)
value = par(1)
If mapper.Exists(key) Then
key = mapper(key)
End If
data.add key, value
Next
tableexists = False
Dim tbl As ListObject
Dim sht As Worksheet
'Loop through each sheet and table in the workbook
For Each sht In ThisWorkbook.Worksheets
For Each tbl In sht.ListObjects
If tbl.name = tableName Then
tableexists = True
Set table = tbl
Set ws = sht
End If
Next tbl
Next sht
If tableexists Then
' Set table = ws.ListObjects(tableName)
Else
Dim tablerange As Range
ws.ListObjects.add(xlSrcRange, Range("A1:CZ1"), , xlYes).name = tableName
i = 0
Set table = ws.ListObjects(tableName)
For Each key In data.Keys
table.Range(i + 1) = key
i = i + 1
Next
End If
Dim newrow As ListRow
Set newrow = table.ListRows.add
For Each str In data.Keys
newrow.Range(table.ListColumns(str).Index) = data(str)
Next
End If
End Sub
Public Function stripShootingLocation(str As Variant)
If str <> "" Then
stripShootingLocation = Mid(str, 2, Len(str) - 2)
Else
stripShootingLocation = ""
End If
End Function
Private Function countGrid(ByRef myCell As Range, ByVal countType As Integer) As Integer
Dim myArrStr As String
Dim myArr() As String
Dim highNumArr() As String
highNumArr = Split("1,2,3,4,5,6,7,8,9", ",")
Dim medNumArr() As String
medNumArr = Split("10,11,12,13,14,15,16,17,18", ",")
Dim lowNumArr() As String
lowNumArr = Split("19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36", ",")
Dim coneNumArr() As String
coneNumArr = Split("1,3,4,6,7,9,10,12,13,15,16,18,19,20,21,22,23,24,25,26,27", ",")
Dim cubeNumArr() As String
cubeNumArr = Split("2,5,8,11,14,17,28,29,30,31,32,33,34,35,36", ",")
Dim totalGamePieces As Integer
Dim highGamePieces As Integer
Dim medGamePieces As Integer
Dim lowGamePieces As Integer
Dim coneCount As Integer
Dim cubeCount As Integer
totalGamePieces = 0
highGamePieces = 0
medGamePieces = 0
lowGamePieces = 0
coneCount = 0
cubeCount = 0
If (myCell.Cells.count > 1) Then
MsgBox ("Pass in only 1 Cell")
countGrid = -1
Exit Function
End If
If Mid(myCell, 1, 1) = "[" And Mid(myCell, Len(myCell), 1) = "]" Then
myArrStr = Mid(myCell, 2, Len(myCell) - 2)
Else
MsgBox ("Cell not formatted correctly")
countGrid = -1
Exit Function
End If
myArr = Split(myArrStr, ",")
Dim item As Variant
For Each item In myArr
totalGamePieces = totalGamePieces + 1
If Not IsError(Application.match(item, highNumArr, 0)) Then
highGamePieces = highGamePieces + 1
End If
If Not IsError(Application.match(item, medNumArr, 0)) Then
medGamePieces = medGamePieces + 1
End If
If Not IsError(Application.match(item, lowNumArr, 0)) Then
lowGamePieces = lowGamePieces + 1
End If
If Not IsError(Application.match(item, coneNumArr, 0)) Then
coneCount = coneCount + 1
End If
If Not IsError(Application.match(item, cubeNumArr, 0)) Then
cubeCount = cubeCount + 1
End If
Next item
If countType = 1 Then
' Total game pieces
countGrid = totalGamePieces
ElseIf countType = 2 Then
' High game pieces
countGrid = highGamePieces
ElseIf countType = 3 Then
' Med game pieces
countGrid = medGamePieces
ElseIf countType = 4 Then
' Low game pieces
countGrid = lowGamePieces
ElseIf countType = 5 Then
' Cones
countGrid = coneCount
ElseIf countType = 6 Then
' Cubes
countGrid = cubeCount
Else
' Unsupported countType
MsgBox ("Unrecognized countType")
countGrid = -1
End If
End Function
Private Function getTotalCount(ByRef myCell As Range) As Integer
getTotalCount = countGrid(myCell, 1)
End Function
Private Function getHighCount(ByRef myCell As Range) As Integer
getHighCount = countGrid(myCell, 2)
End Function
Private Function getMedCount(ByRef myCell As Range) As Integer
getMedCount = countGrid(myCell, 3)
End Function
Private Function getLowCount(ByRef myCell As Range) As Integer
getLowCount = countGrid(myCell, 4)
End Function
Private Function getConeCount(ByRef myCell As Range) As Integer
getConeCount = countGrid(myCell, 5)
End Function
Private Function getCubeCount(ByRef myCell As Range) As Integer
getCubeCount = countGrid(myCell, 6)
End Function
Private Function getAvgCycleTime(ByRef myCell As Range) As Double
Dim myArrStr As String
Dim myArr() As String
If (myCell.Cells.count > 1) Then
MsgBox ("Pass in only 1 Cell")
getAvgCycleTime = -1
Exit Function
End If
If Mid(myCell, 1, 1) = "[" And Mid(myCell, Len(myCell), 1) = "]" Then
myArrStr = Mid(myCell, 2, Len(myCell) - 2)
Else
MsgBox ("Cell not formatted correctly")
getAvgCycleTime = -1
Exit Function
End If
myArr = Split(myArrStr, ",")
Dim total As Double
Dim count As Integer
total = 0
count = 0
Dim item As Variant
For Each item In myArr
Dim numStr As String
Dim num As Double
num = WorksheetFunction.Sum(0 & item)
total = total + num
count = count + 1
Next item
If count = 0 Then
getAvgCycleTime = 0
Else
getAvgCycleTime = total / count
End If
End Function