Skip to content

Commit 838365c

Browse files
committed
Merge branch 'main' of github.com:austenstone/github-value
2 parents 1d7b9e7 + 9868415 commit 838365c

File tree

5 files changed

+90
-17
lines changed

5 files changed

+90
-17
lines changed

backend/src/services/query.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class QueryService {
8686
logger.info(`Task started for ${org}`);
8787
try {
8888
let teamsAndMembers = null;
89-
const mostRecentEntry = await teamsService.getLastUpdatedAt();
89+
const mostRecentEntry = await teamsService.getLastUpdatedAt(org);
9090
const msSinceLastUpdate = new Date().getTime() - new Date(mostRecentEntry).getTime();
9191
const hoursSinceLastUpdate = msSinceLastUpdate / 1000 / 60 / 60;
9292
logger.info(`Teams & Members updated ${hoursSinceLastUpdate.toFixed(2)} hours ago for ${org}.`);

backend/src/services/seats.service.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,40 @@ class SeatsService {
464464
date: "$date",
465465
login: "$assignee_login"
466466
},
467-
daily_time: { $sum: "$total_active_time_ms" }
467+
daily_time: { $sum: "$total_active_time_ms" },
468+
last_activity_at: { $max: "$last_activity_at" },
469+
last_activity_editor: { $last: "$last_activity_editor" },
470+
assignee_id: { $first: "$assignee_id" }
471+
}
472+
},
473+
{
474+
$lookup: {
475+
from: 'members',
476+
localField: '_id.login',
477+
foreignField: 'login',
478+
as: 'memberDetails'
479+
}
480+
},
481+
{
482+
$unwind: {
483+
path: '$memberDetails',
484+
preserveNullAndEmptyArrays: true
468485
}
469486
},
470487
{
471488
$group: {
472489
_id: "$_id.login",
473-
total_time: { $sum: "$daily_time" }
490+
total_time: { $sum: "$daily_time" },
491+
last_activity_at: { $max: "$last_activity_at" },
492+
last_activity_editor: { $last: "$last_activity_editor" },
493+
assignee_id: { $first: "$assignee_id" },
494+
avatar_url: { $first: "$memberDetails.avatar_url" },
495+
name: { $first: "$memberDetails.name" },
496+
url: { $first: "$memberDetails.url" },
497+
html_url: { $first: "$memberDetails.html_url" },
498+
team: { $first: "$memberDetails.team" },
499+
org: { $first: "$memberDetails.org" },
500+
type: { $first: "$memberDetails.type" }
474501
}
475502
},
476503
{ $sort: { total_time: -1 } },
@@ -479,12 +506,22 @@ class SeatsService {
479506
$project: {
480507
_id: 0,
481508
login: '$_id',
482-
total_time: 1
509+
total_time: 1,
510+
last_activity_at: 1,
511+
last_activity_editor: 1,
512+
assignee_id: 1,
513+
avatar_url: 1,
514+
name: 1,
515+
url: 1,
516+
html_url: 1,
517+
team: 1,
518+
org: 1,
519+
type: 1
483520
}
484521
}
485522
]);
486523

487-
return totals.map(t => [t.login, t.total_time]);
524+
return totals;
488525
}
489526
}
490527

frontend/src/app/main/copilot/copilot-dashboard/dashboard-card/active-users-chart/active-users-chart.component.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import { Router } from '@angular/router';
1515
</highcharts-chart>`
1616
})
1717
export class ActiveUsersChartComponent implements OnChanges {
18-
@Input() data?: Record<string, number>;
18+
@Input() data?: {
19+
login: string,
20+
total_time: number,
21+
avatar_url: string,
22+
}[];
1923
@Input() chartOptions?: Highcharts.Options;
2024
Highcharts: typeof Highcharts = Highcharts;
2125
updateFlag = false;
@@ -32,16 +36,20 @@ export class ActiveUsersChartComponent implements OnChanges {
3236
series: [{
3337
name: 'Activity',
3438
type: 'bar',
35-
data: this.data ? Object.values(this.data) : [],
39+
data: [], // Will be updated in ngOnChanges
3640
colorByPoint: true,
3741
borderWidth: 0,
42+
// Use point.options to access custom properties
43+
keys: ['y', 'login', 'avatar_url']
3844
}],
3945
tooltip: {
4046
pointFormat: '<span style="padding:0">{point.y: .1f} hours</span>',
4147
headerFormat: '',
4248
formatter: function () {
4349
const hours = (this.y || 0); // Convert ms to hours
44-
return `<span style="padding:0">@${this.key}</span><br>
50+
// Access login from the keys mapping
51+
const login = (this.point as any).login || this.key;
52+
return `<span style="padding:0">@${login}</span><br>
4553
<span style="padding:0">${hours.toFixed(1)} hours</span>`;
4654
},
4755
outside: true,
@@ -52,8 +60,10 @@ export class ActiveUsersChartComponent implements OnChanges {
5260
dataLabels: [{
5361
enabled: true,
5462
formatter: function () {
63+
// Access avatar_url from the keys mapping
64+
const avatar_url = (this.point as any).avatar_url || `https://github.com/${this.key}.png`;
5565
return `<div style="width: 20px; height: 20px; overflow: hidden; border-radius: 50%; margin-right: -25px">
56-
<img src="https://github.com/${this.key}.png" style="width: 30px; margin-left: -5px; margin-top: -2px">
66+
<img src="${avatar_url}" style="width: 30px; margin-left: -5px; margin-top: -2px">
5767
</div>`
5868
},
5969
useHTML: true,
@@ -65,7 +75,7 @@ export class ActiveUsersChartComponent implements OnChanges {
6575
point: {
6676
events: {
6777
click: (event) => {
68-
this.router.navigate(['/copilot/seats', event.point.name]);
78+
this.router.navigate(['/copilot/seats', (event.point as any).login || event.point.name]);
6979
}
7080
}
7181
}
@@ -78,9 +88,16 @@ export class ActiveUsersChartComponent implements OnChanges {
7888
) { }
7989

8090
ngOnChanges() {
91+
console.log('ngOnChanges', this.data);
8192
this._chartOptions = Object.assign({}, this.chartOptions, this._chartOptions);
8293
if (this._chartOptions?.series && this.data) {
83-
(this._chartOptions?.series as Highcharts.SeriesBarOptions[])[0].data = Object.values(this.data);
94+
// Create an array with [total_time, login, avatar_url] for each point
95+
const seriesData = this.data.map(user => [
96+
user.total_time,
97+
user.login,
98+
user.avatar_url
99+
]);
100+
(this._chartOptions?.series as Highcharts.SeriesBarOptions[])[0].data = seriesData;
84101
this.updateFlag = true;
85102
}
86103
}

frontend/src/app/main/copilot/copilot-metrics/copilot-metrics.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Installation, InstallationsService } from '../../../services/api/instal
88
import { Subject, Subscription, takeUntil } from 'rxjs';
99
import { DashboardCardDrilldownBarChartComponent } from '../copilot-dashboard/dashboard-card/dashboard-card-drilldown-bar-chart/dashboard-card-drilldown-bar-chart.component';
1010
import { ActiveUsersChartComponent } from '../copilot-dashboard/dashboard-card/active-users-chart/active-users-chart.component';
11-
import { SeatService } from '../../../services/api/seat.service';
11+
import { ActivityTotals, SeatService } from '../../../services/api/seat.service';
1212
import { MembersService } from '../../../services/api/members.service';
1313
import { CommonModule } from '@angular/common';
1414
import { LoadingSpinnerComponent } from '../../../shared/loading-spinner/loading-spinner.component';
@@ -38,7 +38,7 @@ export class CopilotMetricsComponent implements OnInit {
3838
metrics?: CopilotMetrics[];
3939
metricsTotals?: CopilotMetrics;
4040
installation?: Installation = undefined;
41-
activityTotals?: Record<string, number>;
41+
activityTotals?: ActivityTotals[];
4242
totalSeats?: number;
4343
subscriptions: Subscription[] = [];
4444
private readonly _destroy$ = new Subject<void>();
@@ -85,14 +85,17 @@ export class CopilotMetricsComponent implements OnInit {
8585

8686
this.reset();
8787

88+
console.log({
89+
since: event.start.toISOString(),
90+
until: event.end.toISOString()
91+
})
8892
this.subscriptions.push(
8993
this.seatService.getActivityTotals({
9094
org: this.installation?.account?.login,
9195
since: event.start.toISOString(),
92-
until: event.end.toISOString(),
93-
limit: 10
96+
until: event.end.toISOString()
9497
}).subscribe(totals => {
95-
this.activityTotals = totals;
98+
this.activityTotals = totals.length > 10 ? totals.slice(0, 10) : totals;
9699
this.cdr.detectChanges();
97100
})
98101
)

frontend/src/app/services/api/seat.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ export interface ActivityResponse2 {
3232
updatedAt: Date;
3333
};
3434
export type ActivityResponse = Record<string, ActivityResponseData>;
35+
36+
export interface ActivityTotals {
37+
total_time: number;
38+
last_activity_at: string | null;
39+
last_activity_editor: string | null;
40+
assignee_id: number;
41+
avatar_url: string;
42+
name: string | null;
43+
url: string;
44+
html_url: string;
45+
team: string | null;
46+
org: string;
47+
type: string;
48+
login: string;
49+
}
50+
3551
@Injectable({
3652
providedIn: 'root'
3753
})
@@ -78,7 +94,7 @@ export class SeatService {
7894
limit?: number;
7995
}) {
8096
if (!queryParams?.org) delete queryParams?.org;
81-
return this.http.get<Record<string, number>>(`${this.apiUrl}/activity/totals`, {
97+
return this.http.get<ActivityTotals[]>(`${this.apiUrl}/activity/totals`, {
8298
params: queryParams
8399
});
84100
}

0 commit comments

Comments
 (0)