Added funding graph for institution bund projects
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import List, Optional
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
@@ -73,3 +73,17 @@ class DfgProjectPage(Page):
|
||||
elements: List[DfgProjectSummary] = Field(
|
||||
default_factory=list, description="The DFG projects on this page."
|
||||
)
|
||||
|
||||
|
||||
class InstitutionFunderSummary(BaseModel):
|
||||
type: Literal["bund", "eu", "dfg"] = Field(
|
||||
description="The type of funding data (e.g., 'bund', 'eu', 'dfg')."
|
||||
)
|
||||
funding_per_year: dict = Field(
|
||||
default_factory=dict,
|
||||
description="A dictionary mapping years to total funding amounts for that year.",
|
||||
)
|
||||
annual_average_over_period: float = Field(
|
||||
default=0.0,
|
||||
description="The average annual funding over the continuous period covered by the data.",
|
||||
)
|
||||
|
||||
@@ -124,7 +124,7 @@ class BundProjectsSearchClient(ProjectsSearchClient):
|
||||
raise ValueError("Elasticsearch INSE API key is missing in settings.")
|
||||
super().__init__(
|
||||
base_url=settings.elasticsearch_inse_url,
|
||||
index="projects_bund",
|
||||
index="projects_bund_v1",
|
||||
api_key=settings.elasticsearch_inse_api_key,
|
||||
)
|
||||
|
||||
@@ -236,24 +236,6 @@ class BundProjectsSearchClient(ProjectsSearchClient):
|
||||
response = await self.make_search_request(query)
|
||||
return self.response_to_bund_project_page(response, page, size)
|
||||
|
||||
async def get_bund_projects_by_institution_name(
|
||||
self,
|
||||
institution_names: List[str],
|
||||
page: int,
|
||||
size: int,
|
||||
sort_by: str = "topic",
|
||||
sort_direction: str = "asc",
|
||||
) -> BundProjectPage:
|
||||
query = self.bund_projects_query(
|
||||
page=page,
|
||||
size=size,
|
||||
institution_names=institution_names,
|
||||
sort_by=sort_by,
|
||||
sort_direction=sort_direction,
|
||||
)
|
||||
response = await self.make_search_request(query)
|
||||
return self.response_to_bund_project_page(response, page, size)
|
||||
|
||||
|
||||
class EuProjectsSearchClient(ProjectsSearchClient):
|
||||
def __init__(self):
|
||||
|
||||
@@ -4,7 +4,12 @@ from typing import Annotated, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, status
|
||||
|
||||
from inse.projects.model import BundProjectPage, DfgProjectPage, EuProjectPage
|
||||
from inse.projects.model import (
|
||||
BundProjectPage,
|
||||
DfgProjectPage,
|
||||
EuProjectPage,
|
||||
InstitutionFunderSummary,
|
||||
)
|
||||
from inse.tags import Tags
|
||||
from inse.projects import service as projects_service
|
||||
from inse.projects.projects_search_client import (
|
||||
@@ -83,6 +88,38 @@ async def get_bund_projects(
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/institution/bund/funding-over-time",
|
||||
summary="Get funding over time for bund projects.",
|
||||
description="Returns the funding over time for bund projects associated with the specified institution.",
|
||||
operation_id="getBundFundingOverTime",
|
||||
responses={
|
||||
status.HTTP_200_OK: {
|
||||
"description": "Successful Response",
|
||||
"model": InstitutionFunderSummary,
|
||||
},
|
||||
status.HTTP_404_NOT_FOUND: {"description": "Institution not found"},
|
||||
},
|
||||
response_model_by_alias=False,
|
||||
)
|
||||
async def get_bund_funding_over_time(
|
||||
bund_search_client: Annotated[
|
||||
BundProjectsSearchClient, Depends(get_bund_search_client)
|
||||
],
|
||||
institutions_search_client: Annotated[
|
||||
InstitutionsSearchClient, Depends(get_institutions_search_client)
|
||||
],
|
||||
institution_id: Annotated[
|
||||
str, Query(description="The institution ID to filter by.")
|
||||
],
|
||||
) -> InstitutionFunderSummary:
|
||||
return await projects_service.get_institution_bund_funding_over_time(
|
||||
bund_search_client=bund_search_client,
|
||||
institutions_search_client=institutions_search_client,
|
||||
institution_id=institution_id,
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/institution/eu/search",
|
||||
summary="Get EU projects.",
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import datetime
|
||||
import logging
|
||||
from typing import List, Optional
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
from inse.projects.projects_search_client import (
|
||||
BundProjectsSearchClient,
|
||||
DfgProjectsSearchClient,
|
||||
EuProjectsSearchClient,
|
||||
)
|
||||
from inse.projects.model import BundProjectPage, DfgProjectPage, EuProjectPage
|
||||
from inse.projects.model import (
|
||||
BundProjectPage,
|
||||
DfgProjectPage,
|
||||
EuProjectPage,
|
||||
InstitutionFunderSummary,
|
||||
)
|
||||
from inse.institutions.institutions_search_client import (
|
||||
InstitutionsSearchClient,
|
||||
)
|
||||
@@ -78,30 +84,6 @@ async def get_eu_projects_by_institution_id(
|
||||
return response
|
||||
|
||||
|
||||
async def get_bund_projects_by_institution_name(
|
||||
bund_search_client: BundProjectsSearchClient,
|
||||
page: int,
|
||||
size: int,
|
||||
institution_names: List[str] = [],
|
||||
sort_by: str = "topic",
|
||||
sort_direction: str = "asc",
|
||||
) -> BundProjectPage:
|
||||
logger.info(
|
||||
f"Fetching bund projects for institution_names={institution_names}, page={page}, size={size}"
|
||||
)
|
||||
response = await bund_search_client.search_bund_projects(
|
||||
page=page,
|
||||
size=size,
|
||||
institution_names=institution_names,
|
||||
sort_by=sort_by,
|
||||
sort_direction=sort_direction,
|
||||
)
|
||||
|
||||
logger.debug(f"get_bund_projects_by_institution_name response: {response}")
|
||||
|
||||
return response
|
||||
|
||||
|
||||
async def get_dfg_projects_by_author_id(
|
||||
dfg_search_client: DfgProjectsSearchClient,
|
||||
author_id: str,
|
||||
@@ -131,3 +113,76 @@ async def get_dfg_projects_by_author_id(
|
||||
sort_direction=sort_direction,
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
async def get_institution_bund_funding_over_time(
|
||||
bund_search_client: BundProjectsSearchClient,
|
||||
institutions_search_client: InstitutionsSearchClient,
|
||||
institution_id: str,
|
||||
) -> InstitutionFunderSummary:
|
||||
logger.info(f"Fetching funding over time for institution_id={institution_id}")
|
||||
institution_aliases = institutions_search_client.get_institution_aliases_by_id(
|
||||
institution_id
|
||||
)
|
||||
logger.debug(
|
||||
f"Found institution aliases for institution_id={institution_id}: {institution_aliases}"
|
||||
)
|
||||
response = await bund_search_client.search_bund_projects(
|
||||
page=0,
|
||||
size=10000,
|
||||
institution_names=institution_aliases,
|
||||
)
|
||||
|
||||
funding_per_year: Dict[int, float] = {}
|
||||
for project in response.elements:
|
||||
funding_start = project.funding_start
|
||||
funding_end = project.funding_end
|
||||
funding_amount = project.grant_amount
|
||||
if not funding_start or not funding_end or not funding_amount:
|
||||
continue
|
||||
|
||||
delta = (funding_end - funding_start).days + 1
|
||||
if delta <= 0:
|
||||
continue
|
||||
|
||||
amount_per_day = funding_amount / delta
|
||||
start_year = funding_start.year
|
||||
end_year = funding_end.year
|
||||
|
||||
for year in range(start_year, end_year + 1):
|
||||
if year == start_year:
|
||||
year_start = funding_start
|
||||
else:
|
||||
year_start = datetime.date(year, 1, 1)
|
||||
|
||||
if year == end_year:
|
||||
year_end = funding_end
|
||||
else:
|
||||
year_end = datetime.date(year, 12, 31)
|
||||
|
||||
days_in_year = (year_end - year_start).days + 1
|
||||
proportional_share = days_in_year * amount_per_day
|
||||
|
||||
funding_per_year[year] = (
|
||||
funding_per_year.get(year, 0.0) + proportional_share
|
||||
)
|
||||
|
||||
sorted_funding_per_year: Dict[int, float] = {}
|
||||
|
||||
if funding_per_year:
|
||||
min_year = min(funding_per_year.keys())
|
||||
max_year = max(funding_per_year.keys())
|
||||
|
||||
for year in range(min_year, max_year + 1):
|
||||
sorted_funding_per_year[year] = funding_per_year.get(year, 0.0)
|
||||
|
||||
total_sum = sum(sorted_funding_per_year.values())
|
||||
annual_average_over_period = total_sum / len(sorted_funding_per_year)
|
||||
else:
|
||||
annual_average_over_period = 0.0
|
||||
|
||||
return InstitutionFunderSummary(
|
||||
type="bund",
|
||||
funding_per_year=sorted_funding_per_year,
|
||||
annual_average_over_period=annual_average_over_period,
|
||||
)
|
||||
|
||||
+136
-16
@@ -456,37 +456,157 @@ Content-Type: application/json
|
||||
|
||||
|
||||
###
|
||||
GET https://inse.nes.uni-due.de/elastic/projects_bund/_mapping
|
||||
GET https://inse.nes.uni-due.de/elastic/projects_bund_v1/_mapping
|
||||
Authorization: ApiKey bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FMEhMZw==
|
||||
Content-Type: application/json
|
||||
|
||||
###
|
||||
GET https://inse.nes.uni-due.de/elastic/projects_bund/_search
|
||||
GET https://inse.nes.uni-due.de/elastic/projects_bund_v1/_search
|
||||
Authorization: ApiKey bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FMEhMZw==
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
|
||||
"size": 10,
|
||||
"from": 1000,
|
||||
"size": 0,
|
||||
"query": {
|
||||
"match": {
|
||||
"Zuwendungsempf\u00e4nger": {
|
||||
"query": "Universit\u00e4t Duisburg-Essen",
|
||||
"operator": "and"
|
||||
}
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"bool": {
|
||||
"should": [
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "university of duisburg-eßen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "university of duisburg-essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universitaet duisburg-essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universitaet duisburg essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universität duisburg-essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universitat duisburg-eßen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universitat duisburg essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "university of duisburg essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universitat duisburg-essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universität duisburg-eßen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"Zuwendungsempfänger": {
|
||||
"query": "universität duisburg essen",
|
||||
"operator": "and"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"minimum_should_match": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"sort": [
|
||||
{
|
||||
"Thema.keyword": {
|
||||
"order": "asc"
|
||||
"aggs": {
|
||||
"distributed_annual_amounts": {
|
||||
"scripted_metric": {
|
||||
"init_script": "state.years_map = [:]",
|
||||
"map_script": "if (doc['funding_start'].size() == 0 || doc['funding_end'].size() == 0 || doc['Fördersumme'].size() == 0) { return; } def start = doc['funding_start'].value.toLocalDate(); def end = doc['funding_end'].value.toLocalDate(); def totalAmount = doc['Fördersumme'].value; def startYear = start.getYear(); def endYear = end.getYear(); if (startYear == endYear) { state.years_map[startYear] = state.years_map.getOrDefault(startYear, 0.0) + totalAmount; } else { long totalDays = ChronoUnit.DAYS.between(start, end) + 1; if (totalDays <= 0) return; double amountPerDay = totalAmount / (double)totalDays; for (int y = startYear; y <= endYear; y++) { def yearStart = (y == startYear) ? start : LocalDate.of(y, 1, 1); def yearEnd = (y == endYear) ? end : LocalDate.of(y, 12, 31); long daysInYear = ChronoUnit.DAYS.between(yearStart, yearEnd) + 1; double proportionalShare = daysInYear * amountPerDay; state.years_map[y] = state.years_map.getOrDefault(y, 0.0) + proportionalShare; } }",
|
||||
"combine_script": "return state.years_map",
|
||||
"reduce_script": "def final_map = [:]; for (state in states) { for (entry in state.entrySet()) { final_map[entry.getKey()] = final_map.getOrDefault(entry.getKey(), 0.0) + entry.getValue(); } } if (final_map.isEmpty()) { return ['funding_per_year': final_map, 'annual_average_over_period': 0.0]; } double totalSum = 0.0; for (val in final_map.values()) { totalSum += val; } double avg = totalSum / final_map.size(); return ['funding_per_year': final_map, 'annual_average_over_period': avg];"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
###
|
||||
|
||||
# {
|
||||
|
||||
# "size": 10,
|
||||
# "from": 1000,
|
||||
# "query": {
|
||||
# "match": {
|
||||
# "Zuwendungsempf\u00e4nger": {
|
||||
# "query": "Universit\u00e4t Duisburg-Essen",
|
||||
# "operator": "and"
|
||||
# }
|
||||
# }
|
||||
# },
|
||||
# "sort": [
|
||||
# {
|
||||
# "Thema.keyword": {
|
||||
# "order": "asc"
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
|
||||
# }
|
||||
|
||||
#{'size': 10, 'from': 0, 'query': {'match': {'Zuwendungsempfänger': {'query': 'Universität Duisburg-Essen', 'operator': 'and'}}}, 'sort': [{'Thema': {'order': 'asc'}}]}
|
||||
|
||||
# {
|
||||
|
||||
@@ -65,6 +65,7 @@ model/groupByResult.ts
|
||||
model/hTTPValidationError.ts
|
||||
model/identityGrant.ts
|
||||
model/institution.ts
|
||||
model/institutionFunderSummary.ts
|
||||
model/institutionGeo.ts
|
||||
model/institutionIds.ts
|
||||
model/institutionInformation.ts
|
||||
|
||||
@@ -24,6 +24,8 @@ import { DfgProjectPage } from '../model/dfgProjectPage';
|
||||
import { EuProjectPage } from '../model/euProjectPage';
|
||||
// @ts-ignore
|
||||
import { HTTPValidationError } from '../model/hTTPValidationError';
|
||||
// @ts-ignore
|
||||
import { InstitutionFunderSummary } from '../model/institutionFunderSummary';
|
||||
|
||||
// @ts-ignore
|
||||
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
|
||||
@@ -41,6 +43,67 @@ export class ProjectsService extends BaseService {
|
||||
super(basePath, configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get funding over time for bund projects.
|
||||
* Returns the funding over time for bund projects associated with the specified institution.
|
||||
* @endpoint get /api/projects/institution/bund/funding-over-time
|
||||
* @param institutionId The institution ID to filter by.
|
||||
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||
* @param reportProgress flag to report request and response progress.
|
||||
*/
|
||||
public getBundFundingOverTime(institutionId: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<InstitutionFunderSummary>;
|
||||
public getBundFundingOverTime(institutionId: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<InstitutionFunderSummary>>;
|
||||
public getBundFundingOverTime(institutionId: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<InstitutionFunderSummary>>;
|
||||
public getBundFundingOverTime(institutionId: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||
if (institutionId === null || institutionId === undefined) {
|
||||
throw new Error('Required parameter institutionId was null or undefined when calling getBundFundingOverTime.');
|
||||
}
|
||||
|
||||
let localVarQueryParameters = new HttpParams({encoder: this.encoder});
|
||||
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
|
||||
<any>institutionId, 'institution_id');
|
||||
|
||||
let localVarHeaders = this.defaultHeaders;
|
||||
|
||||
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||
'application/json'
|
||||
]);
|
||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
|
||||
}
|
||||
|
||||
const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();
|
||||
|
||||
const localVarTransferCache: boolean = options?.transferCache ?? true;
|
||||
|
||||
|
||||
let responseType_: 'text' | 'json' | 'blob' = 'json';
|
||||
if (localVarHttpHeaderAcceptSelected) {
|
||||
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
|
||||
responseType_ = 'text';
|
||||
} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
|
||||
responseType_ = 'json';
|
||||
} else {
|
||||
responseType_ = 'blob';
|
||||
}
|
||||
}
|
||||
|
||||
let localVarPath = `/api/projects/institution/bund/funding-over-time`;
|
||||
const { basePath, withCredentials } = this.configuration;
|
||||
return this.httpClient.request<InstitutionFunderSummary>('get', `${basePath}${localVarPath}`,
|
||||
{
|
||||
context: localVarHttpContext,
|
||||
params: localVarQueryParameters,
|
||||
responseType: <any>responseType_,
|
||||
...(withCredentials ? { withCredentials } : {}),
|
||||
headers: localVarHeaders,
|
||||
observe: observe,
|
||||
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
|
||||
reportProgress: reportProgress
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bund projects.
|
||||
* Returns a page of bund projects based on the provided pagination parameters and optional institution filter.
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Innovation Search Engine API
|
||||
*
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface InstitutionFunderSummary {
|
||||
/**
|
||||
* The type of funding data (e.g., \'bund\', \'eu\', \'dfg\').
|
||||
*/
|
||||
type: InstitutionFunderSummary.TypeEnum;
|
||||
/**
|
||||
* A dictionary mapping years to total funding amounts for that year.
|
||||
*/
|
||||
funding_per_year?: object;
|
||||
/**
|
||||
* The average annual funding over the continuous period covered by the data.
|
||||
*/
|
||||
annual_average_over_period?: number;
|
||||
}
|
||||
export namespace InstitutionFunderSummary {
|
||||
export const TypeEnum = {
|
||||
Bund: 'bund',
|
||||
Eu: 'eu',
|
||||
Dfg: 'dfg'
|
||||
} as const;
|
||||
export type TypeEnum = typeof TypeEnum[keyof typeof TypeEnum];
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ export * from './groupByResult';
|
||||
export * from './hTTPValidationError';
|
||||
export * from './identityGrant';
|
||||
export * from './institution';
|
||||
export * from './institutionFunderSummary';
|
||||
export * from './institutionGeo';
|
||||
export * from './institutionIds';
|
||||
export * from './institutionInformation';
|
||||
|
||||
@@ -9,6 +9,7 @@ import { bundProjectsResolver } from './resolvers/bund-projects.resolver';
|
||||
import { euProjectsResolver } from './resolvers/eu-projects.resolver';
|
||||
import { dfgProjectsResolver } from './resolvers/dfg-projects.resolver';
|
||||
import { institutionsResolver } from './resolvers/institutions.resolver';
|
||||
import { bundProjectsFundingResolver } from './resolvers/bund-projects-funding.resolver';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
@@ -230,6 +231,7 @@ export const routes: Routes = [
|
||||
resolve: {
|
||||
bundProjectPage: bundProjectsResolver,
|
||||
euProjectPage: euProjectsResolver,
|
||||
bundProjectsFunding: bundProjectsFundingResolver,
|
||||
},
|
||||
runGuardsAndResolvers: (from, to) => {
|
||||
const keys = ['page', 'size', 'sort_by', 'sort_direction', 'search'];
|
||||
@@ -239,14 +241,7 @@ export const routes: Routes = [
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
runGuardsAndResolvers: (from, to) => {
|
||||
const keys = ['page', 'size', 'sort_by', 'sort_direction'];
|
||||
|
||||
return keys.some(
|
||||
(key) => from.queryParamMap.get(key) !== to.queryParamMap.get(key),
|
||||
);
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
path: 'error',
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
<div echarts [options]="options"></div>
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
import { Component, effect, input } from '@angular/core';
|
||||
|
||||
import * as echarts from 'echarts/core';
|
||||
import { EChartsOption } from 'echarts';
|
||||
|
||||
import { GridComponent, LegendComponent } from 'echarts/components';
|
||||
import { CanvasRenderer } from 'echarts/renderers';
|
||||
import { NgxEchartsDirective } from 'ngx-echarts';
|
||||
import { InstitutionFunderSummary } from '../../api';
|
||||
|
||||
echarts.use([GridComponent, CanvasRenderer, LegendComponent]);
|
||||
|
||||
type FunderData = {
|
||||
funderName: string;
|
||||
fundingMap: Record<number, number>;
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'app-institution-projects-funding-graph',
|
||||
imports: [NgxEchartsDirective],
|
||||
templateUrl: './institution-projects-funding-graph.component.html',
|
||||
styleUrl: './institution-projects-funding-graph.component.scss',
|
||||
})
|
||||
export class InstitutionProjectsFundingGraphComponent {
|
||||
options!: EChartsOption;
|
||||
|
||||
fundings = input.required<InstitutionFunderSummary[]>();
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const fundings = this.fundings();
|
||||
this.generateChartOptions(fundings);
|
||||
});
|
||||
}
|
||||
|
||||
generateChartOptions(fundings: InstitutionFunderSummary[]): void {
|
||||
const floorToTwoDecimals = (value: number): string => {
|
||||
const floored = Math.floor(value * 100) / 100;
|
||||
return floored.toLocaleString(undefined, {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
};
|
||||
|
||||
const yearsSet = new Set<string>();
|
||||
|
||||
fundings.forEach((series) => {
|
||||
if (series.funding_per_year) {
|
||||
Object.keys(series.funding_per_year).forEach((year) =>
|
||||
yearsSet.add(year),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const xAxisYears = Array.from(yearsSet).sort(
|
||||
(a, b) => Number(a) - Number(b),
|
||||
);
|
||||
|
||||
const currentYearStr = new Date().getFullYear().toString();
|
||||
|
||||
const chartSeries = fundings.map((series, index) => {
|
||||
const fundingMap = (series.funding_per_year || {}) as Record<
|
||||
string,
|
||||
number
|
||||
>;
|
||||
const dataPoints = xAxisYears.map((year) => fundingMap[year] ?? 0);
|
||||
|
||||
const baseSeries: any = {
|
||||
name: series.type.toUpperCase(),
|
||||
type: 'line',
|
||||
stack: 'TotalInstitutionalFunding',
|
||||
areaStyle: {},
|
||||
emphasis: { focus: 'series' },
|
||||
data: dataPoints,
|
||||
};
|
||||
|
||||
if (index === 0) {
|
||||
baseSeries.markLine = {
|
||||
symbol: ['none', 'none'],
|
||||
silent: true,
|
||||
label: {
|
||||
show: true,
|
||||
position: 'end',
|
||||
formatter: 'Aktuelles Jahr',
|
||||
backgroundColor: '#333',
|
||||
color: '#fff',
|
||||
padding: [4, 6],
|
||||
borderRadius: 4,
|
||||
},
|
||||
lineStyle: {
|
||||
color: '#ff4d4f',
|
||||
type: 'dashed',
|
||||
width: 2,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
xAxis: currentYearStr,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
return baseSeries;
|
||||
});
|
||||
|
||||
this.options = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
axisPointer: {
|
||||
type: 'cross',
|
||||
label: { backgroundColor: '#6a7985' },
|
||||
},
|
||||
valueFormatter: (value) => {
|
||||
const numericValue = Array.isArray(value) ? 0 : Number(value ?? 0);
|
||||
return floorToTwoDecimals(numericValue);
|
||||
},
|
||||
},
|
||||
legend: {
|
||||
data: fundings.map((series) => series.type.toUpperCase()),
|
||||
top: '10%',
|
||||
},
|
||||
grid: {
|
||||
left: '4%',
|
||||
right: '4%',
|
||||
bottom: '5%',
|
||||
containLabel: true,
|
||||
},
|
||||
xAxis: [
|
||||
{
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: xAxisYears,
|
||||
},
|
||||
],
|
||||
yAxis: [
|
||||
{
|
||||
type: 'value',
|
||||
axisLabel: {
|
||||
formatter: (value: number) =>
|
||||
value.toLocaleString(undefined, {
|
||||
style: 'currency',
|
||||
currency: 'EUR',
|
||||
maximumFractionDigits: 0,
|
||||
}),
|
||||
},
|
||||
},
|
||||
],
|
||||
series: chartSeries,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,89 @@
|
||||
<div class="content">
|
||||
<h3>Projekte</h3>
|
||||
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-content>
|
||||
<mat-form-field style="width: 100%">
|
||||
<mat-label>Suche nach Themen</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="search"
|
||||
[debounceTime]="300"
|
||||
[(debouncedValue)]="urlSearchTerm"
|
||||
(debouncedValueChange)="handleSearchTermChange($event)" />
|
||||
<mat-icon matPrefix>search</mat-icon>
|
||||
<button matIconButton matSuffix (click)="clearSearchTerm()">
|
||||
<mat-icon>clear</mat-icon>
|
||||
</button>
|
||||
</mat-form-field>
|
||||
<mat-tab-group
|
||||
[selectedIndex]="tabIndex()"
|
||||
(selectedTabChange)="selectedTabChange($event)">
|
||||
<mat-tab label="EU">
|
||||
<app-data-table
|
||||
[data]="euProjectData"
|
||||
[columns]="euProjectColumns"
|
||||
[activeSortKey]="urlSortKey()"
|
||||
[sortDirection]="urlSortDirection()"
|
||||
(sortChange)="handleSortChange($event)" />
|
||||
</mat-tab>
|
||||
<mat-tab label="Bund">
|
||||
<app-data-table
|
||||
[data]="bundProjectData"
|
||||
[columns]="bundProjectColumns"
|
||||
[activeSortKey]="urlSortKey()"
|
||||
[sortDirection]="urlSortDirection()"
|
||||
(sortChange)="handleSortChange($event)" />
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
<mat-paginator
|
||||
[length]="this.pageTotal()"
|
||||
[pageSize]="this.pageSize()"
|
||||
[pageIndex]="this.pageIndex()"
|
||||
(page)="handlePageChange($event)" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
<div class="funding-area">
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-content>
|
||||
<mat-form-field style="width: 100%">
|
||||
<mat-label>Suche nach Themen</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="search"
|
||||
[debounceTime]="300"
|
||||
[(debouncedValue)]="urlSearchTerm"
|
||||
(debouncedValueChange)="handleSearchTermChange($event)" />
|
||||
<mat-icon matPrefix>search</mat-icon>
|
||||
<button matIconButton matSuffix (click)="clearSearchTerm()">
|
||||
<mat-icon>clear</mat-icon>
|
||||
</button>
|
||||
</mat-form-field>
|
||||
<mat-tab-group
|
||||
[selectedIndex]="tabIndex()"
|
||||
(selectedTabChange)="selectedTabChange($event)">
|
||||
<mat-tab label="EU">
|
||||
<app-data-table
|
||||
[data]="euProjectData"
|
||||
[columns]="euProjectColumns"
|
||||
[activeSortKey]="urlSortKey()"
|
||||
[sortDirection]="urlSortDirection()"
|
||||
(sortChange)="handleSortChange($event)" />
|
||||
</mat-tab>
|
||||
<mat-tab label="Bund">
|
||||
<app-data-table
|
||||
[data]="bundProjectData"
|
||||
[columns]="bundProjectColumns"
|
||||
[activeSortKey]="urlSortKey()"
|
||||
[sortDirection]="urlSortDirection()"
|
||||
(sortChange)="handleSortChange($event)" />
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
<mat-paginator
|
||||
[length]="this.pageTotal()"
|
||||
[pageSize]="this.pageSize()"
|
||||
[pageIndex]="this.pageIndex()"
|
||||
(page)="handlePageChange($event)" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
<div class="funding-info-section">
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Förderung über Zeit</mat-card-title>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<app-institution-projects-funding-graph
|
||||
[fundings]="[bundProjectsFunding()]" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
<div class="funding-info-cards">
|
||||
<app-person-network-info-card
|
||||
[description]="'Gesamte Förderung durch Bund'"
|
||||
[value]="
|
||||
(bundTotalFunding()
|
||||
| currency: 'EUR' : 'symbol' : '1.0-0' : 'de') ?? undefined
|
||||
" />
|
||||
<app-person-network-info-card
|
||||
[description]="'Durchschnittliche jährliche Förderung durch Bund'"
|
||||
[value]="
|
||||
(bundAverageAnnualFunding()
|
||||
| currency: 'EUR' : 'symbol' : '1.0-0' : 'de') ?? undefined
|
||||
" />
|
||||
<app-person-network-info-card
|
||||
[description]="'Gesamte Förderung durch die Europäische Union'"
|
||||
[value]="
|
||||
(123456789 | currency: 'EUR' : 'symbol' : '1.0-0' : 'de') ??
|
||||
undefined
|
||||
" />
|
||||
<app-person-network-info-card
|
||||
[description]="
|
||||
'Durchschnittliche jährliche Förderung durch die Europäische Union'
|
||||
"
|
||||
[value]="
|
||||
(12345 | currency: 'EUR' : 'symbol' : '1.0-0' : 'de') ?? undefined
|
||||
" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #fundingStartTmp let-row>
|
||||
|
||||
@@ -6,3 +6,26 @@ mat-card,
|
||||
mat-paginator {
|
||||
background-color: var(--sg-background);
|
||||
}
|
||||
|
||||
.funding-area {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.funding-info-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.funding-info-cards {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 1rem;
|
||||
|
||||
app-person-network-info-card {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
BundProjectPage,
|
||||
EuProject,
|
||||
EuProjectPage,
|
||||
InstitutionFunderSummary,
|
||||
} from '../../api';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
@@ -31,6 +32,8 @@ import { Sort, SortDirection } from '@angular/material/sort';
|
||||
import { DebounceDirective } from '../../directives/debounce.directive';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { InstitutionProjectsFundingGraphComponent } from '../institution-projects-funding-graph/institution-projects-funding-graph.component';
|
||||
import { PersonNetworkInfoCardComponent } from '../person-network-info-card/person-network-info-card.component';
|
||||
|
||||
type BundProjectRow = {
|
||||
topic: string;
|
||||
@@ -62,6 +65,8 @@ type EuProjectRow = {
|
||||
DebounceDirective,
|
||||
MatIconModule,
|
||||
MatButtonModule,
|
||||
InstitutionProjectsFundingGraphComponent,
|
||||
PersonNetworkInfoCardComponent,
|
||||
],
|
||||
templateUrl: './institution-projects.component.html',
|
||||
styleUrl: './institution-projects.component.scss',
|
||||
@@ -79,6 +84,20 @@ export class InstitutionProjectsComponent implements OnInit {
|
||||
bundProjectColumns: GenericColumn<BundProjectRow>[] = [];
|
||||
bundProjectData: BundProjectRow[] = [];
|
||||
|
||||
bundProjectsFunding = input.required<InstitutionFunderSummary>();
|
||||
|
||||
bundTotalFunding = computed(() => {
|
||||
const funding = this.bundProjectsFunding();
|
||||
return Object.values(
|
||||
funding.funding_per_year as Record<string, number>,
|
||||
).reduce((sum, yearFunding) => sum + yearFunding, 0);
|
||||
});
|
||||
|
||||
bundAverageAnnualFunding = computed(() => {
|
||||
const funding = this.bundProjectsFunding();
|
||||
return funding.annual_average_over_period ?? 0;
|
||||
});
|
||||
|
||||
urlSortKey = signal<string>('');
|
||||
urlSortDirection = signal<SortDirection>('');
|
||||
urlSearchTerm = signal<string>('');
|
||||
@@ -118,11 +137,15 @@ export class InstitutionProjectsComponent implements OnInit {
|
||||
const searchTerm = this.urlSearchTerm();
|
||||
if (searchTerm) {
|
||||
this.router.navigate([], {
|
||||
queryParams: { search: searchTerm },
|
||||
queryParams: { search: searchTerm, page: 0, size: 10 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
console.log('Funding over time data:', this.bundProjectsFunding());
|
||||
});
|
||||
}
|
||||
|
||||
readonly queryParams = toSignal(this.activatedRoute.queryParamMap, {
|
||||
@@ -286,14 +309,14 @@ export class InstitutionProjectsComponent implements OnInit {
|
||||
|
||||
handleSearchTermChange(newTerm: string): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: { search: newTerm },
|
||||
queryParams: { search: newTerm, page: 0, size: 10 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
clearSearchTerm(): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: { search: null },
|
||||
queryParams: { search: null, page: 0, size: 10 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { InstitutionFunderSummary, ProjectsService } from '../api';
|
||||
import { inject } from '@angular/core';
|
||||
|
||||
export const bundProjectsFundingResolver: ResolveFn<
|
||||
InstitutionFunderSummary
|
||||
> = (route, state) => {
|
||||
let institutionId = route.paramMap.get('institutionId');
|
||||
if (!institutionId) {
|
||||
institutionId = route.parent?.paramMap.get('institutionId') ?? null;
|
||||
}
|
||||
return inject(ProjectsService).getBundFundingOverTime(institutionId || '');
|
||||
};
|
||||
Reference in New Issue
Block a user