query-283a3c945ecbaf577f26338b04b1b334

rq turtle/ttl

This returns the total number of days experience in Parliament for each party grouping.

MPs are counted with their current group regardless of any historical affiliations.

Day counts are only when they are serving as elected MPs - election day to dissolution -

and do not include any periods outside the Commons (eg defeated and later returned)

Labour Co-Op is counted as Labour; Change UK as independent.

SELECT distinct ?groupLabel (count(distinct ?mp) as ?current_members) (round(sum(?duration)) as ?cumulative_days_experience) (round(?cumulative_days_experience/?current_members) as ?average_days_experience) ((round(?average_days_experience/36.525)/10) as ?average_in_years) #fiddly count to make it decimal WHERE { { ?mp p:P39 ?ps . ?ps ps:P39 ?term . ?ps pq:P580 ?start . ?ps pq:P582 ?end . ?term wdt:P279 wd:Q16707842 . BIND((?end-?start) AS ?duration) } # period for all ended terms for all MPs, regardless of party union { ?mp p:P39 ?ps . ?ps ps:P39 ?term . ?ps pq:P580 ?start . ?term wdt:P279 wd:Q16707842 . filter not exists { ?ps pq:P582 ?end } . BIND(floor((NOW() - ?start)) as ?duration) } # time elapsed in a term which is still ongoing; floor rounds down to whole days # these two clauses count all the days served by MPs, both finished & current terms

   ?mp p:P39 ?currps . ?currps ps:P39 ?currterm . ?currterm wdt:P279 wd:Q16707842 .
   ?currps pq:P4100 ?party . filter not exists { ?currps pq:P582 ?currend } .
 # our MP must hold a current term, ie has no end date, and have a party affiliation

 BIND(IF(?party = wd:Q6467393, wd:Q9630 ,
         (IF(?party = wd:Q61751194 , wd:Q327591 , 
            (IF(?party = wd:Q67153570 , wd:Q327591 , ?party)))
         )
        )             
      AS ?group) .
 # merge Labour/Co-Op, Independent/Change UK/The Independents

 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

} group by ?groupLabel order by desc(?current_members)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# This returns the total number of days experience in Parliament for each party grouping.
# MPs are counted with their current group regardless of any historical affiliations.
# Day counts are only when they are serving as elected MPs - election day to dissolution - 
# and do not include any periods outside the Commons (eg defeated and later returned)
# Labour Co-Op is counted as Labour; Change UK as independent.

SELECT distinct ?groupLabel
  (count(distinct ?mp) as ?current_members)
  (round(sum(?duration)) as ?cumulative_days_experience)
  (round(?cumulative_days_experience/?current_members) as ?average_days_experience)
  ((round(?average_days_experience/36.525)/10) as ?average_in_years) #fiddly count to make it decimal
   WHERE {
     { ?mp p:P39 ?ps . ?ps ps:P39 ?term . ?ps pq:P580 ?start . ?ps pq:P582 ?end . 
       ?term wdt:P279 wd:Q16707842 . BIND((?end-?start) AS ?duration) }
     # period for all ended terms for all MPs, regardless of party
     union
     { ?mp p:P39 ?ps . ?ps ps:P39 ?term . ?ps pq:P580 ?start . ?term wdt:P279 wd:Q16707842 . 
       filter not exists { ?ps pq:P582 ?end } . BIND(floor((NOW() - ?start)) as ?duration) }
     # time elapsed in a term which is still ongoing; floor rounds down to whole days
     # these two clauses count all the days served by MPs, both finished & current terms

       ?mp p:P39 ?currps . ?currps ps:P39 ?currterm . ?currterm wdt:P279 wd:Q16707842 .
       ?currps pq:P4100 ?party . filter not exists { ?currps pq:P582 ?currend } .
     # our MP must hold a current term, ie has no end date, and have a party affiliation

     BIND(IF(?party = wd:Q6467393, wd:Q9630 ,
             (IF(?party = wd:Q61751194 , wd:Q327591 , 
                (IF(?party = wd:Q67153570 , wd:Q327591 , ?party)))
             )
            )             
          AS ?group) .
     # merge Labour/Co-Op, Independent/Change UK/The Independents

     SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} group by ?groupLabel order by desc(?current_members)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v14("?average_days_experience"):::projected v15("?average_in_years") v13("?cumulative_days_experience"):::projected v3("?currend") v13("?current_members"):::projected v2("?currps") v10("?currterm") v10("?duration") v8("?end") v12("?group") v4("?mp"):::projected v11("?party") v5("?ps") v7("?start") v6("?term") c9(["bd:serviceParam"]):::iri c6(["wd:Q16707842"]):::iri c11(["en"]):::literal f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v2("?currend"):::projected e0v1("?currps"):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> v3 v2 --"p:qualifier/P582"--> v3 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; f1[["not "]] subgraph f1e1["Exists Clause"] e1v1 --"p:qualifier/P582"--> e1v2 e1v2("?end"):::projected e1v1("?ps"):::projected end f1--EXISTS--> f1e1 f1 --> v5 f1 --> c1 f1 --> v8 v5 --"p:qualifier/P582"--> v8 v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> v6 v5 --"p:qualifier/P580"--> v7 v6 --"p:direct/P279"--> c6 bind2[/"numeric-floor(NOW() - ?start)"/] v7 --o bind2 bind2 --as--o v10 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v4 --"p:P39"--> v5 v5 --"p:statement/P39"--> v6 v5 --"p:qualifier/P580"--> v7 v5 --"p:qualifier/P582"--> v8 v6 --"p:direct/P279"--> c6 bind3[/"?end - ?start"/] v8 --o bind3 v7 --o bind3 bind3 --as--o v10 end union0r <== or ==> union0l end v4 --"p:P39"--> v2 v2 --"p:statement/P39"--> v10 v10 --"p:direct/P279"--> c6 v2 --"p:qualifier/P4100"--> v11 bind4[/"if(?party = 'wd:Q6467393','wd:Q9630',if(?party = 'wd:Q61751194','wd:Q327591',if(?party = 'wd:Q67153570','wd:Q327591',?party)))"/] v11 --o bind4 bind4 --as--o v12 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end bind7[/"count(?mp)"/] v4 --o bind7 bind7 --as--o v13 bind8[/"numeric-round()"/] null --o bind8 bind8 --as--o v13 bind9[/"numeric-round(?cumulative_days_experience / ?current_members)"/] v13 --o bind9 v13 --o bind9 bind9 --as--o v14 bind10[/"numeric-round(?average_days_experience / '36.525^^xsd:decimal') / '10^^xsd:integer'"/] v14 --o bind10 bind10 --as--o v15