Commit 905f6588 authored by Eduardo L. Buratti's avatar Eduardo L. Buratti

database: Fix operating systems output order

Signed-off-by: Eduardo L. Buratti's avatarEduardo L. Buratti <elb09@c3sl.ufpr.br>
parent 6e7ecd4c
......@@ -6,7 +6,7 @@ AS $$
WHEN 'Debian GNU/Linux 4.0' THEN 'Debian'
WHEN 'Debian GNU/Linux 6.0' THEN 'Debian'
WHEN 'Kernel' THEN 'Outros'
WHEN 'Linux Educacional' THEN 'Linux Educacional 1.0'
WHEN 'Linux Educacional' THEN 'Linux Educacional 3.0'
WHEN 'Linux Educacional 2.0' THEN 'Linux Educacional 2.0'
WHEN 'Linux Educacional 3.0' THEN 'Linux Educacional 3.0'
WHEN 'Linux Educacional 4.0' THEN 'Linux Educacional 4.0'
......@@ -46,37 +46,39 @@ CREATE OR REPLACE FUNCTION os_brazil(proj project_enum, b_date DATE DEFAULT CURR
TABLE (os_distro text, total bigint)
AS $$
BEGIN
CREATE TEMP TABLE temp_os_categories (category text) ON COMMIT DROP;
INSERT INTO temp_os_categories (category) VALUES
('Debian'),
('Linux Educacional 1.0'),
('Linux Educacional 2.0'),
('Linux Educacional 3.0'),
('Linux Educacional 4.0'),
('Linux Educacional 5.0'),
('Outros'),
('Ubuntu'),
('Windows 7'),
('Windows MultiPoint Server');
CREATE TEMP TABLE temp_os_categories (ord integer, category text) ON COMMIT DROP;
INSERT INTO temp_os_categories (ord, category) VALUES
(0, 'Linux Educacional 5.0'),
(1, 'Linux Educacional 4.0'),
(2, 'Linux Educacional 3.0'),
(3, 'Linux Educacional 2.0'),
(4, 'Windows 7'),
(5, 'Windows MultiPoint Server'),
(6, 'Ubuntu'),
(7, 'Debian'),
(8, 'Outros');
RETURN QUERY SELECT
os, sum(c)::bigint
FROM (
(SELECT s.os AS os, count(s.os) AS c
(SELECT tmp.ord AS ord, s.os AS os, count(s.os) AS c
FROM (
SELECT os_categorize(max(inv.os_distro)) AS os
FROM dim_inventory inv
WHERE inv.project = proj AND inv.load_date <= b_date
GROUP BY inv.sch_id, inv.macaddr
) AS s
GROUP BY s.os
ORDER BY count(s.os)
) s, temp_os_categories tmp
WHERE tmp.category = s.os
GROUP BY tmp.ord, s.os
)
UNION ALL
(SELECT category AS os, 0::bigint AS c
(SELECT ord, category AS os, 0::bigint AS c
FROM temp_os_categories)
) uni
GROUP BY os;
GROUP BY ord, os
ORDER BY ord;
DROP TABLE IF EXISTS temp_os_categories;
END;
$$
LANGUAGE plpgsql;
......@@ -102,6 +104,6 @@ AS $$
UNION SELECT current_date) dates
) a
ORDER BY
gen_date,(os_brazil).total;
gen_date;
$$
LANGUAGE SQL;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment