-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_network.rb
512 lines (420 loc) · 16.6 KB
/
_network.rb
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# IMPORT NETWORK DATA FROM CSV FILES INTO AN ICM NETWORK
## Import the 'date' library
require 'date'
WSApplication.use_arcgis_desktop_licence
## parameters
folder='C:/Users/HLewis/Downloads/wwl-mod-infoasset2icm-dev/'
db=WSApplication.open('//10.0.29.43:40000/wastewater ongoing/system_performance',false)
nw = db.model_object_from_type_and_id('Model Network',4765)
## reserve network so no-one else can use it
nw.reserve
## Define a useful class
class ImportTable
attr_accessor :tbl_format, :in_table, :cfg_file, :csv_file, :cb_class
def initialize(tbl_format, in_table, cfg_file, csv_file, cb_class)
@tbl_format = tbl_format
@in_table = in_table
@cfg_file = cfg_file
@csv_file = csv_file
@cb_class = cb_class
end
end
## Attribute Conversion from InfoAsset CSV Files into InfoWorks ICM
# Callback Classes
# Node - from InfoAsset manhole
class ImporterClassNode
def ImporterClassNode.onBeginNode(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
@nodeTypeLookup = {
'ACBH' => 'manhole', #Bore Hole (Well / Wellhead )
'ACCL' => 'break', #Chlorination Point
'ACDP' => 'break', #Cable Draw Point
'ACDW' => 'manhole', #Dry Well
'ACFM' => 'manhole', #Flowmeter Chamber
'ACMH' => 'manhole', #Access Chamber Manhole
'ACPU' => 'manhole', #Pump Chamber
'ACSY' => 'break', #Syphon Chamber
'ACVP' => 'break', #Vent Point
'ACVU' => 'manhole', #Vacuum Chamber / Pit
'ACVX' => 'manhole', #Vortex Chamber
'ACWW' => 'manhole', #Wet Well
'BEND' => 'break', #Bend
'END' => 'manhole', #End
'HHLD' => 'break', #Household
'INGD' => 'gully', #Inlet Grated Open End
'INND' => 'gully', #Inlet Open End
'JOIN' => 'manhole', #Join
'LHCE' => 'break', #Lamphole Cleaning Eye
'METR' => 'break', #Meter
'OTGD' => 'gully', #Outlet Grated Open End
'OTND' => 'gully', #Outlet Open End
'PSTN' => 'manhole', #Pump Station
'RGDN' => 'manhole', #Rain Garden
'SMP1' => 'gully', #Sump Single Side Entry
'SMP2' => 'gully', #Sump Double Side Entry
'SMPD' => 'gully', #Sump Dome
'TEE' => 'break', #Tee
'VALV' => 'break' #Valve
}
end
def ImporterClassNode.onEndRecordNode(obj)
inNodeType = obj['node_type']
inSystemType = obj['system_type']
if !inNodeType.nil?
inNodeType = inNodeType#.downcase
end
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @nodeTypeLookup.has_key? inNodeType
icmNodeNodeType = @nodeTypeLookup[inNodeType]
else
icmNodeNodeType = 'manhole'
end
if @systemTypeLookup.has_key? inSystemType
icmNodeSystemType = @systemTypeLookup[inSystemType]
else
icmNodeSystemType = 'other'
end
obj['node_type'] = icmNodeNodeType
obj['system_type'] = icmNodeSystemType
end
end
# Pipe - from InfoAsset Pipe
#
class ImporterClassPipe
def ImporterClassPipe.onEndRecordConduit(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
inSystemType = obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.upcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
end
end
# Pump - from InfoAsset Pump
#
class ImporterClassPump
def ImporterClassPump.OnEndRecordPump(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
obj['link_suffix'] = obj['id'][-1]
inSystemType=obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
if obj['type'].upcase == 'F'
obj['link_type'] == 'FIXPMP'
elsif obj['type'].upcase == 'V'
obj['link_type'] == 'VSPPMP'
elsif obj['type'].upcase == 'R'
obj['link_type'] = 'ROTPMP'
elsif obj['type'].upcase == 'S'
obj['link_type'] = 'SCRPMP'
end
end
end
# Screen - from InfoAsset Screen
#
class ImporterClassScreen
def ImporterClassScreen.OnEndRecordScreen(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
obj['link_suffix'] = obj['id'][-1]
inSystemType=obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
end
end
# Orifice - from InfoAsset Orifice
#
class ImporterClassOrifice
def ImporterClassOrifice.OnEndRecordOrifice(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
obj['link_suffix'] = obj['id'][-1]
inSystemType=obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
end
end
# Sluice - from InfoAsset Sluice
#
class ImporterClassSluice
def ImporterClassSluice.OnEndRecordSluice(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
obj['link_suffix'] = obj['id'][-1]
inSystemType=obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
end
end
# Flume - from InfoAsset Flume
#
class ImporterClassFlume
def ImporterClassFlume.OnEndRecordFlume(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
obj['link_suffix'] = obj['id'][-1]
inSystemType=obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
end
end
# Siphon - from InfoAsset Siphon
#
class ImporterClassSiphon
def ImporterClassSiphon.OnEndRecordSiphon(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
obj['link_suffix'] = obj['id'][-1]
inSystemType=obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
end
end
# Weir - from InfoAsset Weir
#
class ImporterClassWeir
def ImporterClassWeir.OnEndRecordWeir(obj)
@systemTypeLookup={
'PWDB' => 'water', #Potable Water Distribution
'PWSC' => 'water', #Potable Water Service Connection
'PWST' => 'water', #Potable Water Storage
'PWTM' => 'water', #Potable Water Transmission
'PWTP' => 'water', #Potable Water Treatment
'RWST' => 'water', #Raw Water Storage
'RWTN' => 'water', #Raw Water Transfer
'SWCO' => 'storm', #Stormwater Collection
'SWSC' => 'storm', #Stormwater Service Connection
'SWTD' => 'storm', #Stormwater Treatment Device
'WWCO' => 'foul', #Wastewater Collection
'WWSC' => 'foul', #Wasterwater Service Connection
'WWST' => 'foul', #Wastewater Storage
'WWTP' => 'foul' #Wastewater Treatment
}
obj['link_suffix'] = obj['id'][-1]
inSystemType=obj['system_type']
if !inSystemType.nil?
inSystemType = inSystemType#.downcase
end
if @systemTypeLookup.has_key? inSystemType
icmPipeSystemType = @systemTypeLookup[inSystemType]
else
icmPipeSystemType = 'other'
end
obj['system_type'] = icmPipeSystemType
end
end
## Set up the config files and table names
import_tables = Array.new
import_tables.push ImportTable.new('csv', 'Node', folder + '/_network.cfg', folder + '/exports/csv/network.csv_cams_manhole.csv', ImporterClassNode)
import_tables.push ImportTable.new('csv', 'Conduit', folder + '/_network.cfg', folder + '/exports/csv/network.csv_cams_pipe.csv', ImporterClassPipe)
import_tables.push ImportTable.new('tsv', 'Pump', folder + '/_network.cfg', folder + '/exports/tsv/pump.txt', ImporterClassPump)
import_tables.push ImportTable.new('tsv', 'Screen', folder + '/_network.cfg', folder + '/exports/tsv/screen.txt', ImporterClassScreen)
import_tables.push ImportTable.new('tsv', 'Orifice', folder + '/_network.cfg', folder + '/exports/tsv/orifice.txt', ImporterClassOrifice)
import_tables.push ImportTable.new('tsv', 'Sluice', folder + '/_network.cfg', folder + '/exports/tsv/sluice.txt', ImporterClassSluice)
import_tables.push ImportTable.new('tsv', 'Flume', folder + '/_network.cfg', folder + '/exports/tsv/flume.txt', ImporterClassFlume)
import_tables.push ImportTable.new('tsv', 'Siphon', folder + '/_network.cfg', folder + '/exports/tsv/siphon.txt', ImporterClassSiphon)
import_tables.push ImportTable.new('tsv', 'Weir', folder + '/_network.cfg', folder + '/exports/tsv/weir.txt', ImporterClassWeir)
#import_tables.push ImportTable.new('tsv', 'User control', folder + '/_network.cfg', folder + '/exports/tsv/valve.txt', '')
puts 'Import tables and config file setup'
puts 'Start import'
##set options
options=Hash.new
#options['Error File'] = 'C:\Temp\ImportErrorLog.txt' ## String | blank | Path of error file
#options['Set Value Flag'] = '#A' ## String | blank | Flag used for fields set from data
options['Default Value Flag'] = '#A' ## String | blank | Flag used for fields set from the default value column
#options['Image Folder'] = 'C:\Temp\' ## String | blank | Folder to import images from (Asset networks only)
options['Duplication Behaviour'] = 'Overwrite' ## String | Merge | One of Duplication Behaviour:'Overwrite','Merge','Ignore'
#options['Units Behaviour'] = 'Native' ## String | Native | One of 'Native','User','Custom'
#options['Update Based On Asset ID'] = false ## Boolean | false
#options['Update Only'] = false ## Boolean | false
options['Delete Missing Objects'] = true ## Boolean | false
#options['Allow Multiple Asset IDs'] = false ## Boolean | false
options['Update Links From Points'] = false ## Boolean | false
#options['Blob Merge'] = true ## Boolean | false
#options['Use Network Naming Conventions'] = false ## Boolean | false
#options['Import images'] = false ## Boolean | false | Asset networks only
#options['Group Type'] = false ## Boolean | false | Asset networks only
#options['Group Name'] = false ## Boolean | false | Asset networks only
puts 'specific import options defined'
## import tables into ICM
# Loop over table configs
import_tables.each{|table_info|
options['Callback Class'] = table_info.cb_class
# Do the import
nw.odic_import_ex(
table_info.tbl_format, # input table format
table_info.cfg_file, # field mapping config file
options, # specified options override the default options
table_info.in_table, # import to ICM table name
table_info.csv_file # import from MapDrain table name
)
}
puts 'End import'
## Commit changes and unreserve the network
nw.commit('Data imported from CSV and TSV files')
nw.unreserve
puts 'Committed'