Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
MLumme committed Mar 1, 2024
2 parents e9ec943 + ce04415 commit 906f8f8
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 8 deletions.
60 changes: 59 additions & 1 deletion atlas-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"x": 0.5,
"y": 21,
"width": 28,
"height": 18,
"height": 20,
"fill": "#ebebeb",
"fill-opacity": 1,
"stroke": "black",
Expand Down Expand Up @@ -205,6 +205,64 @@
"textEN": "possible",
"display": "block"
},
"breedingCountTitle": {
"id": "breedingCountTitle",
"class": "title",
"x": 22,
"y": 25,
"font-size": 2.7,
"textFI": "Lkm.",
"textSV": "Nr.",
"textEN": "No.",
"display": "block"
},
"breedingCountClassD": {
"id": "breedingCountClassD",
"class": "breedingColourTitle",
"x": 22,
"y": 29.5,
"font-size": 2.2,
"text": "0",
"display": "block"
},
"breedingCountClassC": {
"id": "breedingCountClassC",
"class": "breedingColourTitle",
"x": 22,
"y": 32.5,
"font-size": 2.2,
"text": "0",
"display": "block"
},
"breedingCountClassB": {
"id": "breedingCountClassB",
"class": "breedingColourTitle",
"x": 22,
"y": 35.5,
"font-size": 2.2,
"text": "0",
"display": "block"
},
"breedingCountTotalTitle": {
"id": "breedingCountTotalTitle",
"class": "breedingColourTitle",
"x": 2,
"y": 38.5,
"font-size": 2.2,
"textFI": "yhteensä",
"textSV": "sum",
"textEN": "total",
"display": "block"
},
"breedingCountTotal": {
"id": "breedingCountTotal",
"class": "breedingColourTitle",
"x": 22,
"y": 38.5,
"font-size": 2.2,
"text": "0",
"display": "block"
},
"activityColourTitle": {
"id": "activityColourTitle",
"class": "title",
Expand Down
12 changes: 12 additions & 0 deletions src/main/dao/apiDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ApiDao {
page: 1,
cache: true,
dayOfYear: time,
needsCheck: false,
qualityIssues: 'NO_ISSUES',
completeListType: 'MY.completeListTypeComplete'
}
Expand All @@ -85,6 +86,7 @@ class ApiDao {
page: 1,
cache: true,
dayOfYear: time,
needsCheck: false,
qualityIssues: 'NO_ISSUES',
}

Expand Down Expand Up @@ -112,6 +114,7 @@ class ApiDao {
page: 1,
cache: true,
dayOfYear: time,
needsCheck: false,
qualityIssues: 'NO_ISSUES',
completeListType: 'MY.completeListTypeComplete'
}
Expand Down Expand Up @@ -142,6 +145,7 @@ class ApiDao {
page: 1,
cache: true,
dayOfYear: time,
needsCheck: false,
qualityIssues: 'NO_ISSUES',
}

Expand Down Expand Up @@ -170,6 +174,7 @@ class ApiDao {
page: 1,
cache: true,
dayOfYear: time,
needsCheck: false,
qualityIssues: 'NO_ISSUES',
}

Expand All @@ -192,6 +197,7 @@ class ApiDao {
page: 1,
cache: true,
dayOfYear: time,
needsCheck: false,
qualityIssues: 'NO_ISSUES',
completeListType: 'MY.completeListTypeComplete'
}
Expand Down Expand Up @@ -247,6 +253,7 @@ class ApiDao {
page: 1,
cache: true,
dayOfYear: time,
needsCheck: false,
qualityIssues: 'NO_ISSUES',
}

Expand Down Expand Up @@ -274,6 +281,7 @@ class ApiDao {
ykj10kmCenter: grid,
recordQuality: 'EXPERT_VERIFIED,COMMUNITY_VERIFIED,NEUTRAL',
hasValue: 'unit.atlasClass',
needsCheck: false,
pageSize: 10000,
cache: true,
}
Expand Down Expand Up @@ -301,6 +309,7 @@ class ApiDao {
coordinateAccuracyMax: 10000,
recordQuality: 'EXPERT_VERIFIED,COMMUNITY_VERIFIED,NEUTRAL',
hasValue: 'unit.atlasClass',
needsCheck: false,
pageSize: 10000,
page: page,
cache: true,
Expand Down Expand Up @@ -328,6 +337,7 @@ class ApiDao {
time: '2022/2025',
recordQuality: 'EXPERT_VERIFIED,COMMUNITY_VERIFIED,NEUTRAL',
hasValue: 'unit.atlasClass',
needsCheck: false,
pageSize: 10000,
cache: true,
}
Expand Down Expand Up @@ -355,6 +365,7 @@ class ApiDao {
recordQuality: 'EXPERT_VERIFIED,COMMUNITY_VERIFIED,NEUTRAL',
birdAssociationAreaId: associationId,
hasValue: 'unit.atlasClass',
needsCheck: false,
pageSize: 10000,
cache: true,
}
Expand Down Expand Up @@ -507,6 +518,7 @@ class ApiDao {
coordinateAccuracyMax: 10000,
taxonId: 'MX.37580',
recordQuality: 'EXPERT_VERIFIED,COMMUNITY_VERIFIED,NEUTRAL',
needsCheck: false,
pageSize: 10000
}
const key = url + JSON.stringify(params)
Expand Down
39 changes: 39 additions & 0 deletions src/main/domain/controllers/taxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,45 @@ class Taxon {
}
}
}

