Skip to content

Commit

Permalink
Improves and fixes the conversations report in Analytics > Metrics > …
Browse files Browse the repository at this point in the history
…Conversations
  • Loading branch information
Nicola Lanzilotto committed Jan 13, 2025
1 parent d839087 commit 56557f1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 47 deletions.
7 changes: 4 additions & 3 deletions src/app/analytics/metrics/requests/requests.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ <h2 class="conv-analytics-indicator-title">

<div class="conv-analytics-indicator-value-wpr">
<h2 color="disabled" class="conv-analytics-indicator-value">
{{totalHuman + totalBot | number:'1.0-0'}}
<!-- {{totalHuman + totalBot | number:'1.0-0'}} -->
{{totalHuman | number:'1.0-0'}}
</h2>
</div>

</div>

<!-- Handled by human -->
<div class="conv-analytics-indicator-container">
<!-- <div class="conv-analytics-indicator-container">
<div class="conv-analytics-indicator-title-wpr">
<h2 class="conv-analytics-indicator-title">
{{'HandledByHuman' | translate}}
Expand All @@ -99,7 +100,7 @@ <h2 color="disabled" class="conv-analytics-indicator-value">
</h2>
</div>
</div>
</div> -->

<!-- Handled by bots -->
<div class="conv-analytics-indicator-container">
Expand Down
85 changes: 44 additions & 41 deletions src/app/analytics/metrics/requests/requests.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class RequestsComponent implements OnInit {
conversationsCountLastMonth: any;
conversationType = [
{ id: '', name: 'All' },
... CHANNELS
...CHANNELS
];

percentageOfRequestsHandledByBots: any;
Expand Down Expand Up @@ -166,16 +166,16 @@ export class RequestsComponent implements OnInit {
}
}

