From 3f9ea37d1c3c87fdbfe5b9c5946a4c5be50183b3 Mon Sep 17 00:00:00 2001
From: Remco Tukker <remco.tukker@geant.org>
Date: Fri, 19 May 2023 13:14:35 +0200
Subject: [PATCH] clean up interfaces a bit further
---
compendium_v2/routes/budget.py | 8 +-
webapp/src/Schema.tsx | 101 +++++++++++---------------
webapp/src/helpers/dataconversion.tsx | 4 +-
3 files changed, 48 insertions(+), 65 deletions(-)
diff --git a/compendium_v2/routes/budget.py b/compendium_v2/routes/budget.py
index 3a7c2774..4d06ec0d 100644
--- a/compendium_v2/routes/budget.py
+++ b/compendium_v2/routes/budget.py
@@ -22,9 +22,9 @@ BUDGET_RESPONSE_SCHEMA = {
'nren': {'type': 'string'},
'nren_country': {'type': 'string'},
'budget': {'type': 'number'},
- 'budget_year': {'type': 'integer'},
+ 'year': {'type': 'integer'},
},
- 'required': ['nren', 'nren_country', 'budget', 'budget_year'],
+ 'required': ['nren', 'nren_country', 'budget', 'year'],
'additionalProperties': False
}
},
@@ -53,11 +53,11 @@ def budget_view() -> Any:
'nren': entry.nren.name,
'nren_country': entry.nren.country,
'budget': float(entry.budget),
- 'budget_year': entry.year,
+ 'year': entry.year,
}
entries = sorted(
[_extract_data(entry) for entry in db.session.scalars(select(BudgetEntry))],
- key=lambda d: (d['budget_year'], d['nren'])
+ key=lambda d: (d['year'], d['nren'])
)
return jsonify(entries)
diff --git a/webapp/src/Schema.tsx b/webapp/src/Schema.tsx
index 936bb30a..305a2a72 100644
--- a/webapp/src/Schema.tsx
+++ b/webapp/src/Schema.tsx
@@ -3,27 +3,57 @@ export interface Nren {
country: string
}
-export interface Budget {
- budget: string,
- budget_year: number,
+export interface FilterSelection {
+ selectedNrens: string[]
+ selectedYears: number[]
+}
+
+export interface NrenAndYearDatapoint {
nren: string,
- nren_country: string
+ nren_country: string,
+ year: number
+}
+
+export interface Budget extends NrenAndYearDatapoint {
+ budget: string
}
-export interface FundingSource {
+export interface FundingSource extends NrenAndYearDatapoint {
client_institutions: number,
commercial: number,
european_funding: number,
gov_public_bodies: number,
- other: number,
- nren: string,
- nren_country: string,
- year: number
+ other: number
}
-export interface FilterSelection {
- selectedNrens: string[]
- selectedYears: number[]
+export interface ChargingStructure extends NrenAndYearDatapoint {
+ fee_type: (string | null)
+}
+
+export interface NrenStaff extends NrenAndYearDatapoint {
+ permanent_fte: number,
+ subcontracted_fte: number,
+ technical_fte: number,
+ non_technical_fte: number
+}
+
+export interface Organisation extends NrenAndYearDatapoint {
+ name: string,
+ role?: string
+}
+
+export interface ECProject extends NrenAndYearDatapoint {
+ project: string
+}
+
+export interface Policy extends NrenAndYearDatapoint {
+ acceptable_use: string,
+ connectivity: string,
+ data_protection: string,
+ environmental: string,
+ equal_opportunity: string,
+ privacy_notice: string,
+ strategic_plan: string
}
export interface BasicDataset {
@@ -38,7 +68,6 @@ export interface BasicDataset {
}
export interface FundingSourceDataset {
-
labels: string[],
datasets: {
label: string,
@@ -54,13 +83,6 @@ export interface FundingSourceDataset {
}[]
}
-export interface ChargingStructure {
- nren: string,
- nren_country: string,
- year: number,
- fee_type: (string | null),
-}
-
export interface ChargingStructureDataset {
labels: string[],
datasets: {
@@ -74,16 +96,6 @@ export interface ChargingStructureDataset {
}[]
}
-export interface NrenStaff {
- nren: string,
- nren_country: string,
- year: number,
- permanent_fte: number,
- subcontracted_fte: number,
- technical_fte: number,
- non_technical_fte: number
-}
-
export interface NrenStaffDataset {
labels: string[],
@@ -100,32 +112,3 @@ export interface NrenStaffDataset {
hidden: boolean
}[]
}
-
-export interface Organisation {
- nren: string,
- nren_country: string,
- year: number,
- name: string,
- role?: string
-}
-
-export interface ECProject {
- nren: string,
- nren_country: string,
- year: number,
- project: string,
-}
-
-export interface Policy {
- nren: string,
- nren_country: string,
- year: number,
- acceptable_use: string,
- connectivity: string,
- data_protection: string,
- environmental: string,
- equal_opportunity: string,
- privacy_notice: string,
- strategic_plan: string
-}
-
diff --git a/webapp/src/helpers/dataconversion.tsx b/webapp/src/helpers/dataconversion.tsx
index d281c258..9a4e7ec1 100644
--- a/webapp/src/helpers/dataconversion.tsx
+++ b/webapp/src/helpers/dataconversion.tsx
@@ -117,14 +117,14 @@ export const createFundingSourceDataset = (fundingSourcesData: FundingSource[])
function createBudgetDataLookup(budgetEntries: Budget[]) {
const dataLookup = new Map<string, number>();
budgetEntries.forEach((item: Budget) => {
- const lookupKey = `${item.nren}/${item.budget_year}`;
+ const lookupKey = `${item.nren}/${item.year}`;
dataLookup.set(lookupKey, Number(item.budget));
})
return dataLookup;
}
export function createBudgetDataset(budgetEntries: Budget[]): BasicDataset {
- const labelsYear = [...new Set(budgetEntries.map((item) => item.budget_year))].sort();
+ const labelsYear = [...new Set(budgetEntries.map((item) => item.year))].sort();
const labelsNREN = [...new Set(budgetEntries.map((item) => item.nren))].sort();
const dataLookup = createBudgetDataLookup(budgetEntries);
--
GitLab