Changeset 35070
- Timestamp:
- 2021-04-14T17:24:52+12:00 (3 years ago)
- Location:
- main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/03-GEN-VOTING-METADATA.sh
r35034 r35070 61 61 62 62 if [ $? = 0 ] ; then 63 $prep_dir/xlsx-tocountry-jsonmetadata.py $prep_dir/eurovision_song_contest_1975_2019.xlsx $prep_dir/metadata-votes-tocountry.json64 63 65 if [ $? != 0 ] ; then 64 $prep_dir/xlsx-fromcountry-jsonmetadata.py \ 65 --votingtype "JT" \ 66 $prep_dir/eurovision_song_contest_1975_2019.xlsx \ 67 $prep_dir/metadata-votes/metadata-votes-fromcountry-comb.json 68 69 if [ $? = 0 ] ; then 70 $prep_dir/xlsx-tocountry-jsonmetadata.py $prep_dir/eurovision_song_contest_1975_2019.xlsx $prep_dir/metadata-votes-tocountry.json 71 72 if [ $? != 0 ] ; then 73 echo "!!!!" 1>&2 74 echo "! Error enountered generating to-country metadata-json: $prep_dir/metadata-votes-tocountry.json" 1>&2 75 echo "!!!!" 1>&2 76 exit_status=1 77 fi 78 else 66 79 echo "!!!!" 1>&2 67 echo "! Error enountered generating to-country metadata-json: $prep_dir/metadata-votes-tocountry.json" 1>&280 echo "! Error enountered generating from-country combined Jury and Televoting metadata-json in $prep_dir/metadata-votes/" 1>&2 68 81 echo "!!!!" 1>&2 69 82 exit_status=1 -
main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/voting-excel/xlsx-fromcountry-jsonmetadata.py
r34986 r35070 17 17 #tele_from_countries = {} 18 18 19 def list_jury_tele_comb_votes(data_hashmap_array): 20 21 data_hashmap_array_filtered = list(filter(xlsxutil.filter_jury_or_tele_votes, data_hashmap_array)) 22 data_hashmap_array_filtered.sort(key=xlsxutil.sortkey_year_from_country_to_country_voting_type) 23 data_hashmap_array_filtered_len = len(data_hashmap_array_filtered) 24 25 data_hashmap_array_filtered_comb_pairs = [] 26 27 i = 0; 28 while (i<data_hashmap_array_filtered_len-1): 29 entry = data_hashmap_array_filtered[i]; 30 next_entry = data_hashmap_array_filtered[i+1]; 31 32 if ((entry.get("Year") == next_entry.get("Year")) and (entry.get("From country") == next_entry.get("From country")) 33 and ((entry.get("Jury or Televoting") == "J") and (next_entry.get("Jury or Televoting") == "T"))): 34 35 comb_entry = entry.copy() 36 comb_entry["Points"] = entry.get("Points") + next_entry.get("Points") 37 comb_entry["Jury or Televoting"] = "JT" 38 39 from_country = entry.get("From country") 40 year = entry.get("Year") 41 from_country_id = "FromCountry-" + re.sub(r'\s+', '', from_country) + str(year) 42 43 comb_entry["FromCountry-Child-Jury"] = from_country_id + "-J" 44 comb_entry["FromCountry-Child-Tele"] = from_country_id + "-T" 45 46 data_hashmap_array_filtered_comb_pairs.append(comb_entry) 47 i = i + 2 48 else: 49 i = i + 1 50 51 return data_hashmap_array_filtered_comb_pairs 52 19 53 20 54 def create_from_country_voting_groups(data_hashmap_array): … … 31 65 # Sort so array entries are grouped by the country receiving the votes in a given year 32 66 data_hashmap_array.sort(key=xlsxutil.sortkey_year_from_country) 67 68 69 # Debug output 70 # 71 # for data_hashmap in data_hashmap_array: 72 # print(data_hashmap.get('From country'), data_hashmap.get('Year'), data_hashmap.get('Points'), "(Points to " + data_hashmap.get('To country') + ")") 73 74 75 # Build array of country groups 76 # A country grouping includes all the votes that country receive that year 77 country_groups = [] 78 79 prev_data_hashmap = data_hashmap_array[0] 80 country_group = [ ] 81 82 i = 1 83 num_rows = len(data_hashmap_array) 84 85 while (i < num_rows): 86 country_group.append(prev_data_hashmap) 87 data_hashmap = data_hashmap_array[i] 88 89 if (data_hashmap.get('From country') != prev_data_hashmap.get('From country')): 90 # moving on to a new country group 91 country_groups.append(country_group) 92 country_group = [ ] 93 94 prev_data_hashmap = data_hashmap 95 i = i + 1 96 97 country_group.append(prev_data_hashmap) 98 country_groups.append(country_group) 99 100 return country_groups 101 102 103 104 105 def XXXXcreate_from_country_voting_pairs_parent(data_hashmap_array): 106 107 # Example values for header-names 108 # (semi-) final: f, sf 109 # Jury or Televoting: J, T 110 # Year: 1975 111 # To country: Belgium 112 # From country: Belgium 113 # Edition: 1975f, 1975sf 114 115 116 # Sort so array entries are grouped by the country receiving the votes in a given year 117 data_hashmap_array.sort(key=xlsxutil.sortkey_year_from_country_voting_type) 33 118 34 119 … … 132 217 metadata_array.append({"name": "FromCountryVoteMode", "content" : vote_mode}) 133 218 metadata_array.append({"name": "FromCountryNuancedType", "content" : nuanced_vote_type}) 219 220 if tl_rec.get("FromCountry-Child-Jury") is not None: 221 metadata_array.append({"name": "FromCountryChildJury", "content" : tl_rec["FromCountry-Child-Jury"]}) 222 if tl_rec.get("FromCountry-Child-Tele") is not None: 223 metadata_array.append({"name": "FromCountryChildTele", "content" : tl_rec["FromCountry-Child-Tele"]}) 224 134 225 135 226 for from_country_year_vote in from_country_year_votes: … … 225 316 parser = argparse.ArgumentParser() 226 317 parser.add_argument('--sheetname', help="The name of the sheet within the Excel file to extractc data from") 227 parser.add_argument('--votingtype', choices=[ 'J','T'], help="Filter to only J=Jury or T=Tele castvotes")318 parser.add_argument('--votingtype', choices=["J","T", "JT"], help="Filter to only J=Jury, T=Tele cast votes, JT=Combined jury and tele votes") 228 319 parser.add_argument('input-file.xlsx') 229 320 parser.add_argument('output-file.json', nargs='?') … … 254 345 if voting_type != None: 255 346 # Further filter down by the type of voting results cast 256 if (voting_type == "J"): 347 if (voting_type == "JT"): 348 data_hashmap_array_filtered = list_jury_tele_comb_votes(data_hashmap_array_filtered) 349 print("Number Jury-Tele *combined* cast data rows: " + str(len(data_hashmap_array_filtered))) 350 elif (voting_type == "J"): 257 351 data_hashmap_array_filtered = list(filter(xlsxutil.filter_jury_votes, data_hashmap_array_filtered)) 258 352 print("Number Jury cast data rows: " + str(len(data_hashmap_array_filtered))) … … 264 358 print() 265 359 360 from_country_year_voting_groups = {} 361 362 # if ((voting_type != None) and (voting_type == "JT")): 363 # from_country_year_voting_groups = create_from_country_combined_voting_groups(data_hashmap_array_filtered) 364 # else: 365 # from_country_year_voting_groups = create_from_country_voting_groups(data_hashmap_array_filtered) 366 266 367 from_country_year_voting_groups = create_from_country_voting_groups(data_hashmap_array_filtered) 368 267 369 debug_print_country_groups(from_country_year_voting_groups) 268 269 # Debug output270 #271 # print(from_country_year_voting_groups)272 370 273 371 print() -
main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/voting-excel/xlsxutil.py
r34995 r35070 45 45 return entry.get("Jury or Televoting") == "T" and entry.get('Duplicate') == None 46 46 47 def filter_jury_or_tele_votes(entry): 48 return (entry.get("Jury or Televoting") == "J" or entry.get("Jury or Televoting") == "T") and entry.get('Duplicate') == None 49 47 50 48 51 def sortkey_year_to_country(entry): … … 51 54 def sortkey_year_from_country(entry): 52 55 return str(entry.get('Year'))+entry.get('From country') 56 57 def sortkey_year_from_country_to_country_voting_type(entry): 58 return str(entry.get('Year'))+entry.get('From country')+entry.get('To country')+entry.get('Jury or Televoting') 59 53 60 54 61
Note:
See TracChangeset
for help on using the changeset viewer.