conversationTypeSelected(selectedChannelId){
conversationTypeSelected(selectedChannelId) {
this.logger.log("[ANALYTICS - CONVS] Selected channel: ", selectedChannelId);
this.lineChart.destroy();
this.subscription.unsubscribe();
if (!this.selectedAgentId) {
this.getRequestByLastNDayMerge(this.selectedDaysId, this.selectedDeptId, selectedChannelId)
console.log('[ANALYTICS - CONVS] agentSelected getRequestByLastNDayMerge REQUEST:', this.selectedDaysId, this.selectedDeptId)
this.logger.log('[ANALYTICS - CONVS] agentSelected getRequestByLastNDayMerge REQUEST:', this.selectedDaysId, this.selectedDeptId)
} else {
this.getRequestByLastNDay(this.selectedDaysId, this.selectedDeptId, this.selectedAgentId, selectedChannelId)
console.log('[ANALYTICS - CONVS] agentSelected getRequestByLastNDay REQUEST:', this.selectedDaysId, this.selectedDeptId, this.selectedAgentId, selectedChannelId)
this.logger.log('[ANALYTICS - CONVS] agentSelected getRequestByLastNDay REQUEST:', this.selectedDaysId, this.selectedDeptId, this.selectedAgentId, selectedChannelId)
}
}

Expand Down Expand Up @@ -209,8 +209,8 @@ export class RequestsComponent implements OnInit {
const projectUsers = this.usersService.getProjectUsersByProjectId();
const bots = this.faqKbService.getAllBotByProjectId();

zip(projectUsers, bots, (_projectUsers: any, _bots: any) => ({ _projectUsers, _bots }))

zip(projectUsers, bots, (_projectUsers: any, _bots: any) => ({ _projectUsers, _bots }))
.subscribe(pair => {
this.logger.log('[ANALYTICS - CONVS] - GET P-USERS-&-BOTS - PROJECT USERS : ', pair._projectUsers);
this.logger.log('[ANALYTICS - CONVS] - GET P-USERS-&-BOTS - BOTS: ', pair._bots);
Expand Down Expand Up @@ -286,12 +286,12 @@ export class RequestsComponent implements OnInit {

getAggregateValue() {
this.analyticsService.getLastMountConversationsCount().subscribe((res: any) => {
console.log("[ANALYTICS - CONVS] LAST MONTH CONVERSATIONS COUNT: ", res);
this.logger.log("[ANALYTICS - CONVS] LAST MONTH CONVERSATIONS COUNT: ", res);
if (res && res[0]) {
this.conversationsCountLastMonth = res[0].totalCount;
console.log("[ANALYTICS - CONVS] --> Conversations Last Month Count: ", this.conversationsCountLastMonth);
this.logger.log("[ANALYTICS - CONVS] --> Conversations Last Month Count: ", this.conversationsCountLastMonth);
} else {
console.log("[ANALYTICS - CONVS] --> Conversations Last Month Count - THERE ARE NOT CONVS IN THE LAST MONTH");
this.logger.log("[ANALYTICS - CONVS] --> Conversations Last Month Count - THERE ARE NOT CONVS IN THE LAST MONTH");
this.conversationsCountLastMonth = 0;
}
}, (error) => {
Expand All @@ -301,10 +301,10 @@ export class RequestsComponent implements OnInit {
}

getRequestByLastNDay(lastdays, depID, participantID, channelID) {
console.log("[ANALYTICS - CONVS] user has filter participantID");
let agentIsAChatbot = false
this.logger.log("[ANALYTICS - CONVS] user has filter participantID");
let agentIsAChatbot = false
if (participantID.includes("bot")) {
console.log("[ANALYTICS - CONVS] Selected Agent is a BOT");
this.logger.log("[ANALYTICS - CONVS] Selected Agent is a BOT");
// try to change chart's colors
agentIsAChatbot = true
}
Expand Down Expand Up @@ -372,21 +372,21 @@ export class RequestsComponent implements OnInit {
this.totalBot = 0
this.percentageOfRequestsHandledByBots = 0
}


console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - _requestsByDay_series_array', _requestsByDay_series_array);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - this.totalBot', this.totalBot);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - this.totalBot', this.totalHuman);


this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - _requestsByDay_series_array', _requestsByDay_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - this.totalBot', this.totalBot);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - this.totalBot', this.totalHuman);

this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - SERIES (ARRAY OF COUNT - to use for debug)', requestsByDay_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - SERIES (+ NEW + ARRAY OF COUNT)', _requestsByDay_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - LABELS (ARRAY OF DAY - to use for debug)', requestsByDay_labels_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - LABELS (+ NEW + ARRAY OF DAY)', _requestsByDay_labels_array);

//get higher value of xvalue array
const higherCount = this.getMaxOfArray(_requestsByDay_series_array);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - -> HIGHTER COUNT ', higherCount);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - ->_requestsByDay_series_array ', _requestsByDay_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - -> HIGHTER COUNT ', higherCount);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - ->_requestsByDay_series_array ', _requestsByDay_series_array);

//set the stepsize
var stepsize;
Expand Down Expand Up @@ -544,19 +544,19 @@ export class RequestsComponent implements OnInit {
}
getMaxValueFromArrays(array1: number[], array2: number[]): number {
const mergedArray = [...array1, ...array2];
console.log('mergedArray', mergedArray)
this.logger.log('mergedArray', mergedArray)
return Math.max(...mergedArray);
}

//-----------LAST n DAYS GRAPH-----------------------
getRequestByLastNDayMerge(lastdays, depID, channelID) {

console.log("[ANALYTICS - CONVS] GET REQUEST TYPE: Merged lastdays" , lastdays)
this.logger.log("[ANALYTICS - CONVS] GET REQUEST TYPE: Merged lastdays", lastdays)
this.subscription = this.analyticsService.requestsByDay(lastdays, depID, '', channelID).subscribe((requestsByDay: any) => {
console.log('[ANALYTICS - CONVS] - REQUESTS BY N-DAY ', requestsByDay);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY N-DAY ', requestsByDay);

this.analyticsService.requestsByDayBotServed(lastdays, depID, '', channelID).subscribe((requestsByDayBotServed: any) => {
console.log('[ANALYTICS - CONVS] - REQUESTS BY N-DAY BOT SERVED ', requestsByDayBotServed);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY N-DAY BOT SERVED ', requestsByDayBotServed);

// CREATES THE INITIAL ARRAY WITH THE LAST SEVEN DAYS (calculated with moment) AND REQUESTS COUNT = O
const last7days_initarray = []
Expand Down Expand Up @@ -590,8 +590,8 @@ export class RequestsComponent implements OnInit {
}
}

console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY FORMATTED ', requestsByDay_array);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY BOT SERVED FORMATTED ', requestByDayBotServed_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY FORMATTED ', requestsByDay_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY BOT SERVED FORMATTED ', requestByDayBotServed_array);

/**
* MERGE THE ARRAY last7days_initarray WITH requestsByDay_array */
Expand All @@ -600,10 +600,10 @@ export class RequestsComponent implements OnInit {
// If not, then the same element in last7days i.e. obj is returned.
// human
const requestByDays_final_array = last7days_initarray.map(obj => requestsByDay_array.find(o => o.day === obj.day) || obj);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - FINAL ARRAY ', requestByDays_final_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - FINAL ARRAY ', requestByDays_final_array);
// bot
const requestByDaysBotServed_final_array = last7days_initarray.map(obj => requestByDayBotServed_array.find(o => o.day === obj.day) || obj);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY BOT SERVED - FINAL ARRAY ', requestByDaysBotServed_final_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY BOT SERVED - FINAL ARRAY ', requestByDaysBotServed_final_array);

// human
const _requestsByDay_series_array = [];
Expand Down Expand Up @@ -632,33 +632,33 @@ export class RequestsComponent implements OnInit {
})



const humanCounts = requestByDays_final_array.map(req => req.count);
const botCounts = requestByDaysBotServed_final_array.map(req => req.count);

console.log('[ANALYTICS - CONVS] - humanCounts ', humanCounts);
console.log('[ANALYTICS - CONVS] - botCounts ', botCounts);
this.logger.log('[ANALYTICS - CONVS] - humanCounts ', humanCounts);
this.logger.log('[ANALYTICS - CONVS] - botCounts ', botCounts);

this.totalHuman = humanCounts.reduce((sum, val) => sum + val, 0);
this.totalBot = botCounts.reduce((sum, val) => sum + val, 0);
this.percentageOfRequestsHandledByBots = this.totalBot > 0 ? ((this.totalBot / (this.totalHuman + this.totalBot)) * 100).toFixed(1).replace('.', ',') : '0';
this.totalHuman = humanCounts.reduce((sum, val) => sum + val, 0);
this.totalBot = botCounts.reduce((sum, val) => sum + val, 0);
this.percentageOfRequestsHandledByBots = this.totalBot > 0 ? ((this.totalBot / (this.totalHuman + this.totalBot)) * 100).toFixed(1).replace('.', ',') : '0';

console.log('[ANALYTICS - CONVS] - totalHuman ', this.totalHuman);
console.log('[ANALYTICS - CONVS] - totalBot ', this.totalBot);
console.log('[ANALYTICS - CONVS] - percentageOfRequestsHandledByBots ', this.percentageOfRequestsHandledByBots);
this.logger.log('[ANALYTICS - CONVS] - totalHuman ', this.totalHuman);
this.logger.log('[ANALYTICS - CONVS] - totalBot ', this.totalBot);
this.logger.log('[ANALYTICS - CONVS] - percentageOfRequestsHandledByBots ', this.percentageOfRequestsHandledByBots);

this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - SERIES (ARRAY OF COUNT - to use for debug)', requestsByDay_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - SERIES (+ NEW + ARRAY OF COUNT)', _requestsByDay_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - SERIES (+ NEW + ARRAY OF COUNT)', _requestsByDayBotServed_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - LABELS (ARRAY OF DAY - to use for debug)', requestsByDay_labels_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - LABELS (+ NEW + ARRAY OF DAY)', _requestsByDay_labels_array);


//get higher value of xvalue array
// const higherCount = this.getMaxOfArray(_requestsByDay_series_array);
const higherCount = this.getMaxValueFromArrays(humanCounts, botCounts);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY -> HIGHTER COUNT ', higherCount);
console.log('[ANALYTICS - CONVS] - REQUESTS BY DAY -> _requestsByDay_series_array ', _requestsByDay_series_array);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY -> HIGHTER COUNT ', higherCount);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY -> _requestsByDay_series_array ', _requestsByDay_series_array);

//set the stepsize
var stepsize;
Expand Down Expand Up @@ -689,7 +689,8 @@ export class RequestsComponent implements OnInit {
pointBorderColor: '#b00e0e'
},
{
label: this.translate.instant('ServedByHumans'), // 'Served by humans',//active labet setting to true the legend value
// label: this.translate.instant('ServedByHumans'), // 'Served by humans',//active labet setting to true the legend value
label: this.translate.instant('TotalConversations'), // 'Served by humans',//active labet setting to true the legend value
data: _requestsByDay_series_array,
fill: true, //riempie zona sottostante dati
lineTension: 0.0,
Expand Down Expand Up @@ -782,7 +783,9 @@ export class RequestsComponent implements OnInit {
// }
// label += Math.round(tooltipItem.yLabel * 100) / 100;
// return label + '';
//this.logger.log("data",data)
// this.logger.log("------ > data", data)
// this.logger.log("------ > tooltipItem", tooltipItem)

const currentItemValue = tooltipItem.yLabel
// let langService = new HumanizeDurationLanguage();
// let humanizer = new HumanizeDuration(langService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
<div class="flex flex-col flex-auto overflow-hidden items-center">

<span class="graph-footer-num">
{{totalHuman + totalBot | number:'1.0-0'}}
<!-- {{totalHuman + totalBot | number:'1.0-0'}} -->
{{totalHuman | number:'1.0-0'}}
</span>
<!-- <span *ngIf="numOfDays === 7" class="graph-footer-num"> {{countOfLastSevenDaysRequests + countOfLastSevenDaysRequestsHandledByBot | number:'1.0-0'}} </span>
<span *ngIf="numOfDays === 30" class="graph-footer-num"> {{countOfLastMonthRequests | number:'1.0-0'}} </span> -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class HomeConvsGraphComponent implements OnInit, OnChanges {

getMaxValueFromArrays(array1: number[], array2: number[]): number {
const mergedArray = [...array1, ...array2];
console.log('mergedArray', mergedArray)
this.logger.log('mergedArray', mergedArray)
return Math.max(...mergedArray);
}

Expand Down Expand Up @@ -419,7 +419,8 @@ export class HomeConvsGraphComponent implements OnInit, OnChanges {
lineTension: 0.4,
},
{
label: this.servedByHumans,
// label: this.servedByHumans,
label: this.translate.instant('TotalConversations'),
data: humanCounts,
fill: true,
backgroundColor: 'rgba(30, 136, 229, 0.6)',
Expand Down

0 comments on commit 56557f1

Please sign in to comment.