Skip to content

Commit

Permalink
feat(api): add columns to repository statistics summary
Browse files Browse the repository at this point in the history
  • Loading branch information
artix1500 authored and MaciejSikorski committed Jul 16, 2020
1 parent 19b6ac0 commit be5771b
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,46 @@
</mat-cell>
</ng-container>

<!-- Reviewers count Column -->
<ng-container matColumnDef="reviewersCount">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span>{{ 'Reviewers count' }}</span>
</mat-header-cell>
<mat-cell *matCellDef="let element">
{{ element.reviewersCount }}
</mat-cell>
</ng-container>

<!-- Average PR waiting Column -->
<ng-container matColumnDef="averagePrWaiting">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span>{{ 'Average PR is waiting' }}</span>
</mat-header-cell>
<mat-cell *matCellDef="let element">
{{ element.averagePrWaiting | timeAgo }}
</mat-cell>
</ng-container>

<!-- Average Code to check Column -->
<ng-container matColumnDef="averageCodeToCheck">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span>{{ 'Average Code to check' }}</span>
</mat-header-cell>
<mat-cell *matCellDef="let element">
{{ element.averageCodeToCheck }}
</mat-cell>
</ng-container>

<!-- Longest waiting PR Column -->
<ng-container matColumnDef="longestWaitingPr">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<span>{{ 'Longest waiting PR' }}</span>
</mat-header-cell>
<mat-cell *matCellDef="let element">
{{ element.longestWaitingPr | timeAgo }}
</mat-cell>
</ng-container>

<!-- Longest PR Column -->
<ng-container matColumnDef="longestPrLinesOfCode">
<mat-header-cell *matHeaderCellDef mat-sort-header>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
mat-header-cell > span {
font-size: 14px;
font-size: 1em;
font-weight: normal;
padding: 0 5px;
padding: 0 0.5em;
}

mat-header-cell > span > mat-icon {
color: #000000;
}

mat-header-cell {
flex-direction: column;
justify-content: center;
}

mat-cell {
padding: 0 5px;
padding: 0 0.5em;
text-align: center;
justify-content: center;
}

.avatar-column {
flex: unset;
width: 62px;
padding: 0 0 0 5px;
width: 4em;
padding: 0 0 0 0.5em;
}

.link-column {
flex: unset;
width: 90px;
width: 6em;
color: rgba(0, 0, 0, 0.6);
> mat-icon {
cursor: pointer;
}
}

.avatar-column__empty-space {
width: 32px;
height: 32px;
width: 2em;
height: 2em;
border-radius: 50%;
margin: auto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ export class StatisticsOverviewTableComponent {
'name',
'pendingPrs',
'sumOfHoursPrsWaiting',
'averagePrWaiting',
'longestWaitingPr',
'linesOfCodeToCheck',
'averageCodeToCheck',
'longestPrLinesOfCode',
'reviewersCount',
'link'
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ export abstract class BaseStatisticsReadModel {
pendingPrs: number;
@ApiProperty()
sumOfHoursPrsWaiting?: number;
@ApiProperty()
reviewersCount: number;
@ApiProperty()
averagePrWaiting: number;
@ApiProperty()
averageCodeToCheck: number;
@ApiProperty()
longestWaitingPr: number;

protected constructor(model: RepositoryEntity | ReviewerEntity, prs: PrEntity[]) {
const sumOfHoursPrsWaiting = this.getSumOfHoursPrsWaiting(prs);
const linesOfCodeToCheck = this.getLinesOfCodeToCheck(prs);

this.id = model.id;
this.name = model.name;
this.pendingPrs = prs.length;
this.sumOfHoursPrsWaiting = this.getSumOfHoursPrsWaiting(prs);
this.linesOfCodeToCheck = this.getLinesOfCodeToCheck(prs);
this.sumOfHoursPrsWaiting = sumOfHoursPrsWaiting;
this.linesOfCodeToCheck = linesOfCodeToCheck;
this.longestPrLinesOfCode = this.getLongestPrLinesOfCode(prs);
this.reviewersCount = this.getReviewersCount(prs);
this.averagePrWaiting = this.getAveragePrWaiting(prs, sumOfHoursPrsWaiting);
this.averageCodeToCheck = this.getAverageCodeToCheck(prs, linesOfCodeToCheck);
this.longestWaitingPr = this.getLongestWaitingPr(prs);
}

private getLongestPrLinesOfCode(prs: PrEntity[]): number {
Expand All @@ -41,12 +56,34 @@ export abstract class BaseStatisticsReadModel {
}

private getSumOfHoursPrsWaiting(prs: PrEntity[]): number {
let result = 0;
const now = new Date();
return Math.round(
prs.reduce((sum, pr) => sum + (now.getTime() - pr.createdAt.getTime()) / (60 * 60 * 1000), 0)
);
}

private getLongestWaitingPr(prs: PrEntity[]): number {
let max = 0;
const now = new Date();
prs.forEach(pr => {
result = (now.getTime() - pr.createdAt.getTime()) / (60 * 60 * 1000);
const newTime = (now.getTime() - pr.createdAt.getTime()) / (60 * 60 * 1000);
if (newTime > max) {
max = newTime;
}
});
return Math.round(max);
}

private getReviewersCount(prs: PrEntity[]): number {
const prAuthorsIds = prs.map(x => x.author.id);
return [...new Set(prAuthorsIds)].length;
}

private getAveragePrWaiting(prs: PrEntity[], sumOfHoursPrsWaiting: number): number {
return prs.length > 0 ? Math.round(sumOfHoursPrsWaiting / prs.length) : 0;
}

return Math.round(result);
private getAverageCodeToCheck(prs: PrEntity[], linesOfCodeToCheck: number): number {
return prs.length > 0 ? Math.round(linesOfCodeToCheck / prs.length) : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ export interface RepositoryStatistics {
pendingPrs?: number;
pictureUrl: string;
sumOfHoursPrsWaiting?: number;
reviewersCount?: number;
averagePrWaiting?: number;
averageCodeToCheck?: number;
longestWaitingPr?: number;
prsStatistics?: PrStatistics[];
}

0 comments on commit be5771b

Please sign in to comment.