وحدة:ملعب/Mr. Ibrahem/cey

من ويكيبيديا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث
توثيق الوحدة[أنشئ] [استخدامات] [قوالب]
يمكن إنشاء توثيق الوحدة في صفحة الشرح
local p = {}

function p.new_classification(frame, s)
	local country = true
	local showgap = false
	
	if wiki == 'da' then country = false end -- those wikis do not want to show the country column as standard
	if wiki == 'es' then country = false end -- those wikis do not want to show the country column as standard
	local s = s
	local h = {
		rider={1, "", "", "", '', ""}, -- rank, rider ID, riderGender, nationality ID, flag ID, team ID
		jersey={""}, -- lots of jerseyID
		value={'', '', '', ''} -- points, time, time_gap, speed
		}
	local available_list = available_list
	local entity = mw.wikibase.getEntityObject( s.item )
	
	--[=[ It is possible to give the classification tables in the article commands to change the standard behaviour. They could look like this:
	{{Cycling race/teamsclassificationbytime|Q18574623|newline=false|country=true}}
	{{Cycling race/teamsclassificationbytime|Q18574623|country= false|newline=false}}
	{{Cycling race/teamsclassificationbypoints|Q18574623|newline =true|country=true}}
	{{Cycling race/teamsclassificationbypoints|Q18574623|newline= true}}
	{{Cycling race/teamsclassificationbypoints|Q18574623|newline = false|country=false}}
	{{Cycling race/teamsclassificationbytime|Q18574623|newline=true|country=true}}
	
	One additional parameter is "newline" with the values "true" or "false". "newline" says, if there is a line brake after the table. Standard is 
	no line break after the tables stageclassification and teamtimetrialclassification. 
	The second parameter is "country" with the values "true" or "false". "country" tells the module to print the country column or not. 
	Most wikis have as standard to print the country columns, some wikis prefer as standard not to show the country column. A few lines above, 
	the command "if wiki == 'da' then country = false end" tells that daWiki do not want to see the country colums as standard. You can add your wiki
	here in, if you do not want to see them as standard. With the new parameter editors are able to tell the module in the article what to do.  
	]=]

		local function jersey(h)
			local jersey
			local jersey_name
			local jersey_string = ' '

			jerseys = {
			['Q24257871'] = {file = 'Jersey yellow.svg', 
				name_ar = 'قميص أصفر لمتصدر الترتيب العام',
				name_fr = 'maillot jaune de leader du classement général',
				name_ru = 'жёлтая майка лидера генеральной классификации'
				},	
			['Q24645209'] = {file = 'Jersey green.svg', 
				name_ar = 'قميص أخضر لمتصدر ترتيب النقاط',
				name_fr = 'maillot vert de leader du classement par points',
				name_ca = 'mallot verd del líder de la classificació per punts',
				name_ru = 'зелёная майка лидера очковой классификации'
				},
			['Q24645383'] = {file = 'Jersey white.svg', 
				name_ar = 'قميص أبيض لمتصدر ترتيب الشباب',
				name_fr = 'maillot blanc de leader du classement du meilleur jeune',
				name_ru = 'белая майка лидера молодёжной классификации',
				name_de = 'weißes Trikot des Führenden der Nachwuchswertung'
				},
			}

			if type(h) == 'table' and h[1] ~= '' then mw.log(h[1])
				for i,k in ipairs(h) do 
					if jerseys[h[i]] ~= nil then mw.log('>')
						jersey = 'File:'.. jerseys[h[i]].file
						local name
						name = 'name_'..wiki
						jersey_name = jerseys[h[i]][name] or jerseys[h[i]]['name_en'] or jerseys[h[i]]['name_fr'] or '' 
						if jersey_name~='' then jersey_string = jersey_string .. '[['..jersey..'|20px|'..jersey_name..']]'
						else jersey_string = jersey_string .. '[['..jersey..'|20px]]'
						end
					else
						local entity_jersey = mw.wikibase.getEntity(h[i])
						pcall(function()
							jersey = 'File:'.. entity_jersey.claims['P18'][1].mainsnak.datavalue.value
							jersey_name = entity_jersey:getLabel('ar') or entity_jersey:getLabel( 'en' ) or entity_jersey:getLabel( 'fr' ) or ''
							if jersey_name~='' then jersey_string = jersey_string .. '[['..jersey..'|20px|'..jersey_name..']]'
							else jersey_string = jersey_string .. '[['..jersey..'|20px]]'
							end
						end)
					end
				end
				return jersey_string
			else return ''
			end
		end -- function end

	local startOfSeason = '' --'+2016-01-01T00:00:00Z'
	pcall(function() startOfSeason = entity.claims["P580"][1].mainsnak.datavalue.value.time end)
	if startOfSeason == '' then
		if pcall(function() startOfSeason = entity.claims["P585"][1].mainsnak.datavalue.value.time end) then
		else
			local Sitelink = entity:getSitelink(wiki .. 'wiki') or entity:getSitelink('enwiki') or entity:getSitelink('frwiki') or entity:getSitelink('dewiki') or '' 
			if Sitelink == '' then return '> Wikidata is missing data about the start time (P580) and end time (P582) of the season'
			else startOfSeason = '+'..string.match(Sitelink, '%d%d%d%d' ) ..'-01-01T00:00:00Z' 
			end
		end
	end

	local v = ''
	local plus = ''

	local localFrame
	if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name
		then localFrame = frame:getParent() else localFrame = frame end
	if localFrame.args[1] ~= nil then localFrame.args[1] = string.gsub(localFrame.args[1], "%c", "") end

	if localFrame.args.country ~= nil then -- switch country column on or off in the article
		if localFrame.args.country == 'true' then country = true end
		if localFrame.args.country == 'false' then country = false end
	end

	local tableStyle, tableNewline
	if localFrame.args.newline == 'false' then -- parameter newline in WP article is 'false'
		tableStyle = "float:right; margin-right:0.5em;"-- border:1px solid rgb(200,200,200)"
		tableNewline = ''
	end
	if localFrame.args.newline == 'true' then -- parameter newline in WP article is 'true'
		tableStyle = ""--border:1px solid rgb(200,200,200)" 
		tableNewline = 'left'--'<br style="clear:left;">'    -- clear:left
	end
	if localFrame.args.newline == nil then -- no second parameter, compatible to the old code
		if s.property == 'P2417' then --stageclassification
			tableStyle = "float:right; margin-right:0.5em;"-- border:1px solid rgb(200,200,200)"
			tableNewline = ''
		else
			tableStyle = ""--"border:1px solid rgb(200,200,200)" 
			tableNewline = 'left'--'<br style="clear:left;">' -- everything else      -- clear:left
		end 
	end

	local tableHeader2_size = table.getn(s.header_2)
	-- '{{بداية نتيجة سباق ركوب الدراجات|style='.. tableStyle.. '\n'..
	--local tableStart = '{| border="0" cellspacing="0" cellpadding="0"\n! colspan="'.. tostring(tableHeader2_size + 1) .. '"'..
	local tableStart = '{{بداية نتيجة سباق ركوب الدراجات|style='.. tableStyle.. '|colspan='.. tostring(tableHeader2_size + 1) .. ''
	--	..	' style="padding:2px 2px; text-align:center; background-color:#FFDF80" | '
	
	if s.team_classification == true or s.property == 'P3497' then
		tableStart = tableStart .. '|teams=t'
	end
	if s.header_2[5] ~= 6 then -- for table teamtimetrialclassification, dont adds speed
		tableStart = tableStart .. '|speed=f'
	end	
	--if (s.header_2[4] ~=4) or (s.property ~= 'P3497') or (s.header_2[4] ~= 5) then --  dont adds gap
		--tableStart = tableStart .. '|gap=f'
	--end	
	if s.property == 'P3494' or  s.property == 'P3496' -- points
		then tableStart = tableStart .. '|points=t'
	end
	
	local tableHeader1 = '|title=' .. 
				--..'<span style="float:right">[[File:Wikidata-logo S.svg|24px|link=d:'
				--..s.item.. '#'.. s.property..']]</span>'
				s.header_function (wiki, s.header_1)  ..
				'|d='.. s.item .. '|property='.. s.property  ..
				'}}\n'

	local tableHeader2 = '|-\n'
	for i,k in ipairs(s.header_2) do
		if i==1 then tableHeader2 = tableHeader2.. '!  colspan="2" nowrap style="text-align:center;padding:2px 2px"|'.. s.header_function (wiki, k) end
		if i==2 and available_list==true and country == true then tableHeader2 = tableHeader2.. '\n! nowrap style="text-align:center;padding:2px 2px"|'.. s.header_function (wiki, k) end
		if i>=3 then
			if i ~= tableHeader2_size then tableHeader2 = tableHeader2.. '\n! nowrap style="text-align:center;padding:2px 2px"|'.. s.header_function (wiki, k).. '\n'
			else tableHeader2 = tableHeader2..'\n!  nowrap style="text-align:center;padding:2px 2px"|'.. s.header_function (wiki, k) .. '\n'
			end
		end
	end
	tableHeader2 = tableHeader2 .. '\n'

	local tableBody = ''
	pcall(function()
		local t_Body = {}
		local bg_color=""
		local nr_jersey

	--##################
			for l, m in pairs(entity.claims[s.property]) do -- look into all statements
			h.rider[1]=''
			--if m.mainsnak["snaktype"] == 'value' then
				local rank
				pcall(function()
					for _, v in pairs(m.qualifiers['P1352']) do -- for property 'rank'
						rank = tonumber(v.datavalue.value.amount) break
					end
					h.rider[1] = rank
					end)
				local riderID = 'Q'.. m.mainsnak.datavalue.value['numeric-id']
				if s.team_classification == false then
					h.rider[2] = WPlink(riderID, 'pure')
					h.rider[6] = national_team(riderID, startOfSeason, entity, s.property, l)
				end

				a, b = pcall(fooA, 'numeric-id', mw.wikibase.getEntityObject( riderID ), 'P21', 1)
				if a == true then 
					if b == 6581097 then h.rider[3] = 'm' end -- men
					if b == 6581072 then h.rider[3] = 'f' end -- female
				else h.rider[3] = 'n' -- for teams
				end
			--end
			pcall(function() -- for property 'points' P1358
				for _, v in pairs(m.qualifiers['P1358']) do h.value[1] = tonumber(v.datavalue.value.amount)	end
			end)

			pcall(function() -- for property 'race time' P2781
				for _, v in pairs(m.qualifiers['P2781']) do	h.value[2] = tonumber(v.datavalue.value.amount)	end
			end)

			pcall(function() -- for property 'time gap' P2911
				for _, v in pairs(m.qualifiers['P2911']) do	h.value[3] = tonumber(v.datavalue.value.amount)	end
				plus = '+ '
			end) 

			pcall(function() -- for property 'speed' P2052
				for _, v in pairs(m.qualifiers['P2052']) do h.value[4] = tonumber(v.datavalue.value.amount) end
			end)

			pcall(function() -- for property 'distinctive jersey'
				h.jersey= {''}
				nr_jersey = 1
				for _, v in pairs(m.qualifiers['P2912']) do
					h.jersey[nr_jersey] = 'Q'..v.datavalue.value['numeric-id']
					nr_jersey = nr_jersey + 1
				end
			end)

			if s.team_classification == true then
				h.rider[6] = transform(riderID, 't', startOfSeason)
			end

			if s.team_classification == false then
				local a, b = timeStartEnd(riderID, "P27", 'numeric-id', startOfSeason)
				if a == true then
					h.rider[5] = flag('Q'..b, startOfSeason)
					if available_list == true and country == true then
						if type( translations.list ) == "function" then h.rider[4] = translations.list('Q'..b) end
						if h.rider[4] == '' then
							local country = mw.wikibase.getEntityObject( 'Q'..b )
							h.rider[4] = country:getLabel('ar') or country:getLabel('en') .. ' (en)'
						end
					end
				end
			end
			if s.team_classification == true then
				local a, b = pcall(fooA, 'numeric-id', mw.wikibase.getEntityObject( riderID ), 'P17', 1)
				if a == true then
					a, b = timeStartEnd(riderID, "P17", 'numeric-id', startOfSeason)
					if a == true then
						h.rider[5] = flag('Q'..b, startOfSeason)
						if available_list == true and country == true then
							if type( translations.list ) == "function" then h.rider[4] = translations.list('Q'..b) end
							if h.rider[4] == '' then
								local country = mw.wikibase.getEntityObject( 'Q'..b )
								h.rider[4] = country:getLabel('ar') or country:getLabel('en') .. ' (en)'
							end
						end
					end
				end
			end
		
			-- ##############################
			--local tBody = '|-'
			local tBody = '{{نتيجة سباق ركوب الدراجات'
			-- find the right background color if a rider has more then one jersey
			-- see Wikidata:WikiProject Cycling/Kit to translate/Jerseys
			if h.jersey[1] ~= '' then
				local num = 1 -- loop for more then one jersey per rider
				while h.jersey[num] ~= nil and h.jersey[num] ~= '' do
					if h.jersey[num] == "Q24257871" then bg_color="#FFFF99" break end -- Jersey yellow.svg (General)
					if h.jersey[num] == "Q24257763" then bg_color="#FFC0CB" -- Jersey pink.svg
						if wiki == "ca" then bg_color="lightpink" end
					break end
					if h.jersey[num] == "Q24257872" then bg_color="#FF8666" break end -- Jersey red.svg (General)
					if h.jersey[num] == "Q24687408" then bg_color="#99CBFF" break end -- Jersey blue.svg (General)
					if h.jersey[num] == "Q24258056" then bg_color="#FFD030" break end -- Jersey orange.svg (General)
					if h.jersey[num] == "Q26696171" then bg_color="#FFFFFF" break end -- Jersey white.svg (General)
					if h.jersey[num] == "Q24258125" then bg_color="#BFFF80" break end -- Jersey green 2.svg (General)
					if h.jersey[num] == "Q24257991" then bg_color="#FFD030" break end -- Jersey gold.svg (General)
					if h.jersey[num] == "Q24645208" then bg_color="#90EE90" break end -- Jersey green.svg (General)
					if h.jersey[num] == "Q26945271" then bg_color="#90EE90" break end -- MaillotVolta.png (General)
					if h.jersey[num] == "Q26945272" then bg_color="#BF80FF" break end -- Jersey violet.svg (General)
					if h.jersey[num] == "Q29982321" then bg_color="#FFFF99" break end -- Jersey combined.svg (General)
					if h.jersey[num] == "Q29594434" then bg_color="#87CEEB" break end -- MaillotCyan.PNG (General)
					if h.jersey[num] == "Q30132459" then bg_color="#FFFF99" break end -- Jersey yellow-bluebar.svg (General)
					if h.jersey[num] == "Q24645209" then bg_color="#90EE90" break end -- Jersey green.svg (Points)
					if h.jersey[num] == "Q25831179" then bg_color="#FFFFFF" break end -- Jersey white.svg (Points)
					if h.jersey[num] == "Q26919974" then bg_color="#FF8666" break end -- Jersey red.svg (Points)
					if h.jersey[num] == "Q24687409" then bg_color="#99CBFF" break end -- Jersey blue.svg (Points)
					if h.jersey[num] == "Q25265938" then bg_color="#BF80FF" break end -- Jersey violet.svg (Points)
					if h.jersey[num] == "Q27114205" then bg_color="#C0C0C0" break end -- Jersey black.svg (Points)
					if h.jersey[num] == "Q28546656" then bg_color="#FFFF99" break end -- Jersey yellow.svg (Points)
					if h.jersey[num] == "Q28820618" then bg_color="#87CEEB" break end -- MaillotCyan.PNG (Points)
					if h.jersey[num] == "Q29982764" then bg_color="#FFD030" break end -- Jersey orange.svg (Points)
					if h.jersey[num] == "Q43276992" then bg_color="#FFC0CB" break end -- Jersey pink.svg (Points)
					if h.jersey[num] == "Q47945989" then bg_color="#6495ED" break end -- Jersey dark blue.svg (Points)	
					if h.jersey[num] == "Q25265958" then bg_color="#FFC0CB" break end -- Jersey polkadot.svg (Mountain)
					if h.jersey[num] == "Q25265959" then bg_color="#E0FFFF" break end -- Jersey blue dotted.png (Mountain)
					if h.jersey[num] == "Q25265960" then bg_color="#FFC0CB" break end -- Jersey climbing Dauphine.png (Mountain)
					if h.jersey[num] == "Q27670178" then bg_color="#FF8666" break end -- Jersey red.svg (Mountain)
					if h.jersey[num] == "Q27670182" then bg_color="#90EE90" break end -- Jersey green.svg (Mountain)
					if h.jersey[num] == "Q27670174" then bg_color="#FFD030" break end -- Jersey orange.svg (Mountain)
					if h.jersey[num] == "Q24790519" then bg_color="#C0C0C0" break end -- Jersey grey.svg (Mountain)
					if h.jersey[num] == "Q27670105" then bg_color="#C0C0C0" break end -- Jersey blackdots.png (Mountain)
					if h.jersey[num] == "Q28604413" then bg_color="#99CBFF" break end -- Jersey blue.svg (Mountain)
					if h.jersey[num] == "Q25266023" then bg_color="#F5DEB3" break end -- Jersey brown.svg (Mountain)
					if h.jersey[num] == "Q27670126" then bg_color="#FF8666" break end -- Jersey granate.svg (Mountain)
					if h.jersey[num] == "Q25831602" then bg_color="#FF69B4" break end -- Jersey rosa.svg (Mountain)
					if h.jersey[num] == "Q29168665" then bg_color="#FFC0CB" break end -- Jersey pink.svg (Mountain)
					if h.jersey[num] == "Q29823248" then bg_color="#FFFFFF" break end -- Jersey white.svg (Mountain)
					if h.jersey[num] == "Q28820591" then bg_color="#F5DEB3" break end -- Jersey red green.svg (Mountain)
					if h.jersey[num] == "Q36859499" then bg_color="#CCFFCC" break end -- Jersey greendots.svg (Mountain)
					if h.jersey[num] == "Q33060977" then bg_color="#C0C0C0" break end -- Jersey black.svg (Mountain)
					if h.jersey[num] == "Q26858731" then bg_color="#FFFFFF" break end -- Jersey white.svg (Combinated)
					if h.jersey[num] == "Q28823004" then bg_color="#FFFF99" break end -- Jersey combined.svg (Combinated)
					if h.jersey[num] == "Q28604421" then bg_color="#FFD030" break end -- Jersey orange.svg (Combinated)
					if h.jersey[num] == "Q43098388" then bg_color="#99CBFF" break end -- Jersey blue.svg (Combinated)
					if h.jersey[num] == "Q24790627" then bg_color="#FF8666" break end -- Jersey red.svg (Sprints)
					if h.jersey[num] == "Q25831754" then bg_color="#99CBFF" break end -- Jersey blue.svg (Sprints)
					if h.jersey[num] == "Q26806427" then bg_color="#90EE90" break end -- Jersey green.svg (Sprints)
					if h.jersey[num] == "Q27478100" then bg_color="#C0C0C0" break end -- Jersey black.svg (Sprints)
					if h.jersey[num] == "Q28060932" then bg_color="#BF80FF" break end -- Jersey violet.svg (Sprints)
					if h.jersey[num] == "Q28483869" then bg_color="#FFFF99" break end -- Jersey yellow.svg (Sprints)
					if h.jersey[num] == "Q33134180" then bg_color="#FF69B4" break end -- Jersey rosa.svg (Sprints)
					if h.jersey[num] == "Q42532690" then bg_color="#E0FFFF" break end -- Jersey light blue.svg (Sprints)
					if h.jersey[num] == "Q43278032" then bg_color="#FFC0CB" break end -- Jersey polkadot.svg (Sprints)
					if h.jersey[num] == "Q47513277" then bg_color="#FFFFFF" break end -- Jersey white.svg (Sprints)					
					if h.jersey[num] == "Q24645383" then bg_color="#FFFFFF" break end -- Jersey white.svg (Best young)
					if h.jersey[num] == "Q26919967" then bg_color="#90EE90" break end -- Jersey green.svg (Best young)
					if h.jersey[num] == "Q26209148" then bg_color="#99CBFF" break end -- Jersey blue.svg (Best young)
					if h.jersey[num] == "Q26696523" then bg_color="#FFD030" break end -- Jersey orange.svg (Best young)
					if h.jersey[num] == "Q29229790" then bg_color="#BF80FF" break end -- Jersey violet.svg (Best young)
					if h.jersey[num] == "Q29982765" then bg_color="#FFC0CB" break end -- Jersey pink.svg (Best young)
					if h.jersey[num] == "Q33134078" then bg_color="#FF8666" break end -- Jersey red.svg (Best young)
					if h.jersey[num] == "Q38929482" then bg_color="#FFFF99" break end -- Jersey yellow.svg (Best young)
					if h.jersey[num] == "Q33026698" then bg_color="#FF8666" break end -- Jersey red.svg (Best young)
					if h.jersey[num] == "Q26953919" then bg_color="#8FBC8F" break end -- Jersey dark green.svg (Combativity)
					if h.jersey[num] == "Q29957114" then bg_color="#87CEEB" break end -- MaillotCyan.PNG (Combativity)
					if h.jersey[num] == "Q25265995" then bg_color="#F5DEB3" break end -- Jersey red green.svg (Combativity)
					if h.jersey[num] == "Q29594765" then bg_color="#C0C0C0" break end -- Jersey black.svg (Combativity)
					if h.jersey[num] == "Q30035039" then bg_color="#FFD030" break end -- Jersey orange.svg (Combativity)
					if h.jersey[num] == "Q30035038" then bg_color="#90EE90" break end -- Jersey green.svg (Combativity)
					if h.jersey[num] == "Q48691401" then bg_color="#F2BC38" break end -- Jersey Goldenrod.svg (Combativity)					
					num = num + 1
				end
			end 
			local tBodystyle = '|style='
			if l == 1 and s.background == 'color' then
				tBodystyle = tBodystyle ..'font-weight:bold;' 		-- winner is formated bold
				if h.jersey[1] ~= '' and bg_color ~= nil then 		-- background color of winner depending on jersey
					tBodystyle = tBodystyle ..'background-color:'..bg_color..''
				else tBodystyle = tBodystyle ..'' end
			end

			if l == 1 and s.background == 'strong' then
				tBodystyle = tBodystyle ..'font-weight:bold;' 		-- winner is formated bold
			end

			tBody =  
				tBody .. '|'.. 
				number(h.rider[3], h.rider[1], wiki).. '|'				--riderGender
			if s.team_classification == false then
				if h.rider[6]==nil then h.rider[6]='' end
				if available_list==false 
				then tBody = 
					tBody..
					h.rider[5].. ' '..				--flag ID
					h.rider[2].. 					--rider ID 
					jersey(h.jersey)..
					'|'.. h.rider[6]				--team ID
				else
					if country == true 
					--rank, rider ID, riderGender, nationality ID, flag ID, team ID
					then tBody = 
						tBody.. 
						h.rider[2].. 				--rider ID 
						jersey(h.jersey)..'|'.. 
						h.rider[5]..' '.. 			--flag ID
						h.rider[4].. '|'.. 			--nationality ID
						h.rider[6]					--team ID
					else tBody = 
						tBody.. 
						h.rider[5].. ' '.. 			--flag ID
						h.rider[2].. 				--rider ID 
						jersey(h.jersey)..
						'|'.. h.rider[6] 			--team ID
					end
				end
			else
				if available_list==false 
				then tBody = 
					tBody.. 
					h.rider[5].. ' '..  			--flag ID
					WPlink(riderID, 'team', startOfSeason).. 
					jersey(h.jersey)
				else
					if country == true 
					then tBody = 
						tBody.. 
						WPlink(riderID, 'team', startOfSeason).. 
						jersey(h.jersey).. 
						'|'.. h.rider[5].. ' '.. 	--flag ID
						h.rider[4] 					--nationality ID
					else tBody =
						tBody.. 
						h.rider[5].. ' '.. 			--flag ID
						WPlink(riderID, 'team', startOfSeason).. 
						jersey(h.jersey) 
						end
				end
			end
			tBody = tBody.. '' --.. '\n'

			if s.header_2[4]==4 then -- for table stageclassification, generalclassification, adds time and time gap
				if l == 1 
				then   -- points, time, time_gap, speed
					tBody = tBody.. '|'.. 
					calculate_time(wiki, h.value[2]).. ''		--time	
				else 
					tBody = tBody.. '|'.. 
					plus.. 
					calculate_time(wiki, h.value[3]).. '' 		-- time_gap
					--showgap = true
				end
			end

			if s.header_2[4] == 7 then -- for table pointsclassification, adds points
				tBody = 
					tBody.. '|'.. 
					h.value[1]									-- points
					--.. '<span style="font-size:80%">'
				if type(h.value[1]) == "number" then if h.value[1] > 1 then tBody = tBody..unit(wiki,7) else tBody = tBody..unit(wiki,6) end end 
				--tBody = tBody.. '</span>' .. '' 
			end

			if s.header_2[3] == 4 then
				if s.property == 'P2417' then -- for table teamtimetrialclassification, adds time
				--	showgap = true
					tBody = tBody.. '| '.. 
							calculate_time(wiki, h.value[2]) .. '' 		--  time
				end
			end
			if s.property == 'P3497' then -- for table teambytimeclassification, adds time and time gap
				if l == 1 
				then 
					tBody = tBody ..'| ' ..  
							calculate_time(wiki, h.value[2]) 		--  time
							.. ''--'\n'
					tBodystyle = tBodystyle .. 'text-align:right;padding:0 0.2em 0 0.2em'
				else 
					tBody = tBody.. '| '.. 
							plus.. 
							calculate_time(wiki, h.value[3]) .. ''		-- time_gap
					--showgap = true
				end				
			end
			if tBodystyle ~= '|style=' then
				tBody = tBody .. 
						tBodystyle
			end
			if s.property == 'P3496' then -- for table teambypointsclassification, adds points
				tBody = tBody.. '| '.. 
						h.value[1]					-- points
						--.. '<span style="font-size:80%">'
				if type(h.value[1]) == "number" 
				then if h.value[1] > 1 
					then tBody = 
						tBody..
						unit(wiki,7) 
					else tBody = 
						tBody..
						unit(wiki,6) 
					end 
				end 
				--tBody = tBody.. '</span>' .. '' 				
			end

			if s.header_2[4] == 5 then -- for table teamtimetrialclassification, adds time gap
				showgap = true
				tBody = tBody.. '|'
				if l > 1 then tBody = tBody.. plus end
				tBody = tBody.. 
						calculate_time(wiki, h.value[3]) .. ''			--  time_gap
			end
			if s.header_2[5] == 6 then -- for table teamtimetrialclassification, adds speed
				tBody = tBody.. '|'
				if type(h.value[4]) == "number" then 
						tBody = 
							tBody.. 
							mw.ustring.format('%.3f', h.value[4]).. 		-- speed
							unit(wiki, 5)
							--'<span style="font-size:80%">'..  unit(wiki, 5).. '</span>'.. ''	
				end
			end	

			if rank ~= nil then	t_Body[rank] = tBody.. '}}\n' end -- sort table row into the right row
		end

	--##################
	
		for _, m in pairs(t_Body) do tableBody = tableBody..m end
	end)
	if showgap == true 	then tableStart  = tableStart  .. '|showgap=t'	end

			-- ##############################
	local tableEnd = '{{نهاية نتيجة سباق ركوب الدراجات'
	
	if tableNewline ~= '' 
		then
			tableEnd = tableEnd .. '|clear=' .. tableNewline .. '}}'
		else
			tableEnd = tableEnd .. '}}'
	end
						--'|-\n|}'
	--if showgap == true 	then tableStart  = tableStart  .. '|showgap=t'	end
	--return '{| style="'.. tableStyle.. '" \n |\n'..
		--tableStart.. tableHeader1.. tableHeader2.. tableBody.. tableEnd.. '\n|}'.. tableNewline
	return --'{{بداية نتيجة سباق ركوب الدراجات|style='.. tableStyle.. '}}\n'..
		tableStart ..
		tableHeader1 ..
		--tableHeader2 ..
		tableBody .. 
		tableEnd -- .. '\n'
		--.. '{{نهاية نتيجة سباق ركوب الدراجات}}' 
		--.. tableNewline
end

return p