(попытка отследить ошибку) |
м (Защищена страница «Модуль:Таблица обновления»: проект, связанный с модулем, закрыт ([Редактирование=Разрешено только администраторам]…) |
||
(не показано 19 промежуточных версий 2 участников) | |||
Строка 1: | Строка 1: | ||
p = {} |
p = {} |
||
− | p.synctableMigration = function(f) |
+ | p.synctableMigration = function(f) -- переход от старой модели «Синхронизационная таблица» |
local args = f.args or f |
local args = f.args or f |
||
if f == mw.getCurrentFrame() and args[1] == nil then |
if f == mw.getCurrentFrame() and args[1] == nil then |
||
Строка 27: | Строка 27: | ||
if (syncDay == "—") then |
if (syncDay == "—") then |
||
− | table.insert(output, '\t\t["дата |
+ | table.insert(output, '\t\t["дата обновления"] = nil,\n') |
else |
else |
||
− | table.insert(output, ('\t\t["дата |
+ | table.insert(output, ('\t\t["дата обновления"] = { ["день"] = %s, ["месяц"] = %s, ["год"] = %s },\n'):format(syncDay, syncMonth, syncYear)) |
end |
end |
||
Строка 50: | Строка 50: | ||
end |
end |
||
− | p. |
+ | p.updateTable = function(f) |
local args = f.args or f |
local args = f.args or f |
||
if f == mw.getCurrentFrame() and args[1] == nil then |
if f == mw.getCurrentFrame() and args[1] == nil then |
||
Строка 57: | Строка 57: | ||
local statuses = { |
local statuses = { |
||
− | ["не начато"] = {"FFCCCC", "CC2929", " |
+ | ["не начато"] = {"FFCCCC", "CC2929", "Обновление не проводилось", 0}, |
− | ["в процессе"] = {"FFFF99", "666614", " |
+ | ["в процессе"] = {"FFFF99", "666614", "Страница закреплена за участником", 0}, |
− | ["подтверждение"] = {"CCCCFF", "2929CC", "Требуется подтверждение |
+ | ["подтверждение"] = {"CCCCFF", "2929CC", "Требуется подтверждение обновления", 0}, |
− | ["частично"] = {"CCFF99", "3D6614", " |
+ | ["частично"] = {"CCFF99", "3D6614", "Обновление завершено (по мере возможности)", 0}, |
− | ["завершено"] = {"99FF99", "146614", " |
+ | ["завершено"] = {"99FF99", "146614", "Обновление завершено", 0}, |
− | ["устарело"] = {"FFCC99", "995B1F", "Требуется |
+ | ["устарело"] = {"FFCC99", "995B1F", "Требуется повторное обновление", 0}, |
− | ["сильно устарело"] = {"CC0000", "FFFFFF", "Требуется |
+ | ["сильно устарело"] = {"CC0000", "FFFFFF", "Требуется срочное повторное обновление!", 0}, |
["неизвестно"] = {"CCCCCC", "666666", "Неизвестно или ошибочный статус", 0} |
["неизвестно"] = {"CCCCCC", "666666", "Неизвестно или ошибочный статус", 0} |
||
} |
} |
||
local total = 0 |
local total = 0 |
||
local tStatusOrder = {"не начато", "в процессе", "подтверждение", "частично", "завершено", "устарело", "сильно устарело", "неизвестно"} |
local tStatusOrder = {"не начато", "в процессе", "подтверждение", "частично", "завершено", "устарело", "сильно устарело", "неизвестно"} |
||
+ | |||
+ | local priorityNames = { |
||
+ | {function(p) return p >= 0.95 end, "Срочный"}, |
||
+ | {function(p) return p >= 0.8 and p < 0.95 end, "Очень высокий"}, |
||
+ | {function(p) return p >= 0.65 and p < 0.8 end, "Высокий"}, |
||
+ | {function(p) return p > 0.55 and p < 0.65 end, "Выше среднего"}, |
||
+ | {function(p) return p >= 0.45 and p <= 0.55 end, "Средний"}, |
||
+ | {function(p) return p > 0.35 and p < 0.45 end, "Ниже среднего"}, |
||
+ | {function(p) return p > 0.2 and p <= 0.35 end, "Низкий"}, |
||
+ | {function(p) return p > 0.05 and p <= 0.2 end, "Очень низкий"}, |
||
+ | {function(p) return p <= 0.05 end, "Минимальный"} |
||
+ | } |
||
local output = {} |
local output = {} |
||
− | table.insert(output, '{|class="wikitable collapsible collapsed" style="width: 100%; text-align: center"\n!colspan="8"|') |
+ | table.insert(output, '{|class="wikitable sortable collapsible collapsed" style="width: 100%; text-align: center"\n!colspan="8"|') |
local content = {} |
local content = {} |
||
− | + | if not mw.title.new(args[1]).exists then |
|
+ | return '<strong class=error>Модуль [[' .. args[1] .. ']] отсутствует. Требуется его создать.</strong>' |
||
+ | end |
||
+ | |||
+ | local updatetable = mw.loadData(args[1]) |
||
− | for index, value in ipairs( |
+ | for index, value in ipairs(updatetable) do |
− | mw.log(index) |
||
local originalName = value["оригинал"] |
local originalName = value["оригинал"] |
||
local translationName = value["перевод"] |
local translationName = value["перевод"] |
||
Строка 82: | Строка 97: | ||
local priority = value["приоритет"] |
local priority = value["приоритет"] |
||
local assignee = value["закреплено за"] |
local assignee = value["закреплено за"] |
||
− | local |
+ | local updateDate = value["дата обновления"] |
+ | local isNotTranslation = value["не перевод"] |
||
local originalRevision = value["версия оригинала"] |
local originalRevision = value["версия оригинала"] |
||
local translationRevision = value["версия перевода"] |
local translationRevision = value["версия перевода"] |
||
local comment = value["комментарий"] |
local comment = value["комментарий"] |
||
+ | if isNotTranslation then |
||
⚫ | |||
+ | table.insert(content, ("|-\n|[[%s]]\n|''(не перевод)''\n"):format(translationName)) |
||
+ | else |
||
⚫ | |||
+ | end |
||
local actualStatus |
local actualStatus |
||
Строка 93: | Строка 113: | ||
actualStatus = "неизвестно" |
actualStatus = "неизвестно" |
||
elseif status == "частично" or status == "завершено" then |
elseif status == "частично" or status == "завершено" then |
||
− | local |
+ | local daysSinceUpdate = math.floor(os.difftime(os.time(), os.time({ |
− | year=tonumber( |
+ | year=tonumber(updateDate["год"]), |
− | month=tonumber( |
+ | month=tonumber(updateDate["месяц"]), |
− | day=tonumber( |
+ | day=tonumber(updateDate["день"]) |
})) / 86400) |
})) / 86400) |
||
− | if |
+ | if daysSinceUpdate >= 90 then |
actualStatus = "сильно устарело" |
actualStatus = "сильно устарело" |
||
− | elseif |
+ | elseif daysSinceUpdate >= 30 then |
actualStatus = "устарело" |
actualStatus = "устарело" |
||
else |
else |
||
Строка 114: | Строка 134: | ||
table.insert(content, ('|style="background: #%s; color: #%s"|%s\n'):format(statusTable[1], statusTable[2], statusTable[3])) |
table.insert(content, ('|style="background: #%s; color: #%s"|%s\n'):format(statusTable[1], statusTable[2], statusTable[3])) |
||
− | local priorityColorRed = math.floor(priority * 255) |
+ | local priorityColorRed = priority > 0.5 and 255 or math.floor(2 * priority * 255) |
− | local priorityColorGreen = math.floor(( |
+ | local priorityColorGreen = priority < 0.5 and 255 or 255 - math.floor(2 * (priority - 0.5) * 255) |
local priorityColor = ("rgb(%d, %d, 0)"):format(priorityColorRed, priorityColorGreen) |
local priorityColor = ("rgb(%d, %d, 0)"):format(priorityColorRed, priorityColorGreen) |
||
+ | local priorityName |
||
⚫ | |||
+ | for index2, value2 in ipairs(priorityNames) do |
||
+ | if value2[1](priority) then |
||
+ | priorityName = value2[2] |
||
+ | break |
||
+ | end |
||
+ | end |
||
⚫ | |||
if not assignee then |
if not assignee then |
||
Строка 125: | Строка 152: | ||
end |
end |
||
− | if |
+ | if not updateDate then |
table.insert(content, '|—\n') |
table.insert(content, '|—\n') |
||
else |
else |
||
− | table.insert(content, ('|%s.%s.%s\n'):format( |
+ | table.insert(content, ('|%s.%s.%s\n'):format(updateDate["день"], updateDate["месяц"], updateDate["год"])) |
end |
end |
||
− | if |
+ | if isNotTranslation then |
+ | table.insert(content, ("|[[Special:Diff/%s/0|Страница здесь]] ''(не перевод)''\n"):format(translationRevision)) |
||
+ | elseif not originalRevision then |
||
table.insert(content, '|—\n') |
table.insert(content, '|—\n') |
||
else |
else |
||
− | table.insert(content, ('|[[:en:Special:Diff/%s/0|Оригинал]], [[Special:Diff/%s/0|перевод]]\n'):format( |
+ | table.insert(content, ('|[[:en:Special:Diff/%s/0|Оригинал]], [[Special:Diff/%s/0|перевод]]\n'):format(tostring(originalRevision), tostring(translationRevision))) |
end |
end |
||
Строка 159: | Строка 188: | ||
end |
end |
||
table.insert(output, table.concat(tStatusCells) .. '</tr></table>') |
table.insert(output, table.concat(tStatusCells) .. '</tr></table>') |
||
− | table.insert(output, '\n|-\n! |
+ | table.insert(output, '\n|-\n!Страница здесь\n!Страница-оригинал\n!Статус\n!Приоритет\n!Закреплено за\n!Дата обновления\n!Базовые версии\n!Комментарий\n') |
table.insert(output, table.concat(content)) |
table.insert(output, table.concat(content)) |
||
table.insert(output, '|}') |
table.insert(output, '|}') |
||
+ | table.insert(output, ('<small>\'\'Таблица сгенерирована функцией <code>updateTable</code> модуля «[[Модуль:Таблица обновления|Таблица обновления]]» на основе данных из страницы [[%s]].\'\'</small>'):format(args[1])) |
||
+ | |||
return table.concat(output) |
return table.concat(output) |
Текущая версия от 13:04, 25 июля 2017
p = {}
p.synctableMigration = function(f) -- переход от старой модели «Синхронизационная таблица»
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
end
local output = {}
table.insert(output, '<pre>\nreturn {\n')
for k, v in ipairs(args) do
local articleName, originalName, status, assignedUser, syncDay, syncMonth, syncYear, baseRevEn, baseRevRu = v:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
baseRevRu = mw.text.trim(baseRevRu)
table.insert(output, '\t{\n')
table.insert(output, ('\t\t["оригинал"] = "%s",\n'):format(originalName))
table.insert(output, ('\t\t["перевод"] = "%s",\n'):format(articleName))
table.insert(output, ('\t\t["статус"] = "%s",\n'):format(status))
table.insert(output, '\t\t["приоритет"] = 0.5,\n')
if (assignedUser == "—") then
table.insert(output, '\t\t["закреплено за"] = nil,\n')
else
table.insert(output, ('\t\t["закреплено за"] = "%s",\n'):format(assignedUser))
end
if (syncDay == "—") then
table.insert(output, '\t\t["дата обновления"] = nil,\n')
else
table.insert(output, ('\t\t["дата обновления"] = { ["день"] = %s, ["месяц"] = %s, ["год"] = %s },\n'):format(syncDay, syncMonth, syncYear))
end
if (baseRevEn == "—") then
table.insert(output, '\t\t["версия оригинала"] = nil,\n')
table.insert(output, '\t\t["версия перевода"] = nil,\n')
else
table.insert(output, ('\t\t["версия оригинала"] = %s,\n'):format(baseRevEn))
table.insert(output, ('\t\t["версия перевода"] = %s,\n'):format(baseRevRu))
end
table.insert(output, '\t\t["комментарий"] = nil\n')
table.insert(output, '\t},\n')
end
table.insert(output, '}\n</pre>\n')
return table.concat(output)
end
p.updateTable = function(f)
local args = f.args or f
if f == mw.getCurrentFrame() and args[1] == nil then
args = f:getParent().args
end
local statuses = {
["не начато"] = {"FFCCCC", "CC2929", "Обновление не проводилось", 0},
["в процессе"] = {"FFFF99", "666614", "Страница закреплена за участником", 0},
["подтверждение"] = {"CCCCFF", "2929CC", "Требуется подтверждение обновления", 0},
["частично"] = {"CCFF99", "3D6614", "Обновление завершено (по мере возможности)", 0},
["завершено"] = {"99FF99", "146614", "Обновление завершено", 0},
["устарело"] = {"FFCC99", "995B1F", "Требуется повторное обновление", 0},
["сильно устарело"] = {"CC0000", "FFFFFF", "Требуется срочное повторное обновление!", 0},
["неизвестно"] = {"CCCCCC", "666666", "Неизвестно или ошибочный статус", 0}
}
local total = 0
local tStatusOrder = {"не начато", "в процессе", "подтверждение", "частично", "завершено", "устарело", "сильно устарело", "неизвестно"}
local priorityNames = {
{function(p) return p >= 0.95 end, "Срочный"},
{function(p) return p >= 0.8 and p < 0.95 end, "Очень высокий"},
{function(p) return p >= 0.65 and p < 0.8 end, "Высокий"},
{function(p) return p > 0.55 and p < 0.65 end, "Выше среднего"},
{function(p) return p >= 0.45 and p <= 0.55 end, "Средний"},
{function(p) return p > 0.35 and p < 0.45 end, "Ниже среднего"},
{function(p) return p > 0.2 and p <= 0.35 end, "Низкий"},
{function(p) return p > 0.05 and p <= 0.2 end, "Очень низкий"},
{function(p) return p <= 0.05 end, "Минимальный"}
}
local output = {}
table.insert(output, '{|class="wikitable sortable collapsible collapsed" style="width: 100%; text-align: center"\n!colspan="8"|')
local content = {}
if not mw.title.new(args[1]).exists then
return '<strong class=error>Модуль [[' .. args[1] .. ']] отсутствует. Требуется его создать.</strong>'
end
local updatetable = mw.loadData(args[1])
for index, value in ipairs(updatetable) do
local originalName = value["оригинал"]
local translationName = value["перевод"]
local status = value["статус"]
local priority = value["приоритет"]
local assignee = value["закреплено за"]
local updateDate = value["дата обновления"]
local isNotTranslation = value["не перевод"]
local originalRevision = value["версия оригинала"]
local translationRevision = value["версия перевода"]
local comment = value["комментарий"]
if isNotTranslation then
table.insert(content, ("|-\n|[[%s]]\n|''(не перевод)''\n"):format(translationName))
else
table.insert(content, ("|-\n|[[%s]]\n|[[:en:%s]]\n"):format(translationName, originalName))
end
local actualStatus
if not statuses[status] then
actualStatus = "неизвестно"
elseif status == "частично" or status == "завершено" then
local daysSinceUpdate = math.floor(os.difftime(os.time(), os.time({
year=tonumber(updateDate["год"]),
month=tonumber(updateDate["месяц"]),
day=tonumber(updateDate["день"])
})) / 86400)
if daysSinceUpdate >= 90 then
actualStatus = "сильно устарело"
elseif daysSinceUpdate >= 30 then
actualStatus = "устарело"
else
actualStatus = status
end
else
actualStatus = status
end
statusTable = statuses[actualStatus]
statusTable[4] = statusTable[4] + 1
table.insert(content, ('|style="background: #%s; color: #%s"|%s\n'):format(statusTable[1], statusTable[2], statusTable[3]))
local priorityColorRed = priority > 0.5 and 255 or math.floor(2 * priority * 255)
local priorityColorGreen = priority < 0.5 and 255 or 255 - math.floor(2 * (priority - 0.5) * 255)
local priorityColor = ("rgb(%d, %d, 0)"):format(priorityColorRed, priorityColorGreen)
local priorityName
for index2, value2 in ipairs(priorityNames) do
if value2[1](priority) then
priorityName = value2[2]
break
end
end
table.insert(content, ('|style="background: %s" data-sort-value="%s"|%s\n'):format(priorityColor, priority, priorityName))
if not assignee then
table.insert(content, '|—\n')
else
table.insert(content, ('|[[User:%s|%s]]\n'):format(assignee, assignee))
end
if not updateDate then
table.insert(content, '|—\n')
else
table.insert(content, ('|%s.%s.%s\n'):format(updateDate["день"], updateDate["месяц"], updateDate["год"]))
end
if isNotTranslation then
table.insert(content, ("|[[Special:Diff/%s/0|Страница здесь]] ''(не перевод)''\n"):format(translationRevision))
elseif not originalRevision then
table.insert(content, '|—\n')
else
table.insert(content, ('|[[:en:Special:Diff/%s/0|Оригинал]], [[Special:Diff/%s/0|перевод]]\n'):format(tostring(originalRevision), tostring(translationRevision)))
end
if not comment then
table.insert(content, '|—\n')
else
table.insert(content, ('|%s\n'):format(comment))
end
end
local tStatuses = {}
for i, v in ipairs(tStatusOrder) do
local statusCount = statuses[v][4]
table.insert(tStatuses, v .. ': ' .. statusCount)
total = total + statusCount
end
table.insert(output, '\n<table style="width: 80%; line-height: 50%; border: 1px solid gray; margin: 0.5em 10%; border-collapse: collapse" title="' .. table.concat(tStatuses, ', ') .. '"><tr>')
local tStatusCells = {}
for i, v in ipairs(tStatusOrder) do
local statusCount = statuses[v][4]
if statusCount ~= 0 then
table.insert(tStatusCells, '<td style="background-color: #' .. statuses[v][1] .. '; width: ' .. math.floor((statusCount/total) * 10000) / 100 .. '%"> </td>')
end
end
table.insert(output, table.concat(tStatusCells) .. '</tr></table>')
table.insert(output, '\n|-\n!Страница здесь\n!Страница-оригинал\n!Статус\n!Приоритет\n!Закреплено за\n!Дата обновления\n!Базовые версии\n!Комментарий\n')
table.insert(output, table.concat(content))
table.insert(output, '|}')
table.insert(output, ('<small>\'\'Таблица сгенерирована функцией <code>updateTable</code> модуля «[[Модуль:Таблица обновления|Таблица обновления]]» на основе данных из страницы [[%s]].\'\'</small>'):format(args[1]))
return table.concat(output)
end
return p