Module:WeatherBoxColors
Appearance
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
Usage
[සංස්කරණය]{{#invoke:WeatherBoxColors|function_name}}
Climate data for Edmonton City Centre (Blatchford Field) Airport (1981−2010) | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Month | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Year |
Record high °C (°F) | 11.7 (53.1) |
14.0 (57.2) |
23.9 (75.0) |
31.1 (88.0) |
32.3 (90.1) |
34.9 (94.8) |
34.6 (94.3) |
34.5 (94.1) |
33.9 (93.0) |
28.6 (83.5) |
21.7 (71.1) |
16.7 (62.1) |
34.9 (94.8) |
Mean daily maximum °C (°F) | −6.0 (21.2) |
−2.7 (27.1) |
2.2 (36.0) |
11.2 (52.2) |
17.5 (63.5) |
21.0 (69.8) |
23.1 (73.6) |
22.6 (72.7) |
17.1 (62.8) |
10.4 (50.7) |
0.0 (32.0) |
−4.5 (23.9) |
9.3 (48.7) |
Daily mean °C (°F) | −10.4 (13.3) |
−7.6 (18.3) |
−2.5 (27.5) |
5.4 (41.7) |
11.5 (52.7) |
15.5 (59.9) |
17.7 (63.9) |
16.9 (62.4) |
11.4 (52.5) |
5.1 (41.2) |
−4.1 (24.6) |
−8.8 (16.2) |
4.2 (39.6) |
Mean daily minimum °C (°F) | −14.8 (5.4) |
−12.5 (9.5) |
−7.2 (19.0) |
−0.5 (31.1) |
5.4 (41.7) |
9.9 (49.8) |
12.3 (54.1) |
11.3 (52.3) |
5.8 (42.4) |
−0.2 (31.6) |
−8.2 (17.2) |
−13.1 (8.4) |
−1.0 (30.2) |
Record low °C (°F) | −44.4 (−47.9) |
−46.1 (−51.0) |
−36.1 (−33.0) |
−25.6 (−14.1) |
−12.2 (10.0) |
−1.1 (30.0) |
0.6 (33.1) |
−1.2 (29.8) |
−11.7 (10.9) |
−25.0 (−13.0) |
−34.1 (−29.4) |
−48.3 (−54.9) |
−48.3 (−54.9) |
Record low wind chill | −52.8 | −50.7 | −44.6 | −37.5 | −14.5 | 0.0 | 0.0 | −3.7 | −13.3 | −34.3 | −50.2 | −55.5 | −55.5 |
Average precipitation mm (inches) | 21.7 (0.85) |
12.0 (0.47) |
15.8 (0.62) |
28.8 (1.13) |
46.1 (1.81) |
77.5 (3.05) |
93.8 (3.69) |
61.9 (2.44) |
43.5 (1.71) |
21.7 (0.85) |
18.0 (0.71) |
15.0 (0.59) |
455.7 (17.94) |
Average rainfall mm (inches) | 1.3 (0.05) |
0.76 (0.03) |
1.7 (0.07) |
14.5 (0.57) |
40.7 (1.60) |
77.5 (3.05) |
93.8 (3.69) |
61.8 (2.43) |
42.4 (1.67) |
10.9 (0.43) |
1.6 (0.06) |
0.73 (0.03) |
347.8 (13.69) |
Average snowfall cm (inches) | 24.5 (9.6) |
13.4 (5.3) |
17.4 (6.9) |
15.3 (6.0) |
4.9 (1.9) |
0.0 (0.0) |
0.0 (0.0) |
0.0 (0.0) |
1.0 (0.4) |
11.6 (4.6) |
19.1 (7.5) |
16.4 (6.5) |
123.5 (48.6) |
Average precipitation days (≥ 0.2 mm) | 11.0 | 7.9 | 8.3 | 8.8 | 11.0 | 14.2 | 14.6 | 11.1 | 9.8 | 8.0 | 8.8 | 9.4 | 122.9 |
Average rainy days (≥ 0.2 mm) | 1.1 | 0.83 | 1.4 | 5.9 | 10.5 | 14.2 | 14.6 | 11.1 | 9.6 | 5.6 | 1.5 | 0.75 | 77.3 |
Average snowy days (≥ 0.2 cm) | 10.7 | 7.7 | 7.7 | 4.2 | 1.2 | 0.0 | 0.0 | 0.0 | 0.50 | 3.2 | 7.9 | 9.3 | 52.4 |
Average relative humidity (%) | 65.2 | 61.2 | 56.5 | 42.9 | 40.4 | 48.2 | 52.6 | 51.4 | 50.1 | 50.5 | 64.7 | 65.4 | 54.1 |
Mean monthly sunshine hours | 100.8 | 121.7 | 176.3 | 244.2 | 279.9 | 285.9 | 307.5 | 282.3 | 192.7 | 170.8 | 98.4 | 84.5 | 2,344.8 |
Percent possible sunshine | 40.2 | 44.1 | 48.1 | 58.2 | 56.8 | 56.2 | 60.2 | 61.5 | 50.4 | 52.0 | 37.8 | 36.0 | 50.1 |
Source: Environment Canada[1] |
- ^ "Edmonton City Centre Airport". Canadian Climate Normals 1981−2010. Environment Canada. August 19, 2013. සම්ප්රවේශය September 10, 2013.
w = {};
convert = require( 'Module:BaseConvert' );
math_mod = require( 'Module:Math' );
function hex( value )
return convert.convert( { n = value, base = 16, width = 2, precision = 0 } );
end
function format_line( background, text_color )
return table.concat( {"background:#", background, ";color:#", text_color, ";font-size:85%;text-align:center;"} );
end
function range_pos( value, start, stop )
if start < stop then
if value < start then
return 0;
elseif value > stop then
return 1;
else
return (value - start) / (stop - start);
end
else
if value < stop then
return 1;
elseif value > start then
return 0;
else
return (start - value) / (start - stop);
end
end
end
function w.color_d( frame )
local val = math_mod._cleanNumber( frame.args[1] );
return w._days_color( val );
end
function w.color_pastel( frame )
local val = math_mod._cleanNumber( frame.args[1] );
return w._pastel_color( val );
end
function w.color_t( frame )
local val = math_mod._cleanNumber( frame.args[1] );
return w._temperature_color( val );
end
function w.color_green( frame )
local val = math_mod._cleanNumber( frame.args[1] );
return w._green_color( val );
end
function w.color_s( frame )
local val = math_mod._cleanNumber( frame.args[1] );
return w._sunshine_color( val );
end
function w.color_h( frame )
local val = math_mod._cleanNumber( frame.args[1] );
return w._humidity_color( val );
end
function w.color_p( frame )
local val = math_mod._cleanNumber( frame.args[1] );
return w._precipitation_color( val );
end
function w._days_color( val )
local item, background, text_color;
if val == nil then
return format_line( "FFFFFF", "000000" );
end
item = hex( range_pos( val, 20, 0 )*255 );
background = item .. item;
item = hex( range_pos( val, 40, 20 )*255 );
background = background .. item;
if val >= 12 then
text_color = "FFFFFF";
else
text_color = "000000";
end
return format_line( background, text_color );
end
function w._green_color( val )
local item1, item2, background, text_color;
if val == nil then
return format_line( "FFFFFF", "000000" );
end
item1 = hex( range_pos( val, 165.6, 0 )*255 );
item2 = hex( range_pos( val, 300, 165.61 )*207 + 48 );
background = table.concat( { item1, item2, item1 } );
if val >= 200 then
text_color = "FFFFFF";
else
text_color = "000000";
end
return format_line( background, text_color );
end
function w._temperature_color( val )
local item, background, text_color;
if val == nil then
return format_line( "FFFFFF", "000000" );
end
if val < 4.5 then
item = range_pos( val, -42.75, 4.5 )*255;
background = hex( item );
else
item = range_pos( val, 60, 41.5 )*255;
background = hex( item );
end
if val <= 4.5 then
item = range_pos( val, -42.75, 4.5 )*255;
background = background .. hex( item );
else
item = range_pos( val, 41.5, 4.5 )*255;
background = background .. hex( item );
end
if val < -42.78 then
item = range_pos( val, -90, -42.78 )*255;
background = background .. hex( item );
else
item = range_pos( val, 23, 4.5 )*255;
background = background .. hex( item );
end
if val < -23.3 or val >= 37.8 then
text_color = "FFFFFF";
else
text_color = "000000";
end
return format_line( background, text_color );
end
function w._precipitation_color( val )
local item, background, text_color;
if val == nil then
return format_line( "FFFFFF", "000000" );
end
item = hex( range_pos( val, 165.6, 0 )*255 );
background = item .. item;
item = hex( range_pos( val, 300, 165.61 )*207 + 48 );
background = background .. item;
if val > 90 then
text_color = "FFFFFF";
else
text_color = "000000";
end
return format_line( background, text_color );
end
function w._humidity_color( val )
local item, background, text_color;
if val == nil then
return format_line( "FFFFFF", "000000" );
end
item = hex( range_pos( val, 66.67, 0 )*255 );
background = item .. item;
item = hex( range_pos( val, 133.33, 66.667 )*255 );
background = background .. item;
if val >= 40 then
text_color = "FFFFFF";
else
text_color = "000000";
end
return format_line( background, text_color );
end
function w._sunshine_color( val )
local item, background, text_color;
if val == nil then
return format_line( "FFFFFF", "000000" );
end
if val < 90 then
item = hex( range_pos( val, 0, 90 )*170 );
elseif val < 180 then
item = hex( range_pos( val, 90, 180 )*42.5 + 170 );
else
item = hex( range_pos( val, 180, 360 )*42.5 + 212.5 );
end
background = item .. item;
if val < 90 then
item = hex( range_pos( val, 0, 90 )*170 );
elseif val < 270 then
item = hex( range_pos( val, 150, 90 )*170 );
else
item = hex( range_pos( val, 270, 720 )*255 );
end
background = background .. item;
if val < 80 then
text_color = "FFFFFF";
else
text_color = "000000";
end
return format_line( background, text_color );
end
function w._pastel_color( val )
local item, background, text_color;
if val == nil then
return format_line( "FFFFFF", "000000" );
end
if val < -15 or val >= 39 then
text_color = "FFFFFF";
else
text_color = "000000";
end
if val >= 51 then
background = 'EE2200';
else
val = math_mod._round( (val + 25.5)/3, 0 );
if val == 1 then
background = 'BB00CC';
elseif val == 2 then
background = 'CC00EE';
elseif val == 3 then
background = 'CC33EE';
elseif val == 4 then
background = 'CC55EE';
elseif val == 5 then
background = 'DD66EE';
elseif val == 6 then
background = 'DD77EE';
elseif val == 7 then
background = 'DD99EE';
elseif val == 8 then
background = 'DDAAEE';
elseif val == 9 then
background = 'DDBBEE';
elseif val == 10 then
background = 'EECCFF';
elseif val == 11 then
background = 'FFDDFF';
elseif val == 12 then
background = 'F1F1F1';
elseif val == 13 then
background = 'FFEEBB';
elseif val == 14 then
background = 'FFFFCC';
elseif val == 15 then
background = 'FFFFBB';
elseif val == 16 then
background = 'FFFFAA';
elseif val == 17 then
background = 'FFFF88';
elseif val == 18 then
background = 'FFCC33';
elseif val == 19 then
background = 'FFBB33';
elseif val == 20 then
background = 'FF9900';
elseif val == 21 then
background = 'FF8844';
elseif val == 22 then
background = 'FF6633';
elseif val == 23 then
background = 'FF5522';
elseif val == 24 then
background = 'FF4422';
elseif val == 25 then
background = 'EE4400';
else
background = 'AA00AA'
end
end
return format_line( background, text_color );
end
function w._none_color( val )
return format_line( "FAFAFA", "000000" );
end
function w.interpret_color_code( code )
code = code:lower();
if code == 't' then
return w._temperature_color;
elseif code == 'pastel' then
return w._pastel_color;
elseif code == 'green' then
return w._green_color;
elseif code == 'h' then
return w._humidity_color;
elseif code == 's' then
return w._sunshine_color;
elseif code == 'p' then
return w._precipitation_color;
elseif code == 'd' then
return w._days_color;
elseif code == 'none' then
return w._none_color;
else
error( 'Unknown color scheme option' );
end
end
return w;