Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions frontend/src/app/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ export class DataService {
return repoData;
}

async loadAllInstitutionsSummaries() {
const institutionData = await this.http
.get<{
institutionsSummaries: InstitutionSummary[];
total: number;
}>(`${environment.api}api/completeInstitutionSummaries`, {})
.pipe(
catchError(error => {
if (error.status === 401) {
this.toastr.error("Ihre Sitzung ist abgelaufen. Bitte melden Sie sich erneut an.", "Login timeout", {disableTimeOut: true});
}
return throwError(error);
})
)
.toPromise();
return institutionData;
}

// request to get all users, repositories, institutions and organizations,
// these are used to get all the data for excel export and is restricted to logged in users
// *****************************************************************************************************
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/app/ranking/ranking.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ <h1>
(change)="includeForksChange($event.checked)"
>Include forks</mat-checkbox
>
<button mat-raised-button [mtBasicSpinner]="isDownloading" [hideText]="true" (click)="downloadData()" *ngIf="isLoggedIn()" style="float: right;">
<mat-icon>cloud_download</mat-icon>
<span>Download Institutions Data</span>
</button>

<p style="color: gray">
Information on OSS Benchmark updated: {{ latestUdpate | date }}
</p>
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/app/ranking/ranking.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class RankingComponent implements OnInit {
recordFilter = '';
state: Date;
completeInstitutions: Institution[];
allInstitutions: InstitutionSumary[] = [];
institutions: InstitutionSumary[];
window: any = window;
includeForks: boolean = false;
Expand All @@ -45,6 +46,7 @@ export class RankingComponent implements OnInit {
sortDirection: 'ASC' | 'DESC' = 'DESC';
latestUdpate: any;
exportService: DataExportService = new DataExportService();
isDownloading: boolean = false;

searchTermRaw: string = '';

Expand Down Expand Up @@ -198,6 +200,33 @@ export class RankingComponent implements OnInit {
this.reloadData();
}

isLoggedIn(): boolean {
return this.authService.isUserLoggedIn();
}

async downloadData(): Promise<void> {
this.isDownloading = true;
try {
let institutionData = await this.dataService.loadAllInstitutionsSummaries();
console.log('institutionData', institutionData);
this.allInstitutions = institutionData.institutionsSummaries;

// Format the date fields
this.allInstitutions = this.allInstitutions.map((institution) => {
if (institution.created_at) {
institution.created_at = this.exportService.formatDate(institution.created_at);
}
return institution;
});

this.exportService.exportData(this.allInstitutions, 'InstitutionRanking');
} catch (error) {
console.error('Error occurred while downloading data:', error);
} finally {
this.isDownloading = false;
}
}



@ViewChild(MatPaginator) paginator: MatPaginator;
Expand Down
32 changes: 29 additions & 3 deletions oss-api/src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ export class ApiController {
return { users, total: users.length };
}

// Institutions Data
//@UseGuards(AuthGuard)
@Get('completeInstitutionSummaries')
async collectInstitutionSummaries() {
const queryConfig = {
sector: [],
search: '',
sort: 'num_repos',
direction: 'DESC',
page: 0,
count: -1,
sendStats: false,
includeForks: false,
};
const institutionsSummaries =
await this.mongoDbService.findInstitutionsWithConditions(
queryConfig.sort,
queryConfig.direction == 'ASC' ? 1 : -1,
queryConfig.count,
queryConfig.page,
queryConfig.includeForks,
[{}],
);
return { institutionsSummaries, total: institutionsSummaries.length };
}

/***********************************Helper************************************************/
/**
* Handle the instiution query with the given conditions
Expand All @@ -150,7 +176,7 @@ export class ApiController {
return queryConfig.sector.includes(sector);
});
}
let conditions: Object[] = [
const conditions: Object[] = [
{
sector: { $in: sectorList },
},
Expand All @@ -160,15 +186,15 @@ export class ApiController {
$text: { $search: queryConfig.search },
});
}
let institutions = await this.mongoDbService.findInstitutionsWithConditions(
const institutions = await this.mongoDbService.findInstitutionsWithConditions(
queryConfig.sort,
queryConfig.direction == 'ASC' ? 1 : -1,
queryConfig.count,
queryConfig.page,
queryConfig.includeForks,
conditions,
);
let foundSectors =
const foundSectors =
await this.mongoDbService.countInstitutionsWithConditions(conditions);
let total = 0;
const sectorcount = {};
Expand Down
Loading