Test Wikimedia Commons testcommonswiki https://test-commons.wikimedia.org/wiki/Main_Page MediaWiki 1.45.0-wmf.3 first-letter Media Special Talk User User talk Commons Commons talk File File talk MediaWiki MediaWiki talk Template Template talk Help Help talk Category Category talk Creator Creator talk TimedText TimedText talk Sequence Sequence talk Institution Institution talk Data Data talk TimedText TimedText talk Module Module talk Translations Translations talk Module:Weekly average temperature chart 828 2427 4995 2025-05-29T16:13:39Z Brooke Vibber (WMF) 1355 Created page with "local p = {} local function celsius_to_fahrenheit(val) return val * 1.8 + 32 end -- -- input data: -- * tabular JSON strcuture with 1 label and 2 temp rows stored in C -- -- arguments: -- * units: "F" or "C" -- function p.convert_temps(tab, args) if args.units == "C" then -- Stored data is in Celsius return tab elseif args.units == "F" then -- Have to convert if asked for Fahrenheit for _, row in ipairs(tab.data) do -- first column is month row[2] = ce..." 4995 Scribunto text/plain local p = {} local function celsius_to_fahrenheit(val) return val * 1.8 + 32 end -- -- input data: -- * tabular JSON strcuture with 1 label and 2 temp rows stored in C -- -- arguments: -- * units: "F" or "C" -- function p.convert_temps(tab, args) if args.units == "C" then -- Stored data is in Celsius return tab elseif args.units == "F" then -- Have to convert if asked for Fahrenheit for _, row in ipairs(tab.data) do -- first column is month row[2] = celsius_to_fahrenheit(row[2]) row[3] = celsius_to_fahrenheit(row[3]) end return tab else error("Units must be either 'C' or 'F'") end end return p fctw0a854fk0jij95ps5uowyuijlxp3 Data:Sample weekly temperature dataset.tab 486 2428 4996 2025-05-29T16:14:19Z Brooke Vibber (WMF) 1355 Created page with "{ "license": "CC0-1.0", "description": { "en": "Sample monthly temperature data" }, "schema": { "fields": [ { "name": "month", "type": "localized", "title": { "en": "Month" } }, { "name": "low", "type": "number", "title": { "en": "Low temp"..." 4996 Tabular.JsonConfig application/json {"license":"CC0-1.0","description":{"en":"Sample monthly temperature data"},"schema":{"fields":[{"name":"month","type":"localized","title":{"en":"Month"}},{"name":"low","type":"number","title":{"en":"Low temp"}},{"name":"high","type":"number","title":{"en":"High temp"}}]},"data":[[{"en":"January"},5,20],[{"en":"July"},15,30]]} gi70dqn2d1y9kpy23je7lxtadq0447i Data:Weekly average temperatures (C).chart 486 2429 4997 2025-05-29T16:14:39Z Brooke Vibber (WMF) 1355 Created page with "{ "license": "CC0-1.0", "version": 1, "type": "bar", "xAxis": { "title": { "en": "Day" } }, "yAxis": { "title": { "en": "Temperature (C)" } }, "source": "Sample weekly temperature dataset.tab" }" 4997 Chart.JsonConfig application/json {"license":"CC0-1.0","version":1,"type":"bar","xAxis":{"title":{"en":"Day"}},"yAxis":{"title":{"en":"Temperature (C)"}},"source":"Sample weekly temperature dataset.tab"} q90vlc1z7k0tw6oz8hp7936ydf6wqor Data:Weekly average temperatures (F).chart 486 2430 4998 2025-05-29T16:14:56Z Brooke Vibber (WMF) 1355 Created page with "{ "license": "CC0-1.0", "version": 1, "type": "bar", "xAxis": { "title": { "en": "Day" } }, "yAxis": { "title": { "en": "Temperature (F)" } }, "transform": { "module": "Weekly average temperature chart", "function": "convert_temps", "args": { "units": "F" } }, "source": "Sample weekly temperature dataset.tab" }" 4998 Chart.JsonConfig application/json {"license":"CC0-1.0","version":1,"type":"bar","xAxis":{"title":{"en":"Day"}},"yAxis":{"title":{"en":"Temperature (F)"}},"source":"Sample weekly temperature dataset.tab","transform":{"module":"Weekly average temperature chart","function":"convert_temps","args":{"units":"F"}}} b7ky176tvv5enipjm8nvcqvk6br4s9p 4999 4998 2025-05-29T16:57:58Z Brooke Vibber (WMF) 1355 4999 Chart.JsonConfig application/json {"license":"CC0-1.0","version":1,"type":"bar","xAxis":{"title":{"en":"Day"}},"yAxis":{"title":{"en":"Temperature (F)"}},"transform":{"module":"Weekly average temperature chart","function":"convert_temps","args":{"units":"F"}},"source":"Sample weekly temperature dataset.tab"} 7kipu3gvljp1k8g4dmtovbv7cuarjaq Module:Charts/Wikibase property/test 828 2431 5000 2025-05-29T22:30:17Z Brooke Vibber (WMF) 1355 Created page with "-- -- Experimental module for Chart transform testing. -- Fetches claims for a single Wikidata item on a single property, -- grouping by a single qualifier. -- -- Can eg show a list of population figures for a city over time. -- -- Returns data in tabular JSON format: -- see https://www.mediawiki.org/wiki/Help:Tabular_data -- -- Meant to be used through reference in a Chart format definition: -- see https://www.mediawiki.org/wiki/Extension:Chart -- but this feature hasn'..." 5000 Scribunto text/plain -- -- Experimental module for Chart transform testing. -- Fetches claims for a single Wikidata item on a single property, -- grouping by a single qualifier. -- -- Can eg show a list of population figures for a city over time. -- -- Returns data in tabular JSON format: -- see https://www.mediawiki.org/wiki/Help:Tabular_data -- -- Meant to be used through reference in a Chart format definition: -- see https://www.mediawiki.org/wiki/Extension:Chart -- but this feature hasn't landed. This test module is living here -- on Commons in order to facilitate production of test data for -- now. -- -- Currently hardcodes values as numbers and qualifiers as datetimes. -- -- To use in a .chart: -- "source": "<any empty template page>.tab" -- "transform": { -- "module": "Charts/Wikibase_property/test", -- "function": "transform", -- "args": { -- "entity": "Q65", // Los Angeles -- "property": "P1082", // population -- "qualifier": "P585" // point in time -- } -- } -- -- To dump raw JSON in a wiki template: -- {{#invoke:Charts/Wikibase_property/test -- |invoke -- |entity=Q65 -- |property=P1082 -- |qualifier=P585}} -- -- maintained by [[User:Brooke Vibber (WMF)]] during testing -- -- @todo clarify localization behavior -- @todo validate data format (numeric) -- @todo validate qualifier format (timestamp, or support grouping others) -- local p = {} function p.transform(tab, args) -- -- Transform function for tabular data loaded into charts -- see https://www.mediawiki.org/wiki/Extension:JsonConfig/Transforms -- -- tab is a template tabular data setfenv -- see https://www.mediawiki.org/wiki/Help:Tabular_data -- return value is modified dataset, with our lookup data inserted -- -- args: -- * entity - entity to look up on, eg 'Q65' - Los Angeles -- * property - property to look up claims for , eg 'P1082' - population -- * qualifier - qualifier to show lookups for, eg 'P585' - point in time local label_entity = mw.wikibase.getLabel(args.entity) local label_prop = mw.wikibase.getLabel(args.property) local label_qualifier = mw.wikibase.getLabel(args.qualifier) tab.description = { ["en"] = label_entity .. " - " .. label_prop } table.insert(tab.schema.fields, { ["name"] = args.qualifier, ["type"] = "string", ["title"] = { ["en"] = label_qualifier }, }) table.insert(tab.schema.fields, { ["name"] = args.entity, ["type"] = "number", -- @todo: support other types ["title"] = { ["en"] = label_prop }, }) local statements = mw.wikibase.getAllStatements(args.entity, args.property) for _, statement in ipairs(statements) do local row = {} local label_qual = "" local qualifiers = statement.qualifiers[args.qualifier] if qualifiers then for _, snak in pairs(qualifiers) do -- hack assumes gregorian date -- @fixme use the month/day if available too local date = string.match(snak.datavalue.value.time, "^+(%d%d%d%d)%-.*$") if date then label_qual = date else label_qual = snak.datavalue.value.time end end end table.insert(row, label_qual) -- hack assumes numeric local value = statement.mainsnak.datavalue.value.amount value = tonumber(value) table.insert(row, value) table.insert(tab.data, row) end table.sort(tab.data, function(a, b) return a[1] < b[1] end) return tab end -- -- #invoke-compatible demo -- dumps raw JSON to output -- function p.invoke(frame) local tab = { ["license"] = "CC0-1.0", ["description"] = {}, ["sources"] = "from wikibase", -- @todo fill out sources ["schema"] = { ["fields"] = {} }, ["data"] = {} } tab = p.transform(tab, frame.args) return mw.text.jsonEncode(tab) end function p.demo(entity) mw.log(p.invoke({ ["args"] = { ["entity"] = entity or "Q65", -- Los Angeles ["property"] = "P1082", -- Population ["qualifier"] = "P585" -- point in time } })) end return p gx6g8lzh87wnu8r24v6dczrqthyeoae Data:Charts/Wikibase property/test-skeleton.tab 486 2432 5001 2025-05-29T22:32:52Z Brooke Vibber (WMF) 1355 Created page with "{ "license": "CC0-1.0", "description": { "en": "Population by year" }, "sources": "from wikibase", "schema": { "fields": [] }, "data": [ ] }" 5001 Tabular.JsonConfig application/json {"license":"CC0-1.0","description":{"en":"Population by year"},"sources":"from wikibase","schema":{"fields":[]},"data":[]} 0inowvdnvwsmzd1sihl0mrd3rd662mr Data:Charts/Wikibase property/test.chart 486 2433 5002 2025-05-29T23:34:23Z Brooke Vibber (WMF) 1355 Created page with "{ "license": "CC0-1.0", "version": 1, "type": "line", "xAxis": { "title": { "en": "Year" } }, "yAxis": { "title": { "en": "Population" } }, "transform": { "module": "Charts/Wikibase property/test", "function": "transform", "args": { "entity": "Q84", "property": "P1082", "qualifier": "P585" } }, "source": "Charts/Wikiba..." 5002 Chart.JsonConfig application/json {"license":"CC0-1.0","version":1,"type":"line","xAxis":{"title":{"en":"Year"}},"yAxis":{"title":{"en":"Population"}},"transform":{"module":"Charts/Wikibase property/test","function":"transform","args":{"entity":"Q84","property":"P1082","qualifier":"P585"}},"source":"Charts/Wikibase property/test-skeleton.tab"} r3fxr3kyfccr2xoh04d41liinya1lfk