Skip to content

Commit

Permalink
New Features:
Browse files Browse the repository at this point in the history
New Pages:

Bugs Corrected:
1. Latency and Trace graphs are sorted by date
To Be Corrected:
0. On product delete, delete trace results
  • Loading branch information
juanfranciscocis committed Jul 23, 2024
1 parent f4235f8 commit 6dfd1f0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 71 deletions.
107 changes: 47 additions & 60 deletions src/app/pages/graph-latency/graph-latency.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,74 +26,61 @@ export class GraphLatencyPage implements OnInit {
private route: ActivatedRoute
) {}

async ionViewWillEnter() {
async ionViewWillEnter() {
this.route.queryParams.subscribe(params => {
this.productObjective = params['product'];
});

const userString = localStorage.getItem('user');
if (!userString) return;

this.user = JSON.parse(userString);
this.orgName = this.user.orgName!;
this.data = [];

await this.getResultsHistoryforLatency();
await this.groupByDate();
await this.groupByCountry();
await this.populateCountries();
this.generateCountryOptions();
}

// get parameters from the URL
this.route.queryParams.subscribe(params => {
this.productObjective = params['product'];
});
async getResultsHistoryforLatency() {
const results = await this.ripeService.getHistoryResults(this.orgName, this.productObjective);
results.forEach(result => {
const [_, idString, day, month, year, time] = result.id.split('-');
const date = `${month}/${day}/${year}`;

// get the user
const userString = localStorage.getItem('user');
if (!userString) {
return;
}
this.user = JSON.parse(userString);
this.orgName = this.user.orgName!;

this.data = [];

this.getResultsHistoryforLatency().then(() => {
this.groupByDate().then(() => {
this.groupByCountry().then(() => {
this.populateCountries();
this.generateCountryOptions();
});
});
});
}
// @ts-ignore
const historyData = result.data.data;

async getResultsHistoryforLatency() {
await this.ripeService.getHistoryResults(this.orgName, this.productObjective).then(r => {
for (let i = 0; i < r.length; i++) {
// split the id
let id = r[i].id.split('-');
let idString = id[1];

let day = id[2];
let month = id[3];
let year = id[4];
let date = month + '/' + day + '/' + year;
this.data.push({ id: idString, data: historyData, date, time });
});
}

let time = id[5];
async groupByDate() {
// create a dictionary to group the data by date
let groupedData: any = {};
for (let i = 0; i < this.data.length; i++) {
let date = this.data[i].date;
if (!groupedData[date]) {
groupedData[date] = [];
}
groupedData[date].push(...this.data[i]['data']);
}

// @ts-ignore
let historyData = r[i]['data']['data'];
// sort the dates
const sortedDates = Object.keys(groupedData).sort((a, b) => new Date(a).getTime() - new Date(b).getTime());

let toSave = {
id: idString,
data: historyData,
date: date,
time: time,
};
this.data.push(toSave);
}
});
// create a new object with sorted dates
let sortedGroupedData: any = {};
for (let date of sortedDates) {
sortedGroupedData[date] = groupedData[date];
}

async groupByDate() {
// create a dictionary to group the data by date
let groupedData: any = {};
for (let i = 0; i < this.data.length; i++) {
let date = this.data[i].date;
if (!groupedData[date]) {
groupedData[date] = [];
}
groupedData[date].push(...this.data[i]['data']);
}
this.data = groupedData;
console.log(this.data);
}
this.data = sortedGroupedData;
console.log(this.data);
}

async groupByCountry() {
let groupedData: any = {};
Expand Down
32 changes: 21 additions & 11 deletions src/app/pages/graph-trace/graph-trace.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,30 @@ export class GraphTracePage implements OnInit {
});
}

async groupByDate() {
// create a dictionary to group the data by date
let groupedData: any = {};
for (let i = 0; i < this.data.length; i++) {
let date = this.data[i].date;
if (!groupedData[date]) {
groupedData[date] = [];
}
groupedData[date].push(...this.data[i]['data']);
async groupByDate() {
// create a dictionary to group the data by date
let groupedData: any = {};
for (let i = 0; i < this.data.length; i++) {
let date = this.data[i].date;
if (!groupedData[date]) {
groupedData[date] = [];
}
this.data = groupedData;
console.log(this.data);
groupedData[date].push(...this.data[i]['data']);
}

// sort the dates
const sortedDates = Object.keys(groupedData).sort((a, b) => new Date(a).getTime() - new Date(b).getTime());

// create a new object with sorted dates
let sortedGroupedData: any = {};
for (let date of sortedDates) {
sortedGroupedData[date] = groupedData[date];
}

this.data = sortedGroupedData;
console.log(this.data);
}

async groupByCountry() {
let groupedData: any = {};
for (let date in this.data) {
Expand Down

0 comments on commit 6dfd1f0

Please sign in to comment.