Skip to content

Commit

Permalink
Merge pull request #25 from unb-mds/feature/jose-graficos
Browse files Browse the repository at this point in the history
📝 charts
  • Loading branch information
joseandre25 authored Nov 30, 2023
2 parents 08acf0a + 852ae1c commit 0b0e6a5
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 49 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"lint": "next lint"
},
"dependencies": {
"apexcharts": "^3.44.0",
"chart.js": "^4.4.0",
"clsx": "2.0.0",
"next": "13.5.6",
"react": "18",
"react-apexcharts": "^1.4.1",
"react-chartjs-2": "^5.2.0",
"react-dom": "18"
},
Expand Down
62 changes: 62 additions & 0 deletions src/components/Charts/GraphComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { useState, useEffect } from 'react';
import dynamic from 'next/dynamic';
import { MunicipioData } from '../Custom/types'; // Defina o tipo de dados conforme necessário

const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });

interface GraphProps {
municipio: string;
}

const GraphComponent: React.FC<GraphProps> = ({ municipio }) => {
const [chartData, setChartData] = useState<any>({});

useEffect(() => {
const fetchData = async () => {
try {
const formattedMunicipio = municipio
.toLowerCase()
.replace(/\s+/g, '-') // Substitui espaços em branco por hífens
.normalize('NFD') // Normaliza caracteres acentuados
.replace(/[\u0300-\u036f]/g, ''); // Remove caracteres diacríticos

const response = await fetch(`https://raw.githubusercontent.com/unb-mds/2023-2-Squad07/main/public/${formattedMunicipio}_monthly_sums.json`);
const data: MunicipioData[] = await response.json();

const chartOptions = {
colors: ['#222831'],
xaxis: {
categories: data.map((item) => item.month),
},
};

const chartSeries = [
{
name: 'Quantidade de Avisos de Licitação',
data: data.map((item) => item.sum_num_avisos_licitacao),
},
];

setChartData({
options: chartOptions,
series: chartSeries,
});
} catch (error) {
console.error('Error fetching data:', error);
setChartData({}); // Limpa os dados do gráfico em caso de erro
}
};

fetchData();
}, [municipio]);

return (
<div>
{chartData.options && chartData.series && (
<Chart options={chartData.options} series={chartData.series} type="bar" height={350} />
)}
</div>
);
};

export default GraphComponent;
Empty file removed src/components/Charts/MyCharts.tsx
Empty file.
6 changes: 6 additions & 0 deletions src/components/Custom/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface MunicipioData {
municipio: string;
month: string;
sum_num_avisos_licitacao: number;
}

88 changes: 47 additions & 41 deletions src/components/Pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,73 +1,79 @@
import Image from "next/image";
import { useState, useEffect } from "react"
import { useState, useEffect } from "react";
import GraphComponent from "../Charts/GraphComponent";
import { MunicipioData } from '../Custom/types';

interface TitleProps {
municipio: string;
ano: string;
}

