-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest_file_generator.py
3862 lines (3539 loc) · 130 KB
/
test_file_generator.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
import os
import pandas as pd
import random
import string
import yaml
import utils
class test_data(object):
"""This class alters clean synthetic data files in order to cause the
altered file to fail the specified edit. Modified files may fail other
edits as well."""
def __init__(self, ts_schema, lar_schema, geographic_data):
"""Set initial class variables.
The crosswak_data variable contains the filepath and name for geographic
cross walk data located in the dependencies folder. The geographic data file contains
relationships between variables such as state, county, census tract, MSA, and
population that are used to generate clean files and edit files. The file
is located in "dependencies/census_2018_MSAMD_name.txt."
"""
#load configuration data from YAML file
#use safe_load instead load
#Loads the clean file configuration.
with open('configurations/clean_file_config.yaml') as f:
clean_config = yaml.safe_load(f)
#Loads the filepath configuration.
with open('configurations/test_filepaths.yaml') as f:
filepaths = yaml.safe_load(f)
#Loads geographic configuration file.
with open('configurations/geographic_data.yaml') as f:
self.geographic_config = yaml.safe_load(f)
bank_name = clean_config["name"]["value"] #load bank name from config file
file_length = clean_config["file_length"]["value"] #load file length from config file
self.name_prefix = "{bank_name}_{line_count}_".format(bank_name=bank_name, line_count=file_length)
self.clean_file_path = filepaths['clean_filepath'].format(bank_name=bank_name)
self.validity_path = filepaths['validity_filepath'].format(bank_name=bank_name)
self.syntax_path = filepaths['syntax_filepath'].format(bank_name=bank_name)
self.quality_path = filepaths['quality_filepath'].format(bank_name=bank_name)
self.lar_field_names = list(lar_schema.field)
self.ts_field_names = list(ts_schema.field)
self.geographic_data = geographic_data
def load_data_frames(self, ts_data, lar_data):
"""Receives dataframes for TS and LAR and writes them as object attributes"""
self.ts_df = ts_data
self.lar_df = lar_data
def load_lar_data(self, lar_df=None):
"""Takes a dataframe of LAR data and stores it as a class variable."""
self.lar_df = lar_df
def load_ts_data(self, ts_df=None):
"""Takes a dataframe of TS data and stores it as a class variable. TS data must be a single row."""
self.ts_df = ts_df
#edits will be broken out into sub parts as in the rules_engine.py class. This will allow test files to be generated such that they fail conditions inside each edit.
#When possible each file will only fail the condition listed in the file name. There will be cases when test files fail additional edits, these cases will be documented
#to the extent possible.
#
def s300_1_file(self):
"""Sets the first character of the first row of the file to 3."""
name = "s300_1.txt"
name = self.name_prefix + name
path = self.syntax_path
ts = self.ts_df.copy() #change to local data from class data object
lar = self.lar_df.copy()
ts.record_id = "3" #modify local data to fail edit test
#write local data to file
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def s300_2_file(self):
""""Sets the first character of each LAR row to 3."""
name = "s300_2.txt"
name = self.name_prefix + name
path = self.syntax_path
ts = self.ts_df.copy()
lar = self.lar_df.copy() #set to local data from class data object
lar.record_id = "3" #modify data to fail edit test
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def s301_file(self):
"""Changes the LEI of a LAR file such that it does not match the TS."""
name = "s301.txt"
name = self.name_prefix + name
path = self.syntax_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
while lar.lei[0] == self.ts_df.lei[0]:
lar.lei = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(20))
print("writing {name}".format(name=name))
utils.write_file(name="s301.txt", path=path, ts_input=ts, lar_input=lar)
def s302_file(self):
"""Sets the year of submission to 2017"""
name = "s302.txt"
name = self.name_prefix + name
path = self.syntax_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.calendar_year = "2017"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v600_file(self):
"""Modifies the LEI of TS and LAR so that they do not meed schema requirements"""
name = "v600.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.lei = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
lar.lei = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def s304_file(self):
"""Changes the number of entries data so that it does not match the number of LAR rows in the file."""
name = "s304.txt"
name = self.name_prefix + name
path = self.syntax_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.lar_entries = 0
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v601_1_file(self):
"""Modifies the TS to blank the FI name."""
name = "v601_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.inst_name = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v601_2_file(self):
"""Modify the TS by blanking out the contact person's name."""
name = "v601_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.contact_name = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v601_3_file(self):
"""Modify the TS by blanking the contact person's E-mail address."""
name = "v601_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.contact_email = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v601_4_file(self):
"""Modify the TS so to blank out the contact person's office street address."""
name = "v601_4.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.contact_street_address = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v602_file(self):
"""Changes TS calendar quarter to 5."""
name = "v602.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.calendar_quarter = "5"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v603_file(self):
"""Changes contact number to alphanumeric string."""
name = "v603.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.contact_tel = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v604_file(self):
"""Converts contact person's office state to two digit number."""
name = "v604.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.office_state = str(random.randint(10,99))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v605_file(self):
"""Convert contact person's ZIP to string of letters."""
name = "v605.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.office_zip = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(5))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v606_file(self):
"""Convert number of entries to a negative number."""
name = "v606.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.lar_entries = "-15"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v607_file(self):
"""Changes tax ID to string of letters."""
name = "v607.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
ts.tax_id = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
# under construction
# def v608_1_file(self):
# """Set a ULI to be a random choice of 22 characters or 46 characters"""
# name = "v608_1.txt"
# name = self.name_prefix + name
# path = self.validity_path
# ts = self.ts_df.copy()
# lar = self.lar_df.copy()
# lar['uli'] = random.choice([lar.lei + "DCM78AVG3FFL1YB5H2BR2EDJKLMNO", lar.lei+"AB"])
# print("writing {name}".format(name=name))
# utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
# def v608_2_file(self):
# """Set a NULI to be greater than 22 characters."""
# name = "v608_2.txt"
# name = self.name_prefix + name
# path = self.validity_path
# ts = self.ts_df.copy()
# lar = self.lar_df.copy()
# lar["uli"] = "DCM78AVG3FFL1YB5H2BR2EDJKLMNO"
# print("writing {name}".format(name=name))
# utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v609_file(self):
"""Change check digit on each row. Ensure that the new check digit fails."""
name = "v609.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
#lar.uli = lar.uli.map(lambda x: x[:-2] + "xy")
lar.uli = lar.lei.map(lambda x: x + ''.join(random.choice(string.ascii_uppercase+string.digits) for _ in range(10)))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v610_1_file(self):
"""Change application date to nine 2's."""
name = "v610_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_date = "222222222"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v610_2_file(self):
"""Set each row to action taken = 3 and application date = NA."""
name = "v610_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_date = "NA"
lar.action_taken = "3"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def s305_file(self):
"""Copies the first line of the file into all subsequent lines."""
name = "s305.txt"
name = self.name_prefix + name
path = self.syntax_path
ts = self.ts_df.copy()
lar_start = self.lar_df.copy()
line = pd.DataFrame(lar_start.iloc[0]).transpose()
lar = line.copy()
for i in range(len(lar_start)-1):
lar = pd.concat([lar, line])
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v611_file(self):
"""Sets loan type to 5."""
name = "v611.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.loan_type = "5"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v612_1_file(self):
"""Set loan purpose to 3."""
name = "v612_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.loan_purpose = "3"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v612_2_file(self):
"""Set preapproval to 1 and loan purpose to a random enumeration that is not 1."""
name = "v612_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "1"
lar.loan_purpose = lar.loan_purpose.map(lambda x: random.choice(["2", "31", "32", "4", "5"]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v613_1_file(self):
"""Set preapproval to 3."""
name = "v613_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "3"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v613_2_file(self):
"""Set action to 7 or 8, set preapproval to 2."""
name = "v613_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.action_taken = lar.action_taken.map(lambda x: random.choice(["7", "8"]))
lar.preapproval = "2"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v613_3_file(self):
"""Set action to random 3, 4, 5, or 6 and preapproval to 1."""
name = "v613_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "1"
lar.action_taken = lar.action_taken.map(lambda x: random.choice(["3", "4", "5", "6"]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v613_4_file(self):
"""Set preapproval to 1 and action taken to random 0, 3, 4, 5, 6."""
name = "v613_4.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "1"
lar.action_taken = lar.action_taken.map(lambda x: random.choice(["0", "3", "4", "5", "6"]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v614_1_file(self):
"""Set loan purpose to random 2, 4, 31, 32, or 5 and preapproval to 1."""
name = "v614_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "1"
lar.loan_purpose = lar.loan_purpose.map(lambda x: random.choice(["2", "4", "31", "32", "5"]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v614_2_file(self):
"""Set affordable units to 1 and preapproval to 1."""
name = "v614_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "1"
lar.affordable_units = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v614_3_file(self):
"""Set reverse mortgage to 1 and preapproval to 1."""
name = "v614_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "1"
lar.reverse_mortgage = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v614_4_file(self):
"""Set open end credit to 1 and preapproval to 1."""
name = "v614_4.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.preapproval = "1"
lar.open_end_credit = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v615_1_file(self):
"""Set construction method to 3."""
name = "v615_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.const_method = "3"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v615_2_file(self):
"""Set manufactured interest to random 1, 2, 3 or 4 and construction method to 1."""
name = "v615_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.manufactured_interest = lar.manufactured_interest.map(lambda x: random.choice(["1", "2", "3", "4"]))
lar.const_method = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v615_3_file(self):
"""Set manufactured type to 1 or 2 and construction method to 1."""
name = "v615_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.manufactured_type = lar.manufactured_type.map(lambda x: random.choice(["1", "2"]))
lar.const_method = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v616_file(self):
"""Set occupancy to 4."""
name = "v616.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.occ_type = "4"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v617_file(self):
"""Set loan amount to 0."""
name = "v617.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.loan_amount = "0"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v618_file(self):
"""Set action taken to 0 or NA."""
name = "v618.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.action_taken = lar.action_taken.map(lambda x: random.choice(["0", "NA"]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v619_1_file(self):
"""Set action taken date to NA."""
name = "v619_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.action_date = "NA"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v619_2_file(self):
"""Set action taken date to 20160101."""
name = "v619_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.action_date = "20160101"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v619_3_file(self):
"""Set action taken date to 20160101"""
name = "v619_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.action_date = "20160101"
lar.app_date = "20181231"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v620_file(self):
"""Set street address to blank."""
name = "v620.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.street_address = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v621_file(self):
"""Set city to blank."""
name = "v621.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.city = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v622_1_file(self):
"""Set street address to random string, set City to NA."""
name = "v622_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.street_address = lar.street_address.map(lambda x: "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)))
lar.city = "NA"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v622_2_file(self):
"""Set street address to random string, set State to NA."""
name = "v622_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.street_address = lar.street_address.map(lambda x: "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)))
lar.state = "NA"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v622_3_file(self):
"""Set street address to random string, set ZIP code to NA."""
name = "v622_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
street_addy = "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
lar.street_address = lar.street_address.map(lambda x: random.choice([street_addy, street_addy, "Exempt"]))
lar.zip_code = "NA"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v623_file(self):
"""Set state code to blank or 11."""
name = "v623.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.state = lar.state.map(lambda x: random.choice(["", "11"]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v624_file(self):
"""Set ZIP code to blank or random string of letters.
Impact of S2155: Update to 1) The required format for Zip Code is 12345-1010, 12345, Exempt, or NA,
and it cannot be left blank."""
name = "v624.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
zip_code = "".join(str(random.choice(string.ascii_uppercase + string.digits)) for _ in range(5))
lar.zip_code = lar.zip_code.map(lambda x: random.choice([zip_code, ""]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v625_1_file(self):
"""Set Census Tract to blank or 11 digit letter string."""
name = "v625_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.tract = lar.tract.map(lambda x: "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(11)))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v625_2_file(self):
"""Set Census Tract to 12345679012."""
name = "v625_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.tract = "12345678901"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v626_file(self):
"""Set County to 6 digit number."""
name = "v626.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.county = "654321"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v627_file(self):
"""Set County and Tract to strings of 5 and 11 digit length."""
name = "v627.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.county = "654321"
lar.tract = "12345678901"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v628_1_file(self):
"""Set all applicant ethnicity fields to blank."""
name = "v628_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_1 = ""
lar.app_eth_2 = ""
lar.app_eth_3 = ""
lar.app_eth_4 = ""
lar.app_eth_5 = ""
lar.app_eth_free = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v628_2_file(self):
"""Set app ethnicity 2-5 to 3."""
name = "v628_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_2 = "3"
lar.app_eth_3 = "3"
lar.app_eth_4 = "3"
lar.app_eth_5 = "3"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v628_3_file(self):
"""Set all applicant ethnicity codes to 1."""
name = "v628_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_1 = "1"
lar.app_eth_2 = "1"
lar.app_eth_3 = "1"
lar.app_eth_4 = "1"
lar.app_eth_5 = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v628_4_file(self):
"""Set applicant ethnicity 1 to 3 or 4. Set all other applicant ethnicities to 1."""
name = "v628_4.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_1 = lar.app_eth_1.map(lambda x: random.choice(["3", "4"]))
lar.app_eth_2 = "1"
lar.app_eth_3 = "1"
lar.app_eth_4 = "1"
lar.app_eth_5 = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v629_1_file(self):
"""Set applicant ethnicity basis to 4."""
name = "v629_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_basis = "4"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v629_2_file(self):
"""Set applicant ethnicity basis to 1. Set applicant ethnicity 1 = 3. Set all other applicant ethnicities to 1."""
name = "v629_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_basis = "1"
lar.app_eth_1 = "3"
lar.app_eth_2 = "1"
lar.app_eth_3 = "1"
lar.app_eth_4 = "1"
lar.app_eth_5 = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v629_3_file(self):
"""Set applicant ethnicity basis to 2. Set applicant ethnicity 1 to 4."""
name = "v629_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_basis = "2"
lar.app_eth_1 = "4"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v630_file(self):
"""Set applicant ethnicity 1 to 4. Set applicant ethnicity basis to 2."""
name = "v630.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_eth_basis = "2"
lar.app_eth_1 = "4"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v631_1_file(self):
"""Set co-app ethnicity 1 to blank. Set co-app ethnicity free text to blank."""
name = "v631_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_1 = ""
lar.co_app_eth_free = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v631_2_file(self):
"""Set co-app ethnicity 2-5 to 3."""
name = "v631_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_2 = "3"
lar.co_app_eth_3 = "3"
lar.co_app_eth_4 = "3"
lar.co_app_eth_5 = "3"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v631_3_file(self):
"""Set all co-app ethnicities to 1."""
name = "v631_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_1 = "1"
lar.co_app_eth_2 = "1"
lar.co_app_eth_3 = "1"
lar.co_app_eth_4 = "1"
lar.co_app_eth_5 = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v631_4_file(self):
"""Set co-app ethnicity 1 to random choice of 3, 4, 5. Set co-app ethnicity 2-5 to 1."""
name = "v631_4.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_1 = lar.co_app_eth_1.map(lambda x: random.choice(["3", "4", "5"]))
lar.co_app_eth_2 = "1"
lar.co_app_eth_3 = "1"
lar.co_app_eth_4 = "1"
lar.co_app_eth_5 = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v632_1_file(self):
"""Set co-app ethnicity basis to 5"""
name = "v632_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_basis = "5"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v632_2_file(self):
"""Set co-app ethnicity basis to 1. Set co-app ethnicity 1 to 3.
Set co-app ethnicity 2 to 3. Set co-app ethnicity 3-5 to 1"""
name = "v632_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_basis = "1"
lar.co_app_eth_1 = "3"
lar.co_app_eth_2 = lar.co_app_eth_2.map(lambda x: random.choice(["2", "3"]))
lar.co_app_eth_3 = "1"
lar.co_app_eth_4 = "1"
lar.co_app_eth_5 = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v632_3_file(self):
"""Set co-app ethnicity basis to 2. Set co-app ethnicity 1 to 4."""
name = "v632_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_1 = "4"
lar.co_app_eth_basis = "2"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v633_file(self):
"""Set co-app ethnicity 1 to 4. Set co-app ethnicity basis to 1."""
name = "v633.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.co_app_eth_1 = "4"
lar.co_app_eth_basis = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v634_file(self):
"""For the first half of the file:
Set co-app ethnicity 1 to 5.
Set co-app ethnicity basis to 3
For the second half of the file:
Set co-app ethnicity 1 to 4.
Set co-app ethnicity basis to 4."""
name = "v634.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
midpoint = len(lar)/2
lar.co_app_eth_1[lar.index <= midpoint] = "5"
lar.co_app_eth_basis[lar.index <= midpoint] = "3"
lar.co_app_eth_1[lar.index > midpoint] = "4"
lar.co_app_eth_basis[lar.index > midpoint] = "4"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v635_1_file(self):
"""Set app race 1 to blank. Set all race text fields to blank."""
name = "v635_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_race_1 = ""
lar.app_race_native_text = ""
lar.app_race_islander_text = ""
lar.app_race_asian_text = ""
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v635_2_file(self):
"""Set app races 2-5 to 6."""
name = "v635_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_race_2 = "6"
lar.app_race_3 = "6"
lar.app_race_4 = "6"
lar.app_race_5 = "6"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v635_3_file(self):
"""Set all applicant race fields to 1."""
name = "v635_3.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_race_1 = "1"
lar.app_race_2 = "1"
lar.app_race_3 = "1"
lar.app_race_4 = "1"
lar.app_race_5 = "1"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v635_4_file(self):
"""Set app race to 6 or 7.
Set app races 2-5 to random choice of 1-5."""
name = "v635_4.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_race_1 = lar.app_race_1.map(lambda x: random.choice(["6", "7"]))
lar.app_race_2 = lar.app_race_1.map(lambda x: random.choice(["1", "2", "3", "4", "5"]))
lar.app_race_3 = lar.app_race_1.map(lambda x: random.choice(["1", "2", "3", "4", "5"]))
lar.app_race_4 = lar.app_race_1.map(lambda x: random.choice(["1", "2", "3", "4", "5"]))
lar.app_race_5 = lar.app_race_1.map(lambda x: random.choice(["1", "2", "3", "4", "5"]))
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v636_1_file(self):
"""Set app race basis to 4."""
name = "v636_1.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_race_basis = "4"
print("writing {name}".format(name=name))
utils.write_file(name=name, path=path, ts_input=ts, lar_input=lar)
def v636_2_file(self):
"""Set app race basis to 1. Set app race 1 to blank. Set app races 2-5 to 6."""
name = "v636_2.txt"
name = self.name_prefix + name
path = self.validity_path
ts = self.ts_df.copy()
lar = self.lar_df.copy()
lar.app_race_basis = "1"
lar.app_race_1 = ""
lar.app_race_2 = "6"