Module:Sports table/WDL OT
Appearance
From Wikipedia, the free encyclopedia
Warning This Lua module is used on approximately 4,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
Page extended-confirmed-protected This module is currently under extended confirmed protection.
Extended confirmed protection prevents edits from all unregistered editors and registered users with fewer than 30 days tenure and 500 edits. The policy on community use specifies that extended confirmed protection can be applied to combat disruption, if semi-protection has proven to be ineffective. Extended confirmed protection may also be applied to enforce arbitration sanctions. Please discuss any changes on the talk page; you may submit an edit request to ask for uncontroversial changes supported by consensus.
Extended confirmed protection prevents edits from all unregistered editors and registered users with fewer than 30 days tenure and 500 edits. The policy on community use specifies that extended confirmed protection can be applied to combat disruption, if semi-protection has proven to be ineffective. Extended confirmed protection may also be applied to enforce arbitration sanctions. Please discuss any changes on the talk page; you may submit an edit request to ask for uncontroversial changes supported by consensus.
Usage
{{#invoke:Sports table/WDL OT|function_name}}
The above documentation is transcluded from Module:Sports table/WDL OT/doc. (edit | history)
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.
-- Style for football tables localpp={} functionpp.header(t,Args,p_sub,pos_label,group_col,VTE_text,full_table,results_header_txt) -- Load relevant modules localyesno=require('Module:Yesno') -- Create table header -- Pre stuff localteam_width=Args['teamwidth']or'190' localscore_width=Args['scorewidth']or'32' localsort_text=yesno(Args['sortable_table']or'no')and' sortable'or'' localshow_played=notyesno(Args['hide_played']or'no') table.insert(t,'{| class="wikitable'..sort_text..'" style="text-align:center;"\n')-- Open table -- Table title ifArgs['title']orArgs['table_header']then table.insert(t,'|+ '..(Args['title']orArgs['table_header'])..'\n') end -- Custom header options localplayed_head_text=Args['pld_header']or'<abbr title="Played">Pld</abbr>' localgroup_head_text=Args['group_header']or'<abbr title="Group">Grp</abbr>' localwin_head_text=Args['win_header']or'<abbr title="Won">W</abbr>' localOTwin_head_text=Args['OTwin_header']or'<abbr title="Overtime win">OTW</abbr>' localOTloss_head_text=Args['OTloss_header']or'<abbr title="Overtime loss">OTL</abbr>' localPKwin_head_text=Args['PKwin_header']orArgs['SOwin_header']or(yesno(Args['showSOwin']or'no') and'<abbr title="Shootout win">SOW</abbr>'or'<abbr title="Penalty kicks win">PKW</abbr>') localPKloss_head_text=Args['PKloss_header']orArgs['SOloss_header']or(yesno(Args['showSOloss']or'no') and'<abbr title="Shootout loss">SOL</abbr>'or'<abbr title="Penalty kicks loss">PKL</abbr>') localloss_head_text=Args['loss_header']or'<abbr title="Lost">L</abbr>' localdraw_head_text=Args['draw_header'] or(yesno(Args['use_tie']or'no')and'<abbr title="Tied">T</abbr>')or'<abbr title="Drawn">D</abbr>' localbonus_head_text=Args['bonus_header']or'<abbr title="Bonus points">BP</abbr>' localtiebr_head_text=Args['tiebr_header']or'<abbr title="Tiebreaker">T</abbr>' -- What to rank the teams by localranking_style=Args['ranking_style']or'pts' localshow_points,show_perc,show_ppg=false,false,false ranking_style=string.lower(ranking_style) ifranking_style=='w'orranking_style=='win'orranking_style=='wins'orranking_style=='none'then -- Based on wins elseifranking_style=='perc'orranking_style=='percentage'orranking_style=='%'then-- NOTE: This is for points %, unlike Module:Sports table/WDL which caculates win % -- Based on percentage show_perc=true elseifranking_style=='ppg'orranking_style=='points per game'orranking_style=='ptspergame'then -- Based on points per game show_ppg=true elseifranking_style=='percpts'orranking_style=='%pts'then -- Based on percentage and points show_perc=true show_points=true elseifranking_style=='ppgpts'then -- Based on ppg and points show_ppg=true show_points=true elseifranking_style=='forpts'then -- Based on goals for and points show_points=true else -- Based on points show_points=true end -- Use points instead of goals for/against localfor_against_style=Args['for_against_style']or'goals' localfa_letter,fa_word_sing,fa_word_plur localhide_for_against=false -- First convert to lower case if it is a string for_against_style=string.lower(for_against_style) iffor_against_style=='g'orfor_against_style=='goal'orfor_against_style=='goals'then fa_letter='G' fa_word_sing='Goal' fa_word_plur='Goals' elseiffor_against_style=='p'orfor_against_style=='point'orfor_against_style=='points'then fa_letter='P' fa_word_sing='Point' fa_word_plur='Points' elseiffor_against_style=='s'orfor_against_style=='set'orfor_against_style=='sets'then fa_letter='S' fa_word_sing='Set' fa_word_plur='Sets' elseiffor_against_style=='none'then hide_for_against=true else fa_letter='G' fa_word_sing='Goal' fa_word_plur='Goals' end -- Whether to use goal ratio (goal average) instead localdo_ratio=yesno(Args['use_goal_ratio']or'no') localdo_average=yesno(Args['use_goal_average']or'no') -- Whether to use goal percentage instead localdo_percentage=yesno(Args['use_goal_percentage']orArgs['use_point_percentage']or'no') -- Whether to suppress the GR/GA/G% column entirely localdo_difference=yesno(Args['use_goal_diff']or'yes') -- True if exist, false otherwise localshow_bonus_points=yesno(Args['show_bonus_points']or'no') localshow_tiebr=yesno(Args['show_tiebr']or'no') -- Whether to show the OT win and OT loss and draw columns localshow_OTwin=yesno(Args['showOTwin']or'yes') localshow_OTloss=yesno(Args['showOTloss']or'yes') localshow_PKwin=yesno(Args['showPKwin']orArgs['showSOwin']or'no') localshow_PKloss=yesno(Args['showPKloss']orArgs['showSOloss']or'no') localshow_draw=yesno(Args['show_draw']or'yes') localloss_first=Args['loss_before_draw']orArgs['loss_before_tie']orfalse localOTloss_after=yesno(Args['OTloss_after_loss']or'no') localPKloss_after=yesno(Args['PKloss_after_loss']orArgs['SOloss_after_loss']or'no') -- Use games behind header localshow_GB=yesno(Args['show_GB']or'no') -- Initialize localtt={} tt.count=0-- Up by one after every call tt.tab_text=t-- Actual text -- Actual headers ifpos_label~=nilthen tt=p_sub.colhead(tt,score_width,pos_label)-- Position col end -- Add group header iffull_tableandgroup_colthen tt=p_sub.colhead(tt,28,group_head_text)-- Group col end tt=p_sub.colhead(tt,team_width,'Team'..VTE_text)-- Team col ifshow_playedthen tt=p_sub.colhead(tt,score_width,played_head_text)-- Matches played col end iffull_tablethen tt=p_sub.colhead(tt,score_width,win_head_text)-- Win col ifshow_OTwinthentt=p_sub.colhead(tt,score_width,OTwin_head_text)end ifshow_PKwinthentt=p_sub.colhead(tt,score_width,PKwin_head_text)end ifshow_drawandnotloss_firstthen tt=p_sub.colhead(tt,score_width,draw_head_text)-- Draw col end ifshow_OTlossandnotOTloss_afterthent=p_sub.colhead(tt,score_width,OTloss_head_text)end ifshow_PKlossandnotPKloss_afterthent=p_sub.colhead(tt,score_width,PKloss_head_text)end tt=p_sub.colhead(tt,score_width,loss_head_text)-- Loss col ifshow_drawandloss_firstthen tt=p_sub.colhead(tt,score_width,draw_head_text)-- Draw col end ifshow_OTlossandOTloss_afterthent=p_sub.colhead(tt,score_width,OTloss_head_text)end ifshow_PKlossandPKloss_afterthent=p_sub.colhead(tt,score_width,PKloss_head_text)end ifshow_tiebrthent=p_sub.colhead(tt,score_width,tiebr_head_text)end ifnothide_for_againstthen tt=p_sub.colhead(tt,score_width,'<abbr title="'..fa_word_plur..' for">'..fa_letter..'F</abbr>')-- For col tt=p_sub.colhead(tt,score_width,'<abbr title="'..fa_word_plur..' against">'..fa_letter..'A</abbr>')-- Against col ifdo_ratioordo_averagethen localratio_word=do_ratioand' ratio'or' average' localratio_letter=do_ratioand'R'or'Av' tt=p_sub.colhead(tt,36,'<abbr title="'..fa_word_sing..ratio_word..'">'..fa_letter..ratio_letter..'</abbr>')-- Ratio col elseifdo_percentagethen tt=p_sub.colhead(tt,28,'<abbr title="'..fa_word_sing..' percentage">%</abbr>')-- Percentage col elseifdo_differencethen tt=p_sub.colhead(tt,score_width,'<abbr title="'..fa_word_sing..' difference">'..fa_letter..'D</abbr>')-- Difference col end end end ifshow_bonus_pointsthen tt=p_sub.colhead(tt,28,bonus_head_text)-- Bonus points col end ifshow_pointsthen tt=p_sub.colhead(tt,score_width,'<abbr title="Points">Pts</abbr>')-- Points col end ifshow_percthen tt=p_sub.colhead(tt,36,'<abbr title="Point percentage">PCT</abbr>')-- Point percentage col end ifshow_ppgthen tt=p_sub.colhead(tt,36,'<abbr title="Points per game">PPG</abbr>')-- Points per game col end iffull_tablethen tt.count=tt.count+1 table.insert(tt.tab_text,results_header_txt) end returntt end functionpp.row(frame,t,Args,p_sub,notes_exist,hth_id_list,full_table,rand_val,team_list,team_code_ii,ii_start,ii_end,ii_fw,bg_col,N_teams,ii,ii_show) -- Build the inner parts of individual rows -- Sub-module usage localmm=require('Module:Math') localyesno=require('Module:Yesno') -- Get custom/default options for in table localwin_points=tonumber(Args['winpoints'])or3 localOTwin_points=tonumber(Args['OTwinpoints'])or2 localdraw_points=tonumber(Args['drawpoints'])or1 localOTloss_points=tonumber(Args['OTlosspoints'])or1 localPKwin_points=tonumber(Args['PKwinpoints']orArgs['SOwinpoints'])or1 localPKloss_points=tonumber(Args['PKlosspoints']orArgs['SOlosspoints'])or0 localloss_points=tonumber(Args['losspoints'])or0 -- Get some input localwins=tonumber(Args['win_'..team_code_ii])or0 localOTwins=tonumber(Args['OTwin_'..team_code_ii])or0 localdraws=tonumber(Args['draw_'..team_code_ii])or0 localOTlosses=tonumber(Args['OTloss_'..team_code_ii])or0 localPKwins=tonumber(Args['PKwin_'..team_code_ii]orArgs['SOwin_'..team_code_ii])or0 localPKlosses=tonumber(Args['PKloss_'..team_code_ii]orArgs['SOloss_'..team_code_ii])or0 locallosses=tonumber(Args['loss_'..team_code_ii])or0 localtiebr=tonumber(Args['tiebr_'..team_code_ii])or0 localgfor=tonumber(Args['gf_'..team_code_ii]orArgs['pf_'..team_code_ii]or'0')or'?' localgaig=tonumber(Args['ga_'..team_code_ii]orArgs['pa_'..team_code_ii]or'0')or'?' locals_pts=tonumber(Args['adjust_points_'..team_code_ii])ortonumber(Args['startpoints_'..team_code_ii])or0 localhth_local=Args['hth_'..team_code_ii]ornil -- Then calculate some values localmatches=wins+OTwins+draws+OTlosses+PKwins+PKlosses+losses localpoints=win_points*wins+OTwin_points*OTwins+draw_points*draws +OTloss_points*OTlosses+loss_points*losses +PKwin_points*PKwins+PKloss_points*PKlosses+s_pts ifArgs['goalpoints']andtonumber(Args['gf_'..team_code_ii]orArgs['pf_'..team_code_ii])then points=points+(tonumber(Args['goalpoints'])or1)*tonumber(Args['gf_'..team_code_ii]orArgs['pf_'..team_code_ii]) end iftonumber(Args['win_'..team_code_ii])==nilortonumber(Args['draw_'..team_code_ii])==nilortonumber(Args['loss_'..team_code_ii])==nilthen matches=tonumber(Args['matches_'..team_code_ii])ormatches end localpercentage_format=Args['percentage_format'] localpoint_perc='' localppg='' iftonumber(matches)==nilor(matches*win_points)==0then -- Escape for zero matches point_perc='—' ppg='—' else ifpercentage_format=='hundred 1 decimal'then point_perc=mm._precision_format(((points)/(matches*win_points)*100),1) elseifpercentage_format=='hundred 2 decimals'then point_perc=mm._precision_format(((points)/(matches*win_points)*100),2) else point_perc=mm._precision_format((points)/(matches*win_points),3) percentage_format='no' end ifpoints~=(matches*win_points)andpercentage_format=='no'then -- Drop the leading zero (from the string) point_perc=string.sub(point_perc,2,string.len(point_perc)) end ppg=mm._precision_format(points/matches,2) end -- Show for/against localfor_against_style=Args['for_against_style']or'goals' localhide_for_against=false for_against_style=string.lower(for_against_style) iffor_against_style=='none'then hide_for_against=true end -- Comparison of for against localgcomp -- Whether to use goal ratio (goal average) instead localskip_sign ifyesno(Args['use_goal_ratio']or'no')oryesno(Args['use_goal_average']or'no')then -- Now it is the goal ratio/goal average if(gfor=='?')or(gaig=='?')or(gaig==0)then gcomp='—' else gcomp=mm._precision_format(gfor/gaig,3) end elseifyesno(Args['use_goal_percentage']or'no')then -- Now it is the percentage if(gfor=='?')or(gaig=='?')orgaig==0then gcomp='—' else gcomp=mm._precision_format(100*gfor/gaig,1) end elseifyesno(Args['use_point_percentage']or'no')then -- Now it is the point percentage if(gfor=='?')or(gaig=='?')or(gfor+gaig)<=0then gcomp='—' else gcomp=mm._precision_format(100*gfor/(gfor+gaig),2) end elseifyesno(Args['use_goal_diff']or'yes')then -- It's goal difference if(gfor=='?')or(gaig=='?')then gcomp='—' else gcomp=gfor-gaig -- Formatting with signs ifgcomp>0then gcomp='+'..gcomp elseifgcomp<0then gcomp='−'..-gcomp end end end -- Use actual values if gfor or gaig is not numeric if(gfor=='?')thengfor=Args['gf_'..team_code_ii]orArgs['pf_'..team_code_ii]or''end if(gaig=='?')thengaig=Args['ga_'..team_code_ii]orArgs['pa_'..team_code_ii]or''end -- Show games behind localshow_GB=yesno(Args['show_GB']or'no') localGB_text='—' ifshow_GBthen localGB_team_no=tonumber(Args['GB_team'])or1 ifii==GB_team_nothen -- Do nothing, it's vs this team else localwins_GB=tonumber(Args['win_'..team_list[GB_team_no]])or0 locallosses_GB=tonumber(Args['loss_'..team_list[GB_team_no]])or0 localGB_num=(wins_GB-wins+losses-losses_GB)/2 -- Display options ifGB_num>0then -- Indicates trailing GB_team GB_text=GB_num elseifGB_num==0then -- Equal, do nothing to get dash else -- Ahead of GB team, should be noted by plus (instead of minus that comes from formula) GB_text='+'..-GB_num end end end -- Whether to show the OT win and OT loss and draw columns localshow_OTwin=yesno(Args['showOTwin']or'yes') localshow_OTloss=yesno(Args['showOTloss']or'yes') localshow_PKwin=yesno(Args['showPKwin']orArgs['showSOwin']or'no') localshow_PKloss=yesno(Args['showPKloss']orArgs['showSOloss']or'no') localshow_draw=yesno(Args['show_draw']or'yes') localloss_first=Args['loss_before_draw']orArgs['loss_before_tie']orfalse localOTloss_after=yesno(Args['OTloss_after_loss']or'no') localPKloss_after=yesno(Args['PKloss_after_loss']orArgs['SOloss_after_loss']or'no') -- Some local vars localhth_string localtt_return=p_sub.hth(frame,Args,full_table,hth_id_list,hth_local,notes_exist,team_list,team_code_ii,ii_start,ii_end,rand_val) hth_string=tt_return.str hth_id_list=tt_return.list notes_exist=tt_return.notes_exist -- What to rank the teams by localranking_style=Args['ranking_style']or'pts' localrank_points,rank_perc,rank_ppg=false,false,false localwin_fw,win_string localfor_style,points_style='','' ranking_style=string.lower(ranking_style) ifranking_style=='w'orranking_style=='win'orranking_style=='wins'then -- Based on wins win_fw='font-weight: bold;' win_string=hth_string elseifranking_style=='perc'orranking_style=='percentage'orranking_style=='%'then -- Based on percentage rank_perc=true win_fw=ii_fw win_string='' elseifranking_style=='ppg'orranking_style=='points per game'orranking_style=='ptspergame'then -- Based on points per game rank_ppg=true win_fw=ii_fw win_string='' elseifranking_style=='percpts'orranking_style=='%pts'then -- Based on percentage and points rank_perc=true rank_points=true points_style='font-weight:bold;' win_fw=ii_fw win_string='' elseifranking_style=='ppgpts'then -- Based on ppg and points rank_ppg=true rank_points=true points_style='font-weight:bold;' win_fw=ii_fw win_string='' elseifranking_style=='none'then win_fw=ii_fw win_string='' elseifranking_style=='forpts'then -- Based on goals for and points rank_points=true points_style='font-weight:bold;' for_style='font-weight:bold;' win_fw=ii_fw win_string='' else -- Based on points rank_points=true points_style='font-weight:bold;' win_fw=ii_fw win_string='' end localshow_played=notyesno(Args['hide_played']or'no') localshow_bonus_points=yesno(Args['show_bonus_points']or'no') localshow_tiebr=yesno(Args['show_tiebr']or'no') -- Row building ifshow_playedthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..matches..'\n')-- Played end iffull_tablethen -- Use actual values if wins, draws, and losses are not numeric if(OTwins==0andPKwins==0andwins==0anddraws==0andOTlosses==0andPKlosses==0andlosses==0)then localfunctionnumorval(s) returnsand((s==''and0)ortonumber(s)ors)or0 end wins=numorval(Args['win_'..team_code_ii]) OTwins=numorval(Args['OTwin_'..team_code_ii]) PKwins=numorval(Args['PKwin_'..team_code_ii]orArgs['SOwin_'..team_code_ii]) draws=numorval(Args['draw_'..team_code_ii]) losses=numorval(Args['loss_'..team_code_ii]) OTlosses=numorval(Args['OTloss_'..team_code_ii]) PKlosses=numorval(Args['PKloss_'..team_code_ii]orArgs['SOloss_'..team_code_ii]) end table.insert(t,'| style="'..win_fw..bg_col..'" |'..wins..win_string..'\n')-- Won ifshow_OTwinthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..OTwins..'\n')-- Won in OT end ifshow_PKwinthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..PKwins..'\n')-- Won on PKs end ifshow_drawandnotloss_firstthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..draws..'\n')-- Drawn end ifshow_OTlossandnotOTloss_afterthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..OTlosses..'\n')-- Lost in OT end ifshow_PKlossandnotPKloss_afterthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..PKlosses..'\n')-- Lost on PKs end table.insert(t,'| style="'..ii_fw..bg_col..'" |'..losses..'\n')-- Lost ifshow_drawandloss_firstthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..draws..'\n')-- Drawn end ifshow_OTlossandOTloss_afterthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..OTlosses..'\n')-- Lost in OT end ifshow_PKlossandPKloss_afterthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..PKlosses..'\n')-- Lost on PKs end ifshow_tiebrthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..tiebr..'\n')-- Tie breaker end ifnothide_for_againstthen table.insert(t,'| style="'..ii_fw..bg_col..for_style..'" |'..gfor..'\n')-- GF table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gaig..'\n')-- GA ifgcompthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..gcomp..'\n')-- Goal comparison end end end ifshow_bonus_pointsthen ifs_pts<0then table.insert(t,'| style="'..bg_col..'" | −'..-s_pts..'\n') else table.insert(t,'| style="'..bg_col..'" | '..s_pts..'\n') end end ifrank_pointsthen -- Add − for negative point totals ifpoints<0then table.insert(t,'| style="'..points_style..bg_col..'" | −'..-points..hth_string..'\n') else table.insert(t,'| style="'..points_style..bg_col..'" | '..points..hth_string..'\n') end end ifrank_percthen table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..point_perc..hth_string..'\n') end ifrank_ppgthen table.insert(t,'| style="font-weight: bold;'..bg_col..'" | '..ppg..hth_string..'\n') end ifshow_GBthen table.insert(t,'| style="'..ii_fw..bg_col..'" |'..GB_text..'\n')-- GB end return{t=t,notes_exist=notes_exist,hth_id_list=hth_id_list} end functionpp.status(Args) -- Declare status options -- ------------------------------------------------------------ -- NOTE: If you add to status_code, also add to status_called and status_letters!! -- Or functionality will be compromised -- ------------------------------------------------------------ localstatus_code,status_called={},{} status_code={A='Advances to a further round',C='Champion',D='Disqualified', E='Eliminated',H='Host',O='Play-off winner',P='Promoted',Q='Qualified to the phase indicated', R='Relegated',T='Qualified, but not yet to the particular phase indicated'} localstatus_letters=(Args['status_order']or'')..'ABCDEFGHIJKLMNOPQRSTUVWXYZ' -- Status position (before or after read and default) localstat_pos_val=Args['status_pos']or'' localstatus_position='after'-- Default location stat_pos_val=string.lower(stat_pos_val) ifstat_pos_val=='before'then status_position='before' elseifstat_pos_val=='after'then status_position='after' end -- Read in custom status options forlinmw.text.gsplit(status_letters,'')do status_called[l]=false status_code[l]=status_code[l]or'?' status_letters=mw.ustring.gsub(status_letters,'('..l..'.-)'..l,'%1') ifArgs['status_text_'..l]then status_code[l]=Args['status_text_'..l] end end return{code=status_code,called=status_called,letters=status_letters,position=status_position} end returnpp