Jump to content

Module talk:European and national party data/Archive 1

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Julius Schwarz (talk | contribs) at 14:41, 9 April 2025 (Manual archiving). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Project roadmap

Task Completion Comments
1.1 Create the module "EU party seats lower upper houses" to give out the number of seats in lower/upper houses held by all the national member parties of a given European political party; the module should also give the associated composition bar Test cases for the module: main function and composition bars; and for the sandbox: main function and composition bars
1.2 Integrate module above into EUPP seats module Module:EUPP seats is now the reference
1.3 Ensure comments are all in the code
1.4 Update documentation of EUPP seats module and its two templates Template:EUPP seats, Template:EUPP composition bar
2.1 Update membership of European parties' national member parties based on APPF data
2.2 Make a table of lower and upper houses and their qID for each EU member state Lower/upper houses per MS
2.3 Find qIDs of all national member parties and update Wikimedia Commons table National party seats in lower/upper houses
2.4 Update Wikidata for seats in lower/upper houses for all relevant national member parties
2.5 Update infoboxes of EUPPs on Wikipedia to use templates
3.1 Create the national_party_composition_bar function (in EUPP seats module) to give out a political party's composition bar in its relevant national lower or upper house (called from national party infobox, takes "lower house" or "upper house" as argument) Deployed
3.2 Create a template for the above function and add documentation (to module and template) Template:EUPP national party
3.3 Check/update the EUPP membership, country, and hex value of national parties on Wikidata
3.4 Add option to query EP seats in national_party_composition_bar(), then update document for module and template
3.5 Check/update the EP seats of national parties on Wikidata
3.6 Update national member parties' infoboxes to use the above template (including a comment with the URL of the party's page on Wikidata to make updates easier) ⚠️

Error for two European parties

As I add data to the wide table, I implement the "EUPP composition bar" template on the relevant pages of European parties, by adding {{EUPP composition bar|ms-upper-house|thisparty|width=80%|percent=yes}} in the infobox (see European Green Party for instance).

So far, it has been very smooth. However, for the Party of the European Left and European People's Party, it gives out "Lua error in Module:EUPP_seats at line 437: attempt to perform arithmetic on a string value", in both cases just for the upper house. Any ideas? I checked the data and it seems in order. Julius Schwarz (talk) 12:43, 4 April 2025 (UTC)[reply]

