Module talk:Goalscorers
Module idea
Thanks again for your work on the ranking module! I've had an idea for a module for a while, unfortunately I am not familiar enough with Lua so I was wondering what you thought.
At UEFA Euro 2016 qualifying#Goalscorers, there is a list of all the top scorers in the qualifying competition. On the qualifying sub-articles (i.e. UEFA Euro 2016 qualifying Group D, UEFA Euro 2016 qualifying play-offs) there are also lists of goalscorers at the bottom. For example, Arkadiusz Milik scored 6 goals in the group, as listed on both articles. Jonathan Walters scored 3 goals in his group, as well as 2 goals in the play-offs, and therefore is lited having scored 5 goals on the main article. Could a module be created, with all goalscorer data, to be able to output the list of scorers by round, sorted by number of goals? For example, in this situation, Jonathan Walters would have his scoring information by round (3 in Group D and 2 in playoffs), and then display the correct amount of goals on the 3 articles (3 Group D, 2 play-offs, 5 main article). Not sure what way the scoring data would be formatted, possibly by national team and then you could define what rounds a team participated in (i.e. POL
→ GrD
and IRL
→ GrD, PO
, or something like GrD
→ GER, POL, IRL, SCO, GEO, GIB
). Think this would be possible? S.A. Julio (talk) 05:39, 12 December 2018 (UTC)
- The first step is determining how the data should be stored. A player table could simply have goals by round so each player has a row: { country name (or code?), player name, 1, 2, 3 ... } and then have a country-group table with each counry having a row { group, country } or a key-value. I'll have a look at the article pages later and comment further. Jts1882 | talk 10:05, 12 December 2018, (UTC)
- I think a single table would be simplest. Then it needs the follow steps
- Table entry for each row: { player, country, group, goals in group, goals in play-off, ... }
goalscorers = { { Arkadiusz Milik, Poland, D, 3, 2 }, ... }
- Iterate through the table and create a table of entries that meet certain criteria, e.g. (group == X AND goals in group > 0), (goals in play-offs > 0), (goals in group > 0 OR goals in play-off > 0). A non-zero threshold could also be set.
- Then this table needs to be sorted by goals (primary) and name (secondary). This is the more difficult step, although I'm sure some sort algorithm can be found somewhere.
- Generate the output as a list.
- Nothing too difficult. It would be a good excercise for you to get into Lua. I learnt it from scratch when converting the {{clade}} template and I'd never heard of Lua beforehand. Writing the Lua code was much simpler than deciphering the template language code. I could outline a module to get it started, then we could work together to develop it further. Jts1882 | talk 14:33, 12 December 2018 (UTC)
- Alright, my goal is to complete goalscorer information for the entire history of Euro qualifying. In 1960 and 1964 there were no groups, just three rounds, so there'd need to be a way to add this as well. 1980 to 1992, along with 2008, should be fairly simple as there was only the group stage. I had created Template:Goalscorers for tournaments (i.e. not multiple rounds), was thinking that template could be merged into this potential module as well? I'd think the module should also calculate the number of goals from the data. Another issue would be own goals and how to format this. If a player had scored one or more goals, and also an own goal, should this be defined in the same line, or maybe list own goals in a separate section? Also, the country(s) they scored the own goal for needs to be listed, example: "
Josep Gómes (against Kazakhstan)". So for own goals, maybe something like { player, country, group, own goals in group, own goal opponent(s) in group, own goals in play-off, own goal opponent(s) in play-off }. Below I've added a few examples to help envision a potential module.
- Alright, my goal is to complete goalscorer information for the entire history of Euro qualifying. In 1960 and 1964 there were no groups, just three rounds, so there'd need to be a way to add this as well. 1980 to 1992, along with 2008, should be fairly simple as there was only the group stage. I had created Template:Goalscorers for tournaments (i.e. not multiple rounds), was thinking that template could be merged into this potential module as well? I'd think the module should also calculate the number of goals from the data. Another issue would be own goals and how to format this. If a player had scored one or more goals, and also an own goal, should this be defined in the same line, or maybe list own goals in a separate section? Also, the country(s) they scored the own goal for needs to be listed, example: "
The following would be on the goalscorer data page: -- { 'round1', 'round2', ...} data.rounds = { Group stage, Play-offs } -- { 'country1', 'country2', ...} data.GrpC = ... data.GrpD = { GER, POL, IRL, SCO, GEO, GIB } data.GrpE = ... The group D article might use the following: {{#invoke:Goalscorers|main|UEFA_Euro_2016_qualifying|round=Group stage|teams=GrpD}} It would show all the 'round1' (Group stage) goals only from players with country codes that match those in "GrpD" Then for the playoffs: {{#invoke:Goalscorers|main|UEFA_Euro_2016_qualifying|round=Play-offs}} Unlike round1 (Group stage), which is sub-divided, round2 (Play-offs) is not, therefore the "teams" parameter wouldn't be necessary
- I've had this idea for a goalscorer template/module for quite a while, but haven't really been able to get anything started. I'll try and learn some Lua, I'd really appreciate any help with this. S.A. Julio (talk) 02:04, 13 December 2018 (UTC)
- I'd be glad to help. A couple of quick question on your proposal above: how flexible do you want it to be? Would you want to get data separately from each of three rounds of the 1960 and 1964 tournments? If not the module just needs to hand a group stage and a knock-out stage (three rounds or the current single round playoffs) and my single table structure (see above) would be sufficient. Do you want something that could be extended to other tournaments (e.g. the Champions League)? This would then require the more complex structure that would be controlled by your data.rounds table, which could hold information about the type of round (group, knock-out, ...). Jts1882 | talk 08:38, 13 December 2018 (UTC)
- I was hoping for something which could be used for other international qualifying tournaments, i.e. UEFA Women's Euro 2017 qualifying / 2019 FIFA Women's World Cup qualification (UEFA) (preliminary group stage, main group stage, playoff round), 2019 Africa Cup of Nations qualification (preliminary knockout round, group stage), or 2018 FIFA World Cup qualification (AFC) (preliminary knockout round, first group stage, second group stage, playoff round). However, for example the AFC World Cup qualifiers don't have dedicated group articles, but rather articles on the four stages (therefore not requiring the group composition to be stored in the module). I was thinking the data.rounds would just be to give a name to identify the various rounds (i.e.
data.rounds = { First round, Second round, Third round, Fourth round }
for the AFC example. Then with{ John Smith, PHI, 3, 5, 7, 1 }
, the "3" correlates to "First round", the "5" to "Second round", etc. The module would then be called by{{#invoke:Goalscorers|main|...|round=Third round}}
to show Third round goalscorers). This wouldn't need to be used for Champions League/other club competitions, only international tournaments which have these goalscorer sections. S.A. Julio (talk) 10:19, 13 December 2018 (UTC)- @S.A. Julio: Got you. That seems straightforward enough. The only tricky bit will be inserting a group stage in the sequence. But I think I'm now clear on what you want.
- Meanwhile to get started, I've creates a prototype, Module:Goalscorers, to produce some simple output when called from {{Goalscorers/sandbox}}. It uses some sample data I've placed in Module:Goalscorers/data/UEFA Euro 2016 qualifying using a single table format. I think a more flexible system needs more thought and this can get the basics of the output dealt with. For now the code now just reads the list and outputs the goalscorer with the goals from the group and play-offs totaled. The sample data is accessed through line 16 and then handled by the main() function (line 47). I think you'll see that this is much easier to follow than the template language. Jts1882 | talk 10:35, 13 December 2018 (UTC)
- Great, the module is looking good! I tried to match the output of {{Goalscorers}}, which formats the columns as such:
<div class="div-col columns column-count column-count-3" style="{{column-count|3}}">...</div>
. I must have messed up the formatting as the edit didn't work, could this be adjusted? Thanks, S.A. Julio (talk) 17:31, 13 December 2018 (UTC)- @S.A. Julio: I think you tried putting the formating around the wrong elements. I've moved the open list and close list template calls to functions, which should make the logic clearer. If you want to use direct HTML instead of {{div col}} and {{div col end}} replace it in those function. I've also put the linked flag icon in a function and it now gets the icon template name from the data module so women's tournaments can use a different template. Jts1882 | talk 08:52, 14 December 2018 (UTC)
- I've updated to use other competitions using the same subpage system as the Sports Rankings. In a Module:Goalscorers/data/test competition I've added a prequalifying round. Note the
data.round
table. Set the rounds to the approapriate goals column, starting with 4 and it should handle as many as needed. If there is no group stage, column three still needs to be set but will be ignored. Jts1882 | talk 09:59, 14 December 2018 (UTC)
- Great, the module is looking good! I tried to match the output of {{Goalscorers}}, which formats the columns as such:
- I was hoping for something which could be used for other international qualifying tournaments, i.e. UEFA Women's Euro 2017 qualifying / 2019 FIFA Women's World Cup qualification (UEFA) (preliminary group stage, main group stage, playoff round), 2019 Africa Cup of Nations qualification (preliminary knockout round, group stage), or 2018 FIFA World Cup qualification (AFC) (preliminary knockout round, first group stage, second group stage, playoff round). However, for example the AFC World Cup qualifiers don't have dedicated group articles, but rather articles on the four stages (therefore not requiring the group composition to be stored in the module). I was thinking the data.rounds would just be to give a name to identify the various rounds (i.e.
- I'd be glad to help. A couple of quick question on your proposal above: how flexible do you want it to be? Would you want to get data separately from each of three rounds of the 1960 and 1964 tournments? If not the module just needs to hand a group stage and a knock-out stage (three rounds or the current single round playoffs) and my single table structure (see above) would be sufficient. Do you want something that could be extended to other tournaments (e.g. the Champions League)? This would then require the more complex structure that would be controlled by your data.rounds table, which could hold information about the type of round (group, knock-out, ...). Jts1882 | talk 08:38, 13 December 2018 (UTC)
- I've had this idea for a goalscorer template/module for quite a while, but haven't really been able to get anything started. I'll try and learn some Lua, I'd really appreciate any help with this. S.A. Julio (talk) 02:04, 13 December 2018 (UTC)
Alright, looks good! I adjusted the module so that players are linked from the data page, this makes it easier for players that need their links piped. Also, how should we format own goals? And I've completed the information on the Euro 2016 data page. One issue I've noticed is that playoff goals are not being calculated in the overall list anymore, this can be seen on the sandbox with Ibrahimović in the Euro 2016 qualifying and test competition sections. The only other problem is the sorting. On the data page, I sorted all the players alphabetically: first by nationality, then by surname. However, when looking at the sandbox, all the players of the same nationality are no longer kept together. Any idea how this could be fixed? S.A. Julio (talk) 22:45, 14 December 2018 (UTC)
- Good idea putting the links and redirects in the data module. Much simpler and more flexible.
- The lack of playoff goals was a silly logic test (<#v rather than <=#v) which meant it was adding rounds exclusive of the last one. I think that is fixed. It now counts all goals from column four until the last one as intended.
- On own goals, I'd not registered that they need the scored against entries, so they will need different handling. I need to break the main function up into select players, sort players, and output (DONE). Then the own-goals just need to be selected differently and get the note added. Your entries with the goals and opponents in alternating columns is one way. Another might be entering them as { goals, opponent } pairs, which will need slightly more intricate code, but then offers the opportunity for a parenthetic note after any entry. Would this be a useful addition? I'll give this a bit more thought.
- The sorting is something I need to look at more. I would have assumed that the order you entered them in would have been retained within each goal block after sorting. However, the Lua handling of tables is quite confusing. It's possible that the sort function (
function( a, b ) return a['goals'] > b['goals'] end
) can be made to do that, but the documentation of the sort function is minimal. The other way might be just to add addition sorts of for each goalnumber in the main loop. Another thing that needs a bit more thought.- The Lua table.sort function allows quite complicated sorting. I've done sorting on goals, then country and then player name. For the player name I've sorted on the second name, so van Persie is under "v". However, this doesn't work for Jóan Símun Edmundsson who gets sorted under "s". This could be resolved by removing Simun from the data module and using a redirect. I doubt there is a simple formula that will work for every player. Unexpectedly, players with a single name are getting shown first, which I don't understand given I've set the second name. Jts1882 | talk 11:14, 15 December 2018 (UTC)
- Anyway, I don't think these modification should present major hurdles. We're getting closr. Jts1882 | talk 08:12, 15 December 2018 (UTC)