Skip to content

Commit

Permalink
wip(mapa): Adiciona mapa de especies
Browse files Browse the repository at this point in the history
  • Loading branch information
Phenome committed Mar 14, 2024
1 parent 3a6c1a3 commit ade129f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
11 changes: 4 additions & 7 deletions web/src/components/Map.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
---
interface Props {
stateList: string[]
full?: boolean
data: [string, any][]
}
const { stateList } = Astro.props
const data = [
['Estado', 'Ocorrência'],
...stateList.map((state) => [state, state])
]
const { data, full } = Astro.props
---

<script type="module">
import 'https://cdn.skypack.dev/@google-web-components/google-chart'
</script>

<google-chart
class="h-[200px] w-auto"
class={full ? 'w-full h-full' : 'h-[200px] w-auto'}
type="geo"
data={JSON.stringify(data)}
options='{"region":"BR", "resolution":"provinces","title":"Ocorrências"}'
Expand Down
26 changes: 26 additions & 0 deletions web/src/lib/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ export async function countTaxa(filter: Record<string, unknown> = {}) {
return await taxa.countDocuments(filter)
}

export async function countTaxaRegions() {
const taxa = await getCollection('dwc2json', 'taxa')
return await taxa
.aggregate([
{
$match: {
taxonomicStatus: 'NOME ACEITO'
}
},
{
$unwind: {
path: '$distribution.occurrence'
}
},
{
$group: {
_id: '$distribution.occurrence',
count: {
$count: {}
}
}
}
])
.toArray()
}

export async function getTaxon(
kingdom: 'Plantae' | 'Fungi' | 'Animalia',
id: string,
Expand Down
18 changes: 18 additions & 0 deletions web/src/pages/mapa.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import Map from '../components/Map.astro'
import { countTaxaRegions } from '../lib/mongo'
const taxaRegions: { _id: string; count: number }[] = await countTaxaRegions()
---

<div
class="h-screen w-screen flex items-stretch justify-stretch overflow-hidden"
>
<Map
full
data={[
['Estado', 'Taxa'],
...taxaRegions.map(({ _id, count }) => [_id, count] as [string, number])
]}
/>
</div>
8 changes: 3 additions & 5 deletions web/src/pages/taxa.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
import BaseLayout from '../layouts/base.astro'
import { listTaxaPaginated } from '../lib/mongo'
import { countTaxa } from '../lib/mongo'
import { countTaxa, listTaxaPaginated } from '../lib/mongo'
const taxaNum = await countTaxa()
Expand Down Expand Up @@ -43,8 +41,8 @@ const searchParamsWithPage = (page: number) => {
}
---

<img src="/logoReflora.svg" alt="Reflora Logo" />
<BaseLayout useTransition title="Procura de Taxa">
<BaseLayout title="Procura de Taxa">
<img src="/logoReflora.svg" alt="Reflora Logo" />
<section class="m-2 p-2 border rounded border-slate-400 inline-block">
<h2 class="text-xl font-bold">Filtro</h2>
<form class="inline-flex flex-col gap-1">
Expand Down

0 comments on commit ade129f

Please sign in to comment.