/**
* Returns the grid counts for specific taxon
* @returns {JSON}
*/
getSpeciesGridStats() {
return async (req, res) => {
try {
const { taxonId } = req.params
const breedingData = await apiDao.getGridAndBreedingdataForSpeciesAndActiveAtlas(taxonId)
const grid = await gridDao.getAll()

const stats = {
'MY.atlasClassEnumB': 0,
'MY.atlasClassEnumC': 0,
'MY.atlasClassEnumD': 0,
total: 0
}

const breedingDataLookup = {};
breedingData.forEach(data => {
breedingDataLookup[`${data['aggregateBy']['gathering.conversions.ykj10kmCenter.lat'].slice(0,3)}:${data['aggregateBy']['gathering.conversions.ykj10kmCenter.lon'].slice(0,3)}`] = urlRemover(data.atlasClassMax)
})

grid.forEach((square) => {
const atlasClass = breedingDataLookup[square.coordinates]

if (stats[atlasClass] !== undefined) {
stats[atlasClass] += 1
stats['total'] += 1
}
})

return res.json(stats)
} catch (e) {
return res.status(500).send(e.message)
}
}
}
}

module.exports = Taxon
7 changes: 7 additions & 0 deletions src/main/domain/maps/createAtlasMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ function createAtlasMap(gridArray, geoJsonArray, config) {
.addElement('rect', config.legend.breedingColourBox2, 'breedingLegend')
.setAttributesOfElement(config.legend.breedingColourBox2.id, {class: 'classB'})
.addElement('text', config.legend.breedingColourTitle2, 'breedingLegend')
.addElement('text', config.legend.breedingCountTotalTitle, 'breedingLegend')
.addElement('text', config.legend.breedingCountTitle, 'breedingLegend')
.addElement('text', config.legend.breedingCountClassD, 'breedingLegend')
.addElement('text', config.legend.breedingCountClassC, 'breedingLegend')
.addElement('text', config.legend.breedingCountClassB, 'breedingLegend')
.addElement('text', config.legend.breedingCountTotal, 'breedingLegend')

return svgImage
}

Expand Down
36 changes: 31 additions & 5 deletions src/main/domain/maps/mapService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {createCanvas, Image} = require('canvas')
const svg64 = require('svg64')
const urlRemover = require('../../helpers/urlRemover')