Ok, the other issue is fixed. Any clue about this, @Trappist the monk? Julius Schwarz (talk) 17:55, 4 April 2025 (UTC)[reply]
I think that I have tracked it to Levice (Q1315362). If I write these templates (takes Module:EUPP_seats/sandbox out of the loop) I get unexpected results for the upper house:
lower house: {{wikidata|property|Q1315362|P1410|P194=Q320265}} → 0 – a number so that's ok
upper house: {{wikidata|property|Q1315362|P1410|P194=Q389423}} → 0 – (apparently empty string) not a number so not ok
Q1315362 property number of seats in assembly (P1410) has 'issues' so perhaps fixing those will fix the problem.
Trappist the monk (talk) 19:03, 4 April 2025 (UTC)[reply]
Yes, I also commented out and back in some entries for the ESN and identified the AfD as the one responsible. But in that case, it's because the entry was indeed empty. I fixed it and it works. Would there be a way to replace a missing entry with a zero but to record that somewhere? The issue here is that the Bundesrat is filled by State-level coalitions and the coalition seemingly decides together, meaning the seats aren't directly attributed to specific parties. So, on the one hand we would need to account for the Bundesrat, but on the other we can't directly link one seat to a party. It's easy for parties that are not in present at all in the coalitions (then it's 0), but not for the rest. Julius Schwarz (talk) 20:43, 4 April 2025 (UTC)[reply]
Turns out Levice was also just simply missing its upper house entry, but for no good reason. Currently, the reason above only affects the EPP (so my changes are pending), but that's because other German parties have 0 as a number of seats for the Bundesrat, but erroneously so. A proposal: we mute the error by replacing a missing value with 0, but we make a test function that would allow me to keep an eye on missing issue and that would report the parties with missing values. Julius Schwarz (talk) 20:51, 4 April 2025 (UTC)[reply]
Created {{#invoke:EUPP seats|test_wikidata_entries}} for this purpose. Seems to work.
Currently: {{#invoke:EUPP seats|test_wikidata_entries}} -> Script error: No such module "EUPP seats". Julius Schwarz (talk) 11:57, 6 April 2025 (UTC)[reply]

Capitalisation

Since it may be that some party/alliance names are not capitalised in the table (and I do not want to force this), I wanted to make sure that, when we compare a requested European party (from the argument) with the entries of the first column, we compare to the capitalised version of the entries (because we force the capitalisation of the arguments.

I tried changing:

if european_party == cfg.tab_data_t[row]['european_party'] then

into:

if european_party == cfg.tab_data_t[row]['european_party']:upper() then

or

if european_party == string.upper(cfg.tab_data_t[row]['european_party']) then

but that did not work. Any idea why? Julius Schwarz (talk) 08:28, 6 April 2025 (UTC)[reply]

I thought I had fixed it -- see latest changes to Module:EUPP seats/sandbox, also deployed to Module:EUPP seats. And when I test both on my own sandbox (User:Julius Schwarz/sandbox), it works. But from Patriots.eu, it doens't work. What am I missing, @Trappist the monk? Julius Schwarz (talk) 11:55, 6 April 2025 (UTC)[reply]
Not obvious that lines 444–447 execute when the module is called from Patriots.eu.
Both of cfg.tab_data_t[row]['european_party']:upper() and string.upper(cfg.tab_data_t[row]['european_party'] work to upcase the value assigned to european_party. But is that code necessary or appropriate? Oughtn't you to be checking that with test_wikidata_entries() rather than upcasing cfg.tab_data_t[row]['european_party'] for every row in the loop?
Trappist the monk (talk) 12:47, 6 April 2025 (UTC)[reply]
Not sure how test_wikidata_entries can help here -- it is just supposed to find issues in Wikidata itself. Here I just want the european_party under consideration to match the tabular data, whether the table has "PATRIOTS" or "Patriots" in the first column. Since the european_party is always capitalised, I was thinking of doing the if test with the capitalised version of the table cell value. And it does work well in the test (I added a non-capitalised version line at the bottom of the tabular data). Julius Schwarz (talk) 13:02, 6 April 2025 (UTC)[reply]
test_wikidata_entries() can ensure that all of the names listed under the european_party heading in the wide table are written using the correct case. That way you don't have to upcase cfg.tab_data_t[row]['european_party'] every time you need that name. test_wikidata_entries() is really a cross-checking function; if there is an error in tested qids in the wide table, there is some chance that the function will catch that error. If you are going to establish a requirement that all parties named in the european_party column are uppercase, it makes sense to test those party names to ensure compliance with the requirement. The user should be able to write patriots, PATRIOTS, or anything in between; Module:EUPP seats will accommodate those variations because it only needs to do it once per template. That is better than doing it 265 times per template.
it does work well in the test but from Patriots.eu, it doens't work. What was the test? How do you know that from Patriots.eu, it doens't work? These seem contradictory to me.
Trappist the monk (talk) 14:04, 6 April 2025 (UTC)[reply]
But I am not establishing a requirement that all names in the first column be capitalised. Most are because they are acronyms, but others (Patriots, DiEM25, Volt, etc.) are not -- well, I capitalised them temporarily so that it would work, but that is just a temporary fix. We all people to call the module/templates with "Patriots" or "PaTrIoTs" and I think we should keep that fleibility in the table, because someone is bound not to respect the capitalisation, starting with me, since the initial table that I have should not have everything capitalised.
As for the last question, when I call {{#invoke:EUPP seats|composition_bar|ms-lower-house|Patriots}} or {{EUPP composition bar|ms-lower-house|Patriots}} from my user sandbox, it works (it finds 734 seats (which accounts for the redundant last line of the table). However, when calling {{EUPP composition bar|ms-lower-house|thisparty}} from the page Patriots.eu, it gives 608 (which does not include the last line of the table, which is not capitalised. Julius Schwarz (talk) 14:30, 6 April 2025 (UTC)[reply]
OR maybe we can force uppercase for the first column when we import the table via the config function? Julius Schwarz (talk) 14:55, 6 April 2025 (UTC)[reply]
(edit conflict)
As you wish.
{{EUPP composition bar|ms-lower-house|Patriots}} doesn't 'work' because in lines 436–442, you do not do the upcasing thing.
Alternate solution: Because we copy the tabular data file into a lua sequence, we can, as we read the data, upcase european_party. Add this at line 123:
row_data_t.european_party = row_data_t.european_party:upper(); -- ensure <european_party> values are always uppercase
Do nothing else; then look at Patriots.eu.
Trappist the monk (talk) 14:59, 6 April 2025 (UTC)[reply]
That's perfect! And I guess in the same way, we would skip an empty line (perhaps by just testing on whether the first column is empty, which it should never be)? Julius Schwarz (talk) 15:46, 6 April 2025 (UTC)[reply]
If the first column is empty, which it should never be, I don't think you want to skip it. You should allow the module to shout an error (as it did when the whole bottom row was empty) because sommat is seriously wrong and needs urgent attention.
Trappist the monk (talk) 16:02, 6 April 2025 (UTC)[reply]
Yeah, that's a good point. Any recommendation for an entirely empty line? Julius Schwarz (talk) 16:44, 6 April 2025 (UTC)[reply]
I would like to avoid that crashing all the pages where the module is used.. Julius Schwarz (talk) 16:44, 6 April 2025 (UTC)[reply]
You could add a null_row export and then as part of build_tab_data(), test each row for all-nil values. If any whole row is nil, set null_row to some value – boolean true, the row number, an error message, etc. Then, in Module:EUPP seats, look at cfg.null_row. If set do something about it.
This idea not tested.
Trappist the monk (talk) 18:00, 6 April 2025 (UTC)[reply]

Error in mobile app

@Trappist the monk, in my browser, all the composition bars on the pages of European parties work. On the Android mobile app, however, several pages show error messages relating to the config file (for instance, Animal Politics EU and European Green Party, but not the European People's Party).

Screenshot error module EUPP seats in Android mobile app

Julius Schwarz (talk) 07:47, 7 April 2025 (UTC)[reply]

Caching problem? What happens if you purge the page? Does that android device have a browser option? Do the errors appear when viewed with the device's browser? That's about all the help that I can offer because I don't have an android device. I don't see the errors when viewing Animal Politics EU and European Green Party on my iphone.
Trappist the monk (talk) 11:31, 7 April 2025 (UTC)[reply]
Thanks @Trappist the monk. I will check the cache and yes it does work from the browser of the same phone. On a separately topic, I note that the module does not work for European political alliances when called with "thisparty", I guess the check is only done on the party table. Unfortunately, I can't check this now, would it be possible for you to have a quick look? PS: data gathering on all national parties is now done and I am working on the "second module". Julius Schwarz (talk) 12:43, 7 April 2025 (UTC)[reply]
Link to someplace that doesn't work? What template specifically doesn't work?
Trappist the monk (talk) 12:55, 7 April 2025 (UTC)[reply]
Sorry, you can take European Pirate Party as an example. You will see in the infobox that figures for upper and lower houses are 0 -- this is not in line with the same calls (but using "PPEU" instead of "thisparty" on my own sandbox. Same for ECA or Volt. Julius Schwarz (talk) 14:23, 7 April 2025 (UTC)[reply]
Maybe line 438; it seems like we try and find "thisparty" only in the list of parties, but not in the list of alliances. Julius Schwarz (talk) 14:30, 7 April 2025 (UTC)[reply]
Dunno whether that was the best way, but I found a quick fix. Julius Schwarz (talk) 14:42, 7 April 2025 (UTC)[reply]
Thanks, I actually almost tried that but wasn't sure it'd work :) Julius Schwarz (talk) 14:58, 7 April 2025 (UTC)[reply]
(edit conflict)
Simplified some. That code should work. Will sum_national_party_seats() ever be called without a party? If so, some sort of error trapping or default value will be needed.
Trappist the monk (talk) 15:02, 7 April 2025 (UTC)[reply]
It should not, no. Because it is only called internally, and it seems always after one of the two party validations functions are called. So if the party given in argument is not really a party, then there should be an error message before it reached that function. Julius Schwarz (talk) 18:44, 7 April 2025 (UTC)[reply]

Double error message

@Trappist the monk, error messages in the two testcases pages (Module talk:EUPP seats/sandbox/testcases and Module talk:EUPP seats/sandbox/testcases composition bar) seem to nest two error messages. For instance

Error: Error: {{EUPP composition bar}}: institution is required (help): unknown party: TEST (help)

where the "institution is required" message seems nested between the first "error" and "unknown party: TEST". Julius Schwarz (talk) 16:11, 8 April 2025 (UTC)[reply]

Doesn't seem to happen in the examples of Module:EUPP seats/sandbox, though. Julius Schwarz (talk) 16:31, 8 April 2025 (UTC)[reply]
The institution is required bit suggests that an empty template is processed by mediawiki after the error message is created by the module which would explain why the institution is required error appears within the unknown party: TEST error message. I'm not sure of the exact mechanism, nor if the issue has something to do with Module:UnitTests or with MediaWiki
{{EUPP seats}}Template:EUPP seats
A fix might be made to the {{$1}} bit of the error message at line 29. Perhaps change one of the { to &#x7B;:
return substitute ('<span style="color:#d33">Error: &#x7B;{$1}}: $2 ([[:Template:$1|$3]])</span>$4',
Trappist the monk (talk) 17:44, 8 April 2025 (UTC)[reply]
Thanks. I can't say that I would have ever figured that one out... Julius Schwarz (talk) 19:10, 8 April 2025 (UTC)[reply]

SPARQL query

Any chance you are also familiar with Sparql queries, @Trappist the monk? ;)

I am trying to list all national parties that are members of a European party and whose country is a member of the European Union. That much I have. However, I also want to display their number of seats in the European Parliament (but it should not be a requirement to have such an entry).

So far, I have:

SELECT ?item ?itemLabel ?countryLabel ?seats
WHERE {
  ?item wdt:P463 [wdt:P31 wd:Q24649]; #member of an instance of European party
        wdt:P17 [wdt:P463 wd:Q458]; #from a country that is a member of the European Union
        wdt:P17 ?country;
        OPTIONAL { ?item p:P1410 [ps:P1410 ?seats; pq:P1410 wdt:Q8889]. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  } 
ORDER BY ?countryLabel ?itemLabel

The OPTIONAL line is what doesn't work as it yields an empty column. Julius Schwarz (talk) 12:02, 9 April 2025 (UTC)[reply]

No experience with database queries. Does the dot after wdt:Q8889] have meaning? What about the dot after en-gb"? For that matter, what about the semicolons?
I see that you have also asked this question at WP:VPT § SPARQL query. If you don't get an answer there, surely someone at Wikidata will know the answer.
Trappist the monk (talk) 13:40, 9 April 2025 (UTC)[reply]
Thanks, and fingers crossed! Julius Schwarz (talk) 14:39, 9 April 2025 (UTC)[reply]

The time allocated for running scripts has expired

You should probably archive some of this page since it now exceeds the Expensive parser function count (886/500) and sometimes exceeds the Lua time usage limit (10 seconds).

Trappist the monk (talk) 13:47, 9 April 2025 (UTC)[reply]