Commit 173a9ca3 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

database: More modifications in the load scripts

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 83edcef2
......@@ -34,15 +34,21 @@ begin
'"dm_avail_machine"...';
insert into dm_avail_machine (project, state, city, inep, school, machine,
color, first_contact, total_contacts, month_contacts, days_last_contact)
select project, state, city, inep, school, machine, ????, first_contact,
total_contacts
from fact_inventory i, dim_school s, dim_machine m, (select
machine_id, min(contact_date) as first_contact from fact_inventory
group by machine_id) t, (select machine_id, count(*) as
total_contacts from fact_inventory group by machine_id) u, (select
machine_id, count(*) as month_contacts from fact_inventory where
contact_date >= date_trunc(month, current_date) group by machine_id) v
where i.machine_id = m.id and m.school_id = s.id;
select project, state, city, inep, school, machine, case when
last_contact < current_date - 30 then 'red'::class_enum when
last_contact < current_date - 10 then 'yellow'::class_enum else
'green'::class_enum end, first_contact, total_contacts,
month_contacts, days_last_contact from fact_inventory i, dim_school
s, dim_machine m, (select machine_id, min(contact_date) as
first_contact, max(contact_date) as last_contact, current_date -
max(contact_date) as days_last_contact from fact_inventory group by
machine_id) t, (select machine_id, count(*) as total_contacts from
fact_inventory group by machine_id) u, (select machine_id, count(*)
as month_contacts from fact_inventory where contact_date >=
date_trunc('month', current_date) group by machine_id) v where
i.machine_id = t.machine_id and i.machine_id = u.machine_id and
i.machine_id = v.machine_id and i.machine_id = m.id and m.school_id
= s.id
get diagnostics tmp = ROW_COUNT;
count_total := count_total + tmp;
raise log 'Done - % rows inserted', tmp;
......
......@@ -165,7 +165,7 @@ begin
i.id, hd2_used, extra_hds, md5(o.id::text || k.id::text ||
p.id::text || m.id::text || h.id::text || hd_used::text ||
coalesce(i.id::text, '') || coalesce(hd2_used::text, '') ||
coalesce(extra_hds::text, '0')) as "hash"
coalesce(extra_hds::text, '0')) as hash
from sa_inventory s
join tmp_machine m using (contact_date, machine, inep)
join tmp_os o using (contact_date, machine, inep)
......@@ -185,7 +185,7 @@ begin
select *, row_number() over (partition by machine_id order by
contact_date) as row_n from (select distinct on (i.machine_id, hash)
i.id, contact_date, i.machine_id, hash, memory_size, detail::integer
as "hd_size" from fact_inventory i, dim_component c, (select
as hd_size from fact_inventory i, dim_component c, (select
machine_id from (select distinct machine_id, hash from
fact_inventory where contact_date >= min_date) s group by machine_id
having count(*) > 1) t where i.machine_id = t.machine_id and i.hd_id
......
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