/**
* Provides an interface for map-related functionalities. When a ready-made atlas map is given as an argument, it is
Expand Down Expand Up @@ -32,18 +33,37 @@ function MapService(atlasMap, config) {
*/
getSpeciesMap: function(data, grid = [], species, callback, type = 'svg', scaleFactor = 4, language = 'fi', atlas, showActivity) {
const speciesMap = atlasMap.copy()
const atlasClassLookup = {}
const counts = {
'MY.atlasClassEnumD': 0,
'MY.atlasClassEnumC': 0,
'MY.atlasClassEnumB': 0,
'total': 0
}
for (let i = 0; i < data.length; i++) {
const cssClass = getClassForAtlasClass(data[i].atlasClass)
speciesMap.setAttributesOfElement(data[i].grid, {class: `cir ${cssClass}`})

atlasClassLookup[data[i].grid] = urlRemover(data[i].atlasClass)
}

if (showActivity) {
for (let i = 0; i < grid.length; i++) {
for (let i = 0; i < grid.length; i++) {
const coords = grid[i].grid
const atlasClass = atlasClassLookup[coords]

if (atlasClass !== undefined && atlasClass.slice(-1) !== 'A') {
counts[atlasClass] += 1
counts['total'] += 1
}

if (showActivity) {
const cssClass = getClassForActivityCategory(grid[i].activityCategory)
const id = `${grid[i].grid}bg`
speciesMap.setAttributesOfElement(id, {class: cssClass})
}
} else {
}

if (!showActivity) {
speciesMap.removeElementById('activityLegend')
}

Expand All @@ -58,7 +78,7 @@ function MapService(atlasMap, config) {
speciesMap.setDimensions('100%', '100%')
}

setLegend(speciesMap, species, language, atlas, showActivity)
setLegend(speciesMap, species, language, atlas, showActivity, counts)
if (type === 'png')
convertToPng(speciesMap, callback, width, height)
else
Expand All @@ -84,7 +104,7 @@ function MapService(atlasMap, config) {
return name.charAt(0).toUpperCase() + name.slice(1)
}

function setLegend(gridOverlay, species, language, atlas, showActivity) {
function setLegend(gridOverlay, species, language, atlas, showActivity, counts) {
const lan = language.toUpperCase()
const speciesName = 'species' + lan
setLegendTitle(gridOverlay, lan, atlas)
Expand All @@ -97,6 +117,12 @@ function MapService(atlasMap, config) {
.setText('breedingColourTitle4', config.legend.breedingColourTitle4[textName])
.setText('breedingColourTitle3', config.legend.breedingColourTitle3[textName])
.setText('breedingColourTitle2', config.legend.breedingColourTitle2[textName])
.setText('breedingCountTotalTitle', config.legend.breedingCountTotalTitle[textName])
.setText('breedingCountTitle', config.legend.breedingCountTitle[textName])
.setText('breedingCountClassD', counts['MY.atlasClassEnumD'])
.setText('breedingCountClassC', counts['MY.atlasClassEnumC'])
.setText('breedingCountClassB', counts['MY.atlasClassEnumB'])
.setText('breedingCountTotal', counts['total'])

if (showActivity) {
gridOverlay.setText('activityColourTitle', config.legend.activityColourTitle[textName])
Expand Down
1 change: 1 addition & 0 deletions src/main/domain/routers/taxonRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const taxon = new Taxon()
const taxonRouter = require('express').Router()
taxonRouter.get('/', taxon.getTaxonList())
taxonRouter.get('/:taxonId', taxon.getSpeciesFromList())
taxonRouter.get('/:taxonId/gridStats', taxon.getSpeciesGridStats())
taxonRouter.get('/biomon/:taxonSet/:grid', taxon.getCompleteList())
module.exports = taxonRouter
20 changes: 18 additions & 2 deletions src/main/static/doc/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,17 @@ schemas:
- prev:
type: object
ref: '#/schemas/Taxon'

TaxonSquareCount:
type: object
properties:
MY.atlasClassEnumD:
type: number
MY.atlasClassEnumC:
type: number
MY.atlasClassEnumB:
type: number
total:
type: number
examples:
grid1:
value:
Expand Down Expand Up @@ -744,4 +754,10 @@ examples:
en: Lesser White-fronted Goose
taxonomicOrder: 9
scientificName: Anser erythropus
intellectualRights: MZ.intellectualRightsCC-BY-4.0
intellectualRights: MZ.intellectualRightsCC-BY-4.0
taxonSquares:
value:
MY.atlasClassEnumD: 20
MY.atlasClassEnumC: 11
MY.atlasClassEnumB: 5
total: 36
18 changes: 18 additions & 0 deletions src/main/static/doc/openAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,24 @@ paths:
examples:
JSON:
$ref: 'components.yaml#/examples/taxon'
/taxon/{taxonId}/gridStats:
get:
parameters:
- $ref: "components.yaml#/parameters/taxonId"
summary: Get grid square counts for different atlas classes
tags:
- taxon
responses:
'200':
description: Count of grid squares in different atlas classes
content:
application/json:
schema:
type: object
$ref: 'components.yaml#/schemas/TaxonSquareCount'
examples:
JSON:
$ref: 'components.yaml#/examples/taxonSquares'
/taxon/biomon/{taxonSetId}/{grid}:
get:
parameters:
Expand Down

0 comments on commit 906f8f8

Please sign in to comment.