Module:AuthorSummary

Documentation for this module may be created at Module:AuthorSummary/doc

local getArgs = require('Module:Arguments').getArgs;
local defArgs = require('Module:Arguments').defaultArgs;
local authorSummary = {};

function authorSummary.vbar( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];

  local Ja = {} -- journals
  local Yr = {} -- publication years
  local first = 10000
  local last = 0
  for au, ja, yr in arg:gmatch("([%a:_]+),([%a_\.]+),(%d+),(%d+)")
        do table.insert(Ja, ja);
        yr = tonumber(yr)
        if (yr < first) then first = yr end
        if (yr > last) then last = yr end
        if (Yr[yr] == null) then Yr[yr] = 1 else Yr[yr] = 1 + Yr[yr]
        end
      end
  step = math.ceil((last - first+1)/10)
  output = "size=500x200;title=publication chart;legend=0.8x0;label="
  if (step > 1)
    then output = output..first.."\\n-"..(first+step-1)
    else output = output..first
  end
  loop = math.ceil((last - first+1)/step)
  for i=first+step, first+(step*loop)-1, step do
    if (step > 1)
      then output = output..","..i.."\\n-"..(i+step-1)
      else output = output..","..i
    end
  end
  for i=0, step-1 do
    if (step == 1)
      then output = output..";count=" 
      else output = output..";mod "..i.."="
    end
    for y = first, first+(step*loop)-1 do
      if (y % step == i) then
        if (Yr[y] == nil)
          then output = output.."0,"
          else output = output..Yr[y]..","
        end
      end
    end
  end
  return output..";"
end

function authorSummary.coauthors( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];

  local author = arg:gmatch("%S+");
  local Au = {}; -- authors
  local count =0;
  local total =0;
  local paper =0.0;
  for aus, ja, yr in arg:gmatch("([%a:_]+),([%a_\.]+),(%d+),(%d+)") do
    paper = paper + 1;
    for au in string.gmatch(aus,"[%a_]+") do
      if (author ~= au) then
        if (Au[au] == null)
          then Au[au] = 1; count = count + 1;
          else Au[au] = 1 + Au[au];
        end
      end
      total = total + 1;
    end
  end
  local output = count .. " coauthors total.<br>(average"
  .. string.format("%.1f",total / paper) .. " / report)\n";
  for k, v in pairs(Au) do
    output = output .. "# {{#volatile:AuthorSummary|" .. k .. " (" .. v .. ")|" .. k .. "|Reference}}\n";
  end
  return frame:preprocess(output);
end

return authorSummary;