-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_validation_validation_updated.py
1159 lines (1007 loc) · 49.8 KB
/
data_validation_validation_updated.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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from distutils.log import error
import os
from matplotlib import scale
import pandas as pd
from wvdot_utils import add_routeid_df, add_geom_validation_df
from os import listdir
from os.path import isfile, join
import numpy as np
import pyodbc
# import format_changer_cleaned
sql_conn = pyodbc.connect('''DRIVER={ODBC Driver 17 for SQL Server};
SERVER=dotb6gisdb01;
DATABASE=RIL_LRS;
Trusted_Connection=yes''')
correct_format={'County_Code':'CountyID','Pct_MC':'PctMotorcycles','Pct_Lgt_Trucks':'PctLightTrucks','Pct_SU_Trucks':'PctSingleUnit','Pct_CU_Trucks':'PctCombination','YEAR_RECORD':'BeginDate','END_POINT':'EndPoint','STATE_CODE':'StateID','ROUTE_ID':'RouteID','VALUE_DATE':'ValueDate','Data_Item':'DataItem','Value_Numeric':'ValueNumeric','Year_Record':'BeginDate','End_Point':'EndPoint','State_Code':'StateID','Value_Date':'ValueDate','Data_Item':'DataItem','Route_ID':'RouteID','Urban_Code':'UrbanID','Value_Text':'ValueText','VALUE_TEXT':'ValueText','BEGIN_POINT':'BeginPoint','Begin_Point':'BeginPoint'}
correct_format_inverse = {}
for k,v in correct_format.items():
correct_format_inverse[v] = k
# print(correct_format_inverse)
urban_code_list = [99999, 99998, 15481, 6139,
21745, 36190, 40753, 59275, 67672, 93592, 94726]
facility_type_list = [1, 2, 4, 5, 6, 7]
functional_class_list = [1, 2, 3, 4, 5, 6, 7]
ownership_list = [1, 2, 3, 4, 11, 12, 21, 25, 26, 27, 31,
32, 40, 50, 60, 62, 63, 64, 66, 67, 68, 69, 70, 72]
signal_list=[1,2,3,4,5]
median_type_list=[1,2,3,4,5,6,7]
shoulder_type_list=[1,2,3,4,5,6]
peak_parking_list=[1,2,3]
widening_potential_list=[1,2,3,4]
curve_list=['A','B','C','D','E','F']
terrain_types_list=[1,2,3]
grades_list=['A','B','C','D','E','F']
surface_type_list=[1,2,3,4,5,6,7,8,9,10,11]
base_type_list=[1,2,3,4,5,6,7,8]
county_id_list=[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,91,93,95,97,99,101,103,105,107,109,111]
strahnet_type_list=[1,2]
nn_list=[1,2]
main_ops_list=[1,2,3,4,11,12,21,25,26,27]
nhfn_list=[1,2,3]
is_restricted_list=[1]
access_control_list=[1,2,3]
route_qualifier_list=[1,2,3,4,5,6,7,8,9,10]
route_signing_list=[1,2,3,4,5,6,7,8,9,10]
off_list=[]
mypath = 'hpms_data_items'
total_errors = pd.DataFrame()
def get_indexes(x):
pair_list=[]
for n in range(len(x)):
for b in range(len(x)):
pair=[n,b]
if pair not in pair_list and n!=b and n<b:
pair_list.append(pair)
print(pair_list)
return pair_list
def overlap_intersect_check(x):
v=False
indexes=get_indexes(x)
# print(indexes)
for i1,i2 in indexes:
# print(x[i1],x[i2])
# s=x[i1]
# s2=x[i2]
s = x[['Route_ID', 'Begin_Point', 'End_Point']].iloc[i1]
s2 = x[['Begin_Point', 'End_Point']].iloc[i2]
rid,bmp1,emp1=s['Route_ID'],s['Begin_Point'],s['End_Point']
bmp2,emp2=s2['Begin_Point'],s2['End_Point']
if _overlap(bmp1,emp1,bmp2,emp2) == True:
v=True
off_list.append({rid:[[bmp1, emp1],[bmp2, emp2]]})
return off_list,v
def _overlap(bmp1,emp1,bmp2,emp2,debug=False):
bmp_overlap1 = bmp2 < bmp1 and emp2 > bmp1
emp_overlap1 = bmp2 < emp1 and emp2 > emp1
bmp_overlap2 = bmp1 < bmp2 and emp1 > bmp2
emp_overlap2 = bmp1 < emp2 and emp1 > emp2
if debug: print(bmp_overlap1,emp_overlap1,bmp_overlap2,emp_overlap2,[bmp1,emp1,bmp2,emp2])
return (bmp_overlap1 or
emp_overlap1 or
bmp_overlap2 or
emp_overlap2)
def rid_overlap(df):
for rid in df['Route_ID'].unique():
tmp = df[df['Route_ID'] == rid]
print(tmp)
print(overlap_intersect_check(tmp))
# TODO add overlaps to error df
# def overlap_checking(df):
# return Overlapping(df)
def add_column_section_length(df):
if 'Section_Length' not in df.columns:
df['Section_Length']=df['End_Point']-df['Begin_Point']
return df
else:
return df
def add_error_df(df, error_message):
global total_errors
if len(df) > 0:
df['Error'] = error_message
total_errors = pd.concat([total_errors, df], ignore_index=True)
print('Wrote Errors df with message: %s and size: %s' % (error_message, len(df)))
else:
print("No errors found for error message | %s" % error_message)
# def read_hpms_csv(x): return pd.read_csv(mypath + "/" + x, sep='|')
def read_hpms_csv(x):
df = pd.read_csv(mypath + "/" + x, sep='|')
return df.rename(columns=correct_format_inverse)
def get_invalid_geom_name(x):
geom_fn = str.split(x, '.')[0]
return geom_fn + '_geom_check.xlsx'
def output_geom_file(geom_check, fn):
geom_fn = get_invalid_geom_name(fn)
geom_check[geom_check.IsValid == False].to_excel(geom_fn, index=False)
print('Output file made! :)')
# def read_hpms_csv(x): return pd.read_csv(mypath + "/" + x, sep='|')
#Beginning of HPMS Validations
def check_fsystem_valid(x, check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data2)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'fsystem geometry check invalid!')
tmpdf = data2[~data2['Value_Numeric'].isin(functional_class_list)]
add_error_df(tmpdf, "Check value numeric for fsystem valid")
tmpdf2 = data2[data2['Section_Length'] == 0]
print(rid_overlap(data2))
add_error_df(
tmpdf2, "Check value numeric for fsystem section length is zero")
def check_urban_code(x, check_geom):
data = read_hpms_csv(x)
# data=overlap_intersect_check(data)
if check_geom:
geom_check = add_geom_validation_df(
data, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'fsystem geometry check invalid!')
# output_geom_file(x)
# print('Urban_Code',geom_check[geom_check.IsValid==False])
# if the geometry is invalid pass that invalid geometry df add error df
tmpdf = data[(data['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(urban_code_list))]
add_error_df(tmpdf, "Urban Code is not in accepted range")
tmpdf2 = data[data['Section_Length'] == 0]
add_error_df(tmpdf2, "Urban Code section length is equal to zero")
def check_facility_type(x, check_geom):
data = read_hpms_csv(x)
if check_geom:
geom_check = add_geom_validation_df(
data, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'fsystem geometry check invalid!')
tmpdf = data[(data['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(facility_type_list))]
add_error_df(
tmpdf, "Facility type error, not a valid facility type in value_numeric")
tmpdf2 = data[data['Section_Length'] == 0]
add_error_df(tmpdf2, "facility type section length is equal to zero")
def check_ownership(x, check_geom):
data = read_hpms_csv(x)
if check_geom:
geom_check = add_geom_validation_df(
data, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Ownership geometry bad, please fix')
tmpdf = data[(data['Value_Numeric'] == '') | (
~data['Value_Numeric'].isin(ownership_list))]
add_error_df(
tmpdf, "Ownership list error, not a valid ownership list in value_numeric")
tmpdf2 = data[data['Section_Length'] == 0]
add_error_df(tmpdf2, "Ownership section length is zero")
def check_through_lanes(x, check_geom):
data = read_hpms_csv(x)
if check_geom:
geom_check = add_geom_validation_df(
data, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'fsystem geometry check invalid!')
tmpdf = data[data.Value_Numeric.isna()]
add_error_df(tmpdf, "Through lanes value numeric is nan")
tmpdf2 = data[data['Section_Length'] == 0]
add_error_df(tmpdf2, "Through laness section length is zero")
def nhs_new_check(x,check_geom):
data = read_hpms_csv(x)
if check_geom:
geom_check = add_geom_validation_df(
data, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'NHS geometry check invalid!')
tmpdf = data[data.Value_Numeric.isna()]
add_error_df(tmpdf, "NHS value numeric is nan")
tmpdf2 = data[data['Section_Length'] == 0]
add_error_df(tmpdf2, "NHS section length is zero")
def check_dir_through_lanes(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Direct through lanes geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Direct through lanes value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Direct Through lanes section length is zero")
def check_aadt(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'AADT geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "AADT value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "AADT section length is zero")
def check_aadt_single_unit(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'AADT Single Unit geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "AADT Single Unit value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "AADT Single Unit section length is zero")
def check_Pct_Peak_Single(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'PCT Peak Single geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "PCT Peak Single value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "PCT Peak Single section length is zero")
def check_AADT_Combination(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'AADT Combination geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "AADT Combination value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "AADT Combination section length is zero")
def check_pct_peak_combination(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data2.columns)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'PCT Peak Combination geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "PCT Peak Combination value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "PCT Peak Combination section length is zero")
def check_k_factor(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'K Factor geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "K Factor value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "K Factor section length is zero")
def dir_factor(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'dir factor geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "dir factor value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "dir factor section length is zero")
def signal_type(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Signal Type geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(signal_list))]
add_error_df(tmpdf, "Signal Type is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Signal Type section length is zero")
def pct_green_time(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Peak green time geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Peak green time numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Peak green time length is zero")
def lane_width(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Lane width geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Lane width numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Lane width section length is zero")
def median_type(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Median type geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(median_type_list))]
add_error_df(tmpdf, "Median type is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Median type section length is zero")
def median_width(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Median width geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Median width numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Median width section length is zero")
def shoulder_type(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Shoulder type geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(shoulder_type_list))]
add_error_df(tmpdf, "Shoulder type is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Shoulder type section length is zero")
def shoulder_width_r(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Shoulder width R geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Shoulder width R value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Shoulder width R section length is zero")
def shoulder_width_l(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Shoulder width L geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Shoulder width L value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Shoulder width L section length is zero")
def peak_parking(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Peak parking geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(peak_parking_list))]
add_error_df(tmpdf, "Peak parking is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Peak parking section length is zero")
def widening_potential(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Widening potential geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(widening_potential_list))]
add_error_df(tmpdf, "Widening potential is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "widening potential section length is zero")
def curves(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'curves geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(curve_list))]
add_error_df(tmpdf, "Curves is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Curves section length is zero")
def terrain_types(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Terrain Type geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(curve_list))]
add_error_df(tmpdf, "Terrain Type is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Terrain section length is zero")
def grades(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'grades geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(grades_list))]
add_error_df(tmpdf, "Grade is not in accepted range")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "grades section length is zero")
def pct_pass_sight(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'PCT Pass Sight geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "PCT Pass Sight value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "PCT Pass Sight section length is zero")
def iri(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'IRI geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "IRI value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "IRI section length is zero")
def surface_type(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'K Factor geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(surface_type_list))]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "K Factor section length is zero")
def rutting(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Rutting geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Rutting section length is zero")
def faulting(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Faulting geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Faulting value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Faulting section length is zero")
def cracking_percent(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Cracking Percent geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Cracking Percent value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Cracking Percent section length is zero")
def year_last_improvement(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Year Last Improvement geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Year Last Improvement value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Year Last Improvement section length is zero")
def year_last_construction(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Year Last Construction geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Year Last Construction value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Year Last Construction section length is zero")
def last_overlay_thickness(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Last Overlay Thickness geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Last Overlay Thickness value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Last Overlay thickness section length is zero")
def thickness_rigid(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'thickness rigid geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Thickness Rigid value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Thickness Rigid section length is zero")
def thickness_flexible(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'thickness flexible geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Thickness Flexible value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Thickness Flexible section length is zero")
def base_type(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Base Type geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(base_type_list))]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Base Type section length is zero")
def base_thickness(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Base thickness geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Base thickness value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Base thickness section length is zero")
def county_id(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'County ID geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(county_id_list))]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "County ID value numeric is nan")
add_error_df(tmpdf2, "County ID section length is zero")
def strahnet_type(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'STRAHNET geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(strahnet_type_list))]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Strahnet Type value numeric is nan")
add_error_df(tmpdf2, "STRAHNET section length is zero")
def nn(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'NN geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(nn_list))]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "NN section length is zero")
def maintenance_operations(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Maintence operations geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(main_ops_list))]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Main operations section length is zero")
def dir_through_lanes(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Direct Through Lanes geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "DIrect Through Lanes value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Direct Through Lanes section length is zero")
def travel_time_code(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Travel Time Code geometry check invalid!')
tmpdf = data2[data2.Value_Numeric.isna()]
add_error_df(tmpdf, "Travel Time Code value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Travel Time Code section length is zero")
def nhfn(x,check_geom):
data = read_hpms_csv(x)
if check_geom:
geom_check = add_geom_validation_df(
data, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'NHFN geometry check invalid!')
tmpdf = data[(data['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(nhfn_list))]
add_error_df(tmpdf, "NHFN value numeric is nan")
tmpdf2 = data[data['Section_Length'] == 0]
add_error_df(tmpdf2, "NHFN section length is zero")
def is_restricted(x,check_geom):
data = read_hpms_csv(x)
if check_geom:
geom_check = add_geom_validation_df(
data, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'K Factor geometry check invalid!')
tmpdf = data[(data['Value_Numeric'].isna()) | (
~data['Value_Numeric'].isin(is_restricted_list))]
tmpdf2 = data[data['Section_Length'] == 0]
add_error_df(tmpdf, "Is Restricted value numeric is nan")
add_error_df(tmpdf2, "K Factor section length is zero")
def access_control(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Access Control geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | (
~data2['Value_Numeric'].isin(access_control_list))]
add_error_df(tmpdf, "Access Control value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Access Control section length is zero")
def peak_lanes(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Peak Lanes geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
add_error_df(tmpdf, "Peak Lanes value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Peak Lanes section length is zero")
def counter_peak_lanes(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Counter Peak Lanes geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
add_error_df(tmpdf, "Counter Peak Lanes value numeric is nan")
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf2, "Counter Peak Lanes section length is zero")
def turn_lanes_r(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Turn Lanes R geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Turn Lanes R value numeric is nan")
add_error_df(tmpdf2, "Turn Lanes R section length is zero")
def turn_lanes_l(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Turn Lanes L geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Turn Lanes L value numeric is nan")
add_error_df(tmpdf2, "Turn Lanes L section length is zero")
def speed_limit(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Speed Limit geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Speed Limit value numeric is nan")
add_error_df(tmpdf2, "Speed Limit section length is zero")
def toll_id(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Toll ID geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | data2['Value_Numeric'] != 288]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Toll ID value numeric is nan")
add_error_df(tmpdf2, "Toll ID section length is zero")
def route_number(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Toll ID geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Route Number value numeric is nan")
add_error_df(tmpdf2, "Route Number section length is zero")
def route_signing(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Route Signing geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())| ~data2['Value_Numeric'].isin(route_qualifier_list)]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Route Signing value numeric is nan or not in list")
add_error_df(tmpdf2, "Route Signing section length is zero")
def route_qualifier(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Route Qualifier geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna()) | ~data2['Value_Numeric'].isin(route_signing_list) ]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Route Qualifier value numeric is nan or not in list")
add_error_df(tmpdf2, "Route Qualifier section length is zero")
def alternative_route_name(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Alternative Route Name geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Alternative Route Name value numeric is nan or not in list")
add_error_df(tmpdf2, "Alternative Route Name section length is zero")
def future_aadt(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom:
geom_check = add_geom_validation_df(
data2, routeid_field='Route_ID', bmp_field='Begin_Point', emp_field='End_Point')
add_error_df(geom_check[geom_check.IsValid ==
False], 'Future AADT geometry check invalid!')
tmpdf = data2[(data2['Value_Numeric'].isna())]
tmpdf2 = data2[data2['Section_Length'] == 0]
add_error_df(tmpdf, "Future AADT value numeric is nan or not in list")
add_error_df(tmpdf2, "Future AADT section length is zero")
def number_signals(x,check_geom):
data = read_hpms_csv(x)
data2=add_column_section_length(data)
# print(data)
if check_geom: