Fix le graph
This commit is contained in:
@@ -62,7 +62,7 @@ export class SummaryComponent implements OnInit {
|
||||
constructor(
|
||||
private serviceApi: StatsService,
|
||||
private serviceComm: ServiceComm,
|
||||
private translateService: TranslateService
|
||||
private translateService: TranslateService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -80,7 +80,7 @@ export class SummaryComponent implements OnInit {
|
||||
const datepipe: DatePipe = new DatePipe("en-US");
|
||||
let formattedDate = datepipe.transform(
|
||||
data.lastJump.jumpDate,
|
||||
"EEEE dd MMMM YYYY"
|
||||
"EEEE dd MMMM YYYY",
|
||||
);
|
||||
this.lastJump = formattedDate + " (" + data.lastJump.dropZone.name + ")";
|
||||
});
|
||||
@@ -90,7 +90,7 @@ export class SummaryComponent implements OnInit {
|
||||
this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
|
||||
data.byJumpType.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
data.byJumpType,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -105,114 +105,28 @@ export class SummaryComponent implements OnInit {
|
||||
public onTabChanged(event: MatTabChangeEvent) {
|
||||
switch (event.index) {
|
||||
case 0:
|
||||
this.serviceApi.getStatsOfLastMonth().subscribe((data) => {
|
||||
data.byDz.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
|
||||
data.byJumpType.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
);
|
||||
});
|
||||
this.statsLastMonth();
|
||||
break;
|
||||
case 1:
|
||||
this.serviceApi.getStatsOfLastYear().subscribe((data) => {
|
||||
data.byDz.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastYearByDz = new MatTableDataSource(data.byDz);
|
||||
data.byJumpType.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastYearByJumpType = new MatTableDataSource(
|
||||
data.byJumpType
|
||||
);
|
||||
});
|
||||
this.statsLastYear();
|
||||
break;
|
||||
case 2:
|
||||
this.serviceApi.getStatsByDz().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByDz = new MatTableDataSource(data);
|
||||
});
|
||||
this.statsByDz();
|
||||
break;
|
||||
case 3:
|
||||
this.serviceApi.getStatsByAircraft().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByAircraft = new MatTableDataSource(data);
|
||||
});
|
||||
this.statsByAircraft();
|
||||
break;
|
||||
case 4:
|
||||
this.serviceApi.getStatsByGear().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByGear = new MatTableDataSource(data);
|
||||
});
|
||||
this.statsByGear();
|
||||
break;
|
||||
case 5:
|
||||
this.serviceApi.getStatsByJumpType().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByType = new MatTableDataSource(data);
|
||||
});
|
||||
this.statsByJumpType();
|
||||
break;
|
||||
case 6:
|
||||
this.serviceApi.getStatsByYear().subscribe((data) => {
|
||||
data.sort((a, b) => b.label.localeCompare(a.label));
|
||||
this.dsNbJumpByYear = new MatTableDataSource(data);
|
||||
});
|
||||
this.statsByYear();
|
||||
break;
|
||||
case 7:
|
||||
this.serviceApi.getStatsByYearByJumpType().subscribe((data) => {
|
||||
data.sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
||||
let firstYear: number = Number(data[0].label);
|
||||
const now = new Date();
|
||||
const currentYear = now.getFullYear();
|
||||
const nbYears = currentYear - firstYear;
|
||||
let listOfYears = new Array(nbYears)
|
||||
.fill(null)
|
||||
.map(() => firstYear++);
|
||||
|
||||
// Prepare the list of jump type with am empty array
|
||||
let tmpResults = new Map<string, number[]>();
|
||||
const listOfJumpType = [...new Set(data.map((obj) => obj.label2))];
|
||||
listOfJumpType.forEach((type) => {
|
||||
tmpResults.set(type, new Array(nbYears).fill(NaN));
|
||||
});
|
||||
|
||||
for (let i = 0; i < listOfYears.length; i++) {
|
||||
const year = listOfYears[i].toString();
|
||||
|
||||
let filteredStats = data.filter((d) => d.label == year);
|
||||
|
||||
if (filteredStats.length > 0) {
|
||||
filteredStats.forEach((fs) => {
|
||||
tmpResults.get(fs.label2)[i] = fs.nb;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const results: {
|
||||
label: string;
|
||||
data: number[];
|
||||
backgroundColor: string;
|
||||
borderColor: string;
|
||||
pointBackgroundColor: string;
|
||||
fill: boolean;
|
||||
pointRadius: number;
|
||||
}[] = [];
|
||||
tmpResults.forEach((value, key) => {
|
||||
const color = this.jumpTypeToColor.get(key);
|
||||
let tmp = {
|
||||
label: key,
|
||||
data: value,
|
||||
backgroundColor: color,
|
||||
borderColor: color,
|
||||
pointBackgroundColor: color,
|
||||
fill: false,
|
||||
pointRadius: 6,
|
||||
};
|
||||
results.push(tmp);
|
||||
});
|
||||
|
||||
this.barChartData = {
|
||||
labels: listOfYears,
|
||||
datasets: results,
|
||||
};
|
||||
});
|
||||
this.statsByYearByJumpType();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -233,7 +147,7 @@ export class SummaryComponent implements OnInit {
|
||||
display: true,
|
||||
},
|
||||
colors: {
|
||||
forceOverride: true,
|
||||
forceOverride: false,
|
||||
},
|
||||
},
|
||||
interaction: {
|
||||
@@ -269,4 +183,122 @@ export class SummaryComponent implements OnInit {
|
||||
["Wingsuit 3", "#9400D3"],
|
||||
]);
|
||||
}
|
||||
|
||||
// #region Private methods to get stats
|
||||
private statsByYearByJumpType() {
|
||||
this.serviceApi.getStatsByYearByJumpType().subscribe((data) => {
|
||||
data.sort((a, b) => a.label.localeCompare(b.label));
|
||||
|
||||
let firstYear: number = Number(data[0].label);
|
||||
const now = new Date();
|
||||
const currentYear = now.getFullYear();
|
||||
const nbYears = currentYear - firstYear;
|
||||
let listOfYears = new Array(nbYears).fill(null).map(() => firstYear++);
|
||||
|
||||
// Prepare the list of jump type with am empty array
|
||||
let tmpResults = new Map<string, number[]>();
|
||||
const listOfJumpType = [...new Set(data.map((obj) => obj.label2))];
|
||||
listOfJumpType.forEach((type) => {
|
||||
tmpResults.set(type, new Array(nbYears).fill(NaN));
|
||||
});
|
||||
|
||||
for (let i = 0; i < listOfYears.length; i++) {
|
||||
const year = listOfYears[i].toString();
|
||||
|
||||
let filteredStats = data.filter((d) => d.label == year);
|
||||
|
||||
if (filteredStats.length > 0) {
|
||||
filteredStats.forEach((fs) => {
|
||||
tmpResults.get(fs.label2)[i] = fs.nb;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const results: {
|
||||
label: string;
|
||||
data: number[];
|
||||
backgroundColor: string;
|
||||
borderColor: string;
|
||||
pointBackgroundColor: string;
|
||||
fill: boolean;
|
||||
pointRadius: number;
|
||||
}[] = [];
|
||||
tmpResults.forEach((value, key) => {
|
||||
const color = this.jumpTypeToColor.get(key);
|
||||
let tmp = {
|
||||
label: key,
|
||||
data: value,
|
||||
backgroundColor: color,
|
||||
borderColor: color,
|
||||
pointBackgroundColor: color,
|
||||
fill: false,
|
||||
pointRadius: 6,
|
||||
};
|
||||
results.push(tmp);
|
||||
});
|
||||
|
||||
this.barChartData = {
|
||||
labels: listOfYears,
|
||||
datasets: results,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private statsByYear() {
|
||||
this.serviceApi.getStatsByYear().subscribe((data) => {
|
||||
data.sort((a, b) => b.label.localeCompare(a.label));
|
||||
this.dsNbJumpByYear = new MatTableDataSource(data);
|
||||
});
|
||||
}
|
||||
|
||||
private statsByJumpType() {
|
||||
this.serviceApi.getStatsByJumpType().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByType = new MatTableDataSource(data);
|
||||
});
|
||||
}
|
||||
|
||||
private statsByGear() {
|
||||
this.serviceApi.getStatsByGear().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByGear = new MatTableDataSource(data);
|
||||
});
|
||||
}
|
||||
|
||||
private statsByAircraft() {
|
||||
this.serviceApi.getStatsByAircraft().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByAircraft = new MatTableDataSource(data);
|
||||
});
|
||||
}
|
||||
|
||||
private statsByDz() {
|
||||
this.serviceApi.getStatsByDz().subscribe((data) => {
|
||||
data.sort((a, b) => b.nb - a.nb);
|
||||
this.dsNbJumpByDz = new MatTableDataSource(data);
|
||||
});
|
||||
}
|
||||
|
||||
private statsLastYear() {
|
||||
this.serviceApi.getStatsOfLastYear().subscribe((data) => {
|
||||
data.byDz.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastYearByDz = new MatTableDataSource(data.byDz);
|
||||
data.byJumpType.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastYearByJumpType = new MatTableDataSource(
|
||||
data.byJumpType,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private statsLastMonth() {
|
||||
this.serviceApi.getStatsOfLastMonth().subscribe((data) => {
|
||||
data.byDz.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastMonthByDz = new MatTableDataSource(data.byDz);
|
||||
data.byJumpType.sort((a, b) => b.nb - a.nb);
|
||||
this.dsJumpForLastMonthByJumpType = new MatTableDataSource(
|
||||
data.byJumpType,
|
||||
);
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user