Skip to content

Commit 5f0252a

Browse files
Merge pull request #1615 from research-software-directory/1596-categories-metadata-overview
Add categories to project metadata overview
2 parents 5cbfd1b + 0b4c9d3 commit 5f0252a

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

database/106-project-views.sql

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,31 @@ GROUP BY
312312
output_for_project.project;
313313
$$;
314314

315+
316+
-- only counts assigned incidental leaf nodes of the category tree
317+
-- (nodes that can have children but of which no child is assigned)
318+
CREATE FUNCTION count_project_categories() RETURNS TABLE (
319+
project UUID,
320+
category_cnt INTEGER
321+
) LANGUAGE sql STABLE AS
322+
$$
323+
WITH project_category_paths AS (
324+
SELECT *
325+
FROM
326+
category_for_project
327+
INNER JOIN category_path(category_for_project.category_id) ON TRUE
328+
)
329+
SELECT
330+
category_for_project.project_id,
331+
COUNT(category_for_project.category_id)
332+
FROM
333+
category_for_project
334+
WHERE
335+
NOT EXISTS (SELECT * FROM project_category_paths WHERE project_category_paths.parent = category_for_project.category_id AND project_category_paths.project_id = category_for_project.project_id)
336+
GROUP BY category_for_project.project_id
337+
$$;
338+
339+
315340
CREATE FUNCTION project_status() RETURNS TABLE (
316341
project UUID,
317342
status VARCHAR(20)
@@ -347,7 +372,8 @@ CREATE FUNCTION project_quality(show_all BOOLEAN DEFAULT FALSE) RETURNS TABLE (
347372
keyword_cnt INTEGER,
348373
research_domain_cnt INTEGER,
349374
impact_cnt INTEGER,
350-
output_cnt INTEGER
375+
output_cnt INTEGER,
376+
category_cnt INTEGER
351377
) LANGUAGE sql STABLE AS
352378
$$
353379
SELECT
@@ -368,7 +394,8 @@ SELECT
368394
COALESCE(count_project_keywords.keyword_cnt, 0),
369395
COALESCE(count_project_research_domains.research_domain_cnt, 0),
370396
COALESCE(count_project_impact.impact_cnt, 0),
371-
COALESCE(count_project_output.output_cnt, 0)
397+
COALESCE(count_project_output.output_cnt, 0),
398+
COALESCE(count_project_categories.category_cnt, 0)
372399
FROM
373400
project
374401
LEFT JOIN
@@ -387,6 +414,8 @@ LEFT JOIN
387414
count_project_impact() ON project.id = count_project_impact.project
388415
LEFT JOIN
389416
count_project_output() ON project.id = count_project_output.project
417+
LEFT JOIN
418+
count_project_categories() ON project.id = count_project_categories.project
390419
WHERE
391420
CASE WHEN show_all IS TRUE THEN TRUE ELSE project.id IN (SELECT * FROM projects_of_current_maintainer()) END;
392421
$$;

frontend/components/user/project-quality/apiProjectQuality.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
// SPDX-FileCopyrightText: 2023 - 2025 Ewan Cahen (Netherlands eScience Center) <[email protected]>
2+
// SPDX-FileCopyrightText: 2023 - 2025 Netherlands eScience Center
13
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all)
2-
// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]>
3-
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
44
// SPDX-FileCopyrightText: 2023 dv4all
55
//
66
// SPDX-License-Identifier: Apache-2.0
@@ -29,6 +29,7 @@ export type ProjectQualityProps = {
2929
research_domain_cnt: number,
3030
impact_cnt: number,
3131
output_cnt: number,
32+
category_cnt: number,
3233
score: number
3334
}
3435

@@ -53,8 +54,9 @@ realLabels.set('keyword_cnt', {'label': 'Keywords', 'type': 'number'})
5354
realLabels.set('research_domain_cnt', {'label': 'Research domains', 'type': 'number'})
5455
realLabels.set('impact_cnt', {'label': 'Impact', 'type': 'number'})
5556
realLabels.set('output_cnt', {'label': 'Output', 'type': 'number'})
57+
realLabels.set('category_cnt', {'label': 'Categories', 'type': 'number'})
5658

57-
async function fetchProjectQuality(showAll: boolean, token:string) {
59+
async function fetchProjectQuality(showAll: boolean, token:string): Promise<ProjectQualityProps[]> {
5860
try {
5961
const url = getBaseUrl() + `/rpc/project_quality?show_all=${showAll}`
6062
const resp = await fetch(url, {
@@ -64,8 +66,7 @@ async function fetchProjectQuality(showAll: boolean, token:string) {
6466
})
6567
if (resp.status === 200) {
6668
const json:ProjectQualityProps[] = await resp.json()
67-
const data = handleData(json)
68-
return data
69+
return handleData(json)
6970
}
7071
logger(`fetchProjectQuality...${resp.status}: ${resp.statusText}`)
7172
return []
@@ -75,20 +76,23 @@ async function fetchProjectQuality(showAll: boolean, token:string) {
7576
}
7677
}
7778

78-
function handleData(data: ProjectQualityProps[]) {
79+
function handleData(data: ProjectQualityProps[]): ProjectQualityProps[] {
7980
data.forEach(element => {
8081
element.score = calculateScore(element)
8182
})
8283
return data
8384
}
8485

85-
function calculateScore(element:ProjectQualityProps) {
86+
function calculateScore(element:ProjectQualityProps): number {
8687
let score = 0
8788
let kpiCount = 0
8889

8990
const keys = Object.keys(element) as ProjectQualityKeys[]
9091
keys.forEach((key) => {
91-
if (key === 'title' || key === 'slug' || key === 'score') return
92+
if (key === 'title' || key === 'slug' || key === 'score') {
93+
return
94+
}
95+
9296
const value = element[key]
9397
if (typeof value !== 'undefined' && (value === true || (Number.isInteger(value) && value as number > 0) || typeof value === 'string')){
9498
score += 1

0 commit comments

Comments
 (0)