Repository navigation
Expand file tree
/
Copy pathcontrollers.py
More file actions
5099 lines (4651 loc) · 266 KB
/
Copy pathcontrollers.py
File metadata and controls
5099 lines (4651 loc) · 266 KB
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
# voter_guide/controllers.py
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-
from ballot.models import OFFICE, CANDIDATE, MEASURE
from candidate.controllers import retrieve_candidate_list_for_all_prior_elections_this_year, \
retrieve_candidate_list_for_all_upcoming_elections
from candidate.models import CandidateManager, CandidateListManager
from config.base import get_environment_variable
import copy
from datetime import datetime, timedelta
from django.http import HttpResponse
from election.controllers import retrieve_this_years_election_id_list, retrieve_upcoming_election_id_list
from election.models import ElectionManager
from exception.models import handle_record_not_found_exception
from follow.models import FollowOrganizationList, FollowIssueList, FOLLOWING
from friend.controllers import heal_current_friend
from friend.models import FriendManager
from itertools import chain
from issue.models import OrganizationLinkToIssueList
import json
from measure.controllers import add_measure_name_alternatives_to_measure_list_light, \
retrieve_measure_list_for_all_upcoming_elections
from measure.models import ContestMeasureListManager, ContestMeasureManager
from office.models import ContestOfficeManager
from organization.controllers import organization_follow_or_unfollow_or_ignore, \
push_organization_data_to_other_table_caches, \
refresh_organization_data_from_master_tables, retrieve_organization_list_for_all_upcoming_elections
from organization.models import OrganizationManager, OrganizationListManager, INDIVIDUAL
from pledge_to_vote.models import PledgeToVoteManager
from position.controllers import retrieve_ballot_item_we_vote_ids_for_organizations_to_follow, \
retrieve_ballot_item_we_vote_ids_for_organization_static
from position.models import ANY_STANCE, FRIENDS_AND_PUBLIC, FRIENDS_ONLY, INFORMATION_ONLY, OPPOSE, \
PositionEntered, PositionManager, PositionListManager, PUBLIC_ONLY, SUPPORT
import pytz
from share.models import ShareManager
from twitter.models import TwitterUserManager
from voter.models import fetch_voter_id_from_voter_device_link, fetch_voter_we_vote_id_from_voter_device_link, \
fetch_voter_we_vote_id_from_voter_id, VoterManager
from voter_guide.controllers_possibility import candidates_found_on_url, organizations_found_on_url
from voter_guide.models import ENDORSEMENTS_FOR_CANDIDATE, ORGANIZATION_ENDORSING_CANDIDATES, UNKNOWN_TYPE, \
VoterGuide, VoterGuideListManager, VoterGuideManager, \
VoterGuidePossibility, VoterGuidePossibilityManager, VoterGuidePossibilityPosition
import wevote_functions.admin
from wevote_functions.functions import convert_to_int, is_voter_device_id_valid, positive_value_exists, \
process_request_from_master, is_link_to_video
logger = wevote_functions.admin.get_logger(__name__)
VOTER_GUIDES_SYNC_URL = get_environment_variable("VOTER_GUIDES_SYNC_URL") # voterGuidesSyncOut
WE_VOTE_API_KEY = get_environment_variable("WE_VOTE_API_KEY")
WE_VOTE_SERVER_ROOT_URL = get_environment_variable("WE_VOTE_SERVER_ROOT_URL")
# TODO: 9/17/19, URLs for sites excluded from highlighting - should be in the db
URLS_TO_NEVER_HIGHLIGHT = [
'*.google.com',
'*.newrelic.com',
'*.slack.com',
'*.wevote.us',
'*.zendesk.com',
'api.wevoteusa.org',
'dashlane.com',
'github.com'
'localhost',
'localhost:3000',
'localhost:8000',
'localhost:8001',
'sketchviewer.com',
'*.travis-ci.com',
'*.travis-ci.org',
'blank',
'platform.twitter.com',
's7.addthis.com',
'vars.hotjar.com',
'regex101.com',
]
def convert_candidate_endorsement_list_light_to_possible_endorsement_list(endorsement_list_light):
status = ""
success = True
possible_endorsement_list = []
possible_endorsement_list_found = False
# one_endorsement = {
# 'ballot_item_display_name': candidate.display_candidate_name(),
# 'candidate_we_vote_id': candidate.we_vote_id,
# 'google_civic_election_id': candidate.google_civic_election_id,
# 'office_we_vote_id': candidate.contest_office_we_vote_id,
# 'measure_we_vote_id': '',
# }
number_index = 1
for one_endorsement in endorsement_list_light:
if not positive_value_exists(one_endorsement['ballot_item_display_name']):
continue
google_civic_election_id = one_endorsement['google_civic_election_id'] \
if 'google_civic_election_id' in one_endorsement else ''
possible_endorsement = {
'ballot_item_name': one_endorsement['ballot_item_display_name'],
'candidate_we_vote_id': one_endorsement['candidate_we_vote_id'],
'google_civic_election_id': google_civic_election_id,
'measure_we_vote_id': one_endorsement['measure_we_vote_id'],
'more_info_url': "",
'organization_we_vote_id': "",
'possibility_position_number': str(number_index),
'possibility_should_be_deleted': False,
'possibility_should_be_ignored': False,
'position_should_be_removed': False,
'position_stance': "SUPPORT",
'statement_text': "",
}
possible_endorsement_list.append(possible_endorsement)
number_index += 1
if len(possible_endorsement_list):
possible_endorsement_list_found = True
results = {
'status': status,
'success': success,
'possible_endorsement_list': possible_endorsement_list,
'possible_endorsement_list_found': possible_endorsement_list_found,
}
return results
def convert_organization_endorsement_list_light_to_possible_endorsement_list(endorsement_list_light):
status = ""
success = True
possible_endorsement_list = []
possible_endorsement_list_found = False
# one_endorsement = {
# 'ballot_item_display_name': candidate.display_candidate_name(),
# 'candidate_we_vote_id': candidate.we_vote_id,
# 'google_civic_election_id': candidate.google_civic_election_id,
# 'office_we_vote_id': candidate.contest_office_we_vote_id,
# 'measure_we_vote_id': '',
# }
number_index = 1
for one_endorsement in endorsement_list_light:
if 'organization_we_vote_id' not in one_endorsement \
or not positive_value_exists(one_endorsement['organization_we_vote_id']):
continue
possible_endorsement = {
'ballot_item_name': "",
'candidate_we_vote_id': one_endorsement['candidate_we_vote_id'],
'google_civic_election_id': "",
'measure_we_vote_id': "",
'more_info_url': "",
'organization_name': one_endorsement['organization_name'],
'organization_website': one_endorsement['organization_website'],
'organization_we_vote_id': one_endorsement['organization_we_vote_id'],
'possibility_position_number': str(number_index),
'possibility_should_be_deleted': False,
'possibility_should_be_ignored': False,
'position_should_be_removed': False,
'position_stance': "SUPPORT",
'statement_text': "",
}
possible_endorsement_list.append(possible_endorsement)
number_index += 1
if len(possible_endorsement_list):
possible_endorsement_list_found = True
results = {
'status': status,
'success': success,
'possible_endorsement_list': possible_endorsement_list,
'possible_endorsement_list_found': possible_endorsement_list_found,
}
return results
def augment_with_voter_guide_possibility_position_data(voter_guide_possibility_list):
# Identify how many endorsements already have positions stored
voter_guide_possibility_list_modified = []
voter_guide_possibility_manager = VoterGuidePossibilityManager()
google_civic_election_id_list_this_year = retrieve_this_years_election_id_list()
for one_voter_guide_possibility in voter_guide_possibility_list:
one_voter_guide_possibility.number_of_endorsements_with_position = 0
possible_endorsement_list = []
possible_endorsement_list_found = False
# (ORGANIZATION_ENDORSING_CANDIDATES, 'Organization or News Website Endorsing Candidates'),
# (ENDORSEMENTS_FOR_CANDIDATE, 'List of Endorsements for One Candidate'),
# (UNKNOWN_TYPE, 'List of Endorsements for One Candidate'),
if one_voter_guide_possibility.voter_guide_possibility_type == ORGANIZATION_ENDORSING_CANDIDATES \
or one_voter_guide_possibility.voter_guide_possibility_type == UNKNOWN_TYPE:
# Note that this extraction is limited to 200 possibilities to avoid very slow page loads
results = extract_voter_guide_possibility_position_list_from_database(one_voter_guide_possibility)
if results['possible_endorsement_list_found']:
possible_endorsement_list = results['possible_endorsement_list']
# Match incoming endorsements to candidates already in the database
results = match_endorsement_list_with_candidates_in_database(
possible_endorsement_list, google_civic_election_id_list=google_civic_election_id_list_this_year)
if results['possible_endorsement_list_found']:
possible_endorsement_list = results['possible_endorsement_list']
possible_endorsement_list_found = True
# Match incoming endorsements to measures already in the database
results = match_endorsement_list_with_measures_in_database(
possible_endorsement_list, google_civic_election_id_list=google_civic_election_id_list_this_year)
if results['possible_endorsement_list_found']:
possible_endorsement_list = results['possible_endorsement_list']
possible_endorsement_list_found = True
elif one_voter_guide_possibility.voter_guide_possibility_type == ENDORSEMENTS_FOR_CANDIDATE:
# Note that this extraction is limited to 200 possibilities to avoid very slow page loads
results = extract_voter_guide_possibility_position_list_from_database(one_voter_guide_possibility)
if results['possible_endorsement_list_found']:
possible_endorsement_list = results['possible_endorsement_list']
# Match incoming endorsements to candidates already in the database
results = match_endorsement_list_with_candidates_in_database(
possible_endorsement_list, google_civic_election_id_list=google_civic_election_id_list_this_year)
if results['possible_endorsement_list_found']:
possible_endorsement_list = results['possible_endorsement_list']
possible_endorsement_list_found = True
if possible_endorsement_list_found:
one_voter_guide_possibility.number_of_ballot_items = \
voter_guide_possibility_manager.number_of_ballot_items(one_voter_guide_possibility.id)
one_voter_guide_possibility.number_of_ballot_items_not_matched = \
voter_guide_possibility_manager.number_of_ballot_items_not_matched(one_voter_guide_possibility.id)
one_voter_guide_possibility.number_of_candidates_in_database = \
voter_guide_possibility_manager.number_of_candidates_in_database(one_voter_guide_possibility.id)
one_voter_guide_possibility.number_of_measures_in_database = \
voter_guide_possibility_manager.number_of_measures_in_database(one_voter_guide_possibility.id)
one_voter_guide_possibility.positions_ready_to_save_as_batch = \
voter_guide_possibility_manager.positions_ready_to_save_as_batch(one_voter_guide_possibility)
maximum_number_of_possible_endorsements_analyzed = 200
number_of_possible_endorsements_analyzed = 0
for one_possible_endorsement in possible_endorsement_list:
number_of_possible_endorsements_analyzed += 1
if number_of_possible_endorsements_analyzed > maximum_number_of_possible_endorsements_analyzed:
break
if 'candidate_we_vote_id' in one_possible_endorsement \
and positive_value_exists(one_possible_endorsement['candidate_we_vote_id']):
position_exists_query = PositionEntered.objects.filter(
organization_we_vote_id=one_voter_guide_possibility.organization_we_vote_id,
candidate_campaign_we_vote_id=one_possible_endorsement['candidate_we_vote_id'])
position_count = position_exists_query.count()
if positive_value_exists(position_count):
one_voter_guide_possibility.number_of_endorsements_with_position += 1
elif 'measure_we_vote_id' in one_possible_endorsement \
and positive_value_exists(one_possible_endorsement['measure_we_vote_id']):
position_exists_query = PositionEntered.objects.filter(
organization_we_vote_id=one_voter_guide_possibility.organization_we_vote_id,
contest_measure_we_vote_id=one_possible_endorsement['measure_we_vote_id'])
position_count = position_exists_query.count()
if positive_value_exists(position_count):
one_voter_guide_possibility.number_of_endorsements_with_position += 1
voter_guide_possibility_list_modified.append(one_voter_guide_possibility)
return voter_guide_possibility_list_modified
def convert_list_of_names_to_possible_endorsement_list(ballot_items_list, starting_endorsement_number=1,
incoming_text_organization_names=False,
candidate_we_vote_id_to_include='',
organization_we_vote_id_to_include=''):
status = ""
success = True
possible_endorsement_list = []
possible_endorsement_list_found = False
number_index = starting_endorsement_number
for one_name in ballot_items_list:
if not positive_value_exists(one_name):
continue
possible_endorsement = {
'ballot_item_name': '' if incoming_text_organization_names else one_name,
'candidate_we_vote_id': candidate_we_vote_id_to_include,
'statement_text': "",
'google_civic_election_id': 0,
'measure_we_vote_id': "",
'more_info_url': "",
'organization_name': one_name if incoming_text_organization_names else '',
'organization_we_vote_id': organization_we_vote_id_to_include,
'possibility_position_number': str(number_index),
'possibility_should_be_deleted': False,
'possibility_should_be_ignored': False,
'position_should_be_removed': False,
'position_stance': "SUPPORT",
}
possible_endorsement_list.append(possible_endorsement)
number_index += 1
if len(possible_endorsement_list):
possible_endorsement_list_found = True
results = {
'status': status,
'success': success,
'possible_endorsement_list': possible_endorsement_list,
'possible_endorsement_list_found': possible_endorsement_list_found,
}
return results
def extract_import_position_list_from_voter_guide_possibility(voter_guide_possibility):
"""
Take the data from the VoterGuidePossibility database and convert it to the format we use for the Import Export
Batch System.
:param voter_guide_possibility:
:return:
"""
status = ""
success = True
position_json_list = []
position_json_list_found = False
more_info_url = voter_guide_possibility.voter_guide_possibility_url
# DEBUG=1 Phase out state_code for entire voter_guide_possibility?
state_code = voter_guide_possibility.state_code \
if positive_value_exists(voter_guide_possibility.state_code) else ""
# ######################
# If we are starting from a single organization endorsing many candidates,
# we store that organization information once
if voter_guide_possibility.voter_guide_possibility_type == ORGANIZATION_ENDORSING_CANDIDATES \
or voter_guide_possibility.voter_guide_possibility_type == UNKNOWN_TYPE:
organization_name = voter_guide_possibility.organization_name \
if positive_value_exists(voter_guide_possibility.organization_name) else ""
organization_we_vote_id = voter_guide_possibility.organization_we_vote_id \
if positive_value_exists(voter_guide_possibility.organization_we_vote_id) else ""
organization_twitter_handle = voter_guide_possibility.organization_twitter_handle \
if positive_value_exists(voter_guide_possibility.organization_twitter_handle) else ""
else:
organization_name = ""
organization_we_vote_id = ""
organization_twitter_handle = ""
# ######################
# If we are starting from a single candidate endorsed by many "organizations" (which may be people),
# we store this candidate information once
if voter_guide_possibility.voter_guide_possibility_type == ENDORSEMENTS_FOR_CANDIDATE:
candidate_name = voter_guide_possibility.candidate_name \
if positive_value_exists(voter_guide_possibility.candidate_name) else ""
candidate_twitter_handle = voter_guide_possibility.candidate_twitter_handle \
if positive_value_exists(voter_guide_possibility.candidate_twitter_handle) else ""
candidate_we_vote_id = voter_guide_possibility.candidate_we_vote_id \
if positive_value_exists(voter_guide_possibility.candidate_we_vote_id) else ""
contest_office_name = ""
candidate_manager = CandidateManager()
results = candidate_manager.retrieve_candidate_from_we_vote_id(candidate_we_vote_id)
if results['candidate_found']:
candidate = results['candidate']
contest_office_name = candidate.contest_office_name
else:
candidate_name = ""
candidate_twitter_handle = ""
candidate_we_vote_id = ""
contest_office_name = ""
possibility_position_query = VoterGuidePossibilityPosition.objects.filter(
voter_guide_possibility_parent_id=voter_guide_possibility.id).order_by('possibility_position_number')
possibility_position_list = list(possibility_position_query)
for possibility_position in possibility_position_list:
if positive_value_exists(possibility_position.more_info_url):
more_info_url = possibility_position.more_info_url
else:
more_info_url = voter_guide_possibility.voter_guide_possibility_url
if voter_guide_possibility.voter_guide_possibility_type == ORGANIZATION_ENDORSING_CANDIDATES \
or voter_guide_possibility.voter_guide_possibility_type == UNKNOWN_TYPE:
# The organization variables have been set above
# Note that UNKNOWN_TYPE might be set if we are looking at organization
# ######################
# If we are starting from a single organization endorsing many candidates,
# we store that candidate information once
if positive_value_exists(possibility_position.candidate_we_vote_id):
candidate_name = possibility_position.ballot_item_name
position_json = {
'candidate_name': candidate_name,
'candidate_we_vote_id': possibility_position.candidate_we_vote_id,
'candidate_twitter_handle': possibility_position.candidate_twitter_handle,
'google_civic_election_id': possibility_position.google_civic_election_id,
'more_info_url': more_info_url,
'organization_name': organization_name,
'organization_we_vote_id': organization_we_vote_id,
'organization_twitter_handle': organization_twitter_handle,
'stance': possibility_position.position_stance,
'statement_text': possibility_position.statement_text,
'state_code': state_code,
}
position_json_list.append(position_json)
elif positive_value_exists(possibility_position.measure_we_vote_id):
measure_title = possibility_position.ballot_item_name
position_json = {
'google_civic_election_id': possibility_position.google_civic_election_id,
'measure_title': measure_title,
'measure_we_vote_id': possibility_position.measure_we_vote_id,
'more_info_url': more_info_url,
'organization_name': organization_name,
'organization_we_vote_id': organization_we_vote_id,
'organization_twitter_handle': organization_twitter_handle,
'stance': possibility_position.position_stance,
'statement_text': possibility_position.statement_text,
'state_code': state_code,
}
position_json_list.append(position_json)
else:
status += "MISSING_BOTH_CANDIDATE_AND_MEASURE_WE_VOTE_ID "
elif voter_guide_possibility.voter_guide_possibility_type == ENDORSEMENTS_FOR_CANDIDATE:
# ######################
# If we are starting from a single candidate endorsed by many "organizations" (which may be people),
# we store the unique organization information in the VoterGuidePossibilityPosition table
organization_name = possibility_position.organization_name \
if positive_value_exists(possibility_position.organization_name) else ""
organization_we_vote_id = possibility_position.organization_we_vote_id \
if positive_value_exists(possibility_position.organization_we_vote_id) else ""
organization_twitter_handle = possibility_position.organization_twitter_handle \
if positive_value_exists(possibility_position.organization_twitter_handle) else ""
position_json = {
'candidate_name': candidate_name,
'candidate_we_vote_id': candidate_we_vote_id,
'candidate_twitter_handle': candidate_twitter_handle,
'contest_office_name': contest_office_name,
'google_civic_election_id': possibility_position.google_civic_election_id,
'measure_we_vote_id': possibility_position.measure_we_vote_id,
'more_info_url': more_info_url,
'organization_name': organization_name,
'organization_we_vote_id': organization_we_vote_id,
'organization_twitter_handle': organization_twitter_handle,
'stance': possibility_position.position_stance,
'statement_text': possibility_position.statement_text,
'state_code': state_code,
}
position_json_list.append(position_json)
else:
# This is an error condition which should not be reached
status += "UNRECOGNIZED_VOTER_POSSIBILITY_TYPE "
if len(position_json_list):
position_json_list_found = True
results = {
'status': status,
'success': success,
'position_json_list': position_json_list,
'position_json_list_found': position_json_list_found,
}
return results
def extract_voter_guide_possibility_position_list_from_database(
voter_guide_possibility, voter_guide_possibility_position_id=0):
"""
Get voter_guide_possibility data from the database and put it into the Voter Guide Possibility system format we use
:param voter_guide_possibility:
:param voter_guide_possibility_position_id: This is included if we only want to retrieve one possible position
:return:
"""
status = ""
success = True
possible_endorsement_list = []
possible_endorsement_list_found = False
# DEBUG=1 Phase out state_code for entire voter_guide_possibility?
state_code = voter_guide_possibility.state_code \
if positive_value_exists(voter_guide_possibility.state_code) else ""
# ######################
# If we are starting from a single organization endorsing many candidates,
# we store that organization information once
if voter_guide_possibility.voter_guide_possibility_type == ORGANIZATION_ENDORSING_CANDIDATES \
or voter_guide_possibility.voter_guide_possibility_type == UNKNOWN_TYPE:
organization_name = voter_guide_possibility.organization_name \
if positive_value_exists(voter_guide_possibility.organization_name) else ""
organization_we_vote_id = voter_guide_possibility.organization_we_vote_id \
if positive_value_exists(voter_guide_possibility.organization_we_vote_id) else ""
organization_twitter_handle = voter_guide_possibility.organization_twitter_handle \
if positive_value_exists(voter_guide_possibility.organization_twitter_handle) else ""
else:
organization_name = ""
organization_we_vote_id = ""
organization_twitter_handle = ""
# ######################
# If we are starting from a single candidate endorsed by many "organizations" (which may be people),
# we store this candidate information once
if voter_guide_possibility.voter_guide_possibility_type == ENDORSEMENTS_FOR_CANDIDATE:
candidate_twitter_handle = voter_guide_possibility.candidate_twitter_handle \
if positive_value_exists(voter_guide_possibility.candidate_twitter_handle) else ""
candidate_we_vote_id = voter_guide_possibility.candidate_we_vote_id \
if positive_value_exists(voter_guide_possibility.candidate_we_vote_id) else ""
# candidate_manager = CandidateManager()
# results = candidate_manager.retrieve_candidate_from_we_vote_id(candidate_we_vote_id)
# if results['candidate_found']:
# candidate = results['candidate']
# contest_office_name = candidate.contest_office_name
else:
# candidate_name = ""
candidate_twitter_handle = ""
candidate_we_vote_id = ""
# contest_office_name = ""
possibility_position_query = VoterGuidePossibilityPosition.objects.filter(
voter_guide_possibility_parent_id=voter_guide_possibility.id).order_by('possibility_position_number')
if positive_value_exists(voter_guide_possibility_position_id):
possibility_position_query = possibility_position_query.filter(id=voter_guide_possibility_position_id)
possibility_position_query = possibility_position_query[:200] # Limit to 200 to avoid very slow page loading
possibility_position_list = list(possibility_position_query)
candidate_manager = CandidateManager()
for possibility_position in possibility_position_list:
candidate_alternate_names = []
if positive_value_exists(possibility_position.more_info_url):
more_info_url = possibility_position.more_info_url
else:
more_info_url = voter_guide_possibility.voter_guide_possibility_url
if voter_guide_possibility.voter_guide_possibility_type == ORGANIZATION_ENDORSING_CANDIDATES \
or voter_guide_possibility.voter_guide_possibility_type == UNKNOWN_TYPE:
# The organization variables have been set above
# Note that UNKNOWN_TYPE might be set if we are looking at organization
# ######################
# If we are starting from a single organization endorsing many candidates,
# we refresh the candidate information from the VoterGuidePossibilityPosition table with each loop
candidate_we_vote_id = possibility_position.candidate_we_vote_id \
if positive_value_exists(possibility_position.candidate_we_vote_id) else ""
candidate_twitter_handle = possibility_position.candidate_twitter_handle \
if positive_value_exists(possibility_position.candidate_twitter_handle) else ""
# If this is a list of candidates being endorsed by one organization, add on the alternate_names
if positive_value_exists(candidate_we_vote_id):
candidate_results = candidate_manager.retrieve_candidate_from_we_vote_id(candidate_we_vote_id)
if candidate_results['candidate_found']:
candidate_alternate_names = candidate_results['candidate'].display_alternate_names_list()
elif voter_guide_possibility.voter_guide_possibility_type == ENDORSEMENTS_FOR_CANDIDATE:
# ######################
# If we are starting from a single candidate endorsed by many "organizations" (which may be people),
# we refresh the organization information from the VoterGuidePossibilityPosition table with each loop
organization_name = possibility_position.organization_name \
if positive_value_exists(possibility_position.organization_name) else ""
organization_we_vote_id = possibility_position.organization_we_vote_id \
if positive_value_exists(possibility_position.organization_we_vote_id) else ""
organization_twitter_handle = possibility_position.organization_twitter_handle \
if positive_value_exists(possibility_position.organization_twitter_handle) else ""
else:
status += "PROBLEM-SHOULD_NOT_BE_HERE "
candidate_we_vote_id = ""
organization_name = ""
organization_we_vote_id = ""
organization_twitter_handle = ""
position_json = {
'possibility_position_id': possibility_position.id,
'possibility_position_number': possibility_position.possibility_position_number,
'ballot_item_name': possibility_position.ballot_item_name,
'candidate_alternate_names': candidate_alternate_names,
'candidate_twitter_handle': candidate_twitter_handle,
'candidate_we_vote_id': candidate_we_vote_id,
# 'contest_office_name': contest_office_name,
'google_civic_election_id': possibility_position.google_civic_election_id,
'measure_we_vote_id': possibility_position.measure_we_vote_id,
'more_info_url': more_info_url,
'organization_name': organization_name,
'organization_twitter_handle': organization_twitter_handle,
'organization_we_vote_id': organization_we_vote_id,
'possibility_should_be_deleted': False,
'possibility_should_be_ignored': possibility_position.possibility_should_be_ignored,
'position_should_be_removed': possibility_position.position_should_be_removed,
'position_we_vote_id': possibility_position.position_we_vote_id,
'position_stance': possibility_position.position_stance,
'statement_text': possibility_position.statement_text,
'state_code': state_code,
}
possible_endorsement_list.append(position_json)
if len(possible_endorsement_list):
possible_endorsement_list_found = True
results = {
'status': status,
'success': success,
'possible_endorsement_list': possible_endorsement_list,
'possible_endorsement_list_found': possible_endorsement_list_found,
}
return results
def augment_candidate_possible_position_data(
possible_endorsement,
google_civic_election_id_list=[],
limit_to_this_state_code="",
all_possible_candidates=[],
attach_objects=True):
status = ""
success = True
candidate_manager = CandidateManager()
candidate_list_manager = CandidateListManager()
contest_office_manager = ContestOfficeManager()
possible_endorsement_matched = False
possible_endorsement_return_list = []
possible_endorsement_count = 0
possible_endorsement['withdrawn_from_election'] = False
possible_endorsement['withdrawal_date'] = ''
if 'candidate_we_vote_id' in possible_endorsement \
and positive_value_exists(possible_endorsement['candidate_we_vote_id']):
possible_endorsement_matched = True
results = candidate_manager.retrieve_candidate_from_we_vote_id(
possible_endorsement['candidate_we_vote_id'])
if results['candidate_found']:
candidate = results['candidate']
if positive_value_exists(attach_objects):
possible_endorsement['candidate'] = candidate
possible_endorsement['ballot_item_name'] = candidate.display_candidate_name()
possible_endorsement['google_civic_election_id'] = candidate.google_civic_election_id
possible_endorsement['office_name'] = candidate.contest_office_name
possible_endorsement['office_we_vote_id'] = candidate.contest_office_we_vote_id
possible_endorsement['political_party'] = candidate.party
possible_endorsement['ballot_item_image_url_https_large'] = \
candidate.we_vote_hosted_profile_image_url_large
possible_endorsement['ballot_item_image_url_https_medium'] = \
candidate.we_vote_hosted_profile_image_url_medium
if not positive_value_exists(possible_endorsement['google_civic_election_id']) \
and positive_value_exists(candidate.contest_office_we_vote_id):
possible_endorsement['google_civic_election_id'] = \
contest_office_manager.fetch_google_civic_election_id_from_office_we_vote_id(
candidate.contest_office_we_vote_id)
possible_endorsement['withdrawn_from_election'] = candidate.withdrawn_from_election
possible_endorsement['withdrawal_date'] = candidate.withdrawal_date
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement)
elif 'ballot_item_name' in possible_endorsement and \
positive_value_exists(possible_endorsement['ballot_item_name']):
possible_endorsement_matched = True
# If here search for possible candidate matches
matching_results = candidate_list_manager.retrieve_candidates_from_non_unique_identifiers(
google_civic_election_id_list=google_civic_election_id_list,
state_code=limit_to_this_state_code,
candidate_name=possible_endorsement['ballot_item_name'])
if matching_results['candidate_found']:
candidate = matching_results['candidate']
# If one candidate found, add we_vote_id here
possible_endorsement['candidate_we_vote_id'] = candidate.we_vote_id
if positive_value_exists(attach_objects):
possible_endorsement['candidate'] = candidate
possible_endorsement['ballot_item_name'] = candidate.display_candidate_name()
possible_endorsement['google_civic_election_id'] = candidate.google_civic_election_id
possible_endorsement['office_name'] = candidate.contest_office_name
possible_endorsement['office_we_vote_id'] = candidate.contest_office_we_vote_id
possible_endorsement['political_party'] = candidate.party
possible_endorsement['ballot_item_image_url_https_large'] = \
candidate.we_vote_hosted_profile_image_url_large
possible_endorsement['ballot_item_image_url_https_medium'] = \
candidate.we_vote_hosted_profile_image_url_medium
if not positive_value_exists(possible_endorsement['google_civic_election_id']) \
and positive_value_exists(candidate.contest_office_we_vote_id):
possible_endorsement['google_civic_election_id'] = \
contest_office_manager.fetch_google_civic_election_id_from_office_we_vote_id(
candidate.contest_office_we_vote_id)
possible_endorsement['withdrawn_from_election'] = candidate.withdrawn_from_election
possible_endorsement['withdrawal_date'] = candidate.withdrawal_date
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement)
elif matching_results['candidate_list_found']:
# Keep the current option
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement)
possible_endorsement_matched = True
# ...and add entries for other possible matches
status += "MULTIPLE_CANDIDATES_FOUND "
candidate_list = matching_results['candidate_list']
for candidate in candidate_list:
possible_endorsement_copy = copy.deepcopy(possible_endorsement)
# Reset the possibility position id
possible_endorsement_copy['possibility_position_id'] = 0
# If one candidate found, add we_vote_id here
possible_endorsement_copy['candidate_we_vote_id'] = candidate.we_vote_id
if positive_value_exists(attach_objects):
possible_endorsement_copy['candidate'] = candidate
possible_endorsement_copy['ballot_item_name'] = candidate.display_candidate_name()
possible_endorsement_copy['google_civic_election_id'] = candidate.google_civic_election_id
possible_endorsement_copy['office_name'] = candidate.contest_office_name
possible_endorsement_copy['office_we_vote_id'] = candidate.contest_office_we_vote_id
possible_endorsement_copy['political_party'] = candidate.party
possible_endorsement_copy['ballot_item_image_url_https_large'] = \
candidate.we_vote_hosted_profile_image_url_large
possible_endorsement_copy['ballot_item_image_url_https_medium'] = \
candidate.we_vote_hosted_profile_image_url_medium
if not positive_value_exists(possible_endorsement_copy['google_civic_election_id']) \
and positive_value_exists(candidate.contest_office_we_vote_id):
possible_endorsement_copy['google_civic_election_id'] = \
contest_office_manager.fetch_google_civic_election_id_from_office_we_vote_id(
candidate.contest_office_we_vote_id)
possible_endorsement_copy['withdrawn_from_election'] = candidate.withdrawn_from_election
possible_endorsement_copy['withdrawal_date'] = candidate.withdrawal_date
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement_copy)
elif not positive_value_exists(matching_results['success']):
possible_endorsement_matched = True
status += "RETRIEVE_CANDIDATE_FROM_NON_UNIQUE-NO_SUCCESS "
status += matching_results['status']
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement)
else:
status += "RETRIEVE_CANDIDATE_FROM_NON_UNIQUE-CANDIDATE_NOT_FOUND "
# Now we want to do a reverse search, where we cycle through all upcoming candidates and search
# within the incoming text for a known candidate name
for one_endorsement_light in all_possible_candidates:
if one_endorsement_light['ballot_item_display_name'] in possible_endorsement['ballot_item_name']:
possible_endorsement['candidate_we_vote_id'] = one_endorsement_light['candidate_we_vote_id']
possible_endorsement['ballot_item_name'] = one_endorsement_light['ballot_item_display_name']
if 'google_civic_election_id' in one_endorsement_light:
possible_endorsement['google_civic_election_id'] = \
one_endorsement_light['google_civic_election_id']
else:
possible_endorsement['google_civic_election_id'] = 0
matching_results = candidate_manager.retrieve_candidate_from_we_vote_id(
possible_endorsement['candidate_we_vote_id'])
if matching_results['candidate_found']:
candidate = matching_results['candidate']
# If one candidate found, add we_vote_id here
possible_endorsement['candidate_we_vote_id'] = candidate.we_vote_id
if positive_value_exists(attach_objects):
possible_endorsement['candidate'] = candidate
possible_endorsement['ballot_item_name'] = candidate.display_candidate_name()
possible_endorsement['google_civic_election_id'] = candidate.google_civic_election_id
possible_endorsement['office_name'] = candidate.contest_office_name
possible_endorsement['office_we_vote_id'] = candidate.contest_office_we_vote_id
possible_endorsement['political_party'] = candidate.party
possible_endorsement['ballot_item_image_url_https_large'] = \
candidate.we_vote_hosted_profile_image_url_large
possible_endorsement['ballot_item_image_url_https_medium'] = \
candidate.we_vote_hosted_profile_image_url_medium
if not positive_value_exists(possible_endorsement['google_civic_election_id']) \
and positive_value_exists(candidate.contest_office_we_vote_id):
possible_endorsement['google_civic_election_id'] = \
contest_office_manager.fetch_google_civic_election_id_from_office_we_vote_id(
candidate.contest_office_we_vote_id)
possible_endorsement['withdrawn_from_election'] = candidate.withdrawn_from_election
possible_endorsement['withdrawal_date'] = candidate.withdrawal_date
possible_endorsement_matched = True
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement)
break
if not possible_endorsement_matched:
# We want to check 'alternate_names' candidate names in upcoming elections
# (ex/ Candidate name with middle initial in alternate_names)
# against the possible endorsement ()
# NOTE: one_endorsement_light is a candidate or measure for an upcoming election
# NOTE: possible endorsement is one of the incoming new endorsements we are trying to match
synonym_found = False
for one_endorsement_light in all_possible_candidates:
# Hanging off each ballot_item_dict is a alternate_names that includes
# shortened alternative names that we should check against decide_line_lower_case
if 'alternate_names' in one_endorsement_light and \
positive_value_exists(one_endorsement_light['alternate_names']):
alternate_names = one_endorsement_light['alternate_names']
for ballot_item_display_name_alternate in alternate_names:
if ballot_item_display_name_alternate.lower() in \
possible_endorsement['ballot_item_name'].lower():
# Make a copy so we don't change the incoming object -- if we find multiple upcoming
# candidates that match, we should use them all
possible_endorsement_copy = copy.deepcopy(possible_endorsement)
possible_endorsement_copy['candidate_we_vote_id'] = \
one_endorsement_light['candidate_we_vote_id']
possible_endorsement_copy['ballot_item_name'] = \
one_endorsement_light['ballot_item_display_name']
if 'google_civic_election_id' in one_endorsement_light:
possible_endorsement_copy['google_civic_election_id'] = \
one_endorsement_light['google_civic_election_id']
else:
possible_endorsement_copy['google_civic_election_id'] = 0
matching_results = candidate_manager.retrieve_candidate_from_we_vote_id(
possible_endorsement_copy['candidate_we_vote_id'])
if matching_results['candidate_found']:
candidate = matching_results['candidate']
# If one candidate found, augment the data if we can
if positive_value_exists(attach_objects):
possible_endorsement_copy['candidate'] = candidate
possible_endorsement_copy['ballot_item_name'] = candidate.candidate_name
possible_endorsement_copy['google_civic_election_id'] = candidate.google_civic_election_id
possible_endorsement_copy['office_name'] = candidate.contest_office_name
possible_endorsement_copy['office_we_vote_id'] = candidate.contest_office_we_vote_id
possible_endorsement_copy['political_party'] = candidate.party
possible_endorsement_copy['ballot_item_image_url_https_large'] = \
candidate.we_vote_hosted_profile_image_url_large
possible_endorsement_copy['ballot_item_image_url_https_medium'] = \
candidate.we_vote_hosted_profile_image_url_medium
possible_endorsement_copy['withdrawn_from_election'] = candidate.withdrawn_from_election
possible_endorsement_copy['withdrawal_date'] = candidate.withdrawal_date
synonym_found = True
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement_copy)
break
if not synonym_found:
# If an entry based on a synonym wasn't found, then store the original possibility
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement)
results = {
'status': status,
'success': success,
'possible_endorsement_return_list': possible_endorsement_return_list,
'possible_endorsement_count': possible_endorsement_count,
}
return results
def augment_organization_possible_position_data(possible_endorsement, attach_objects=True):
status = ""
success = True
organization_manager = OrganizationManager()
organization_list_manager = OrganizationListManager()
possible_endorsement_return_list = []
possible_endorsement_count = 0
if 'organization_we_vote_id' in possible_endorsement \
and positive_value_exists(possible_endorsement['organization_we_vote_id']):
results = organization_manager.retrieve_organization_from_we_vote_id(
possible_endorsement['organization_we_vote_id'])
if results['organization_found']:
organization = results['organization']
if positive_value_exists(attach_objects):
possible_endorsement['organization'] = organization
possible_endorsement['organization_name'] = organization.organization_name
possible_endorsement['organization_twitter_handle'] = organization.organization_twitter_handle
possible_endorsement['organization_website'] = organization.organization_website
possible_endorsement['we_vote_hosted_profile_image_url_large'] = \
organization.we_vote_hosted_profile_image_url_large
possible_endorsement['we_vote_hosted_profile_image_url_medium'] = \
organization.we_vote_hosted_profile_image_url_medium
possible_endorsement['we_vote_hosted_profile_image_url_tiny'] = \
organization.we_vote_hosted_profile_image_url_tiny
possible_endorsement_count += 1
possible_endorsement_return_list.append(possible_endorsement)
elif 'organization_name' in possible_endorsement and \
positive_value_exists(possible_endorsement['organization_name']):
# If here search for possible organization matches
results = organization_list_manager.retrieve_organizations_from_organization_name(
organization_name=possible_endorsement['organization_name'])
if results['organization_found']:
organization = results['organization']
if positive_value_exists(attach_objects):
possible_endorsement['organization'] = organization
possible_endorsement['organization_name'] = organization.organization_name
possible_endorsement['organization_twitter_handle'] = organization.organization_twitter_handle
possible_endorsement['organization_we_vote_id'] = organization.we_vote_id
possible_endorsement['organization_website'] = organization.organization_website
possible_endorsement['we_vote_hosted_profile_image_url_large'] = \
organization.we_vote_hosted_profile_image_url_large
possible_endorsement['we_vote_hosted_profile_image_url_medium'] = \
organization.we_vote_hosted_profile_image_url_medium
possible_endorsement['we_vote_hosted_profile_image_url_tiny'] = \
organization.we_vote_hosted_profile_image_url_tiny
possible_endorsement_return_list.append(possible_endorsement)
possible_endorsement_count += 1
elif results['organization_list_found']:
organization_list = results['organization_list']
first_in_list = True
for organization in organization_list:
if first_in_list:
first_in_list = False
else:
possible_endorsement = copy.deepcopy(possible_endorsement)
if positive_value_exists(attach_objects):
possible_endorsement['organization'] = organization
possible_endorsement['organization_name'] = organization.organization_name
possible_endorsement['organization_twitter_handle'] = organization.organization_twitter_handle
possible_endorsement['organization_website'] = organization.organization_website
possible_endorsement['organization_we_vote_id'] = organization.we_vote_id
possible_endorsement['we_vote_hosted_profile_image_url_large'] = \
organization.we_vote_hosted_profile_image_url_large
possible_endorsement['we_vote_hosted_profile_image_url_medium'] = \
organization.we_vote_hosted_profile_image_url_medium
possible_endorsement['we_vote_hosted_profile_image_url_tiny'] = \
organization.we_vote_hosted_profile_image_url_tiny
possible_endorsement_return_list.append(possible_endorsement)
possible_endorsement_count += 1
results = {
'status': status,
'success': success,
'possible_endorsement_return_list': possible_endorsement_return_list,
'possible_endorsement_count': possible_endorsement_count,
}
return results
def match_endorsement_list_with_candidates_in_database(
possible_endorsement_list=[],
google_civic_election_id_list=[],
state_code='',
all_possible_candidates_list_light=[],
attach_objects=True):
"""
:param possible_endorsement_list:
:param google_civic_election_id_list:
:param state_code:
:param all_possible_candidates_list_light: Only use when trying to match to new candidates
:param attach_objects:
:return:
"""
status = ""
success = True
possible_endorsement_list_found = False
possible_endorsement_list_modified = []
for possible_endorsement in possible_endorsement_list:
results = augment_candidate_possible_position_data(
possible_endorsement,
google_civic_election_id_list=google_civic_election_id_list,
limit_to_this_state_code=state_code,
all_possible_candidates=all_possible_candidates_list_light,
attach_objects=attach_objects)
if results['possible_endorsement_count'] > 0:
possible_endorsement_list_modified += results['possible_endorsement_return_list']
else:
possible_endorsement_list_modified.append(possible_endorsement)
if len(possible_endorsement_list_modified):
possible_endorsement_list_found = True
results = {
'status': status,
'success': success,
'possible_endorsement_list': possible_endorsement_list_modified,
'possible_endorsement_list_found': possible_endorsement_list_found,
}
return results
def match_endorsement_list_with_measures_in_database(
possible_endorsement_list, google_civic_election_id_list, state_code='', all_possible_measures_list_light=[],
attach_objects=True):
"""
:param possible_endorsement_list: This is the list of measures and candidates that were either found on the
page or entered manually (ex/ "Prop 1")
:param google_civic_election_id_list:
:param state_code:
:param all_possible_measures_list_light: This is the list of actual candidates or measures in the database
:param attach_objects: Should we attach objects that won't convert to json?
:return:
"""
status = ""
success = True
possible_endorsement_list_found = False
possible_endorsement_list_modified = []
measure_manager = ContestMeasureManager()
measure_list_manager = ContestMeasureListManager()
for possible_endorsement in possible_endorsement_list:
possible_endorsement_matched = False
if 'measure_we_vote_id' in possible_endorsement \
and positive_value_exists(possible_endorsement['measure_we_vote_id']):
results = measure_manager.retrieve_contest_measure_from_we_vote_id(
possible_endorsement['measure_we_vote_id'])
if results['contest_measure_found']:
measure = results['contest_measure']
if positive_value_exists(attach_objects):
possible_endorsement['measure'] = measure
possible_endorsement['ballot_item_name'] = measure.measure_title
possible_endorsement['google_civic_election_id'] = measure.google_civic_election_id
possible_endorsement_matched = True
possible_endorsement_list_modified.append(possible_endorsement)
elif 'candidate_we_vote_id' in possible_endorsement \
and positive_value_exists(possible_endorsement['candidate_we_vote_id']):
possible_endorsement_matched = True
possible_endorsement_list_modified.append(possible_endorsement)
# Go to the next entry in this possible_endorsement_list loop
continue
elif 'ballot_item_name' in possible_endorsement and \
positive_value_exists(possible_endorsement['ballot_item_name']):
# If here search for possible measure matches
matching_results = measure_list_manager.retrieve_contest_measures_from_non_unique_identifiers(
google_civic_election_id_list, state_code, possible_endorsement['ballot_item_name'])
if matching_results['contest_measure_found']:
measure = matching_results['contest_measure']
# If one measure found, add we_vote_id here
possible_endorsement['measure_we_vote_id'] = measure.we_vote_id
if positive_value_exists(attach_objects):
possible_endorsement['measure'] = measure
possible_endorsement['ballot_item_name'] = measure.measure_title
possible_endorsement['google_civic_election_id'] = measure.google_civic_election_id
possible_endorsement_matched = True
possible_endorsement_list_modified.append(possible_endorsement)
elif matching_results['multiple_entries_found']:
status += "MULTIPLE_MEASURES_FOUND-CANNOT_MATCH "
# possible_endorsement_list_modified.append(possible_endorsement)
elif not positive_value_exists(matching_results['success']):
status += "RETRIEVE_MEASURES_FROM_NON_UNIQUE-NO_SUCCESS "