export const Home = ({ municipio, ano }: TitleProps) => {
const [titleText, setTitleText] = useState("Brasília");
const [bids, setBids] = useState<any>([]);

const buildTitle = () => {
fetch(`https://raw.githubusercontent.com/unb-mds/2023-2-Squad07/main/public/resultados.json`, {
method: 'GET',
}).then(res => res.json())
.then(res => setBids(res))
};
export const Home: React.FC<TitleProps> = ({ ano }) => {
const [selectedMunicipio, setSelectedMunicipio] = useState<string | null>(null);
const [titleText, setTitleText] = useState("Ceará");
const [bids, setBids] = useState<MunicipioData[]>([]);

useEffect(() => {
buildTitle();

if (municipio === 'geral') {
setTitleText('Ceará')
if (selectedMunicipio) {
setTitleText(selectedMunicipio);
} else {
setTitleText("Ceará");
}
}, [municipio]);
}, [selectedMunicipio]);

// Função para formatar a saída dos avisos
const formatAviso = (bid: any) => {
return (
<div className="aviso">
No dia <span className="text-red-500">{bid.pdf_filename.replace(/APRECE_(\d{2})_(\d{2})_(\d{2}).pdf/, '$1/$2/$3')}</span> houveram <span className="text-red-500">{bid.num_avisos_licitacao} avisos de licitação</span>.
</div>
);
const municipios = [
"Abaiara", "Acopiara", "Altaneira", "Alto Santo", "Antonina do Norte", "Aratuba", "Arneiroz", "Assaré",
"Banabuiú", "Barbalha", "Boa Viagem", "Campos Sales", "Cariús", "Chorozinho", "Croatá", "Ereré", "Farias Brito", "Fortim",
"Frecheirinha", "Groaíras", "Guaraciaba do Norte", "Ibaratama", "Ibicuitinga", "Icó", "Iguatu", "Irauçuba",
"Jaguaretama", "Jardim", "Jati", "Mauriti", "Milagres", "Mombaça", "Morada Nova", "Nova Olinda", "Nova Russas",
"Orós", "Palhano", "Piquet Carneiro", "Potengi", "Quiterianópolis", "Quixáda", "Quixelô", "Quixeré", "Salitre",
"Santana do Cariri", "Tabuleiro do Norte", "Várzea Alegre"
];

const handleMunicipioChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedMunicipio(event.target.value);
};

return (
<div className="flex">
<div className="bg-[#7f1d1d] w-80 h-screen p-4 text-white">
<p className="text-white font-bold text-2xl mt-4 mb-4">Confira as Licitação dos municípios do Ceará.</p>
<p className="text-white mt-4">Coletamos os diários oficiais municipais, separamos por municipios e analisamos as licitações. Com foco em simplicidade e replicabilidade, queremos impactar a forma como monitoramos atos do executivos nos municipios do Ceara</p>
{/* Logo da Universidade com dois espaços */}
<div className="bg-[#7f1d1d] w-80 h-screen p-4 text-white">
<p className="text-white font-bold text-2xl mt-4 mb-4">Confira a quantidade de avisos de licitação nos municípios do Ceará.</p>
<p className="text-white mt-4">Este projeto foi realizado pelo Squad 07 durante o segundo semestre de 2023 na disciplina Métodos de Desenvolvimento de Software da Universidade de Brasília.</p>
<Image
alt="logo-unb"
width={240}
height={240}
src="https://i.pinimg.com/originals/84/a7/86/84a786798c453d6a536f31cba73e5409.png"
/>
</div>
<div className="p-4 text-2xl 2xl:text-3xl 3xl:text-[2.4375rem] font-semibold lg:w-[42.93rem] leading-10">
<div className="p-4 text-2xl 2xl:text-3xl 3xl:text-[2.4375rem] font-semibold lg:w-[42.93rem] leading-10">
<div>
<label>Selecione o Município:</label>
<select
onChange={handleMunicipioChange}
value={selectedMunicipio || ''}
>
<option value="">Todos</option>
{municipios.map((municipio) => (
<option key={municipio} value={municipio}>
{municipio}
</option>
))}
</select>
</div>
{ano === "geral" ? (
<>
Acompanhe a quantidade de avisos de licitação que ocorreram no
<span className="text-[#4AA381]">{(" " + titleText) as string}</span>
Acompanhe a quantidade de avisos de licitação que ocorreram em todos os meses de 2023 em
<span className="text-[#802323]">{(" " + titleText) as string}</span>
</>
) : (
<>
Acompanhe a quantidade de avisos de licitação que ocorreram no
Acompanhe a quantidade de avisos de licitação que ocorreram em 2023 em
<span className="text-[#4AA381]">{(" " + titleText) as string} - {(" " + ano) as string}</span>
</>
)}
<br />
<div className="font-semibold">
{bids.map((bid: any, i: number) => (
<div key={i} className="flex-row pt-5 pb-5">
{formatAviso(bid)}
</div>
))}
</div>
<GraphComponent municipio={selectedMunicipio || ''} />
</div>
</div>
)
}
);
};
9 changes: 1 addition & 8 deletions src/components/Pages/Sobre.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Sobre = () => {
<h1 className="p-20 text-2xl 2xl:text-3xl 3xl:text-[2.4375rem] font-semibold lg:w-[42.93rem] leading-10">Conheça um pouco mais sobre os desenvolvedores do projeto</h1>
<section className="p-10 flex flex-col gap-y-6">
<p className="">
<strong>Jose Andre Rabelo: </strong>
<strong>José André Rabelo: </strong>
discente do curso de Engenharia de Software da UnB campus FGA
</p>
<p className=" font-normal">
Expand All @@ -37,16 +37,9 @@ export const Sobre = () => {
<strong>Rafael Oliveira Bonach: </strong>
discente do curso de Engenharia de Software da UnB campus FGA
</p>
<div className="bg-white p-9 rounded-3x1">
<p>O projeto tem como principal objetivo coletar, transformar em texto os diarios oficiais do Ceara</p>
<p>Alem da separaçao do conteudo por municipio, e separado por atos normativos </p>
<p>Tambem iremos ultilizar algoritmos computacionais para classificar e extrair informacoes </p>
<p> Mais especificamente, o nosso foco sera em abertura de edital de licitacao.</p>
</div>
</section>
</div>
<div>

</div>
</div>
)
Expand Down
File renamed without changes.
80 changes: 80 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@yr/monotone-cubic-spline@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@yr/monotone-cubic-spline/-/monotone-cubic-spline-1.0.3.tgz#7272d89f8e4f6fb7a1600c28c378cc18d3b577b9"
integrity sha512-FQXkOta0XBSUPHndIKON2Y9JeQz5ZeMqLYZVVK93FliNBFm7LNMIZmY6FrMEB9XPcDbE2bekMbZD6kzDkxwYjA==

acorn-jsx@^5.3.2:
version "5.3.2"
resolved "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz"
Expand Down Expand Up @@ -330,6 +335,19 @@ anymatch@~3.1.2:
normalize-path "^3.0.0"
picomatch "^2.0.4"

apexcharts@^3.44.0:
version "3.44.0"
resolved "https://registry.yarnpkg.com/apexcharts/-/apexcharts-3.44.0.tgz#b52f95b0d0c2a5357b4614fa42faac956b69a4a9"
integrity sha512-u7Xzrbcxc2yWznN78Jh5NMCYVAsWDfBjRl5ea++rVzFAqjU2hLz4RgKIFwYOBDRQtW1e/Qz8azJTqIJ1+Vu9Qg==
dependencies:
"@yr/monotone-cubic-spline" "^1.0.3"
svg.draggable.js "^2.2.2"
svg.easing.js "^2.0.0"
svg.filter.js "^2.0.2"
svg.pathmorphing.js "^0.1.3"
svg.resize.js "^1.4.3"
svg.select.js "^3.0.1"

arg@^5.0.2:
version "5.0.2"
resolved "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz"
Expand Down Expand Up @@ -1991,6 +2009,13 @@ queue-microtask@^1.2.2:
resolved "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz"
integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==

react-apexcharts@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/react-apexcharts/-/react-apexcharts-1.4.1.tgz#95ab31e4d2201308f59f3d2a4b65d10d9d0ea4bb"
integrity sha512-G14nVaD64Bnbgy8tYxkjuXEUp/7h30Q0U33xc3AwtGFijJB9nHqOt1a6eG0WBn055RgRg+NwqbKGtqPxy15d0Q==
dependencies:
prop-types "^15.8.1"

react-chartjs-2@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/react-chartjs-2/-/react-chartjs-2-5.2.0.tgz#43c1e3549071c00a1a083ecbd26c1ad34d385f5d"
Expand Down Expand Up @@ -2287,6 +2312,61 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

svg.draggable.js@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/svg.draggable.js/-/svg.draggable.js-2.2.2.tgz#c514a2f1405efb6f0263e7958f5b68fce50603ba"
integrity sha512-JzNHBc2fLQMzYCZ90KZHN2ohXL0BQJGQimK1kGk6AvSeibuKcIdDX9Kr0dT9+UJ5O8nYA0RB839Lhvk4CY4MZw==
dependencies:
svg.js "^2.0.1"

svg.easing.js@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/svg.easing.js/-/svg.easing.js-2.0.0.tgz#8aa9946b0a8e27857a5c40a10eba4091e5691f12"
integrity sha512-//ctPdJMGy22YoYGV+3HEfHbm6/69LJUTAqI2/5qBvaNHZ9uUFVC82B0Pl299HzgH13rKrBgi4+XyXXyVWWthA==
dependencies:
svg.js ">=2.3.x"

svg.filter.js@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/svg.filter.js/-/svg.filter.js-2.0.2.tgz#91008e151389dd9230779fcbe6e2c9a362d1c203"
integrity sha512-xkGBwU+dKBzqg5PtilaTb0EYPqPfJ9Q6saVldX+5vCRy31P6TlRCP3U9NxH3HEufkKkpNgdTLBJnmhDHeTqAkw==
dependencies:
svg.js "^2.2.5"

svg.js@>=2.3.x, svg.js@^2.0.1, svg.js@^2.2.5, svg.js@^2.4.0, svg.js@^2.6.5:
version "2.7.1"
resolved "https://registry.yarnpkg.com/svg.js/-/svg.js-2.7.1.tgz#eb977ed4737001eab859949b4a398ee1bb79948d"
integrity sha512-ycbxpizEQktk3FYvn/8BH+6/EuWXg7ZpQREJvgacqn46gIddG24tNNe4Son6omdXCnSOaApnpZw6MPCBA1dODA==

svg.pathmorphing.js@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/svg.pathmorphing.js/-/svg.pathmorphing.js-0.1.3.tgz#c25718a1cc7c36e852ecabc380e758ac09bb2b65"
integrity sha512-49HWI9X4XQR/JG1qXkSDV8xViuTLIWm/B/7YuQELV5KMOPtXjiwH4XPJvr/ghEDibmLQ9Oc22dpWpG0vUDDNww==
dependencies:
svg.js "^2.4.0"

svg.resize.js@^1.4.3:
version "1.4.3"
resolved "https://registry.yarnpkg.com/svg.resize.js/-/svg.resize.js-1.4.3.tgz#885abd248e0cd205b36b973c4b578b9a36f23332"
integrity sha512-9k5sXJuPKp+mVzXNvxz7U0uC9oVMQrrf7cFsETznzUDDm0x8+77dtZkWdMfRlmbkEEYvUn9btKuZ3n41oNA+uw==
dependencies:
svg.js "^2.6.5"
svg.select.js "^2.1.2"

svg.select.js@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/svg.select.js/-/svg.select.js-2.1.2.tgz#e41ce13b1acff43a7441f9f8be87a2319c87be73"
integrity sha512-tH6ABEyJsAOVAhwcCjF8mw4crjXSI1aa7j2VQR8ZuJ37H2MBUbyeqYr5nEO7sSN3cy9AR9DUwNg0t/962HlDbQ==
dependencies:
svg.js "^2.2.5"

svg.select.js@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/svg.select.js/-/svg.select.js-3.0.1.tgz#a4198e359f3825739226415f82176a90ea5cc917"
integrity sha512-h5IS/hKkuVCbKSieR9uQCj9w+zLHoPh+ce19bBYyqF53g6mnPB8sAtIbe1s9dh2S2fCmYX2xel1Ln3PJBbK4kw==
dependencies:
svg.js "^2.6.5"

tailwindcss@3, tailwindcss@^3.1:
version "3.3.3"
resolved "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.3.3.tgz"
Expand Down

0 comments on commit 0b0e6a5

Please sign in to comment.