Skip to content

Commit

Permalink
teste sumarios inicial e final
Browse files Browse the repository at this point in the history
  • Loading branch information
ppKrauss committed Oct 8, 2018
1 parent d7e3e7b commit 11ca563
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 10 deletions.
Binary file added entregas/neuro2018_capa.docx
Binary file not shown.
Binary file added entregas/neuro2018_idx.docx
Binary file not shown.
18 changes: 9 additions & 9 deletions relatorio.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@

# Relatório de contagens e cosistência

## Avaliação individual dos arquivos
Cada arquivo quanto ao total de registros, distribuição por temas e normalização dos campos.

### ApresOral
Total 288 registros, porém 48 únicos, demais repetidos com mesmo código e a maioria com mesmo título.
<!-- select count(*) n, count(distinct codigo) n_unicos from neuro.ApresOral; -->

### ApresPoster
<!-- select count(*) n, count(distinct codigo) n_unicos from neuro.apresposter;
n | n_unicos
------+----------
9348 | 1558
-->
Total 9348 registros, porém 1558 únicos, demais repetidos com mesmo código e a maioria com mesmo título.

### RelTrabalhos

Total 1606 registros, consistente com o total de itens distintos de cada tipo de apresentação:

* Itens não-repetidos de ApresOral: 48<!-- select count(distinct codigo) from neuro.reltrabalhos where codigo IN (select codigo from neuro.apresoral); -- 48 -->
* Itens não-repetidos de ApresOral: 48
* Itens não-repetidos de ApresPoster: 1548

Distribuição por tema:
Expand Down Expand Up @@ -50,6 +44,13 @@ Sono
Transtornos do Movimento | Oral 7, Poster 154
Traumatismo cranioencefálico | Poster 23
<!--
scripts dos resultados acima:
select count(*) n, count(distinct codigo) n_unicos from neuro.ApresOral;
select count(*) n, count(distinct codigo) n_unicos from neuro.apresposter;
SELECT count(distinct codigo) from neuro.reltrabalhos where codigo IN (select codigo from neuro.apresoral); 48
SELECT temario, array_to_string(array_agg(tipo||' '||n),', ') n
FROM (
SELECT rr.temario, CASE
Expand All @@ -68,4 +69,3 @@ FROM (
## Etapa final, layout HTML

....

50 changes: 49 additions & 1 deletion src/lib.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

CREATE or replace FUNCTION file_get_contents(p_file text) RETURNS text AS $f$
with open(args[0],"r") as content_file:
content = content_file.read()
Expand Down Expand Up @@ -59,12 +60,28 @@ CREATE FUNCTION neuro.metadata_bycod(p_codigo int) RETURNS jsonb AS $f$
where codigo=$1
$f$ LANGUAGE SQL IMMUTABLE;

ALTER TABLE neuro.reltrabalhos ADD COLUMN pub_id text;
UPDATE neuro.reltrabalhos
SET pub_id = t2.pub_prefix||'&#160;'|| CASE
WHEN num_painel IS NULL THEN lpad(rk::text, 2, '0')
ELSE lpad(num_painel::text, 4, '0')
END
FROM (
SELECT *, DENSE_RANK() OVER (partition by pub_prefix ORDER BY codigo) rk
FROM (
SELECT codigo, CASE WHEN num_painel IS NULL THEN 'TL' ELSE 'PO' END as pub_prefix
FROM neuro.reltrabalhos
ORDER BY codigo
) t1
) t2
WHERE t2.codigo=reltrabalhos.codigo;

CREATE VIEW neuro.vw_relxml1 AS
SELECT xmlelement(
name "article-dump",
xmlattributes(
1 as version_id, codigo as article_id,
CASE WHEN num_painel IS NULL THEN 'O'|| DENSE_RANK() OVER (ORDER BY codigo) ELSE 'P'||num_painel END as pub_id,
pub_id as pub_id,
'working' as status, 'simple-jatsfront-level1' as dtd_label
),
xmlelement(name article,
Expand All @@ -77,3 +94,34 @@ CREATE VIEW neuro.vw_relxml1 AS
FROM neuro.relTrabalhos
ORDER BY codigo
;

CREATE or replace FUNCTION neuro.sumario( p_tipo text DEFAULT 'Oral') RETURNS xml AS $f$
SELECT xmlelement(name section,
xmlelement(name title, p_tipo),
(
SELECT xmlagg(line) cpa
FROM (
SELECT xmlelement(name p , '- Tema '||DENSE_RANK() OVER (ORDER BY temario) || ' - '||temario||' ... '|| n ||' resumos')
line
FROM (
SELECT temario, count(*) n
FROM neuro.reltrabalhos rr
WHERE neuro.apres_tipo(modalidade)=$1
group by 1 order by 1
) t1
) t2
),
(SELECT xmlelement(
name p,
'(Total na seção: ' ||count(*) || ' resumos)'
)
FROM neuro.reltrabalhos WHERE neuro.apres_tipo(modalidade)=$1
)
)
$f$ LANGUAGE SQL IMMUTABLE;


CREATE or replace FUNCTION name_for_index(p_name text) RETURNS text AS $f$
SELECT upper(x[array_length(x,1)])||',&#160;'|| initcap(array_to_string(x[1:array_length(x,1)-1],' '))
FROM regexp_split_to_array($1, E'\\s+') t(x);
$f$ LANGUAGE SQL IMMUTABLE;
23 changes: 23 additions & 0 deletions src/toSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,26 @@
)
)
FROM neuro.vw_relxml1;

-- Indice da Capa:
SELECT file_put_contents(
'/tmp/neuro2018_capa.htm',
xmlconcat(
neuro.sumario('Oral'),
neuro.sumario('Pôster'),
(select xmlelement(name p, 'Total geral '|| (SELECT count(*) FROM neuro.reltrabalhos) || ' resumos' ))
)::text
);

-- Indice dos autores:
SELECT file_put_contents(
'/tmp/neuro2018_idx.htm',
replace(xmlagg( xmlelement(name p, autor ||'...'|| array_to_string(itens,', ')) )::text, '<p', E'\n<p')
)
FROM (
SELECT
name_for_index(nome_full) autor, array_agg(r.pub_id) itens
FROM neuro.relTrabalhos r, LATERAL jsonb_to_recordset( (neuro.metadata_bycod(r.codigo))->'contribs' ) t(nome_full text)
GROUP BY 1
ORDER BY 1
) t;

0 comments on commit 11ca563

Please sign in to comment.