-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.livecode
953 lines (953 loc) · 43 KB
/
generate.livecode
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
on mouseUp
-- [ CLEANING UP ]
-- clearing alert field and messages
put empty into field "alertfield1"
put empty into field "alertfield2"
put empty into field "outmessage1"
put empty into field "outmessage2"
-- more cleaning up to avoid fields that are not replaced
put empty into field "people1"
put empty into field "people2"
-- clearing variables
put empty into myname
-- as variables: language, p(default), p(dr?) for better speed and fewer typos in the code
put selection of button "langselector" into lang
if lang is "German" then put "DE" into shortlang -- needed to acccess correct fields
if lang is "French" then put "FR" into shortlang
if lang is "Italian" then put "IT" into shortlang
-- [ INPUT VALIDATION ]
-- check necerssary information is provided so that we can generate the messages
put field "objectname" into objectname
if objectname is empty then
put "Error" into field "alertfield1"
put "Error" into field "alertfield2"
answer "Invalid input: property name is required."
exit mouseup
end if
put field "thelocation" into thelocation
if thelocation is empty then
put "Error" into field "alertfield1"
put "Error" into field "alertfield2"
answer "Invalid input: location is required."
exit mouseup
end if
put field "pdefault" into pdefault
put field "pdr" into pdr
if pdefault < 0 or pdefault > 1 then -- input validation
put "Error" into field "alertfield1"
put "Error" into field "alertfield2"
answer "Invalid input: probability must be between 0 and 1."
put 0.5 into field "pdefault" -- put default value back in
exit mouseup
end if
if pdr < 0 or pdr > 1 then -- input validation
put "Error" into field "alertfield1"
put "Error" into field "alertfield2"
answer "Invalid input: probability must be between 0 and 1."
put 0.5 into field "pdr" -- put default value back in
exit mouseup
end if
-- [ GENERATING HOW MANY PEOPLE WILL LIVE IN THE PROPERTY ]
-- room to people; fields only for accessibility
put field "rooms" into rooms
if rooms < 1 or rooms > 6 then -- input validation
put "Error" into field "alertfield1"
put "Error" into field "alertfield2"
answer "Invalid input: number of rooms must be between 1 and 6. Check if the room number is valid or skip property."
put empty into field "rooms"
exit mouseup
end if
if rooms is not among the words of "1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6" then -- input validation
put "Error" into field "alertfield1"
put "Error" into field "alertfield2"
answer "Invalid input: number of rooms must be between 1 and 6, with 1.5 etc. allowed. Check if there is no trailing space."
put empty into field "rooms"
exit mouseup
end if
if rooms is 1 or rooms is 1.5 or rooms is 2 then -- 1 person; using separate if/then for readability
put 1 into field "people1"
put 1 into field "people2"
end if
if rooms is 2.5 or rooms is 3 then -- 1 or 2 people
put random(2) into field "people1"
put random(2) into field "people2"
end if
if rooms is 3.5 or rooms is 4 then -- 2 or 3 people
put 1+random(2) into field "people1"
put 1+random(2) into field "people2"
end if
if rooms is 4.5 or rooms is 5 then -- 3 or 4 people
put 2+random(2) into field "people1"
put 2+random(2) into field "people2"
end if
if rooms is 5.5 or rooms is 6 then -- 4 people
put 4 into field "people1"
put 4 into field "people2"
end if
if field "people1" is 1 then
put "Single" into field "type1" -- human readable what this means
put 0 into field "kids1"
end if
if field "people1" is 2 then
put "Couple" into field "type1"
put 0 into field "kids1"
end if
if field "people1" >= 3 then
put "Family" into field "type1"
put field "people1" - 2 into field "kids1"
end if
if field "people2" is 1 then
put "Single" into field "type2"
put 0 into field "kids2"
end if
if field "people2" is 2 then
put "Couple" into field "type2"
put 0 into field "kids2"
end if
if field "people2" >= 3 then
put "Family" into field "type2"
put field "people2" - 2 into field "kids2"
end if
put field "people1" into people1 -- variable
put field "people2" into people2 -- variable
put field "kids1" into kids1 -- variable
put field "kids2" into kids2 -- variable
-- [ GENERATING INCOME]
put field "rentinadvert" into rent
put 2.5 into rentkfactor
if rent is empty then
-- no rent is specified, no income is calculated
put "NA" into field "income1"
put "NA" into field "income2"
else
-- first person:
put random(50)/100 into randfactor
put rentkfactor + randfactor into multifactor
put round(rent/100 *multifactor)*100 into field "income1"
-- if field "joblevel1" is "low" then put field "income1" + 500 into field "income1"
-- if field "joblevel1" is "high" then put field "income1" + 1000 into field "income1"
-- second person:
put field "income1" into field "income2"
repeat while field "income1" is field "income2"
put random(50)/100 into randfactor
put rentkfactor + randfactor into multifactor
put round(rent/100 *multifactor)*100 into field "income2"
-- if field "joblevel2" is "low" then put field "income2" + 500 into field "income2"
-- if field "joblevel2" is "high" then put field "income2" + 1000 into field "income2"
end repeat
repeat while field "income1" < 3000
put round((field "income1" / 100)) * 110 into field "income1" -- increase by 10%
end repeat
repeat while field "income2" < 3000
put round((field "income2" / 100)) * 110 into field "income2" -- increase by 10%
end repeat
end if
-- [ GENERATING ORIGIN OF APPLICANT ]
-- random origin: one is Swiss, the other is one of the three 'foreigners'
if random(2) = 1 then
-- profile 1 is Swiss
put "Swiss" into field "origin1"
put empty into field "permit1"
put line random(3)+1 of field "nationalityfield" of card "Details" into field "origin2"
if field "origin2" is "Neighbour" then put lang into field "origin2" -- depends on language which neighbour country is chosen
put line random(2) of field "permitfield" of card "Details" into field "permit2" -- only for non-Swiss origin
else
-- profile 2 is Swiss
put "Swiss" into field "origin2"
put empty into field "permit2"
put line random(3)+1 of field "nationalityfield" of card "Details" into field "origin1"
if field "origin1" is "Neighbour" then put lang into field "origin1" -- depends on language which neighbour country is chosen
put line random(2) of field "permitfield" of card "Details" into field "permit1"
end if
put field "origin1" into origin1 -- variable
put field "origin2" into origin2 -- variable
put field "permit1" into permit1 -- variable
put field "permit2" into permit2 -- variable
-- [ GENERATING GENDER ]
if random (2) is 1 then
put "female" into field "gender1"
else
put "male" into field "gender1"
end if
if random(2) is 1 then
put "female" into field "gender2"
else
put "male" into field "gender2"
end if
put field "gender1" into gender1 -- variable
put field "gender2" into gender2 -- variable
-- [ GENERATING NAME ]
-- random name, based on language and gender; include matching e-mail
put empty into field "name1"
put empty into field "namefam1"
put empty into field "name2"
put empty into field "namefam2"
if lang is "German" then
if field "origin1" is "Swiss" then
if field "gender1" is "female" then -- female
put line random(6) of field "name_f_chde" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_chde" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_chde" of card "Names" into field "namefam1"
put line rvar of field "mail_chde" of card "Names" into field "email1"
end if
if field "origin1" is "Kosovo" then
if field "gender1" is "female" then
put line random(6) of field "name_f_kv" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_kv" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_kv" of card "Names" into field "namefam1"
put line rvar of field "mail_kv" of card "Names" into field "email1"
end if
if field "origin1" is "German" then
if field "gender1" is "female" then
put line random(6) of field "name_f_de" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_de" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_de" of card "Names" into field "namefam1"
put line rvar of field "mail_de" of card "Names" into field "email1"
end if
if field "origin1" is "Turkish" then
if field "gender1" is "female" then
put line random(6) of field "name_f_tr" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_tr" of card "Names" into field "name1"
end if
put random(12) into rvar -- 12 because of the accented variations
put line rvar of field "name_y_tr" of card "Names" into field "namefam1"
put line rvar of field "mail_tr" of card "Names" into field "email1"
end if
-- name 2
if field "origin2" is "Swiss" then
if field "gender2" is "female" then
put line random(6) of field "name_f_chde" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_chde" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_chde" of card "Names" into field "namefam2"
put line rvar of field "mail_chde" of card "Names" into field "email2"
end if
if field "origin2" is "Kosovo" then
if field "gender2" is "female" then
put line random(6) of field "name_f_kv" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_kv" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_kv" of card "Names" into field "namefam2"
put line rvar of field "mail_kv" of card "Names" into field "email2"
end if
if field "origin2" is "German" then
if field "gender2" is "female" then
put line random(6) of field "name_f_de" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_de" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_de" of card "Names" into field "namefam2"
put line rvar of field "mail_de" of card "Names" into field "email2"
end if
if field "origin2" is "Turkish" then
if field "gender2" is "female" then
put line random(6) of field "name_f_tr" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_tr" of card "Names" into field "name2"
end if
put random(12) into rvar -- 12 because of the accented versions
put line rvar of field "name_y_tr" of card "Names" into field "namefam2"
put line rvar of field "mail_tr" of card "Names" into field "email2"
end if
end if
if lang is "French" then
-- French case
if field "origin1" is "Swiss" then
if field "gender1" is "female" then -- female
put line random(6) of field "name_f_chfr" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_chfr" of card "Names" into field "name1"
end if
put random(6) into rvar -- 6 is the number of names we have; could be changed to a variable depending on the number of lines in the field
put line rvar of field "name_y_chfr" of card "Names" into field "namefam1"
put line rvar of field "mail_chfr" of card "Names" into field "email1"
end if
if field "origin1" is "Kosovo" then
if field "gender1" is "female" then
put line random(6) of field "name_f_kv" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_kv" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_kv" of card "Names" into field "namefam1"
put line rvar of field "mail_kv" of card "Names" into field "email1"
end if
if field "origin1" is "French" then
if field "gender1" is "female" then
put line random(6) of field "name_f_fr" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_fr" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_fr" of card "Names" into field "namefam1"
put line rvar of field "mail_fr" of card "Names" into field "email1"
end if
if field "origin1" is "Turkish" then
if field "gender1" is "female" then
put line random(6) of field "name_f_tr" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_tr" of card "Names" into field "name1"
end if
put random(12) into rvar -- 12 because of the accented variations
put line rvar of field "name_y_tr" of card "Names" into field "namefam1"
put line rvar of field "mail_tr" of card "Names" into field "email1"
end if
-- name 2
if field "origin2" is "Swiss" then
if field "gender2" is "female" then
put line random(6) of field "name_f_chfr" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_chfr" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_chfr" of card "Names" into field "namefam2"
put line rvar of field "mail_chfr" of card "Names" into field "email2"
end if
if field "origin2" is "Kosovo" then
if field "gender2" is "female" then
put line random(6) of field "name_f_kv" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_kv" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_kv" of card "Names" into field "namefam2"
put line rvar of field "mail_kv" of card "Names" into field "email2"
end if
if field "origin2" is "French" then
if field "gender2" is "female" then
put line random(6) of field "name_f_fr" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_fr" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_fr" of card "Names" into field "namefam2"
put line rvar of field "mail_fr" of card "Names" into field "email2"
end if
if field "origin2" is "Turkish" then
if field "gender2" is "female" then
put line random(6) of field "name_f_tr" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_tr" of card "Names" into field "name2"
end if
put random(12) into rvar -- 12 because of the accented versions
put line rvar of field "name_y_tr" of card "Names" into field "namefam2"
put line rvar of field "mail_tr" of card "Names" into field "email2"
end if
end if
-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if lang is "Italian" then
-- Italian case
if field "origin1" is "Swiss" then
if field "gender1" is "female" then -- female
put line random(6) of field "name_f_chit" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_chit" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_chit" of card "Names" into field "namefam1"
put line rvar of field "mail_chit" of card "Names" into field "email1"
end if
if field "origin1" is "Kosovo" then
if field "gender1" is "female" then
put line random(6) of field "name_f_kv" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_kv" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_kv" of card "Names" into field "namefam1"
put line rvar of field "mail_kv" of card "Names" into field "email1"
end if
if field "origin1" is "Italian" then
if field "gender1" is "female" then
put line random(6) of field "name_f_it" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_it" of card "Names" into field "name1"
end if
put random(6) into rvar
put line rvar of field "name_y_it" of card "Names" into field "namefam1"
put line rvar of field "mail_it" of card "Names" into field "email1"
end if
if field "origin1" is "Turkish" then
if field "gender1" is "female" then
put line random(6) of field "name_f_tr" of card "Names" into field "name1"
else -- male
put line random(6) of field "name_m_tr" of card "Names" into field "name1"
end if
put random(12) into rvar -- 12 because of the accented variations
put line rvar of field "name_y_tr" of card "Names" into field "namefam1"
put line rvar of field "mail_tr" of card "Names" into field "email1"
end if
-- name 2
if field "origin2" is "Swiss" then
if field "gender2" is "female" then
put line random(6) of field "name_f_chit" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_chit" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_chit" of card "Names" into field "namefam2"
put line rvar of field "mail_chit" of card "Names" into field "email2"
end if
if field "origin2" is "Kosovo" then
if field "gender2" is "female" then
put line random(6) of field "name_f_kv" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_kv" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_kv" of card "Names" into field "namefam2"
put line rvar of field "mail_kv" of card "Names" into field "email2"
end if
if field "origin2" is "Italian" then
if field "gender2" is "female" then
put line random(6) of field "name_f_it" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_it" of card "Names" into field "name2"
end if
put random(6) into rvar
put line rvar of field "name_y_it" of card "Names" into field "namefam2"
put line rvar of field "mail_it" of card "Names" into field "email2"
end if
if field "origin2" is "Turkish" then
if field "gender2" is "female" then
put line random(6) of field "name_f_tr" of card "Names" into field "name2"
else -- male
put line random(6) of field "name_m_tr" of card "Names" into field "name2"
end if
put random(12) into rvar -- 12 because of the accented versions
put line rvar of field "name_y_tr" of card "Names" into field "namefam2"
put line rvar of field "mail_tr" of card "Names" into field "email2"
end if
end if
-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-- [ GENERATING JOB ]
-- define variables so that we can compare below; they will be overwritten with the correct (random) job
put -1 into rhi1
put -1 into rlo1
-- JOB 1:
if random (2) is 1 then -- highly qualified
put "high" into field "joblevel1"
put random(5) into rhi1
if gender1 is "male" then put line rhi1 in field ("jobfield"& shortlang&"hiM") on card "Details" into field "job1"
if gender1 is "female" then put line rhi1 in field ("jobfield"& shortlang&"hiF") on card "Details" into field "job1"
if random(10000)/10000 < pdr then -- is a Dr?
if lang is "German" then
put "Dr. " into field "dr1" -- space at the end needed _here_ to combine it with the name, and there is no space if the string is empty
end if
if lang is "French" then
put "Dr. " into field "dr1"
end if
if lang is "Italian" then
if gender1 is "female" then -- different strings for male and female
put "Dr. ssa " into field "dr1"
else -- male
put "Dr. " into field "dr1"
end if
end if
else
put empty into field "dr1"
end if
else -- low skilled
put "low" into field "joblevel1"
put random(5) into rlo1
if gender1 is "male" then put line rlo1 in field ("jobfield"& shortlang&"loM") on card "Details" into field "job1"
if gender1 is "female" then put line rlo1 in field ("jobfield"& shortlang&"loF") on card "Details" into field "job1"
put empty into field "dr1"
end if
-- JOB 2
if random(2) is 1 then -- highly qualified, job 2
put "high" into field "joblevel2"
put random(5) into rhi2
-- check here rhi1 neq rh2 using while
repeat while rhi1 is rhi2
put random(5) into rhi2 -- choose a different job 2
end repeat
if gender2 is "male" then put line rhi2 in field ("jobfield"& shortlang&"hiM") on card "Details" into field "job2"
if gender2 is "female" then put line rhi2 in field ("jobfield"& shortlang&"hiF") on card "Details" into field "job2"
if random(10000)/10000 < pdr then -- dr?
if lang is "German" then
put "Dr. " into field "dr2"
end if
if lang is "French" then
put "Dr. " into field "dr2"
end if
if lang is "Italian" then
if gender2 is "female" then -- different strings for male and female
put "Dr. ssa " into field "dr2"
else -- male
put "Dr. " into field "dr2"
end if
end if
else
put empty into field "dr2"
end if
else
put "low" into field "joblevel2"
put random(5) into rlo2
-- check here rlo1 neq rlo2 using while
repeat while rlo1 is rlo2
put random(5) into rlo2 -- choose a different job 2
end repeat
if gender2 is "male" then put line rlo2 in field ("jobfield"& shortlang&"loM") on card "Details" into field "job2"
if gender2 is "female" then put line rlo2 in field ("jobfield"& shortlang&"loF") on card "Details" into field "job2"
put empty into field "dr2"
end if
-- [ GENERATING AGE ]
-- random age, two ranges
if random (2) is 1 then
put 26 + random(3) into field "age1" -- young
else
put 41 + random(3) into field "age1" -- old
end if
if random(2) is 1 then
put 26 + random(3) into field "age2" -- young
else
put 41 + random(3) into field "age2" -- old
end if
-- checking they have different age ¦ 0202
if field "age1" is field "age2" then
if random(2) is 1 then
put 1 into diffvar -- add 1 year
else
put -1 into diffvar -- remove 1 year
end if
put field "age2" + diffvar into field "age2"
end if
-- [ GENERATING CONTACT DETAILS ]
-- random address and telephone number; this is 'brute force' and could be changed to use the fields dynamically with the short language string
if lang is "German" then
if random(2) is 1 then
put field "telDE_a" on card "Addresses" into field "phone1"
put field "telDE_b" on card "Addresses" into field "phone2"
else
put field "telDE_a" on card "Addresses" into field "phone2"
put field "telDE_b" on card "Addresses" into field "phone1"
end if
if random(2) is 1 then
put field "adrDE_a" on card "Addresses" into field "address1"
put field "adrDE_b" on card "Addresses" into field "address2"
else
put field "adrDE_a" on card "Addresses" into field "address2"
put field "adrDE_b" on card "Addresses" into field "address1"
end if
end if
if lang is "French" then
if random(2) is 1 then
put field "telFR_a" on card "Addresses" into field "phone1"
put field "telFR_b" on card "Addresses" into field "phone2"
else
put field "telFR_a" on card "Addresses" into field "phone2"
put field "telFR_b" on card "Addresses" into field "phone1"
end if
if random(2) is 1 then
put field "adrFR_a" on card "Addresses" into field "address1"
put field "adrFR_b" on card "Addresses" into field "address2"
else
put field "adrFR_a" on card "Addresses" into field "address2"
put field "adrFR_b" on card "Addresses" into field "address1"
end if
end if
if lang is "Italian" then
if random(2) is 1 then
put field "telIT_a" on card "Addresses" into field "phone1"
put field "telIT_b" on card "Addresses" into field "phone2"
else
put field "telIT_a" on card "Addresses" into field "phone2"
put field "telIT_b" on card "Addresses" into field "phone1"
end if
if random(2) is 1 then
put field "adrIT_a" on card "Addresses" into field "address1"
put field "adrIT_b" on card "Addresses" into field "address2"
else
put field "adrIT_a" on card "Addresses" into field "address2"
put field "adrIT_b" on card "Addresses" into field "address1"
end if
end if
-- [ WHICH TEMPLATE TO USE? ]
-- randomizing template
put random(10000)/10000 into rdefault -- using default message?
put rdefault into field "pcurrent"
-- which template?
put random(2) into rwhichdetailed -- which detailed message template?
if rdefault < pdefault then -- default message to send
-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX DEFAULT MESSAGE
put "Send default message" into field "alertfield1" -- irrespective of language
put "Send default message" into field "alertfield2"
if lang is "German" then -- German default message
do field "defaultDE" on card "Default Messages"
put themessage into field "outmessage1"
put themessage into field "outmessage2"
put "default" into field "template1"
put "default" into field "template2"
end if
if lang is "French" then -- French default messages
if gender1 is "Male" then -- French male default message for applicant 1
do field "defaultFR_m" on card "Default Messages"
put themessage into field "outmessage1"
put "default" into field "template1"
else -- French female
do field "defaultFR_f" on card "Default Messages"
put themessage into field "outmessage1"
put "default" into field "template1"
end if
if gender2 is "Male" then -- French male default message for applicant 2
do field "defaultFR_m" on card "Default Messages"
put themessage into field "outmessage2"
put "default" into field "template2"
else -- French female
do field "defaultFR_f" on card "Default Messages"
put themessage into field "outmessage2"
put "default" into field "template2"
end if
end if
if lang is "Italian" then -- Italian default message
do field "defaultIT" on card "Default Messages"
put themessage into field "outmessage1"
put themessage into field "outmessage2"
put "default" into field "template1"
put "default" into field "template2"
end if
else -- detailed message to send
-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX DETAILED MESSAGE
-- application 1
-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
put field "age1" into myage
put field "job1" into myjob
put field "name1" && field "namefam1" into myname
put field "permit1" into mypermitEN -- can be: empty, "Swiss", "Permit C"
-- permitstrings
-- using a 'brute force' approach here to have readable code
if mypermitEN is empty then -- Swiss applicant; irrespective of language ¦ 0130 moved up
put empty into mypermitstring
put empty into mypermitstringund
put empty into mypermitstringcomma
put "und " into myund -- for German | 02/02
put "Sto" into mypermitstringundcap -- only for Italian
end if
if lang is "German" then
if mypermit is not empty then -- not a Swiss applicant
put "" into myund
end if
if gender1 is "female" and mypermitEN is "Swiss" then -- female Swiss
put "bin Schweizerin" into mypermit
end if
if gender1 is "male" and mypermitEN is "Swiss" then -- male Swss
put "bin Schweizer" into mypermit
end if
if mypermitEN is "Permit C" then -- irrespective of gender
put "habe einen Ausweis C" into mypermit
end if
put " und" && mypermit into mypermitstring -- space in front required so that this plays nicely with empty string
put ", und" && mypermit into mypermitstringcomma
put "," && mypermit into mypermitshortcomma -- | 20/2
put " " & mypermit && "und" into mypermitstringund
if mypermitEN is "" then -- Swiss without details ¦ 0130
put empty into mypermitstring
put empty into mypermitstringcomma
put empty into mypermitstringund
put empty into mypermitshortcomma -- | 20/2
end if
end if
if lang is "French" then
-- optional "et" for nicer flow: Swiss (without indication)
put " et" into et1
put "" into et2
-- foreign origin:
if mypermitEN is "Swiss" then -- irrespective of gender
put "je suis de nationalité suisse" into mypermit
put "Je suis de nationalité suisse" into mypermitCAP -- ¦ added 0130
put "," into et1
put " et" into et2
end if
if mypermitEN is "Permit C" then -- irrespective of gender
if random(2) is 1 then
-- random variation with equal chances
put "je détiens un permis C" into mypermit
put "Je détiens un permis C" into mypermitCAP
else
put "j'ai un permis C" into mypermit
put "J'ai un permis C" into mypermitCAP
end if
put "," into et1
put " et" into et2
end if
put " et" && mypermit into mypermitstring -- space in front required so that this plays nicely with empty string
put "," && mypermit into mypermitstringcomma
put mypermitCAP && "et je suis" into mypermitstringund -- | added "je suis" 0202; removed extra space 20/2
if origin1 is "Swiss" then -- Swiss without details | 0130
put empty into mypermitstring
put empty into mypermitstringcomma
put "Je suis" into mypermitstringund
put " et" into et1
put empty into et2
end if
end if
if lang is "Italian" then
if gender1 is "female" and mypermitEN is "Swiss" then -- female Swiss
put "sono svizzera" into mypermit
end if
if gender1 is "male" and mypermitEN is "Swiss" then -- male Swss
put "sono svizzero" into mypermit
end if
if mypermitEN is "Permit C" then -- irrespective of gender
put "ho un permesso C" into mypermit
end if
put " e" && mypermit into mypermitstring -- space in front required so that this plays nicely with empty string
put "," && mypermit into mypermitstringcomma
put " " & mypermit && "e" into mypermitstringund
put mypermit into mypermitcap -- capitalize
if first word of mypermit is "sono" then
put "Sono" into first word of mypermitcap
end if
if first word of mypermit is "ho" then
put "Ho" into first word of mypermitcap
end if
put " " & mypermitcap && "e sto" into mypermitstringundcap -- only Italian
if mypermitEN is "" then -- Swiss without details | 20/2
put empty into mypermitstring
put empty into mypermitstringcomma
put empty into mypermitstringund
put empty into mypermitcap
put " Sto" into mypermitstringundcap
end if
end if
put field "dr1" into mydrstring
if lang is "German" then
if field "kids1" is 1 then
put "einem Kind" into mykidsstring
put "unser Kind" into mykidsour --| added 20/2
else
put field "kids1" && "Kindern" into mykidsstring
put "unsere Kinder" into mykidsour --| added 20/2
end if
end if
if lang is "French" then
if field "kids1" is 1 then
put "un enfant" into mykidsstring
put "notre enfant" into mykidsour --| added 20/2
else
put field "kids1" && "enfants" into mykidsstring
put "nos enfants" into mykidsour --| added 20/2
end if
end if
if lang is "Italian" then
if field "kids1" is 1 then
if random(2) is 1 then
-- equal chances of having a son or a daughter; no universal equivalent
put "un figlio" into mykidsstring
put "nostro figlio" into mykidsour -- | added 20/2
else
put "una figlia" into mykidsstring
put "nostra figlia" into mykidsour --| added 20/2
end if
else
put field "kids1" && "di figli" into mykidsstring
put "i nostri figli" into mykidsour --| added 20/2
end if
end if
-- which template to use?
-- Step 1: 1 out of 6 templates are randomly chosen
put random(6) into tnum1
put random(6) into tnum2
-- we don't want the templates to be the same (tnum1 = tnum2), and we don't want the templates to be from the same level
-- i.e. we want to exclude 1,2 and 3,4 and 5,6 as combinations
repeat while (tnum1 is tnum2) or (tnum1=1 and tnum2=2) or (tnum1=3 and tnum2=4) or (tnum1=5 and tnum2=6) or (tnum1=2 and tnum2=1) or (tnum1=4 and tnum2=3) or (tnum1=6 and tnum2=5)
put random(6) into tnum2 -- keep trying until it is different and acceptable
end repeat
-- Step 2: sing, coup, or fam
if field "type1" is "Single" then put "sing" into ttyp1
if field "type1" is "Couple" then put "coup" into ttyp1
if field "type1" is "Family" then put "fam" into ttyp1
if field "type2" is "Single" then put "sing" into ttyp2
if field "type2" is "Couple" then put "coup" into ttyp2
if field "type2" is "Family" then put "fam" into ttyp2
-- Step 3: M or F
if field "gender1" is "female" then put "F" into tgen1
if field "gender2" is "female" then put "F" into tgen2
if field "gender1" is "male" then put "M" into tgen1
if field "gender2" is "male" then put "M" into tgen2
-- Step 4: put everything together
put tnum1 & ttyp1 & tgen1 into template1
put tnum2 & ttyp2 & tgen2 into template2
put template1 into field "template1"
put template2 into field "template2"
if lang is "German" then
do field("T"&template1) on card "Templates DE"
end if
if lang is "French" then
do field("T"&template1) on card "Templates FR"
end if
if lang is "Italian" then
do field("T"&template1) on card "Templates IT"
end if
put themessage into field "outmessage1"
-- application 2
-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
put field "age2" into myage
put field "job2" into myjob
put field "name2" && field "namefam2" into myname
put field "permit2" into mypermitEN -- can be: empty, "Swiss", "Permit C"
-- permitstrings
if mypermitEN is empty then -- Swiss applicant; irrespective of language ¦ 0130 moved up; so I can overwrite this below for each language if needed
put empty into mypermitstring
put empty into mypermitstringund
put empty into mypermitstringcomma
put "und " into myund -- for German | 0202
put "Sto" into mypermitstringundcap -- only for Italian
end if
if lang is "German" then
if mypermit is not empty then -- not a Swiss applicant
put "" into myund
end if
if gender2 is "female" and mypermitEN is "Swiss" then -- female Swiss
put "bin Schweizerin" into mypermit
end if
if gender2 is "male" and mypermitEN is "Swiss" then -- male Swss
put "bin Schweizer" into mypermit
end if
if mypermitEN is "Permit C" then -- irrespective of gender
put "habe einen Ausweis C" into mypermit
end if
put " und" && mypermit into mypermitstring -- space in front required so that this plays nicely with empty string
put ", und" && mypermit into mypermitstringcomma
put "," && mypermit into mypermitshortcomma -- | 20/2
put " " & mypermit && "und" into mypermitstringund
if mypermitEN is "" then -- Swiss without details ¦ 0130
put empty into mypermitstring
put empty into mypermitstringcomma
put empty into mypermitshortcomma -- | 20/2
put empty into mypermitstringund
end if
end if
if lang is "French" then
-- Swiss (empty) first:
put " et" into et1
put "" into et2
-- foreign origin:
if mypermitEN is "Swiss" then -- irrespective of gender
put "suis de nationalité suisse" into mypermit
put "Je suis de nationalité suisse" into mypermitCAP
put "," into et1
put " et" into et2
end if
if mypermitEN is "Permit C" then -- irrespective of gender
if random(2) is 1 then
-- random variation with equal chances
put "je détiens un permis C" into mypermit
put "Je détiens un permis C" into mypermitCAP
else
put "j'ai un permis C" into mypermit
put "J'ai un permis C" into mypermitCAP
end if
put "," into et1
put " et" into et2
end if
put " et" && mypermit into mypermitstring -- space in front required so that this plays nicely with empty string
put "," && mypermit into mypermitstringcomma
put mypermitCAP && "et je suis" into mypermitstringund --| removed extra space 20/2
if origin2 is "Swiss" then -- Swiss without details ¦ 0130
put empty into mypermitstring
put empty into mypermitstringcomma
put "Je suis" into mypermitstringund
put " et" into et1
put empty into et2
end if
end if
if lang is "Italian" then
if gender2 is "female" and mypermitEN is "Swiss" then -- female Swiss
put "sono svizzera" into mypermit
end if
if gender2 is "male" and mypermitEN is "Swiss" then -- male Swss
put "sono svizzero" into mypermit
end if
if mypermitEN is "Permit C" then -- irrespective of gender
put "ho un permesso C" into mypermit
end if
put " e" && mypermit into mypermitstring -- space in front required so that this plays nicely with empty string
put "," && mypermit into mypermitstringcomma
put " " & mypermit && "e" into mypermitstringund
put mypermit into mypermitcap -- capitalize
if first word of mypermit is "sono" then
put "Sono" into first word of mypermitcap
end if
if first word of mypermit is "ho" then
put "Ho" into first word of mypermitcap
end if
put " " & mypermitcap && "e sto" into mypermitstringundcap -- only Italian
if mypermitEN is "" then -- Swiss without details | 20/2
put empty into mypermitstring
put empty into mypermitstringcomma
put empty into mypermitstringund
put empty into mypermitcap
put " Sto" into mypermitstringundcap -- |2/20
end if
end if
put field "dr2" into mydrstring
if lang is "German" then
if field "kids2" is 1 then
put "einem Kind" into mykidsstring
put "unser Kind" into mykidsour --| added 20/2
else
put field "kids2" && "Kindern" into mykidsstring
put "unsere Kinder" into mykidsour --| added 20/2
end if
end if
if lang is "French" then
if field "kids2" is 1 then
put "un enfant" into mykidsstring
put "notre enfant" into mykidsour --| added 20/2
else
put field "kids2" && "enfants" into mykidsstring
put "nos enfants" into mykidsour --| added 20/2
end if
end if
if lang is "Italian" then
if field "kids2" is 1 then
if random(2) is 1 then
-- equal chances of having a son or a daughter; no universal equivalent
put "un figlio" into mykidsstring
put "nostro figlio" into mykidsour --| 20/2
else
put "una figlia" into mykidsstring
put "nostra figlia" into mykidsour -- | 20/2
end if
else
put field "kids2" && "di figli" into mykidsstring
put "i nostri figli" into mykidsour --|20/2
end if
end if
-- which template to use?
-- Step 1: 1 out of 6
put random(6) into tnum1
put random(6) into tnum2
repeat while (tnum1 is tnum2) or (tnum1=1 and tnum2=2) or (tnum1=3 and tnum2=4) or (tnum1=5 and tnum2=6) or (tnum1=2 and tnum2=1) or (tnum1=4 and tnum2=3) or (tnum1=6 and tnum2=5)
put random(6) into tnum2 -- keep trying until it is different and acceptable
end repeat
-- cut here the "put everything together part", no need to do this again
if lang is "German" then
do field("T"&template2) on card "Templates DE"
end if
if lang is "French" then
do field("T"&template2) on card "Templates FR"
end if
if lang is "Italian" then
do field("T"&template2) on card "Templates IT"
end if
put themessage into field "outmessage2"
end if
end mouseUp