Changeset 34960 for main


Ignore:
Timestamp:
2021-03-09T23:30:43+13:00 (3 years ago)
Author:
davidb
Message:

Changes associated with adding in Combined and Single Voting totals; adjustments to DL based on Terhi's feedback

Location:
main/trunk/model-sites-dev/eurovision-lod/collect/eurovision
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/etc/collectionConfig.xml

    r34943 r34960  
    8282      </xsl:if>
    8383
     84      <gsf:switch>
     85        <gsf:metadata name='FinishingPos'/>
     86        <gsf:when test='exists'>
     87      <br />
     88      <font style="font-size: 80%;">
     89        Place: <gsf:metadata name='FinishingPos' />
     90        (Total Score: <gsf:metadata name="VoteGrandTotal"/>)
     91      </font>
     92        </gsf:when>
     93      </gsf:switch>
     94     
    8495    </gsf:template>
    8596
     
    156167        </gsf:choose-metadata>
    157168      </gsf:link>
     169     
     170      <gsf:switch>
     171            <gsf:metadata name='Creator'/>
     172            <gsf:when test='exists'>
     173         
     174              <gsf:switch>
     175        <gsf:metadata name="Creator"/>
     176        <gsf:when test="notEquals" test-value="Unknown">
     177         
     178          by <gsf:metadata name='Creator'/>
     179        </gsf:when>
     180              </gsf:switch>
     181         
     182            </gsf:when>
     183      </gsf:switch>
     184
     185      <gsf:switch>
     186            <gsf:metadata name='Country'/>
     187            <gsf:when test='exists'>
     188          representing <gsf:metadata name='Country'/>
     189            </gsf:when>
     190      </gsf:switch>
     191
     192      <gsf:switch>
     193            <gsf:metadata name='Year'/>
     194            <gsf:when test='exists'>
     195          (<gsf:metadata name='Year'/>)
     196            </gsf:when>
     197      </gsf:switch>
     198     
     199          <gsf:switch>
     200            <gsf:metadata name='FinishingPos'/>
     201            <gsf:when test='exists'>
     202          <br />
     203          <font style="font-size: 80%;">
     204        Place: <gsf:metadata name='FinishingPos' />
     205        (Total Score: <gsf:metadata name="VoteGrandTotal"/>)
     206          </font>
     207            </gsf:when>
     208      </gsf:switch>
     209     
    158210    </td>
    159211   
     
    163215
    164216  <search type="jenaTDB" orthogonal="true"/>
     217
    165218
    166219  <infodb type="jdbm"/>
     
    481534    <gsf:metadata name="FromCountryType"/>
    482535    <gsf:metadata name="FromCountryYear"/>
     536
    483537    <gsf:metadata name="VotesCountryJSON-J" />
    484538    <gsf:metadata name="VotesCountryJSON-T" />
     539    <gsf:metadata name="VotesCountryJSON-C" />
     540    <gsf:metadata name="VotesCountryJSON-S" />
     541
    485542    <gsf:metadata name="VotesPointsJSON-J" />
    486543    <gsf:metadata name="VotesPointsJSON-T" />
     544    <gsf:metadata name="VotesPointsJSON-C" />
     545    <gsf:metadata name="VotesPointsJSON-S" />
    487546
    488547    <gsf:metadata name="dc.Title"/>
     
    505564    <gsf:metadata name="WikipediaURL_uri"/>
    506565
     566    <gsf:metadata name="VoteMode" />
     567    <gsf:metadata name="VoteGrandTotal" />
     568    <gsf:metadata name="FinishingPos" />
     569   
    507570    <gsf:metadata name="JuryVotesJSON" />
    508571    <gsf:metadata name="TeleVotesJSON" />
     572    <gsf:metadata name="CombVotesJSON" />
     573    <gsf:metadata name="SingVotesJSON" />
     574
    509575    <gsf:metadata name="JuryVotesTotal" />
    510576    <gsf:metadata name="TeleVotesTotal" />
     577    <gsf:metadata name="CombVotesTotal" />
     578    <gsf:metadata name="SingVotesTotal" />
     579
     580    <!-- boolean as to whether finalist or not -->
    511581    <gsf:metadata name="Final" />
    512582   
     
    610680    <gsf:metadata name="Ukraine-T" />
    611681    <gsf:metadata name="UnitedKingdom-T" />
     682
     683    <gsf:metadata name="Albania-C" />
     684    <gsf:metadata name="Andorra-C" />
     685    <gsf:metadata name="Armenia-C" />
     686    <gsf:metadata name="Austria-C" />
     687    <gsf:metadata name="Azerbaijan-C" />
     688    <gsf:metadata name="Belarus-C" />
     689    <gsf:metadata name="Belgium-C" />
     690    <gsf:metadata name="BosniaandHerzegovina-C" />
     691    <gsf:metadata name="Bulgaria-C" />
     692    <gsf:metadata name="Croatia-C" />
     693    <gsf:metadata name="Cyprus-C" />
     694    <gsf:metadata name="CzechRepublic-C" />
     695    <gsf:metadata name="Denmark-C" />
     696    <gsf:metadata name="Estonia-C" />
     697    <gsf:metadata name="Finland-C" />
     698    <gsf:metadata name="France-C" />
     699    <gsf:metadata name="Georgia-C" />
     700    <gsf:metadata name="Germany-C" />
     701    <gsf:metadata name="Greece-C" />
     702    <gsf:metadata name="Hungary-C" />
     703    <gsf:metadata name="Iceland-C" />
     704    <gsf:metadata name="Ireland-C" />
     705    <gsf:metadata name="Israel-C" />
     706    <gsf:metadata name="Italy-C" />
     707    <gsf:metadata name="Latvia-C" />
     708    <gsf:metadata name="Lithuania-C" />
     709    <gsf:metadata name="Macedonia-C" />
     710    <gsf:metadata name="Malta-C" />
     711    <gsf:metadata name="Moldova-C" />
     712    <gsf:metadata name="Monaco-C" />
     713    <gsf:metadata name="Montenegro-C" />
     714    <gsf:metadata name="Netherlands-C" />
     715    <gsf:metadata name="Norway-C" />
     716    <gsf:metadata name="Poland-C" />
     717    <gsf:metadata name="Portugal-C" />
     718    <gsf:metadata name="Romania-C" />
     719    <gsf:metadata name="Russia-C" />
     720    <gsf:metadata name="SanMarino-C" />
     721    <gsf:metadata name="Serbia-C" />
     722    <gsf:metadata name="SerbiaandMontenegro-C" />
     723    <gsf:metadata name="Slovakia-C" />
     724    <gsf:metadata name="Slovenia-C" />
     725    <gsf:metadata name="Spain-C" />
     726    <gsf:metadata name="Sweden-C" />
     727    <gsf:metadata name="Switzerland-C" />
     728    <gsf:metadata name="Turkey-C" />
     729    <gsf:metadata name="Ukraine-C" />
     730    <gsf:metadata name="UnitedKingdom-C" />
     731
     732    <gsf:metadata name="Austria-S" />
     733    <gsf:metadata name="Belgium-S" />
     734    <gsf:metadata name="BosniaandHerzegovina-S" />
     735    <gsf:metadata name="Croatia-S" />
     736    <gsf:metadata name="Cyprus-S" />
     737    <gsf:metadata name="Denmark-S" />
     738    <gsf:metadata name="Estonia-S" />
     739    <gsf:metadata name="Finland-S" />
     740    <gsf:metadata name="France-S" />
     741    <gsf:metadata name="Germany-S" />
     742    <gsf:metadata name="Greece-S" />
     743    <gsf:metadata name="Hungary-S" />
     744    <gsf:metadata name="Iceland-S" />
     745    <gsf:metadata name="Ireland-S" />
     746    <gsf:metadata name="Israel-S" />
     747    <gsf:metadata name="Italy-S" />
     748    <gsf:metadata name="Latvia-S" />
     749    <gsf:metadata name="Lithuania-S" />
     750    <gsf:metadata name="Luxembourg-S" />
     751    <gsf:metadata name="Macedonia-S" />
     752    <gsf:metadata name="Malta-S" />
     753    <gsf:metadata name="Monaco-S" />
     754    <gsf:metadata name="Morocco-S" />
     755    <gsf:metadata name="Netherlands-S" />
     756    <gsf:metadata name="Norway-S" />
     757    <gsf:metadata name="Poland-S" />
     758    <gsf:metadata name="Portugal-S" />
     759    <gsf:metadata name="Romania-S" />
     760    <gsf:metadata name="Russia-S" />
     761    <gsf:metadata name="Slovakia-S" />
     762    <gsf:metadata name="Slovenia-S" />
     763    <gsf:metadata name="Spain-S" />
     764    <gsf:metadata name="Sweden-S" />
     765    <gsf:metadata name="Switzerland-S" />
     766    <gsf:metadata name="Turkey-S" />
     767    <gsf:metadata name="UnitedKingdom-S" />
     768    <gsf:metadata name="Yugoslavia-S" />
    612769   
    613770      </gsf:headMetaTags>
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/js/eurovision.js

    r34956 r34960  
    6060        if (trans_i < num_countries) {
    6161        var from_country  = VotesJSON[trans_i];
     62
     63        // map -C and -S to -J for now
     64        from_country = from_country.replace(/-C$/,"-J");
     65        from_country = from_country.replace(/-S$/,"-J");
     66       
    6267        var from_country_points = gs.documentMetadata[from_country];
    6368        var year = gs.documentMetadata["Year"];
     
    206211function ssq_load(query_text_id)
    207212{
    208     $('#sample-sparql-query').text($('#'+query_text_id).text().trim());
     213    $('#sample-sparql-query').val($('#'+query_text_id).text().trim());
    209214    $('.exec-ssq').hide();
    210215    $('#exec-'+query_text_id).show();
     
    263268function ssv_load(query_text_id)
    264269{
    265     $('#sample-data-sgvizler-query').text($('#'+query_text_id).text().trim());
     270    //$('#sample-data-sgvizler-query').text($('#'+query_text_id).text().trim());
     271    $('#sample-data-sgvizler-query').val($('#'+query_text_id).text().trim());
    266272    $('.exec-ssq').hide();
    267273    $('#exec-'+query_text_id).show();
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/voting-excel/xlsx-fromcountry-jsonmetadata.py

    r34910 r34960  
    122122    tl_from_country_id = "FromCountry-" + re.sub(r'\s+', '', tl_from_country) + str(tl_year) + "-" + tl_vote_type
    123123
     124    vote_mode = xlsxutil.voting_mode(tl_year)
     125    nuanced_vote_type = xlsxutil.nuanced_voting_type(tl_from_country,tl_year)
     126   
    124127    metadata_array.append({"name": "Identifier",      "content" : tl_from_country_id})
    125128    metadata_array.append({"name": "FromCountry",     "content" : tl_from_country})
    126129    metadata_array.append({"name": "FromCountryYear", "content" : tl_year})
    127130    metadata_array.append({"name": "FromCountryType", "content" : tl_vote_type})
     131
     132    metadata_array.append({"name": "FromCountryVoteMode",    "content" : vote_mode})
     133    metadata_array.append({"name": "FromCountryNuancedType", "content" : nuanced_vote_type})
    128134   
    129135    for from_country_year_vote in from_country_year_votes:
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/voting-excel/xlsx-tocountry-jsonmetadata.py

    r34957 r34960  
    1717jury_from_countries = {}
    1818tele_from_countries = {}
    19 
    20 
     19comb_from_countries = {}
     20sing_from_countries = {}
     21
     22# 1997:
     23# Televoting by
     24#  Austria, Germany, Sweeden, Switzerland, United Kingdom
     25
     26# 1998-2000: Televote, with Jury voting as backup plan
     27
     28# 2001-2002: All televote, or 50-50 mix if country so chooses, Jury backup
     29#    2001: Jury: Bosnia & Herzegovina, Turkey, Russia
     30#    2001: Mix:  Croatia, Greece, Malta
     31#
     32#    2002: Jury: Bosnia & Herzegovina, Turkey, Russia, FYR Macedonia, Romania
     33#    2002: Mix:  Cyprus, Greece, Spain, Croatia, Finland, Malta, Slovenia, Lithuania
     34
     35# 2003: back to all Televote, with Jury voting as backup
     36# 2004-2008: same as 2003
     37
     38# 2009-2012: Combined, except San Marino which was 100% Jury (due to size), Jury as backup
     39
     40# 2013-2015: As before, but how two types of votes combined different
     41
     42# 2016-      Jury and Tele given separately, added in
     43
     44def XXXXvoting_mode(year):
     45
     46    vote_mode = None
     47
     48    if (year>=2013):
     49        # Separate voting: Jury and Tele
     50        vote_mode = "Separated"
     51    elif ((year>=2001) and (year<=2012)):
     52        vote_mode = "Combined"
     53    else:
     54        vote_mode = "Single"
     55
     56    return vote_mode
     57
     58
     59def XXXXnuanced_voting_type(country,year):
     60
     61    vote_type = None
     62
     63    if (year>=2013):
     64        # Separate voting: Jury and Tele
     65        vote_type = "JT"
     66       
     67    elif ((year>=2009) and (year<=2012)):
     68        if (country=="San Marino"):
     69            vote_type = "J"
     70        else:
     71            # Combined Jury and Tele
     72            vote_type = "C"
     73    elif ((year>=2003) and (year<=2008)):
     74        vote_type = "T"
     75    elif (year==2002):
     76        jury_list = [ "Bosnia & Herzegovina", "Turkey", "Russia", "FYR Macedonia", "Romania"]
     77        comb_list = [ "Cyprus", "Greece", "Spain", "Croatia", "Finland", "Malta", "Slovenia", "Lithuania" ]
     78        if (country in jury_list):
     79            vote_type = "J"
     80        elif (country in comb_list):
     81            vote_type = "C"
     82        else:
     83            vote_type = "T"
     84    elif (year==2001):
     85        jury_list = [ "Bosnia & Herzegovina", "Turkey", "Russia" ]
     86        comb_list = [ "Croatia", "Greece", "Malta" ]
     87        if (country in jury_list):
     88            vote_type = "J"
     89        elif (country in comb_list):
     90            vote_type = "C"
     91    elif ((year>=1998) and (year<=2000)):
     92        vote_type = "T"
     93    elif (year==1997):
     94        tele_list = [ "Austria", "Germany", "Sweeden", "Switzerland", "United Kingdom" ]
     95        if (country in tele_list):
     96            vote_type = "T"
     97        else:
     98            vote_type = "J"
     99    else:
     100        vote_type = "J"
     101
     102    return vote_type
     103
     104
     105           
    21106def create_to_country_voting_groups(data_hashmap_array):
    22107
     
    68153
    69154
    70 def fileset_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping):
     155def create_to_year_then_country_voting_groups(data_hashmap_array):
     156
     157    # Example values for header-names
     158    #   (semi-) final:      f, sf
     159    #   Jury or Televoting: J, T
     160    #   Year:               1975, ...
     161    #   To country:         Belgium
     162    #   From country:       Belgium
     163    #   Edition:            1975f, 1975sf
     164
     165    # Build array of year groups
     166    #   A year group contains within it a country grouping that in turn
     167    #   includes all the votes that country receive that year
     168    year_groups = []
     169
     170    # Rely on sorting as done in first line of create_to_country_voting_groups,
     171    # which is the (innermost) place where the sorting is needed
     172    country_groups = create_to_country_voting_groups(data_hashmap_array)
     173   
     174    prev_to_country_votes = country_groups[0]
     175    year_group = [ ]
     176
     177    i = 1
     178    num_rows = len(country_groups)
     179
     180    while (i < num_rows):       
     181        year_group.append(prev_to_country_votes)
     182        to_country_votes = country_groups[i]
     183
     184        if (to_country_votes[0].get('Year') != prev_to_country_votes[0].get('Year')):
     185            # moving on to a new year group
     186##            print("**** year change from:" + str(to_country_votes[0].get('Year')) + " to " + str(prev_to_country_votes[0].get('Year')))
     187            year_groups.append(year_group)
     188            year_group = [ ]
     189           
     190        prev_to_country_votes = to_country_votes
     191        i = i + 1
     192       
     193    year_group.append(prev_to_country_votes)       
     194    year_groups.append(year_group)
     195
     196    print("****")
     197    print("Number of years voting is available for: " + str(len(year_groups)));
     198    print("****")
     199   
     200    return year_groups
     201
     202
     203
     204def augment_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping):
     205
     206    jury_metadata_vals = []
     207    tele_metadata_vals = []
     208    comb_metadata_vals = []
     209    sing_metadata_vals = []
     210
     211    to_country_jury_total = 0
     212    to_country_tele_total = 0
     213    to_country_comb_total = 0
     214    to_country_sing_total = 0
     215
     216    to_country_grand_total = 0
     217   
     218    # Use the first record to be a representative for 'top level' (tl)
     219    # metadata about the votes cast 'To country'
     220    tl_rec = to_country_year_votes[0]
     221
     222    tl_to_country = tl_rec.get('To country')
     223    tl_year       = tl_rec.get('Year')
     224    tl_final      = tl_rec.get("(semi-) final") == "f"   
     225
     226    tl_to_country_id = re.sub(r'\s+', '', tl_to_country) + str(tl_year)
     227
     228    tl_rec["Final"] = tl_final
     229
     230    # tl_to_country_lc = tl_to_country.lower()
     231    tl_to_country_uri = countrylabel_to_uri_mapping.get(tl_to_country)
     232    if (tl_to_country_uri != None):
     233        tl_rec["CountryDBURI"] = tl_to_country_uri
     234    else:
     235        util.eprint("Warning: Failed to find DBpedia Country URI match for: " + tl_to_country)
     236               
     237    for to_country_year_vote in to_country_year_votes:
     238#        to_country   = to_country_year_vote.get('To country')
     239        year         = to_country_year_vote.get('Year')
     240        from_country = to_country_year_vote.get('From country')
     241        vote_type    = to_country_year_vote.get('Jury or Televoting')
     242        points       = to_country_year_vote.get('Points')
     243
     244        id_from_country = re.sub(r'\s+', '', from_country)
     245           
     246#        tl_rec[id_from_country+"-"+vote_type] = points
     247
     248        vote_mode = xlsxutil.voting_mode(year)
     249        nuanced_vote_type = xlsxutil.nuanced_voting_type(from_country,year)
     250
     251        if (vote_mode == "Separated"):
     252           
     253            if (vote_type == "J"):
     254                jury_metadata_vals.append(id_from_country+"-J")
     255                jury_from_countries[id_from_country] = 1
     256                to_country_jury_total = to_country_jury_total + points
     257           
     258            elif (vote_type == "T"):
     259                tele_metadata_vals.append(id_from_country+"-T")
     260                tele_from_countries[id_from_country] = 1
     261                to_country_tele_total = to_country_tele_total + points
     262            else:           
     263                util.eprint("Warning: Unrecognized voting type: " + vote_type)
     264
     265        elif (vote_mode == "Combined"):
     266            comb_metadata_vals.append(id_from_country+"-C")
     267            comb_from_countries[id_from_country] = 1
     268            to_country_comb_total = to_country_comb_total + points
     269        else:
     270            # Single
     271            sing_metadata_vals.append(id_from_country+"-S")
     272            sing_from_countries[id_from_country] = 1
     273            to_country_sing_total = to_country_sing_total + points
     274
     275        to_country_grand_total = to_country_grand_total + points
     276           
     277    tl_rec["VoteMode"] = vote_mode
     278       
     279    if (len(jury_metadata_vals)>0):
     280        tl_rec["JuryVotesJSON"] = jury_metadata_vals
     281        tl_rec["JuryVotesTotal"] = to_country_jury_total
     282    if (len(tele_metadata_vals)>0):
     283        tl_rec["TeleVotesJSON"] = tele_metadata_vals
     284        tl_rec["TeleVotesTotal"] = to_country_tele_total
     285    if (len(comb_metadata_vals)>0):
     286        tl_rec["CombVotesJSON"] = comb_metadata_vals
     287        tl_rec["CombVotesTotal"] = to_country_comb_total
     288    if (len(sing_metadata_vals)>0):
     289        tl_rec["SingVotesJSON"] = sing_metadata_vals
     290        tl_rec["SingVotesTotal"] = to_country_sing_total
     291
     292    tl_rec["VoteGrandTotal"] = to_country_grand_total
     293
     294def fileset_voting_for_esc_country_in_year(to_country_year_votes):
    71295
    72296    # Looking to build data-structure (for output as JSON) in the form
     
    89313    metadata_array = []
    90314
    91     jury_metadata_vals = []
    92     tele_metadata_vals = []
    93 
    94     to_country_jury_total = 0
    95     to_country_tele_total = 0
     315#    jury_metadata_vals = []
     316#    tele_metadata_vals = []
     317
     318#    to_country_jury_total = 0
     319#    to_country_tele_total = 0
    96320
    97321    # Use the first record to be a representative for 'top level' (tl)
     
    101325    tl_to_country = tl_rec.get('To country')
    102326    tl_year       = tl_rec.get('Year')
    103     tl_final      = tl_rec.get("(semi-) final") == "f"   
     327    # tl_final      = tl_rec.get("(semi-) final") == "f"   
    104328
    105329    tl_to_country_id = re.sub(r'\s+', '', tl_to_country) + str(tl_year)
    106330
     331    tl_final = tl_rec["Final"]
     332    tl_to_country_uri = tl_rec.get("CountryDBURI")
     333
     334    vote_mode = tl_rec.get("VoteMode")
     335   
     336    jury_metadata_vals = tl_rec.get("JuryVotesJSON")
     337    tele_metadata_vals = tl_rec.get("TeleVotesJSON")
     338    comb_metadata_vals = tl_rec.get("CombVotesJSON")
     339    sing_metadata_vals = tl_rec.get("SingVotesJSON")
     340
     341    to_country_jury_total = tl_rec.get("JuryVotesTotal")
     342    to_country_tele_total = tl_rec.get("TeleVotesTotal")
     343    to_country_comb_total = tl_rec.get("CombVotesTotal")
     344    to_country_sing_total = tl_rec.get("SingVotesTotal")
     345
     346    to_country_grand_total = tl_rec.get("VoteGrandTotal")
     347    to_country_finishing_pos = tl_rec.get("FinishingPos")
     348   
    107349    # Country and Year are set as metadata elsewhere so don't need
    108350    # to set them here -- however, do want DBpedia *Country* *URI*
     
    115357    metadata_array.append({ "name": "Final",  "content": tl_final })
    116358
    117     # tl_to_country_lc = tl_to_country.lower()
    118     tl_to_country_uri = countrylabel_to_uri_mapping.get(tl_to_country)
     359    ## tl_to_country_lc = tl_to_country.lower()
     360    #tl_to_country_uri = countrylabel_to_uri_mapping.get(tl_to_country)
    119361    if (tl_to_country_uri != None):
    120362        metadata_array.append({ "name": "CountryDBURI","content": tl_to_country_uri })
    121     else:
    122         util.eprint("Warning: Failed to find DBpedia Country URI match for: " + tl_to_country)
    123                
     363#    else:
     364#        util.eprint("Warning: Failed to find DBpedia Country URI match for: " + tl_to_country)
     365
    124366    for to_country_year_vote in to_country_year_votes:
    125367        to_country   = to_country_year_vote.get('To country')
     
    135377        metadata_array.append(voting_rec)
    136378
    137         if (vote_type == "J"):
    138             jury_metadata_vals.append(id_from_country+"-J")
    139             jury_from_countries[id_from_country] = 1
    140             to_country_jury_total = to_country_jury_total + points
    141            
    142         elif (vote_type == "T"):
    143             tele_metadata_vals.append(id_from_country+"-T")
    144             tele_from_countries[id_from_country] = 1
    145             to_country_tele_total = to_country_tele_total + points
    146         else:           
    147             util.eprint("Warning: Unrecognized voting type: " + vote_type)
    148 
    149     if (len(jury_metadata_vals)>0):
     379#        if (vote_type == "J"):
     380#            jury_metadata_vals.append(id_from_country+"-J")
     381#            jury_from_countries[id_from_country] = 1
     382#            to_country_jury_total = to_country_jury_total + points
     383#           
     384#        elif (vote_type == "T"):
     385#            tele_metadata_vals.append(id_from_country+"-T")
     386#            tele_from_countries[id_from_country] = 1
     387#            to_country_tele_total = to_country_tele_total + points
     388#        else:           
     389#            util.eprint("Warning: Unrecognized voting type: " + vote_type)
     390
     391    metadata_array.append({ "name": "VoteMode", "content": vote_mode })
     392 
     393    if ((jury_metadata_vals != None) and len(jury_metadata_vals)>0):
    150394        metadata_array.append({ "name": "JuryVotesJSON", "content": json.dumps(jury_metadata_vals) })
    151395        metadata_array.append({ "name": "JuryVotesTotal", "content": to_country_jury_total})
    152     if (len(tele_metadata_vals)>0):
     396    if ((tele_metadata_vals != None) and len(tele_metadata_vals)>0):
    153397        metadata_array.append({ "name": "TeleVotesJSON", "content": json.dumps(tele_metadata_vals) })
    154398        metadata_array.append({ "name": "TeleVotesTotal", "content": to_country_tele_total})
    155                          
     399    if ((comb_metadata_vals != None) and len(comb_metadata_vals)>0):
     400        metadata_array.append({ "name": "CombVotesJSON", "content": json.dumps(comb_metadata_vals) })
     401        metadata_array.append({ "name": "CombVotesTotal", "content": to_country_comb_total})
     402    if ((sing_metadata_vals != None) and len(sing_metadata_vals)>0):
     403        metadata_array.append({ "name": "SingVotesJSON", "content": json.dumps(sing_metadata_vals) })
     404        metadata_array.append({ "name": "SingVotesTotal", "content": to_country_sing_total})
     405
     406    metadata_array.append({ "name": "VoteGrandTotal", "content": to_country_grand_total})
     407    metadata_array.append({ "name": "FinishingPos", "content": to_country_finishing_pos})
     408   
    156409    filename_id = tl_to_country_id + "\\.nul"
    157410
     
    193446       
    194447    for to_country_year_votes in to_country_year_voting_groups:
    195        
    196         fileset = fileset_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping)
     448
     449        augment_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping)
     450        fileset = fileset_voting_for_esc_country_in_year(to_country_year_votes)
    197451        directory_metadata.append(fileset)
    198452
     
    201455       
    202456        print("  " + filename_id.ljust(28) + ": " + str(num_countries_voting_data) + " votes")
     457
     458
     459    greenstone_metadata_json = { "DirectoryMetadata": directory_metadata }
     460
     461    return greenstone_metadata_json
     462
     463
     464
     465def augment_voting_in_year_then_country(to_country_year_votes,countrylabel_to_uri_mapping):
     466
     467    for to_year_votes in to_year_then_country_voting_groups:
     468
     469        for to_country_year_votes in to_year_votes:
     470
     471            augment_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping)
     472
     473
     474        to_year_votes.sort(key=lambda v: v[0].get("VoteGrandTotal"), reverse=True)
     475        to_year_num_votes = len(to_year_votes)
     476        for i in range(to_year_num_votes):
     477            finishing_pos = i+1
     478            to_year_votes[i][0]["FinishingPos"] = finishing_pos
     479
     480           
     481def gs_yc_directory_metadata(to_year_then_country_voting_groups):
     482    # Next step is to express the grouped to-country voting data
     483    # in the Greenstone JSON metadata format:
     484   
     485    # { "DirectoryMetadata":
     486    #   [
     487    #     { "FileSet":
     488    #       [
     489    #         { "FileName": "France1991\.nul" },
     490    #         { "Description":
     491    #           {
     492    #             "Metadata":
     493    #              [
     494    #                { "name": "Germany-J", "content": "12" }, # J = Jury Vote
     495    #                  ...
     496    #              ]
     497    #           }
     498    #         }
     499    #       ]
     500    #     }
     501    #     ...
     502    #    ]
     503    #  }
     504
     505    directory_metadata = []
     506
     507    for to_year_votes in to_year_then_country_voting_groups:
     508       
     509        for to_country_year_votes in to_year_votes:
     510
     511##            augment_voting_for_esc_country_in_year(to_country_year_votes,countrylabel_to_uri_mapping)
     512            fileset = fileset_voting_for_esc_country_in_year(to_country_year_votes)
     513            directory_metadata.append(fileset)
     514
     515            filename_id = fileset.get('FileSet')[0].get('FileName')
     516            num_countries_voting_data = len(fileset.get('FileSet')[1].get('Description').get('Metadata'))
     517           
     518            print("  " + filename_id.ljust(28) + ": " + str(num_countries_voting_data) + " votes")
    203519
    204520
     
    223539        print("    <gsf:metadata name=\""+from_country+"-T\" />")
    224540
     541    print()
     542    for from_country in sorted(comb_from_countries.keys()):
     543        print("    <gsf:metadata name=\""+from_country+"-C\" />")
     544
     545    print()
     546    for from_country in sorted(sing_from_countries.keys()):
     547        print("    <gsf:metadata name=\""+from_country+"-S\" />")
     548       
    225549    print("  </gsf:headMetaTags>")
    226550
     
    271595
    272596
    273     to_country_year_voting_groups = create_to_country_voting_groups(data_hashmap_array_filtered)
     597    # to_country_year_voting_groups = create_to_country_voting_groups(data_hashmap_array_filtered)
     598    to_year_then_country_voting_groups = create_to_year_then_country_voting_groups(data_hashmap_array_filtered)
    274599
    275600    # Debug output
    276601    #
    277     # print(to_country_year_voting_groups)
     602    # print(to_year_then_country_voting_groups)
    278603   
    279604    print()
    280605    print("Generating Greenstone JSON to-country voting metadata received by:")
    281     greenstone_metadata_json = gs_directory_metadata(to_country_year_voting_groups,countrylabel_to_uri_mapping)
     606    ##greenstone_metadata_json = gs_directory_metadata(to_country_year_voting_groups,countrylabel_to_uri_mapping)
     607    augment_voting_in_year_then_country(to_year_then_country_voting_groups,countrylabel_to_uri_mapping)
     608    greenstone_metadata_json = gs_yc_directory_metadata(to_year_then_country_voting_groups)
    282609   
    283610    print("Saving output as: " + json_output_filename)   
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/prepare/voting-excel/xlsxutil.py

    r34910 r34960  
    5353
    5454
     55
     56# 1997:
     57# Televoting by
     58#  Austria, Germany, Sweeden, Switzerland, United Kingdom
     59
     60# 1998-2000: Televote, with Jury voting as backup plan
     61
     62# 2001-2002: All televote, or 50-50 mix if country so chooses, Jury backup
     63#    2001: Jury: Bosnia & Herzegovina, Turkey, Russia
     64#    2001: Mix:  Croatia, Greece, Malta
     65#
     66#    2002: Jury: Bosnia & Herzegovina, Turkey, Russia, FYR Macedonia, Romania
     67#    2002: Mix:  Cyprus, Greece, Spain, Croatia, Finland, Malta, Slovenia, Lithuania
     68
     69# 2003: back to all Televote, with Jury voting as backup
     70# 2004-2008: same as 2003
     71
     72# 2009-2012: Combined, except San Marino which was 100% Jury (due to size), Jury as backup
     73
     74# 2013-2015: As before, but how two types of votes combined different
     75
     76# 2016-      Jury and Tele given separately, added in
     77
     78def voting_mode(year):
     79
     80    vote_mode = None
     81
     82    if (year>=2013):
     83        # Separate voting: Jury and Tele
     84        vote_mode = "Separated"
     85    elif ((year>=2001) and (year<=2012)):
     86        vote_mode = "Combined"
     87    else:
     88        vote_mode = "Single"
     89
     90    return vote_mode
     91
     92
     93def nuanced_voting_type(country,year):
     94
     95    vote_type = None
     96
     97    if (year>=2013):
     98        # Separate voting: Jury and Tele
     99        vote_type = "JT"
     100       
     101    elif ((year>=2009) and (year<=2012)):
     102        if (country=="San Marino"):
     103            vote_type = "J"
     104        else:
     105            # Combined Jury and Tele
     106            vote_type = "C"
     107    elif ((year>=2003) and (year<=2008)):
     108        vote_type = "T"
     109    elif (year==2002):
     110        jury_list = [ "Bosnia and Herzegovina", "Turkey", "Russia", "FYR Macedonia", "Romania"]
     111        comb_list = [ "Cyprus", "Greece", "Spain", "Croatia", "Finland", "Malta", "Slovenia", "Lithuania" ]
     112        if (country in jury_list):
     113            vote_type = "J"
     114        elif (country in comb_list):
     115            vote_type = "C"
     116        else:
     117            vote_type = "T"
     118    elif (year==2001):
     119        jury_list = [ "Bosnia and Herzegovina", "Turkey", "Russia" ]
     120        comb_list = [ "Croatia", "Greece", "Malta" ]
     121        if (country in jury_list):
     122            vote_type = "J"
     123        elif (country in comb_list):
     124            vote_type = "C"
     125        else:
     126            vote_type = "T"
     127    elif ((year>=1998) and (year<=2000)):
     128        vote_type = "T"
     129    elif (year==1997):
     130        tele_list = [ "Austria", "Germany", "Sweeden", "Switzerland", "United Kingdom" ]
     131        if (country in tele_list):
     132            vote_type = "T"
     133        else:
     134            vote_type = "J"
     135    else:
     136        vote_type = "J"
     137
     138    return vote_type
     139
     140
     141
    55142def load_xslx_sheet(excel_input_filename,sheetname):
    56143    print "Loading: " + excel_input_filename
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/transform/pages/document.xsl

    r34918 r34960  
    191191
    192192    <div id="to-country-votes">
     193      <gsf:switch>
     194    <gsf:metadata name='FinishingPos'/>
     195    <gsf:when test='exists'>
     196      <h2>
     197        Overall Final Postion: <gsf:metadata name='FinishingPos'/>
     198      </h2>
     199    </gsf:when>
     200      </gsf:switch>
     201     
    193202      <gsf:script>
    194203    append_to_country_votes("Jury Votes","JuryVotesJSON","JuryVotesTotal");
    195204    append_to_country_votes("Televotes","TeleVotesJSON","TeleVotesTotal");
     205
     206    append_to_country_votes("Combined Jury &amp; Tele Votes","CombVotesJSON","CombVotesTotal");
     207    append_to_country_votes("Voting Exclusively by Jury","SingVotesJSON","SingVotesTotal");
    196208      </gsf:script>
    197209
  • main/trunk/model-sites-dev/eurovision-lod/collect/eurovision/transform/pages/sparql.xsl

    r34956 r34960  
    103103          </textarea>
    104104         
    105           <div style="display:none;">
     105          <div style="displayXXXX:none;">
    106106        <div>
    107107          Output:
     
    229229    ?esc_entrant_uri dc:Relation.isPartOf &lt;http://127.0.0.1:8383/greenstone3/library/collection/eurovision&gt;.
    230230
    231     ?esc_entrant_uri gsextracted:JuryVotesTotal ?total.
     231    ?esc_entrant_uri gsextracted:SingVotesTotal ?total.
    232232    BIND(xsd:integer(?total) AS ?total_int).
    233233   
     
    268268</xsl:text>
    269269        </div>
     270
     271
     272        <div id="ssq-winning-totals" style="display: none;">
     273<!-- -->
     274<xsl:text>
     275PREFIX gsextracted: &lt;http://greenstone.org/gsextracted#&gt;
     276PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;
     277PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;
     278
     279
     280SELECT ?year ?country ?total_max WHERE {
     281  GRAPH &lt;http://localhost:3030/greenstone/data/eurovision&gt;  {
     282
     283    {
     284      SELECT ?year (STR(MAX(?total_int_inner)) as ?total_max) WHERE {
     285     
     286        ?esc_entrant_uri gsextracted:VoteGrandTotal ?total.
     287        BIND(xsd:integer(?total) AS ?total_int_inner).
     288   
     289        ?esc_entrant_uri gsextracted:Year ?year.
     290      }
     291      GROUP BY ?year
     292     }
     293
     294    ?esc_entrant_uri gsextracted:VoteGrandTotal ?total_max.   
     295    ?esc_entrant_uri gsextracted:Year ?year.
     296    ?esc_entrant_uri gsextracted:Country ?country.
     297
     298    BIND(xsd:integer(?total_max) as ?total_int).   
     299  }
     300}
     301ORDER BY DESC(?total_int)
     302</xsl:text>
     303        </div>
     304
     305
     306        <div id="ssq-winning-freq-count" style="display: none;">
     307<!-- -->
     308<xsl:text>
     309
     310PREFIX gsextracted: &lt;http://greenstone.org/gsextracted#&gt;
     311PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;
     312PREFIX dc: &lt;http://purl.org/dc/elements/1.1/&gt;
     313
     314
     315SELECT ?country (STR(COUNT(?country)) as ?number_of_vote_wins) WHERE {
     316  GRAPH &lt;http://localhost:3030/greenstone/data/eurovision&gt;  {
     317
     318
     319    {
     320      SELECT ?year (STR(MAX(?total_int)) as ?total_max) WHERE {
     321
     322     
     323        ?esc_entrant_uri gsextracted:VoteGrandTotal ?total.
     324        BIND(xsd:integer(?total) AS ?total_int).
     325   
     326        ?esc_entrant_uri gsextracted:Year ?year.
     327      }
     328      GROUP BY ?year
     329    }
     330
     331    ?esc_entrant_uri gsextracted:VoteGrandTotal ?total_max.   
     332    ?esc_entrant_uri gsextracted:Year ?year.
     333    ?esc_entrant_uri gsextracted:Country ?country.   
     334  }
     335}
     336GROUP BY ?country
     337ORDER BY DESC(?number_of_vote_wins)
     338</xsl:text>
     339        </div>
     340
     341
    270342
    271343
     
    350422
    351423          <li>
    352         Jury Voting Totals in 1975:<br/>
     424        Voting Totals in 1975:<br/>
    353425        <button type="button" class="load-ssq" id="load-ssq-jury-votes-totals-1975" onclick="ssq_load('ssq-jury-votes-totals-1975')">Load query above</button>
    354426        <button type="button" class="exec-ssq" id="exec-ssq-jury-votes-totals-1975" onclick="ssq_execute()">Get Results</button><br/>
    355427       
    356         The jury vote totals countries received in 1975, ranked to score.
     428        In 1975 all voting was done exclusively by jury.  This query retrieves the
     429        totals of this Single voting format, and orders them by that score.
    357430          </li>
    358431         
     
    365438          </li>
    366439
     440
     441          <li>
     442        Most points won:<br/>
     443        <button type="button" class="load-ssq" id="load-ssq-winning-totals" onclick="ssq_load('ssq-winning-totals')">Load query above</button>
     444        <button type="button" class="exec-ssq" id="exec-ssq-winning-totals" onclick="ssq_execute()">Get Results</button><br/>
     445       
     446        List the coutries which won and their voting totals, sorted by total score.
     447          </li>
     448
     449          <li>
     450        Number of Times Countries Have Won:<br/>
     451        <button type="button" class="load-ssq" id="load-ssq-winning-freq-count" onclick="ssq_load('ssq-winning-freq-count')">Load query above</button>
     452        <button type="button" class="exec-ssq" id="exec-ssq-winning-freq-count" onclick="ssq_execute()">Get Results</button><br/>
     453
     454        The number of times a country has won Eurovision across the years.  The includes
     455        the years when only Juries voted (1956-2000) through to the introduction
     456        of Televotes, where a variety of forms have been used such as only
     457        Televotes, a pre-combined score based on Televotes and Jury votes, to
     458        (from 2016 onwards) where the Jury and Tele votes are explicitly
     459        given individually per country, then combined.
     460          </li>
     461         
     462
    367463          <li>
    368464        Facts and Figures About Competing Countries:<br/>
     
    374470         
    375471        </ul>
     472
     473        <p>
     474          Looking for something a bit more visual?  Why not head over to our
     475          <a href="{$library_name}/collection/{$collName}/page/sgvizler"><i>SGVizler page</i></a> and try the SPARQL-based visualization samples there.
     476        </p>
    376477       
    377478      </div>
Note: See TracChangeset for help on using the changeset viewer.