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 and in the home page
  • Loading branch information
Nicola Lanzilotto committed Jan 14, 2025
1 parent 8f49f9b commit 7ed24b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/app/analytics/metrics/requests/requests.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ <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 | number:'1.0-0'}}
<span *ngIf="!agentIsAChatbot">
{{totalHuman | number:'1.0-0'}}
</span>
<span *ngIf="agentIsAChatbot">
{{totalBot | number:'1.0-0'}}
</span>

</h2>
</div>

Expand Down
31 changes: 25 additions & 6 deletions src/app/analytics/metrics/requests/requests.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class RequestsComponent implements OnInit {
percentageOfRequestsHandledByBots: any;
totalHuman: number;
totalBot: number;

agentIsAChatbot: boolean = false;
constructor(
private analyticsService: AnalyticsService,
private translate: TranslateService,
Expand Down Expand Up @@ -302,11 +302,14 @@ export class RequestsComponent implements OnInit {

getRequestByLastNDay(lastdays, depID, participantID, channelID) {
this.logger.log("[ANALYTICS - CONVS] user has filter participantID");
let agentIsAChatbot = false
this.totalBot = 0;
this.totalHuman = 0;
this.agentIsAChatbot = false

if (participantID.includes("bot")) {
this.logger.log("[ANALYTICS - CONVS] Selected Agent is a BOT");
// try to change chart's colors
agentIsAChatbot = true
this.agentIsAChatbot = true
}
this.logger.log("[ANALYTICS - CONVS] GET REQUEST TYPE: For Agent/Bot")
this.subscription = this.analyticsService.requestsByDay(lastdays, depID, participantID, channelID).subscribe((requestsByDay: any) => {
Expand Down Expand Up @@ -363,16 +366,25 @@ export class RequestsComponent implements OnInit {
_requestsByDay_labels_array.push(splitted_date[0] + ' ' + this.monthNames[splitted_date[1]])
});

if (agentIsAChatbot) {
if (this.agentIsAChatbot) {
this.totalBot = _requestsByDay_series_array.reduce((sum, val) => sum + val, 0);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - totalBot 1', this.totalBot);
this.totalHuman = 0
this.percentageOfRequestsHandledByBots = 100
if (this.totalBot > 0) {
this.percentageOfRequestsHandledByBots = 100
} else {
this.percentageOfRequestsHandledByBots = 0
}

} else {
this.totalHuman = _requestsByDay_series_array.reduce((sum, val) => sum + val, 0);
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY DAY - totalHuman 1', this.totalBot);
this.totalBot = 0
this.percentageOfRequestsHandledByBots = 0
}

// this.percentageOfRequestsHandledByBots = this.totalBot > 0 ? ((this.totalBot / (this.totalHuman)) * 100).toFixed(1).replace('.', ',') : '0';


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);
Expand Down Expand Up @@ -551,6 +563,11 @@ export class RequestsComponent implements OnInit {
//-----------LAST n DAYS GRAPH-----------------------
getRequestByLastNDayMerge(lastdays, depID, channelID) {

this.logger.log("[ANALYTICS - CONVS] user NOT has filter participantID");
this.totalBot = 0;
this.totalHuman = 0;
this.agentIsAChatbot = false

this.logger.log("[ANALYTICS - CONVS] GET REQUEST TYPE: Merged lastdays", lastdays)
this.subscription = this.analyticsService.requestsByDay(lastdays, depID, '', channelID).subscribe((requestsByDay: any) => {
this.logger.log('[ANALYTICS - CONVS] - REQUESTS BY N-DAY ', requestsByDay);
Expand Down Expand Up @@ -641,7 +658,9 @@ export class RequestsComponent implements OnInit {

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.totalBot
this.percentageOfRequestsHandledByBots = this.totalBot > 0 ? ((this.totalBot / (this.totalHuman )) * 100).toFixed(2).replace('.', ',') : '0';


this.logger.log('[ANALYTICS - CONVS] - totalHuman ', this.totalHuman);
this.logger.log('[ANALYTICS - CONVS] - totalBot ', this.totalBot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ export class HomeConvsGraphComponent implements OnInit, OnChanges {
this.totalBot = botCounts.reduce((sum, val) => sum + val, 0);

const higherCount = this.getMaxValueFromArrays(humanCounts, botCounts);

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

// + this.totalBot
this.percentageOfRequestsHandledByBots = this.totalBot > 0 ? ((this.totalBot / (this.totalHuman )) * 100).toFixed(2).replace('.', ',') : '0';

this.logger.log('[HOME-CONVS-GRAPH] - -> NEW METHOD Human Total:', this.totalHuman);
this.logger.log('[HOME-CONVS-GRAPH] - -> NEW METHOD Bot Total:', this.totalBot);
Expand Down

0 comments on commit 7ed24b0

Please sign in to comment.