Module:Sports table/ক্ৰিকেট ৰাণৰ হাৰ
অৱয়ব
Documentation for this module may be created at Module:Sports table/ক্ৰিকেট ৰাণৰ হাৰ/doc
-- Style for cricket tables
local pp = { }
local convert = require('Module:সংখ্যা ৰূপান্তৰক').convert
local function args_points(Args)
local pts = {}
-- Do not change these defaults without first checking which tables use them
pts.win = tonumber(Args['winpoints']) or 2
pts.tie = tonumber(Args['tiepoints']) or 1
pts.nr = tonumber(Args['nrpoints']) or 1
pts.loss = tonumber(Args['losspoints']) or 0
pts.bonus = tonumber(Args['bonuspoints']) or 1
return pts
end
local function abbr_header(txt, abbr, show_header_pts, pts)
if show_header_pts then
txt = txt .. ' – ' .. pts .. (pts == 1 and ' পইণ্ট' or ' পইণ্ট')
end
return '<abbr title="' .. txt .. '">' .. abbr .. '</abbr>'
end
function pp.header(t, Args, p_sub, pos_label, group_col, VTE_text, full_table, results_header_txt)
-- Load relevant modules
local yesno = require('Module:Yesno')
-- Create table header
-- Pre stuff
local team_width = Args['teamwidth'] or '180'
local sort_text = yesno(Args['sortable_table'] or 'no') and ' sortable' or ''
table.insert(t,'{|class="wikitable'..sort_text..'" style="text-align:center;"\n') -- Open table
-- Table title
if Args['title'] then
table.insert(t,'|+ ' .. Args['title'] .. '\n')
end
--Header specific options
local show_pts = yesno(Args['show_header_pts'] or 'no')
local pts = args_points(Args)
local group_head_text = Args['group_header'] or 'গ্রুপ'
local team_head_text = Args['team_header'] or 'দল'
local tie_head_text = Args['tie_header'] or abbr_header('টাই হয়', 'টাই', show_pts, pts.tie)
local nr_head_text = Args['nr_header'] or abbr_header('ফলাফল হয়নি', 'ফহ', show_pts, pts.nr)
local bonus_head_text = Args['bonus_header'] or '<abbr title="বোনাচ পইণ্ট">বোপ</abbr>'
local deduct_head_text = Args['deduct_header'] or '<abbr title="বিয়োগ">বি</abbr>'
local nrr_head_text = Args['nrr_header'] or '<abbr title="ৰাণৰ হাৰৰ পাৰ্থক্য">[[ৰাণৰ হাৰৰ পাৰ্থক্য|ৰা.হা.পা.]]</abbr>'
--
local loss_first = yesno(Args['loss_before_tie'] or 'yes')
local show_tie = yesno(Args['show_tie'] or 'yes')
local show_nr = yesno(Args['show_nr'] or 'yes')
local show_deduct = yesno(Args['show_deductions'] or 'no')
local show_bonus_points = yesno(Args['show_bonus_points'] or 'no')
local show_nrr = yesno(Args['show_nrr'] or 'yes')
local show_nrr_fa = yesno(Args['show_nrr_fa'] or 'no') and show_nrr
-- Initialize
local tt = {}
tt.count = 0 -- Up by one after every call
tt.tab_text = t -- Actual text
-- Actual headers
if pos_label ~= nil then
tt = p_sub.colhead(tt,28,pos_label) -- Position col
end
-- Add group header
if full_table and group_col then
tt = p_sub.colhead(tt,28,group_head_text) -- Group col
end
tt = p_sub.colhead(tt, team_width, team_head_text..VTE_text) -- Team col
tt = p_sub.colhead(tt,28,'<abbr title="খেলিছিল">খেলা</abbr>') -- Matches played col
if full_table then
tt = p_sub.colhead(tt,28,abbr_header('জয়','জ',show_pts,pts.win)) -- Win col
local loss_head_text = abbr_header('হাৰ', 'হা', show_pts, pts.loss)
if loss_first then
tt = p_sub.colhead(tt,28,loss_head_text) -- Loss col
if show_tie then
tt = p_sub.colhead(tt,28,tie_head_text) -- Tie col
end
else
if show_tie then
tt = p_sub.colhead(tt,28,tie_head_text) -- Tie col
end
tt = p_sub.colhead(tt, 28, loss_head_text) -- Loss col
end
if show_nr then
tt = p_sub.colhead(tt,28,nr_head_text) -- No result col
end
if show_bonus_points then
tt = p_sub.colhead(tt,28,bonus_head_text) -- Bonus points col
end
if show_deduct then
tt = p_sub.colhead(tt,28,deduct_head_text) -- Deduction col
end
end
tt = p_sub.colhead(tt, 28, 'পইণ্ট') -- Points col
if full_table then
if show_nrr then
tt = p_sub.colhead(tt,28,nrr_head_text) -- NRR col
end
if show_nrr_fa then
tt = p_sub.colhead(tt, 60, 'সপক্ষে')
tt = p_sub.colhead(tt, 60, 'বিপক্ষে')
end
tt.count = tt.count+1
table.insert(tt.tab_text, results_header_txt)
end
return tt
end
local function rr_to_dec(runs, overs, balls_per_over)
if overs == 0 then
return 0
end
local balls = overs % 1
return runs / (overs - balls + balls * 10 / balls_per_over)
end
function pp.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
local mm = require('Module:Math')
local yesno = require('Module:Yesno')
-- table options, to match those in the header
local loss_first = yesno(Args['loss_before_tie'] or 'yes')
local show_tie = yesno(Args['show_tie'] or 'yes')
local show_nr = yesno(Args['show_nr'] or 'yes')
local show_bonus_points = yesno(Args['show_bonus_points'] or 'no')
local show_deduct = yesno(Args['show_deductions'] or 'no')
local show_nrr = yesno(Args['show_nrr'] or 'yes')
local show_nrr_fa = yesno(Args['show_nrr_fa'] or 'no') and show_nrr
-- Get some input
local wins = tonumber(Args['win_'..team_code_ii]) or 0
local ties = tonumber(Args['tie_'..team_code_ii]) or 0
local losses = tonumber(Args['loss_'..team_code_ii]) or 0
local noresults = tonumber(Args['nr_'..team_code_ii]) or 0
local bonuses = tonumber(Args['bonus_'..team_code_ii]) or 0
local deductions = tonumber(Args['ded_'..team_code_ii]) or 0
local nrr = tonumber(Args['nrr_'..team_code_ii]) or nil
local oversbowled = tonumber(Args['ob_'..team_code_ii]) or 0
local runsconceded = tonumber(Args['rc_'..team_code_ii]) or 0
local oversreceived = tonumber(Args['or_'..team_code_ii]) or 0
local runsscored = tonumber(Args['rs_'..team_code_ii]) or 0
local balls_per_over = tonumber(Args['balls_per_over']) or 6
local hth_local = Args['hth_'..team_code_ii] or nil
-- Then calculate some values
local matches = wins + losses + ties + noresults
local pts = args_points(Args)
local s_bps = pts.bonus*bonuses
local points = pts.win*wins + pts.loss*losses + pts.tie*ties + pts.nr*noresults + s_bps - deductions
-- Some local vars
local hth_string
local tt_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
local ranking_style = Args['ranking_style'] or 'pts'
local win_fw, win_string, pts_fw, pts_string
ranking_style = string.lower(ranking_style)
if ranking_style=='p' or ranking_style=='pts' or ranking_style=='points' or ranking_style=='পইণ্ট' then
-- Based on points
win_fw = ii_fw
win_string = ''
pts_fw = 'font-weight: bold;'
pts_string = hth_string
else
-- Based on wins
win_fw = 'font-weight: bold;'
win_string = hth_string
pts_fw = ii_fw
pts_string = ''
end
local nrr_for = rr_to_dec(runsscored, oversreceived, balls_per_over)
local nrr_against = rr_to_dec(runsconceded, oversbowled, balls_per_over)
local nri = nrr_for - nrr_against
local sign
-- Set Net Run Rate. This is probabaly over-engineered and could just be done with a single precalculated value
if nrr == nil then
if nri > 0 then
sign = '+'
else
sign = ''
end
elseif nrr > 0 then
sign = '+'
else
sign = ''
end
if nrr ~= nil then
nrr = mm._precision_format(nrr, 3)
elseif (oversbowled == 0) or (oversreceived == 0) then -- if 0 or null then have mdash rather than 0?
nrr = '—'
else
nrr = mm._precision_format(nrr_for - nrr_against, 3)
end
nrr = sign..nrr
-- Row building
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..convert('bn', tostring(matches))..'\n') -- Played
if full_table then
-- Use actual values if wins, ties, and losses are not numeric. Copied this from other module.
if (wins == 0 and ties == 0 and losses == 0) then
local function numorval(s)
return s and((s == '' and 0) or tonumber(s) or s) or 0
end
wins = numorval(Args['win_'..team_code_ii])
ties = numorval(Args['tie_'..team_code_ii])
losses = numorval(Args['loss_'..team_code_ii])
end
table.insert(t,'| style="'..win_fw..bg_col..'" |'..convert('bn', tostring(wins..win_string))..'\n') -- Won
if loss_first then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..convert('bn', tostring(losses))..'\n') -- Lost
if show_tie then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..convert('bn', tostring(ties))..'\n') -- Ties
end
else
if show_tie then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..convert('bn', tostring(ties))..'\n') -- Ties
end
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..convert('bn', tostring(losses))..'\n') -- Lost
end
if show_nr then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..convert('bn', tostring(noresults))..'\n') -- No Results
end
if show_bonus_points then
if s_bps< 0 then
table.insert(t,'| style="'..bg_col..'" | −'..convert('bn', tostring(-s_bps))..'\n')
else
table.insert(t,'| style="'..bg_col..'" | '..convert('bn', tostring(s_bps))..'\n')
end
end
if show_deduct then
table.insert(t,'| style="'..ii_fw..bg_col..'" | '..convert('bn', tostring(deductions))..'\n')
end
end
if points<0 then
table.insert(t,'| style="'..pts_fw..bg_col..'" | −'..convert('bn', tostring(-points))..pts_string..'\n')
else
table.insert(t,'| style="'..pts_fw..bg_col..'" | '..convert('bn', tostring(points))..pts_string..'\n')
end
if full_table then
if show_nrr then
table.insert(t,'| style="'..ii_fw..bg_col..'" |'..convert('bn', tostring(nrr))..'\n') -- Net run rate
end
if show_nrr_fa then
local nrr_for_text = oversreceived > 0 and convert('bn', tostring(runsscored))..'/'..convert('bn', tostring(oversreceived)) or '—'
local nrr_against_text = oversbowled > 0 and convert('bn', tostring(runsconceded))..'/'..convert('bn', tostring(oversbowled)) or '—'
table.insert(t, '| data-sort-value="'..nrr_for..'" style="'..ii_fw..bg_col..'" |'..nrr_for_text..'\n')
table.insert(t, '| data-sort-value="'..nrr_against..'" style="'..ii_fw..bg_col..'" |'..nrr_against_text..'\n')
end
end
return {t=t, notes_exist=notes_exist, hth_id_list=hth_id_list}
end
function pp.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
-- ------------------------------------------------------------
local status_code, status_called = {},{}
status_code = { A='পৰৱৰ্তী পৰ্যায়লৈ আগবাঢ়িব', C='বিজয়ী', D='অযোগ্য',
E='বাদ', G='আলহী দল', H='ঘৰুৱা দল', O='প্লে-অফ বিজয়ী', P='উন্নতি হৈছে', Q='প্ৰতিযোগিতাৰ নিৰ্দিষ্ট পৰ্যায়লৈ আগবাঢ়ি যোৱাৰ যোগ্য',
R='অৱনতি হৈছে', T='যোগ্য, কিন্তু এতিয়াও প্ৰতিযোগিতাৰ নিৰ্দিষ্ট পৰ্যায় নিৰ্দিষ্ট কৰা হোৱা নাই' }
local status_letters = (Args['status_order'] or '') .. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-- Status position(before or after read and default)
local stat_pos_val = string.lower(Args['status_pos'] or '')
local status_position = 'পাছত'-- Default location
if stat_pos_val=='before' or stat_pos_val=='আগতে' then
status_position = 'আগতে'
elseif stat_pos_val=='after' or stat_pos_val=='পাছত' then
status_position = 'পাছত'
end
for l in mw.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')
if Args['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
return pp