(исправление ошибки) |
(попытка исправить ошибку) |
||
Строка 152: | Строка 152: | ||
table.insert(content, '|—\n') |
table.insert(content, '|—\n') |
||
else |
else |
||
− | table.insert(content, ('|[[:en:Special:Diff/%s/0|Оригинал]], [[Special:Diff/%s/0|перевод]]\n'):format(baseRevEn, baseRevRu)) |
+ | table.insert(content, ('|[[:en:Special:Diff/%s/0|Оригинал]], [[Special:Diff/%s/0|перевод]]\n'):format(tostring(baseRevEn), tostring(baseRevRu))) |
end |
end |
||
Версия от 09:19, 8 мая 2016
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.synctable = 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 = {}
local synctable = mw.loadData(args[1])
for index, value in ipairs(synctable) do
local originalName = value["оригинал"]
local translationName = value["перевод"]
local status = value["статус"]
local priority = value["приоритет"]
local assignee = value["закреплено за"]
local syncDate = value["дата синхронизации"]
local originalRevision = value["версия оригинала"]
local translationRevision = value["версия перевода"]
local comment = value["комментарий"]
table.insert(content, ("|-\n|[[%s]]\n|[[:en:%s]]\n"):format(translationName, originalName))
local actualStatus
if not statuses[status] then
actualStatus = "неизвестно"
elseif status == "частично" or status == "завершено" then
local daysSinceSync = math.floor(os.difftime(os.time(), os.time({
year=tonumber(syncDate["год"]),
month=tonumber(syncDate["месяц"]),
day=tonumber(syncDate["день"])
})) / 86400)
if daysSinceSync >= 90 then
actualStatus = "сильно устарело"
elseif daysSinceSync >= 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 syncDate then
table.insert(content, '|—\n')
else
table.insert(content, ('|%s.%s.%s\n'):format(syncDate["день"], syncDate["месяц"], syncDate["год"]))
end
if not originalRevision then
table.insert(content, '|—\n')
else
table.insert(content, ('|[[:en:Special:Diff/%s/0|Оригинал]], [[Special:Diff/%s/0|перевод]]\n'):format(tostring(baseRevEn), tostring(baseRevRu)))
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, '|}\n')
table.insert(output, ('<small>\'\'Таблица сгенерирована модулем [[Модуль:Синхронизационная таблица|Синхронизационная таблица]] на основе данных из страницы [[%s]].\'\'</small>'):format(args[1]))
return table.concat(output)
end
return p