stringtranslate.com

Módulo: Resultados deportivos

-- Módulo para construir tablas cruzadas de resultados para clasificaciones en Deportes -- Ver documentación para detalles require ( 'strict' ) local p = {} -- Función principal function p . main ( frame ) -- Obtener los argumentos, eliminando los valores en blanco local getArgs = require ( 'Module:Arguments' ). getArgs local Args = getArgs ( frame , { parentFirst = true }) -- Salir antes si estamos usando la transclusión de sección para una sección diferente local tsection = frame : getParent (). args [ 'transcludesection' ] o frame : getParent (). args [ 'section' ] o '' local bsection = frame . args [ 'section' ] o '' si ( tsection ~= '' y bsection ~= '' ) entonces si ( tsection ~= bsection ) entonces devuelve '' fin fin -- Declarar variables locales local t = {} local t_footer = {} local t_return = {} local team_list = {} local notes_exist = false local ii , ii_fw , bg_col , team_name , team_code_ii , ii_start , ii_end -- Encabezado de equipo personalizado opcional local team_header = Args [ 'team_header' ] o 'Local \\ Visitante' -- Número de etapas local legs = tonumber ( Args [ 'legs' ]) o 1 local multirowlegs = ( Args [ 'multirowlegs'                                                                           ]  o  'no' )  ~=  'no' - Editar enlaces si se solicita local baselink = frame : getParent (): getTitle () if mw . title . getCurrentTitle (). fullText == baselink then baselink = '' end local template_name = Args [ 'template_name' ] or ( baselink ~= '' and ( ':' .. baselink )) or '' local edit_links = template_name == '' and '' or require ( 'Module:Navbar' ). _navbar ({ template_name , mini = 1 , style = 'float:right' }) - Obtener el punto de inicio personalizado para la tabla (la mayoría comenzará de forma predeterminada en 1) local top_pos = tonumber ( Args [ 'highest_pos' ]) o 1 - Obtener el punto final personalizado para la tabla (sin restricciones si bottom_pos es < top_pos) local bottom_pos = tonumber ( Args [ 'lowest_pos' ]) o 0 local N_teams = top_pos - 1 - Predeterminado a 0 al inicio, pero se necesita un número mayor para omitir ciertas entradas - Cargar algunos otros módulos local p_sub = require ( 'Module:Sports table/sub' ) - Sintaxis alternativa para la lista de equipos if Args [ 'team_order' ] and Args [ 'team_order' ] ~= '' then local tlist = mw . text . dividir ( Args [ 'orden_de_equipo' ], '%s*[;,]%s*' ) para k ,tname en ipairs ( tlist ) hacer si tname ~= ''                                                                   entonces Args [ 'team' .. k ] = tname end end end si Args [ 'team_header_note' ] entonces notes_exist = verdadero local note_string = frame : expandTemplate { título = 'efn' , args = { grupo = 'lower-alpha' , Args [ 'team_header_note' ]} } team_header = team_header .. note_string fin -- Leer el número de equipos consecutivos (ignorar las entradas después de saltear un lugar) ii_start = N_teams mientras Args [ 'team' .. N_teams + 1 ] ~= nil y ( bottom_pos < top_pos o N_teams < bottom_pos ) hacer N_teams = N_teams + 1 -- Agregarlo disimuladamente dos veces al parámetro team_list, una para la clasificación real, la segunda para la búsqueda de posición en subtablas -- Esto es posible porque Lua permite tanto números como cadenas como índices. team_list [ N_teams ] = Args [ 'team' .. N_teams ] -- la entrada i^th es el equipo X team_list [ Args [ 'team' .. N_teams ]] = N_teams -- la entrada del equipo X es la posición i end ii_end = N_teams -- Obtener el equipo a mostrar local ii_show = team_list [ Args [ 'showteam' ]] -- nulo si no existe -- Establecer el tamaño de fuente local font_size = Args [ 'font_size' ] o '100%' -- Crear encabezado -- Abrir tabla table.insert ( t , '{|class="wikitable plainrowheaders" style="text-align:center;font-size:' .. font_size ..';" \n ' ) -- Título de la tabla si Args                                                     [ 'title' ]  entonces tabla.insert ( t , '|+ ' .. Args [ 'title' ] .. ' \n ' ) fin - Primera columna t_return .count = 0 - Parámetro ficticio, usar la llamada a la subfunción parece mejor en este punto porque ambos módulos están entrelazados t_return .tab_text = t - Texto real t_return = p_sub .colhead ( t_return , 'auto' , edit_links .. ' ' .. team_header ) - Otras columnas pasadas a la subfunción t_return = p .header ( t_return , Args , p_sub , N_teams , team_list , legs , multirowlegs ) t = t_return . tab_text -- Valor aleatorio usado para unicidad math.randomseed ( os.clock () * 10 ^ 8 ) local rand_val = math.random () local note_string , note_id local note_id_list = {} -- Ahora crea filas individuales ii_start = tonumber ( Args [ 'highest_row' ]) y ( tonumber ( Args [ 'highest_row' ]) > top_pos ) y tonumber ( Args [ 'highest_row' ]) o top_pos ii_end = tonumber ( Args [ 'lowest_row' ]) y ( tonumber ( Args [ 'lowest_row' ]) < N_teams ) y tonumber ( Args [ 'lowest_row' ]) o N_teams para ii = ii_start , ii_end do -- Obtener información del equipo                                                      team_code_ii  =  team_list [ ii ] team_name = Args [ 'nombre_' .. team_code_ii ] o team_code_ii local ii_style = 'text-align:' .. ( Args [ 'team_align' ] o 'derecha' ) .. ';' .. ( ii y ii == ii_show y 'font-weight:bold;' o '' ) .. ( Args [ 'team_nowrap' ] y 'white-space:nowrap;' o '' ) local team_note = Args [ 'note_' .. team_code_ii ] if team_note then notes_exist = true -- Solo cuando existe -- Primero verifica la existencia de una referencia para la nota if not Args [ 'note_' .. team_note ] then -- Es la entrada -- Agrega un final aleatorio para una ID única si hay más tablas presentes en el artículo (que de otra manera podrían compartir una ID) note_id = '"table_note_' .. team_code_ii .. rand_val .. '"' note_id_list [ team_code_ii ] = note_id note_string = frame : expandTemplate { title = 'efn' , args = { group = 'lower-alpha' , name = note_id ,team_note } } else -- Verificar existencia en otro lugar local note_local_num = team_list [ team_note ] o ii_end + 1 if note_id_list [ team_note ] o (( note_local_num >= ii_start ) y ( note_local_num <= ii_end )) then -- Existe note_id = '"table_note_' .. team_note                                                                       .. rand_val .. '"'  -- Identificador note_string = frame : extensionTag { name = 'ref' , args = { group = 'lower-alpha' , name = note_id } } else -- Ahora defina el identificador para esto -- Agregue un final aleatorio para un ID único note_id = '"table_note_' .. team_note .. rand_val .. '"' note_id_list [ team_note ] = note_id note_string = frame : expandTemplate { title = 'efn' , args = { group = 'lower-alpha' , name = note_id , Args [ 'note_' .. team_note ]} } end end -- Ahora agregue esto a la cadena team_name team_name = team_name .. note_string end -- Nombres de los equipos table.insert ( t , '|- \n ' ) -- Nueva fila table.insert ( t , '!scope="row"' .. ( multirowlegs y ' rowspan=' .. legs o '' ) .. 'style="' .. ii_style .. '"| ' .. team_name .. ' \n ' ) -- Número de posición -- Ahora incluye una nota para hacer coincidir los resultados si es necesario para jj = top_pos , N_teams do local team_code_jj = team_list [ jj ] if ii == jj then -- Nada más para l = 1 , legs do local m = ( legs == 1 ) y 'match_' o 'match' ..l .. '_' local                                                                     match_note  =  Args [ m  .. team_code_ii .. '_' .. team_code_jj .. '_note' ] if match_note then notes_exist = true -- Solo cuando existe -- Primero se comprueba la existencia de una referencia para la nota si no ( Args [ 'note_' .. match_note ] o Args [ m .. match_note .. '_note' ]) then -- Es la entrada -- Agregar final aleatorio para ID único si hay más tablas presentes en el artículo (que de otra manera podrían compartir una ID) note_id = '"table_note_' .. l .. "_" .. team_code_ii .. '_' .. team_code_jj .. rand_val .. '"' note_id_list [ team_code_ii .. '_' .. team_code_jj ] = note_id note_string = frame : expandTemplate { title = 'efn' , args = { grupo = 'lower-alpha' , nombre = note_id , match_note } } else - Verificar existencia en otro lugar local note_local_num = team_list [ match_note ] o ii_end + 1 if note_id_list [ match_note ] then - Hacer referencia a una nota existente note_id = note_id_list [ match_note ] - Tomar prestado el identificador existente note_string = frame : extensionTag { nombre = 'ref' , args = { grupo = 'lower-alpha' , nombre = note_id } } elseif ( note_local_num >= ii_start ) and ( note_local_num <= ii_end ) then                                                           -- Hacer referencia a una nota de jugador de una nota de partido. En este caso, eliminamos la parte de la pierna note_id = '"table_note_' .. match_note .. rand_val .. '"' note_string = frame : extensionTag { name = 'ref' , args = { group = 'lower-alpha' , name = note_id } } else -- Hacer referencia a una nota de coincidencia diferente antes de que se defina con su contenido note_id = '"table_note_' .. l .. "_" .. match_note .. rand_val .. '"' note_id_list [ match_note ] = note_id note_string = frame : expandTemplate { title = 'efn' , args = { group = 'lower-alpha' , name = note_id , Args [ 'note_' .. match_note ]} } end end -- Ahora agregue esto a la cadena de resultado de la coincidencia Args [ m .. team_code_ii .. '_' .. team_code_jj ] = ( Args [ m .. team_code_ii .. '_' .. team_code_jj ] o '–' ) .. note_string fin fin fin fin -- Entonces los resultados individuales t = p . row ( t , Args , N_teams , team_list , ii , ii_show , legs , multirowlegs ) fin -- Cerrar la tabla table.insert ( t ,'|} \n ' ) -- Obtener información para el pie de página actualización local = Args [ 'update' ] o 'unknown' fecha de inicio local = Args [                                             'start_date' ] o 'desconocido' fuente local = Args [ 'source' ] o frame : expandTemplate { title = 'cita necesaria' , args = { reason = 'No hay parámetro de fuente definido' , date = os.date ( '%B %Y' ) } } -- Crear texto de pie de página -- Actualización de fecha if string.lower ( update ) == 'complete' then -- No hacer nada elseif update == '' then -- Parámetro vacío table.insert ( t_footer , 'Actualizado a los partidos jugados el desconocido. ' ) elseif string.lower ( update ) == 'future' then -- Fecha de inicio futura table.insert ( t_footer , 'Se jugarán los primeros partidos: ' .. start_date .. '. ' ) else table.insert ( t_footer , 'Actualizado a los partidos jugados el ' .. update .. '. ' ) end table.insert ( t_footer , 'Fuente: ' .. fuente ) si ( Args [ 'matches_style' ] o '' ) == 'FBR' entonces tabla.insert ( t_footer , Args [ 'team_header' ] y '<br />Leyenda: Azul = victoria del equipo de la columna izquierda; Amarillo = empate; Rojo = victoria del equipo de la fila superior.' o '<br />Leyenda: Azul = victoria del equipo local; Amarillo = empate; Rojo = victoria del equipo visitante.' ) si no ( Args [ 'matches_style' ] o '' ) == 'BSR' entonces tabla.insert ( t_footer , Args [ 'team_header' ] y '<br />Leyenda: Azul = victoria del equipo de la columna izquierda; Rojo = victoria del equipo de la fila superior.' o '<br />Leyenda: Azul = victoria del equipo local; Rojo = victoria del equipo visitante.' ) fin                                      if  Args [ 'a_note' ]  then table.insert ( t_footer , '<br />Para los próximos partidos, una "a" indica que hay un artículo sobre la rivalidad entre los dos participantes.' ) end if Args [ 'ot_note' ] then table.insert ( t_footer , '<br />Los partidos con sombreado de fondo más claro se decidieron después del tiempo extra.' ) end local templatestyles = frame : extensionTag { name = 'templatestyles' , args = { src = 'Module:Sports results/styles.css' } } -- Agregar notas (si corresponde) if notes_exist then table.insert ( t_footer , '<br>Notas:' ) t_footer = templatestyles .. '<div class="sports-results-notes">' .. table.concat ( t_footer ) .. '</div>' t_footer = t_footer .. frame : expandTemplate { title = 'notelist' , args = { group = 'lower-alpha' } } else t_footer = templatestyles .. '<div class="sports-results-notes">' .. table.concat ( t_footer ) .. '</div>' end -- Agregar pie de página a la tabla de texto principal table.insert ( t , t_footer ) -- Reescribir enlaces de anclaje para k = 1 , # t do if t [ k ] : match ( ' %[%[#[^%[%]]*%|' ) then t [ k ] = mw.ustring.gsub ( t [ k ], '(%[%[)(#[^%[%]]*%|)' , ' %1 ' .. baselink ..'%2' ) fin fin devolver ' <div style="overflow:hidden">'                                                 ..  '<div class="noresize overflowbugx" style="overflow:auto"> \n ' .. table.concat ( t ) .. '</div></div>' fin -- Otras funciones función local get_short_name ( s , t , n , ss ) -- devuelve el nombre corto si está definido si s y s ~= '' entonces devuelve s fin -- desmarca si es necesario si ss y n entonces si ss == 'noflag' entonces n = mw . ustring . gsub ( n , '%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*%]%]' , '' ) n = mw . ustring . gsub ( n , '^%s* %s*' , '' ) elseif ss == 'flag' entonces n = mw . ustring . gsub ( n , '(<span class="flagicon">%s*%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*link=)[^%|%[%]]*(%]%][^<>]*</span>)%s*%[%[([^%[%]%|]*)%|[^%[%]]*%]%]' , '%1%3%2' ) n = mw . ustring . gsub ( n , '(%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*link=)[^%|%[%]]*(%]%])%s* %s*%[%[([^%[%]%|]*)%|[^%[%]]*%]%' , '%1%3%2' ) n = mw . ustring . gsub ( n , '(%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*link=)[^%|%[%]]*(%]%])%s*%[%[([^%[%]%|]*)%|[^%[%]]*%]%' , '%1%3%2' ) n = mw . ustring . gsub ( n , '.*(<span class="flagicon">%s*%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*%]%][^<>]*</span>).*' , '%1' ) n = mw . ustring . gsub ( n , '.*(%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*%]%]).*' , '%1' ) n = mw . cuerda .                                                         gsub ( n ,  ' (</span>)' ,  '%1' ) fin fin -- reemplazar el texto del enlace en el nombre con la abbr del equipo si es posible si n y t y n : coinciden ( '(%[%[[^%[%]]*%]%])' ) entonces n = mw . ustring . gsub ( n , '(%[%[[^%|%]]*%|)[^%|%]]*(%]%])' , '%1' .. t .. '%2' ) n = mw . ustring . gsub ( n , '(%[%[[^%|%]]*)(%]%])' , '%1|' .. t .. '%2' ) n = mw . ustring . gsub ( n , '(%[%[[^%|%]]*%|)([AZ][AZ][AZ])(%]%]) <span[^<>]*>%([AZ][AZ][AZ]%)</span>' , '%1%2%3' ) return n end -- nada funcionó, así que solo devuelve el equipo no vinculado abbr return t o '' end local function get_score_background ( s , c ) local s1 , s2 -- Define el color local wc , lc , tc if c == 'level2' then wc , lc , tc = '#CCF9FF' , '#FCC' , '#FFC' -- blue2, red2, yellow2 elseif c == 'level3' then wc , lc , tc = '#DDFCFF' , '#FDD' , '#FFD' -- blue3, rojo3, amarillo3 de lo contrario si c == 'nivel4' entonces wc , lc , tc = '#EEFFFF' , '#FEE' , '#FFE' -- azul4, rojo4, amarillo4 de lo contrario wc , lc , tc = '#BBF3FF' ,'#FBB' , '#FFB' -- final azul1, rojo1, amarillo1                                                                              -- comprobar si hay anulación si s : coincide ( '^%s*<span%s+style%s*=[" \' %s]*background[%-colr]*%s*:([^ \' ";<>]*).-$' ) entonces local c = mw . ustring . gsub ( s , '^%s*<span%s+style%s*=[" \' %s]*background[%-colr]*%s*:([^ \' ";<>]*).-$' , '%1' ) return c fin -- desvincular si es necesario if s : match ( '^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]' ) then s = s : match ( '^%s*%[%[[^%[%]]*%|([^%[%]]*)%]%]' ) fin if s : match ( '^%s*%[[^%[%]%s]*%s([^%[%]]*)%]' ) then s = s : match ( '^%s*%[[^%[%]%s]*%s([^%[%]]*)%]' ) fin si s : match ( '<span[^<>]*>(.-)</span>' ) entonces s = s : match ( '<span[^<>]*>(.-)</span>' ) fin -- obtener las puntuaciones s1 = tonumber ( mw . ustring . gsub ( s o '' , '^%s*([%d%.]+)%s*–%s*([%d%.]+).*' , '%1' ) o '' ) o '' s2 = tonumber ( mw . ustring . gsub ( s o '' , '^%s*([%d%.]+)%s*–%s*([%d%.]+).*' ,'%2' ) o '' ) o '' - devuelve el color si es posible si s1 ~= '' y s2 ~= '' entonces devuelve ( s1 > s2 ) y wc o (( s2 > s1 ) y lc o tc ) de lo contrario devuelve 'transparente' fin fin                                                                formato de función  local_puntuación ( s ) s = mw . ustring . gsub ( s o '' , '^%s*([%d%.]+)%s*[–−—%-]%s*([%d%.]+)' , '%1–%2' ) s = mw . ustring . gsub ( s , '^%s*([%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)' , '%1–%2' ) s = mw . ustring . gsub ( s , '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*%-%s*([%d%.]+)' , '%1–%2' ) s = mw . ustring . gsub ( s , '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*%-%s*([%d%.]+)' , '%1–%2' ) s = mw . cuerda . gsub ( s , '^%s*(%[%[[^%[%]]*%|[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)' , '%1–%2' ) s = mw . cuerda . gsub ( s , '^%s*(%[[^%[%]%s]*%s+[%d%.]+)%s*&[MmNn][Dd][Aa][Ss][Hh];%s*([%d%.]+)' , '%1–%2' ) return s end function p . header ( tt , Args , p_sub , N_teams , team_list , legs , multirowlegs ) local ii , team_code_ii , short_name legs = legs or 1 -- Establecer el ancho de la columna de coincidencia local col_width = Args [ 'match_col_width' ] or '28' -- Obtener algunos valores predeterminados en caso de que no comience en 1 local top_pos = tonumber ( Args [ 'highest_pos' ]) or 1 for l = 1 ,las piernas hacen si hay varias filas y l > 1 entonces se rompen al final                                                      ii = top_pos , N_equipos  hacer team_code_ii = team_list [ ii ] short_name = get_short_name ( Args [ 'short_' .. team_code_ii ], team_code_ii , Args [ 'name_' .. team_code_ii ], Args [ 'short_style' ] o '' ) local bl = legs > 1 y ii == top_pos y ' style="border-left:2px solid #aaa;"' o '' tt = p_sub . colhead ( tt , col_width .. bl , short_name ) fin fin devolver tt fin función p . row ( tt , Args , N_teams , team_list , ii , ii_show , legs , multirowlegs ) - Nota ii es el número de fila que se muestra local jj , fw , bg , result , result_extra , team_code_ii , team_code_jj legs = legs o 1 - Establecer el estilo de la celda de puntuación local matches_style = Args [ 'matches_style' ] o '' team_code_ii = team_list [ ii ] - Obtener algunos valores predeterminados en caso de que no comience en 1 local top_pos = tonumber ( Args [ 'highest_pos' ]) o 1 para l = 1 , legs lo hacen si multirowlegs y l > 1 entonces table.insert ( tt , '|- \n ' ) - Nuevo final de fila para jj = top_pos , N_teams lo hacen                                                             team_code_jj  =  team_list [ jj ] local m = ( legs == 1 ) y 'match_' o 'match' .. l .. '_' resultado = Args [ m .. team_code_ii .. '_' .. team_code_jj ] o '' resultado_extra = Args [ 'result_' .. team_code_ii .. '_' .. team_code_jj ] o '' local bl = legs > 1 y jj == top_pos y 'border-left:2px solid #aaa;' o '' si ii == jj o resultado == 'null' entonces -- Celda sólida fw = 'font-weight:' .. ( ii == ii_show y 'bold' o 'normal' ) .. ';' bg = 'background:transparent;' -- Color de fondo gris para celda sólida si Args [ 'solid_cell' ] == 'grey' entonces tabla.insert ( tt , '| style="' .. fw .. bl .. 'background:#bbb;" | \n ' ) de lo contrario tabla.insert ( tt , '| style="' .. fw .. bl .. bg .. '" | — \n ' ) de lo contrario -- Celda de contenido -- Establecer negrita y fondo fw = 'font-weight:' .. (( ii == ii_show o jj == ii_show ) y 'bold' o 'normal' ) .. ';' bg = 'background:transparente;' - Reformatear guiones si resultado ~= '' entonces resultado = format_score ( resultado                                                                                ) fin - Coloración de fondo si está habilitado si matches_style == 'FBR' y resultado ~= '' entonces si result_extra == 'OT' entonces bg = 'background:' .. get_score_background ( resultado , 'level2' ) .. ';' de lo contrario si result_extra == 'PK' entonces bg = 'background:' .. get_score_background ( resultado , 'level3' ) .. ';' de lo contrario bg = 'background:' .. get_score_background ( resultado , '' ) .. ';' fin de lo contrario si matches_style == 'BSR' y resultado ~= '' entonces si result_extra == 'OT' entonces bg = 'background:' .. get_score_background ( resultado , 'level3' ) .. ';' de lo contrario, si resultado_extra == 'OTL' entonces bg = 'fondo:' .. obtener_puntuación_fondo ( '0–1' , 'nivel3' ) .. ';' de lo contrario, si resultado_extra == 'OTW' entonces bg = 'fondo:' .. obtener_puntuación_fondo ( '1–0' , 'nivel3' ) .. ';' de lo contrario, si resultado_extra == 'L' entonces bg = 'fondo:' .. obtener_puntuación_fondo ( '0–1' , '' ) .. ';' de lo contrario, si resultado_extra == 'W' entonces bg = 'fondo:' .. obtener_puntuación_fondo ( '1–0' , '' ) ..';' de lo contrario bg = 'background:' .. get_score_background ( resultado , '' ) ..                                                                                                  ';' fin fin tabla.insert ( tt , '|style="white-space:nowrap;' .. fw .. bl .. bg .. '" |' .. resultado .. ' \n ' ) fin fin fin return tt fin return p