Get statistic data about Slovak municipalities.
This template is a sibling ofПредлошка:SK.
This template use the data from CC-BY database.
Original first author:Dušan Kreheľ.
Reference implementation is on hrwiki.
| Meaning | Parameter | Code | Code output |
|---|---|---|---|
| Population | p | {{#invoke:SK|sk|p|SK0417524395}} | 2550 |
| Population (source URL) | P | {{#invoke:SK|sk|P|SK0417524395}}<br>{{#invoke:SK|sk|P|SK}}<br>{{#invoke:SK|sk|P|SK0106}} | https://datacube.statistics.sk/#!/view/sk/vbd_dem/om7101rr/v_om7101rr_00_00_00_sk https://datacube.statistics.sk/#!/view/sk/vbd_dem/om7102rr/v_om7102rr_00_00_00_sk https://datacube.statistics.sk/#!/view/sk/vbd_dem/om7102rr/v_om7102rr_00_00_00_sk |
| Population (ex. for table) | p | {{#invoke:SK|sk|o|SK0417524395}} | 2.550 |
| Population Id | r | {{#invoke:SK|sk|r|SK0417524395}} | om7101rr |
| Area | a | {{#invoke:SK|sk|a|SK0417524395}} | 11,24 |
| Area (source URL) | A | {{#invoke:SK|sk|A|SK0417524395}} | https://datacube.statistics.sk/#!/view/sk/vbd_dem/om7014rr/v_om7014rr_00_00_00_sk |
| Area Id | b | {{#invoke:SK|sk|b|SK0417524395}} | om7014rr |
| Population density (as population/area) | d | {{#invoke:SK|sk|d}} | 226,78 |
| Data year | y | {{#invoke:SK|sk|y}} | |
| Last acces | l | {{#invoke:SK|sk|l}} | |
| Last update | u | {{#invoke:SK|sk|u}} | |
| Is slovak municipality (none support %i) | i | {{#invoke:SK|sk|i|SK0417524395}} | 1 |
| Get NUTS/LAU code (none support %e) | e |
You can used both the format string likeprintf() with parameters from table.
| Code: | {{#invoke:SK|sk|%p (source: %P)|SK0417524395}} |
| Output: | 2550 (source:https://datacube.statistics.sk/#!/view/sk/vbd_dem/om7101rr/v_om7101rr_00_00_00_sk |
It is a STUN or LAU code for place sup-place (ex.SK0417524395). If none, then code is automatic based on the actual page.
localsk={}sk.error_place="Непознато место."sk.error_code="Непознат код."sk.decimal_separator=","sk.thousands_separator="."sk.percentage_delimer=" "sk.year_suffix=""sk.minus="−"functionsk.get_nuts_lua()localplace_infolocalnuts_laucode=mw.wikibase.getEntityIdForCurrentPage()ifcode==nilthenreturnnillend-- Source of 2 codes: https://commons.wikimedia.org/w/index.php?title=Data:Statistics_of_Slovak_supmunicipalities.tab&oldid=1001162094ifcode=="Q1780"thenreturn"SK_CAP"endifcode=="Q25409"thenreturn"SK0422_0425"endifcode=="Q214"thenreturn"SK0"endifcode=="SK"thenreturn"SK0"endwhile1doplace_info=mw.wikibase.getBestStatements(code,"P605")ifplace_info[1]==nilthenbreakendnuts_lau=place_info[1]["mainsnak"]['datavalue']['value']ifnuts_lau==nilthenelsereturnnuts_lauendbreakendwhile1doplace_info=mw.wikibase.getBestStatements(code,"P782")ifplace_info[1]==nilthenbreakendnuts_lau=place_info[1]["mainsnak"]['datavalue']['value']ifnuts_lau==nilthenelsereturnnuts_lauendbreakendreturnnilendfunctionsk.is_slovak(args)localnuts_lau=args.args[1]ifnuts_lau==nilornuts_lau==""thennuts_lau=sk.get_nuts_lua()ifnuts_lau==nillthenreturn""endendifstring.sub(nuts_lau,1,2)=="SK"thenreturn"1"endreturn""endfunctionsk.localised_number(number)localnumber2localoffsetlocaloffset_endlocalfirstlocalsecondlocalfirst_lengthlocalOutputnumber2=tostring(number)offset,offset_end=string.find(number2,"%.")ifoffset==nillthenfirst=numbersecond=""elsefirst=string.sub(number2,1,offset-1)second=sk.decimal_separator..string.sub(number2,offset+1,offset+2)endiffirst==nillthenfirst=""endfirst_length=string.len(first)if(first_length<=4)thenreturnfirst..secondendOutput=string.sub(first,-3,-1)if(first_length>3)thenOutput=string.sub(first,-6,-4)..sk.thousands_separator..Outputendif(first_length>6)thenOutput=string.sub(first,-9,-7)..sk.thousands_separator..Outputendif(first_length>9)thenOutput=string.sub(first,-12,-10)..sk.thousands_separator..Outputendifsecond==nilthenreturnOutputelsereturnOutput..secondendendfunctionsk.localised_number_strict(number)-- NNNN is as N.NNNNlocalnumber2localoffsetlocaloffset_endlocalfirstlocalsecondlocalfirst_lengthlocalOutputnumber2=tostring(number)offset,offset_end=string.find(number2,"%.")ifoffset==nillthenfirst=numbersecond=""elsefirst=string.sub(number2,1,offset-1)second=sk.decimal_separator..string.sub(number2,offset+1,offset+2)endfirst_length=string.len(first)if(first_length<=3)thenreturnfirst..secondendOutput=string.sub(first,-3,-1)if(first_length>3)thenOutput=string.sub(first,-6,-4)..sk.thousands_separator..Outputendif(first_length>6)thenOutput=string.sub(first,-9,-7)..sk.thousands_separator..Outputendif(first_length>9)thenOutput=string.sub(first,-12,-10)..sk.thousands_separator..Outputendifsecond==nilthenreturnOutputelsereturnOutput..secondendendfunctionsk.delta_progress(count_a,count_b)-- count_a < count_bifcount_a==0orcount_b==0thenreturn"–"endlocalvaluevalue=tostring(count_b/(count_a/100)-100)ifstring.sub(value,1,1)=="-"thenvalue_string=string.sub(value,2)value=sk.minus..sk.localised_number(value_string)..sk.percentage_delimer.."%"elsevalue="+"..sk.localised_number(value)..sk.percentage_delimer.."%"endreturnvalueendfunctionsk.get_line_data(data,nuts_lau)index=1while1doitem=data.data[index]ifitem==nilthenbreakendifitem[1]==nuts_lauthenbreakendindex=index+1endifitem==nilthenerror(sk.error_place)endreturnitemendfunctionsk.constant_code(code)ifcode==nilthenreturnnilendifstring.len(code)==2then-- Source of 2 codes: https://commons.wikimedia.org/w/index.php?title=Data:Statistics_of_Slovak_supmunicipalities.tab&oldid=1001162094ifcode=="BA"thenreturn"SK_CAP"endifcode=="KE"thenreturn"SK0422_0425"endifcode=="SK"thenreturn"SK0"endendreturncodeend-- Reference data are for populationfunctionsk.population_table(args)localstyle=args.args[1]-- formatlocalnuts_lau=args.args[2]-- nuts / LAU, default: automaticlocalcount_yearslocalcount_years_stoplocaldatalocalheadlocalindexlocalitemlocali_startlocali_endlocaltextlocalone_step_yearlocalone_step_valueslocalvaluelocalvalue_stringlocalyearlocalyears={}nuts_lau=sk.constant_code(nuts_lau)-- get NUTS/LUA for pageifnuts_lau==nilornuts_lau==""thennuts_lau=sk.get_nuts_lua()ifnuts_lau==nillthenreturn""endend-- select date lineifstring.len(nuts_lau)==12thendata=mw.ext.data.get("Population statistic of Slovak municipalities (some years).tab")elsedata=mw.ext.data.get("Population statistic of Slovak supmunicipalities (some years).tab")end-- get yearshead=""text=data.sourcesi_start,i_end=string.find(text,"years: ")offset=i_start+7count_years=0while1doyear=string.sub(text,offset,offset+3)count_years=count_years+1years[count_years]=yearifstring.sub(text,offset+4,offset+4)==" "thenoffset=offset+7breakendoffset=offset+6endyear=string.sub(text,offset,offset+3)count_years=count_years+1years[count_years]=yearcount_years_stop=count_years+1head=""fori=2,count_years_stopdoyear_index=i-1while1doifyear_index+1<count_years_stopthenif(years[year_index]-years[year_index+1])==-1thenbreakendendhead=head.."<th>"..years[year_index]..sk.year_suffix.."</th>"breakendendifstyle=="h"thenreturnheadend-- valuesitem=sk.get_line_data(data,nuts_lau)ifitem==nilthenerror(sk.error_place)end-- get valuescontent=""ifstyle=="d"orstyle=="Y"orstyle=="V"orstyle=="P"thenone_step_year=""one_step_values=""one_step_progress=""content="<td></td>\n"fori=3,count_years_stopdoyear_index=i-1while1do-- check the first item with delta = 1ifyear_index+1<count_years_stopthenif(years[year_index]-years[year_index+1])==-1thenone_step_year=one_step_year.."<th>"..years[year_index]..sk.year_suffix.."</th>"one_step_values=one_step_values.."<td>"..sk.localised_number(item[i]).."</td>"one_step_progress=one_step_progress.."<td></td>"breakendend-- check the second item with delta = 1ifyear_index>1thenif(years[year_index]-years[year_index-1])==1thenone_step_year=one_step_year.."<th>"..years[year_index]..sk.year_suffix.."</th>"one_step_values=one_step_values.."<td>"..sk.localised_number(item[i]).."</td>"one_step_progress=one_step_progress.."<td>"..sk.delta_progress(item[i-1],item[i]).."</td>"content=content.."<td>"..sk.delta_progress(item[i-2],item[i]).."</td>\n"breakendendcontent=content.."<td>"..sk.delta_progress(item[i-1],item[i]).."</td>\n"breakendendifstyle=="Y"thenreturnone_step_yearendifstyle=="V"thenreturnone_step_valuesendifstyle=="P"thenreturnone_step_progressendreturncontentendcontent=""fori=2,count_years_stopdoyear_index=i-1while1doifyear_index+1<count_years_stopthenif(years[year_index]-years[year_index+1])==-1thenbreakendendcontent=content.."<td>"..sk.localised_number(item[i]).."</td>"breakendendreturncontentendfunctionsk.sk(args)localstyle=args.args[1]-- formatlocalnuts_lau=args.args[2]-- nuts / LAU, default: automaticlocalcodelocaldatalocalindexlocalinfolocalitemlocali_startlocali_start2locali_endlocallast_acceslocallast_updatelocalplace_infolocalurl_populationlocalurl_arealocalyear-- select date linenuts_lau=sk.constant_code(nuts_lau)ifnuts_lau==nilornuts_lau==""thennuts_lau=sk.get_nuts_lua()ifnuts_lau==nillthenreturn""endendifstyle=="i"thenlocalparameters={args={nuts_lau}}returnsk.is_slovak(parameters)endifstyle=="e"theni_start,i_end=string.find(nuts_lau,"_")ifi_start==nilthenreturnnuts_lauelsereturn""endend-- select date lineifstring.len(nuts_lau)==12thendata=mw.ext.data.get("Statistics of Slovak municipalities.tab")elsedata=mw.ext.data.get("Statistics of Slovak supmunicipalities.tab")end-- get NUTS/LUA for pageifstyle=="l"orstyle=="u"orstyle=="y"thenelseitem=sk.get_line_data(data,nuts_lau)ifitem==nilthenerror(sk.error_place)endend-- yeari_start,i_end=string.find(data.sources,"year: ")year=string.sub(data.sources,i_start+6,i_start+9)-- last accesi_start,i_end=string.find(data.sources,"acces: ")ifi_start==niltheni_start,i_end=string.find(data.sources,"access: ")last_acces=string.sub(data.sources,i_start+8,i_start+17)elselast_acces=string.sub(data.sources,i_start+7,i_start+16)end-- last updatei_start,i_end=string.find(data.sources,"update: ")last_update=string.sub(data.sources,i_start+8,i_start+17)-- url_populationi_start,i_end=string.find(data.sources,"http")i_start2,i_end=string.find(string.sub(data.sources,i_start)," ")i_start2=i_start+i_start2-1url_population=string.sub(data.sources,i_start,i_start2)-- url_areai_start,i_end=string.find(data.sources,"http")info=string.sub(data.sources,i_start+1)i_start,i_end=string.find(info,"http")i_start2,i_end=string.find(string.sub(info,i_start)," ")i_start2=i_start+i_start2-1url_area=string.sub(info,i_start,i_start2)-- population_idi_start,i_end=string.find(url_population,"/vbd_dem/")info=string.sub(url_population,i_start+9)i_start,i_end=string.find(info,"/")population_id=string.sub(info,1,i_start-1)-- area_idi_start,i_end=string.find(url_area,"/vbd_dem/")info=string.sub(url_area,i_start+9)i_start,i_end=string.find(info,"/")area_id=string.sub(info,1,i_start-1)-- renderi_start,i_end=string.find(style,"%%")ifi_start==nilthenifstyle=="p"thenreturnsk.localised_number(item[2])endifstyle=="P"thenreturnurl_populationendifstyle=="o"thenreturnsk.localised_number_strict(item[2])endifstyle=="a"thenreturnsk.localised_number(item[3])endifstyle=="A"thenreturnurl_areaendifstyle=="d"thenreturnsk.localised_number(item[2]/item[3])endifstyle=="y"thenreturnyearendifstyle=="l"thenreturnlast_accesendifstyle=="u"thenreturnlast_updateendifstyle=="r"thenreturnpopulation_idendifstyle=="b"thenreturnarea_idenderror(sk.error_code)elseOutput=styleOutput=string.gsub(Output,"%%p",sk.localised_number(item[2]))Output=string.gsub(Output,"%%P",url_population)Output=string.gsub(Output,"%%a",sk.localised_number(item[3]))Output=string.gsub(Output,"%%o",sk.localised_number_strict(item[2]))Output=string.gsub(Output,"%%A",url_area)Output=string.gsub(Output,"%%d",sk.localised_number(item[2]/item[3]))Output=string.gsub(Output,"%%y",year)Output=string.gsub(Output,"%%l",last_acces)Output=string.gsub(Output,"%%u",last_update)Output=string.gsub(Output,"%%r",population_id)Output=string.gsub(Output,"%%b",area_id)returnOutputendendreturnsk