יחידה:מועדון החברים/טבלת מפגשים

מתוך ויקיפדיה, האנציקלופדיה החופשית

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:מועדון החברים/טבלת מפגשים/תיעוד

local p = {}

yes = "[[קובץ:Green check.svg|15px]]"
no = "[[קובץ:X mark.svg|15px]]"
maybe = "[[קובץ:Symbol question.svg|15px]] "
maybe = maybe .. '<span style="color: #0000C0;">'
maybe = maybe .. "'''מתלבט/ת'''</span>"

-- date time calculator --
datetime = {day, month, year}
datetime.baseDate = {1,1,2022,7}
datetime.dayList = {"ראשון", "שני", "שלישי", "רביעי", "חמישי", "שישי", "שבת"}
datetime.monthList = {"ינואר", "פברואר", "מרץ", "אפריל", "מאי", "יוני", "יולי", "אוגוסט", "ספטמבר", "אוקטובר", "נובמבר", "דצמבר"}
datetime.daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

function datetime.isLeapYear(year)
  return year % 4 == 0 and year % 100 > 0 or year % 400 == 0
end

function datetime.calculateDiffInDays(month, year)
  local function daysInMonth(month, year)
      if month == 2 and datetime.isLeapYear(year)
      then
        return datetime.daysInMonth[2] + 1
      end
      return datetime.daysInMonth[month]
  end
  if year == datetime.year -- good for 2022, after 2022 we should add "else" tag
  then
    if month == datetime.month
    then
      return datetime.day + datetime.baseDate[4] - 2 -- ??
    end
    return daysInMonth(month, year) + datetime.calculateDiffInDays(month+1, year)
  end
  end

--datetime.day = 3
--datetime.month = 4
--datetime.year = 2022

function datetime.incDay()
  datetime.day = datetime.day + 1
  if datetime.day > datetime.daysInMonth[datetime.month]
  then
    datetime.day = 1
    datetime.month = datetime.month + 1
    if datetime.month > 12
    then
      datetime.month = 1
      datetime.year = datetime.year + 1
    end
  end
end

function datetime.getMonth()
  return datetime.monthList[datetime.month]
end

function datetime.getDay()
  return datetime.dayList[datetime.calculateDiffInDays(1,2022) % 7 + 1]
end

--print(datetime.getDay())
-- END date time calculator --

local prefix = [[
{| class="wikitable sortable" style="margin:.5em auto; text-align: center;"
]]
local suffix = [[
|-
|}
]]

function p.printTitle()
  
  
  --mytable = datetime.day .. " " .. datetime.month --.. " " .. datetime.year
  
  
  p.mytable = p.mytable .. "![[ויקיפדיה:ויקיפד|ויקיפד]]\n"
 -- mytable = mytable .. "!next1\n"
 -- mytable = mytable .. "!next2\n"
  
	for i=0, p.range-1, 1 do
		
		p.mytable = p.mytable .. "!" .. datetime.day .. " ב" .. datetime.getMonth() .. "\n"
		
    p.mytable =p. mytable .. datetime.getDay() .. "\n"
		
    datetime.incDay()
  end
	
--	return datetime.day
  --return mytable
end

function p.printSum()
	local function printvalue(val)
		local result
		if val < 0
		then
			result = 'style="background: #ff0000;| '
			return result .. (0 - val) .. "-"
		elseif val == 0
		then
			result = 'style="background: #ffff00;| '
			return result .. 0
		end
		result = 'style="background: #00ff00;| '
		return result .. val
	end
	p.mytable = p.mytable .. "!<center>'''ציון'''</center>".. "\n"
	for i=1, p.range, 1
	do
		p.mytable = p.mytable .. "| " .. printvalue(tonumber(p.sum[i])) .. "\n"
	end
end

function p.init(args)
	p.range = tonumber(args.args["טווח"])
	p.numberOfWikipedians = tonumber(args.args["מספר חברים בקבוצה"])
	datetime.day = tonumber(args.args["יום"])
	datetime.month = tonumber( args.args["חודש"])
	datetime.year = tonumber( args.args["שנה"])
	p.mytable = prefix
	p.sum = {}
	for i=1, p.range, 1
	do
		p.sum[i] = 0	
	end
	end

function p.setColor()
	local cyan = "#00FFFF"
   local turquoise = "#30D5C8"
	
	if p.color == 1
	  	then
	  	p.mytable = p.mytable .. '| style="background: '.. cyan ..'; "'
	  	else
	  	p.mytable = p.mytable .. '| style="background: '.. turquoise ..'; "'	
	  	end
	end

p.main = function (args)
	p.init(args)
  p.printTitle()
   p.mytable = p.mytable .. "\n|-\n"
   
   p.color = 1
  
  for wiki=1, p.numberOfWikipedians, 1 do
  	
  	if p.color == 1 then p.color = 0 else p.color = 1 end
  	
  	name =   "ויקיפד".. wiki
  	
  	--p.setColor()
  	p.mytable = p.mytable .. "!" .. args.args[name] .. "\n"
	  	
	  for st=1, p.range, 1 do
	  	
	  	p.setColor()
	  	
	  	p.mytable = p.mytable .. "|"
	  	index = wiki .. "_" .. st
	  	if args.args[index] == "כן"
		then 
	  		 p.mytable = p.mytable .. yes
	  		 p.sum[st] = p.sum[st] + 1
	  	elseif args.args[index] == "לא"
	  	then
	  		p.mytable = p.mytable .. no
	  		p.sum[st] = p.sum[st] - 1
	  	elseif args.args[index] == "אולי" or args.args[index] == "מתלבט" or args.args[index] == "מתלבטת"
	  	then
	  		p.mytable = p.mytable .. maybe
	  	end
		p.mytable = p.mytable .. "\n"
  	end
  	p.mytable = p.mytable .. "|-" .. "\n"
  end
  p.printSum()
  return p.mytable .. suffix
end
--main({3,4,2022})


return p