Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #114 from sanchis/change-api-infected
Browse files Browse the repository at this point in the history
Change api infected
  • Loading branch information
sanchis authored Jul 2, 2022
2 parents 8cb28b1 + 92f1155 commit 950658a
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 267 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
env:
NEW_INFECTED_URL: ${{ secrets.NEW_INFECTED_URL }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
jobs:
CD:
runs-on: ubuntu-latest
env:
NEW_INFECTED_URL: ${{ secrets.NEW_INFECTED_URL }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
Expand Down
21 changes: 5 additions & 16 deletions .github/workflows/schedule_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,15 @@ jobs:

- name: Install dependencies 👨🏻‍💻
run: npm ci --prefer-offline --no-audit

- name: Update latest number COVID-19
run: npm run update-log

- name: Upload update log
run: |
git config user.name cron-daily-update
git config user.email cron@cron.com
git add .
git commit -m "chore: Add report for today"
git push

- name: Run build 🏗
run: npm run build

- name: Run export 🚢
run: npm run export

# - name: Deploy 🚀
# uses: JamesIves/github-pages-deploy-action@v4.3.4
# with:
# branch: gh-pages # The branch the action should deploy to.
# folder: out # The folder the action should deploy.
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.4
with:
branch: gh-pages # The branch the action should deploy to.
folder: out # The folder the action should deploy.
29 changes: 14 additions & 15 deletions components/charts/NewInfectedChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import { CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, X
import Select from '../ui/select'

function dateParse (date) {
return parse(date, 'yyyy-MM-dd', new Date())
return parse(date, 'dd/MM/yy', new Date())
}
const valuesFilter = [
{
name: 'Últimos 6 meses',
value: '6MONTHS',
filter: (data) => data.filter(obj => isBefore(subMonths(new Date(), 6), dateParse(obj.fecha)))
filter: (data) => data.filter(obj => isBefore(subMonths(new Date(), 6), dateParse(obj.date)))
},
{
name: 'Últimos 3 meses',
value: '3MONTHS',
filter: (data) => data.filter(obj => isBefore(subMonths(new Date(), 3), dateParse(obj.fecha)))
filter: (data) => data.filter(obj => isBefore(subMonths(new Date(), 3), dateParse(obj.date)))
},
{
name: 'Ultimo mes',
name: 'Últimos 30 días',
value: '1MONTHS',
filter: (data) => data.filter(obj => isBefore(subMonths(new Date(), 1), dateParse(obj.fecha)))
filter: (data) => data.filter(obj => isBefore(subDays(new Date(), 30), dateParse(obj.date)))
},
{
name: 'Últimos 15 días',
value: '15DAYS',
filter: (data) => data.filter(obj => isBefore(subDays(new Date(), 15), dateParse(obj.fecha)))
filter: (data) => data.filter(obj => isBefore(subDays(new Date(), 15), dateParse(obj.date)))
},
{
name: 'Desde inicio hasta ahora',
Expand All @@ -41,18 +41,18 @@ export default function NewInfectedChart ({ newInfected }) {
function onChangeFilter (event) {
const filterFn = valuesFilter.find(filter => filter.value === event.target.value).filter
setFilter(event.target.value)
setData(filterFn(newInfected.chart))
setData(filterFn(newInfected))
}

useEffect(() => {
setData(DEFAULT_FILTER.filter(newInfected.chart))
}, [newInfected.chart])
setData(DEFAULT_FILTER.filter(newInfected))
}, [newInfected])

return (
<>
<h2>Nuevos casos COVID</h2>
<p className='text-cursive'>
Número de hospitalizaciones, número de ingresos en UCI y número de defunciones.
Número de positivos.
</p>
<Select
label='Filtro' style={{
Expand All @@ -66,13 +66,12 @@ export default function NewInfectedChart ({ newInfected }) {
<ResponsiveContainer height={500}>
<LineChart data={data} width={500} height={500}>
<CartesianGrid strokeDasharray='3 3' />
<XAxis dataKey='fecha' fontSize='12px' minTickGap={0} interval='preserveStartEnd' />
<XAxis dataKey='date' fontSize='12px' minTickGap={0} interval='preserveStartEnd' />
<Tooltip />
<Legend />
<Line type='monotone' name='Nuevos positivos' dataKey='numCasos' stroke='#77aab9' />
<Line type='monotone' name='Nuevos hospitalizados' dataKey='numHosp' stroke='#5883a9' />
<Line type='monotone' name='Nuevos UCI' dataKey='numUci' stroke='#305486' />
<Line type='monotone' name='Nuevas defunciones' dataKey='numDef' stroke='#15404a' />
<Line type='monotone' name='Nuevos positivos' dataKey='positiveNumber' stroke='#77aab9' />
<Line type='monotone' name='Nuevos positivos hombres' dataKey='men' stroke='#5883a9' />
<Line type='monotone' name='Nuevos positivos mujeres' dataKey='women' stroke='#305486' />
</LineChart>
</ResponsiveContainer>
</>
Expand Down
22 changes: 22 additions & 0 deletions components/charts/ZoneChart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import { CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, Tooltip, XAxis } from 'recharts'

export default function ZoneChart ({ data }) {
return (
<>
<h2>Datos zona sanitaria <span style={{ color: 'var(--primary-light-2)' }}>{data.name}</span></h2>
<p className='text-cursive'>
Número de PCR positivas.
</p>
<ResponsiveContainer height={500}>
<LineChart data={data.value} width={500} height={500}>
<CartesianGrid strokeDasharray='3 3' />
<XAxis dataKey='date' fontSize='12px' minTickGap={0} interval='preserveStartEnd' />
<Tooltip />
<Legend />
<Line type='monotone' name='Nuevos positivos' dataKey='positiveNumber' stroke='rgb(21,64,74)' />
</LineChart>
</ResponsiveContainer>
</>
)
}
19 changes: 19 additions & 0 deletions components/zonesList/components/filterZones/filterZones.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.containerFilter {
margin: var(--size-8) 0 var(--size-6) 0;
display: flex;
}

.selectOrder {
min-width: 200px;
width: auto;
}

@media (max-width: 600px) {
.containerFilter {
flex-direction: column;
margin: 0px;
}
.selectOrder {
width: 100%;
}
}
19 changes: 19 additions & 0 deletions components/zonesList/components/filterZones/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Card from 'components/ui/card'
import Input from 'components/ui/input'
import Select from 'components/ui/select'
import debounce from 'just-debounce-it'
import styles from './filterZones.module.css'

export default function FilterZones ({ onChangeSearchText, onChangeOrderBy }) {
const debounceOnChangeSearch = debounce((event) => onChangeSearchText(event.target.value), 250)
return (
<Card className={styles.containerFilter}>
<Select className={styles.selectOrder} onChange={(event) => onChangeOrderBy(event.target.value)}>
<option value='name'>Alfabéticamente</option>
<option value='positiveNumber'>Positivos COVID</option>
</Select>
<Input placeholder='Buscar por nombre' type='text' onChange={debounceOnChangeSearch} />

</Card>
)
}
48 changes: 48 additions & 0 deletions components/zonesList/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Card from 'components/ui/card'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import FilterZones from './components/filterZones'
import styles from './zonesList.module.css'

export default function ZonesList ({ zonesData }) {
const [searchText, setSearchText] = useState('')
const [orderBy, setOrderBy] = useState('name')
const [zones, setZones] = useState(zonesData)
const router = useRouter()

useEffect(() => {
setZones(
zonesData
.filter(zonesFilter => zonesFilter.name.toLowerCase().includes(searchText))
)
}, [searchText, zonesData])

useEffect(() => {
setZones(zn =>
[...zn].sort((a, b) =>
isNaN(a[orderBy])
? (a[orderBy] > b[orderBy] ? 1 : -1)
: (a[orderBy] < b[orderBy] ? 1 : -1)
)
)
}, [orderBy])

return (
<>
<h2 className={styles.header}>Información sobre distrito sanitarios</h2>
<p className='text-cursive'>Datos de los últimos 14 días</p>

<FilterZones onChangeOrderBy={(val) => setOrderBy(val)} onChangeSearchText={(val) => setSearchText(val.trim().toLowerCase())} />
<div className={styles.cardContainer}>
{zones
.map(zn =>
<Card key={zn.name} onClick={() => router.push(`zone/${zn.name}`)}>
<h3>{zn.name}</h3>
<h1 className='align-center'>{zn.positiveNumber}</h1>
<small className={`align-center ${styles.descriptionLabel}`}>Positivos</small>
</Card>)}
</div>
</>

)
}
17 changes: 17 additions & 0 deletions components/zonesList/zonesList.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.header {
margin-top: var(--size-1);
}

.cardContainer {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
justify-content: center;
align-items: center;
align-content: center;
grid-gap: var(--size-4);
}

.descriptionLabel{
margin-top: 0px;
display: block;
}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"build": "next build",
"export": "next export",
"start": "next start",
"update-log": "node ./scripts/index.js",
"debug": "NODE_OPTIONS='--inspect' next dev",
"lint": "next lint && standard",
"postbuild": "next-sitemap",
Expand All @@ -23,9 +22,7 @@
"recharts": "2.1.12"
},
"devDependencies": {
"@fast-csv/parse": "4.3.6",
"axios": "0.27.2",
"cheerio": "1.0.0-rc.12",
"date-fns": "2.28.0",
"dotenv": "16.0.1",
"eslint": "8.18.0",
Expand Down Expand Up @@ -54,6 +51,12 @@
"release": {
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github"
]
}
}
12 changes: 8 additions & 4 deletions pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import NewInfectedChart from 'components/charts/NewInfectedChart'
import newInfected from 'scripts/data/infected.json'
import ZonesList from 'components/zonesList'
import Head from 'next/head'
import { getNewInfected } from 'services/infected'

export default function Home ({ newInfected, municipalitiesData }) {
export default function Home ({ infected, zones }) {
return (
<>
<Head>
<title>Covid-19 Alicante | Estadísticas diarias</title>
</Head>

<NewInfectedChart newInfected={newInfected} />
<NewInfectedChart newInfected={infected} />
<ZonesList zonesData={zones} />
</>
)
}

export async function getStaticProps () {
const { zones, infected } = await getNewInfected()
return {
props: {
newInfected
infected,
zones
}
}
}
35 changes: 35 additions & 0 deletions pages/zone/[id].jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Head from 'next/head'
import ZoneChart from 'components/charts/ZoneChart'
import { getNewInfected } from 'services/infected'

export default function Municipios ({ data }) {
const title = `Covid-19 ${data.name} | Estadísticas diarias`
return (
<>
<Head>
<meta name='description' content={`Ultimas estadísticas sobre el covid en la zona sanitaria de ${data.name}. Información sobre todos los municipios de la ciudad de Alicante`} />
<title>{title}</title>
<meta property='og:description' content={`Ultimas estadísticas sobre el covid en la zona sanitaria de ${data.name}. Información sobre todos los municipios de la ciudad de Alicante`} />
<meta property='og:title' content={`Covid 19 ${data.name} | Estadísticas diarias`} />
</Head>
<ZoneChart data={data} />
</>
)
}

export async function getStaticProps ({ params }) {
const { zones } = await getNewInfected()
const zone = zones.find(zn => zn.name === params.id)

return {
props: {
data: zone
}
}
}

export async function getStaticPaths () {
const { zones } = await getNewInfected()
const paths = zones.map(zn => ({ params: { id: zn.name } }))
return { paths, fallback: false }
}
Loading

0 comments on commit 950658a

Please sign in to comment.