Skip to content

Commit

Permalink
feat(tagstatistics): add number of campaign executions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashimpens committed Oct 7, 2024
1 parent 507388c commit 5735de7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tika.sax.Link;
import org.cerberus.core.crud.dao.ITagStatisticDAO;
import org.cerberus.core.crud.entity.*;
import org.cerberus.core.crud.service.IApplicationService;
Expand All @@ -37,8 +36,6 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
Expand Down Expand Up @@ -317,6 +314,7 @@ public Map<String, JSONObject> createMapAggregatedStatistics(Map<String, Map<Str
double sumPercOK = 0;
double sumPercReliability = 0;
int sumNumberExeUsefull = 0;
int numberCampaignExecutions = 0;
String campaignGroup1 = "";
JSONArray systemsByCampaign = new JSONArray();
JSONArray applicationsByCampaign = new JSONArray();
Expand All @@ -338,6 +336,7 @@ public Map<String, JSONObject> createMapAggregatedStatistics(Map<String, Map<Str
sumPercReliability += ((double) mapTagEntry.getInt("nbExeUsefull") / mapTagEntry.getInt("nbExe"));
sumNumberExeUsefull += mapTagEntry.getInt("nbExeUsefull");
totalDuration += mapTagEntry.getLong("duration");
numberCampaignExecutions++;

if (aggregateType.equals("CAMPAIGN")) {
campaignGroup1 = mapTagEntry.getString("campaignGroup1");
Expand All @@ -358,7 +357,7 @@ public Map<String, JSONObject> createMapAggregatedStatistics(Map<String, Map<Str
String country = key.split("_")[1];
statistics = createJsonCampaignStatByEnvCountry(systemsByCampaign, applicationsByCampaign, environment, country, avgDuration, minDateStart, maxDateEnd, avgOK, avgReliability, avgNbExeUsefull);
} else {
statistics = createJsonCampaignStat(key, systemsByCampaign, applicationsByCampaign, campaignGroup1, avgDuration, minDateStart, maxDateEnd, avgOK, avgReliability, avgNbExeUsefull);
statistics = createJsonCampaignStat(key, systemsByCampaign, applicationsByCampaign, campaignGroup1, avgDuration, minDateStart, maxDateEnd, avgOK, avgReliability, avgNbExeUsefull, numberCampaignExecutions);
}

aggregateByCampaign.put(key, statistics);
Expand Down Expand Up @@ -410,9 +409,9 @@ private String updateMaxCampaignDateEnd(String maxDateEnd, JSONObject mapTagEntr
}

public boolean userHasRightSystems(String user, List<TagStatistic> tagStatistics) {
List<String> systemsAllowedforUser = null;
List<String> systemsAllowedForUser;
try {
systemsAllowedforUser = getSystemsAllowedForUser(user);
systemsAllowedForUser = getSystemsAllowedForUser(user);
} catch (CerberusException exception) {
LOG.error("Unable to get systems allowed for user: ", exception);
return false;
Expand All @@ -425,7 +424,7 @@ public boolean userHasRightSystems(String user, List<TagStatistic> tagStatistics
.replace("]", "")
.split(","))
.collect(Collectors.toList());
if (!new HashSet<>(systemsAllowedforUser).containsAll(systemList)) {
if (!new HashSet<>(systemsAllowedForUser).containsAll(systemList)) {
return false;
}
}
Expand Down Expand Up @@ -467,7 +466,7 @@ private JSONObject createJsonCampaignStatByEnvCountry(JSONArray systems, JSONArr
.put("avgNbExeUsefull", avgNbExeUsefull);
}

private JSONObject createJsonCampaignStat(String campaign, JSONArray systems, JSONArray applications, String group1, double avgDuration, String minDateStart, String maxDateEnd, double avgOK, double avgReliability, int avgNbExeUsefull) throws JSONException {
private JSONObject createJsonCampaignStat(String campaign, JSONArray systems, JSONArray applications, String group1, double avgDuration, String minDateStart, String maxDateEnd, double avgOK, double avgReliability, int avgNbExeUsefull, int numberCampaignExecutions) throws JSONException {
return new JSONObject(new LinkedHashMap<>())
.put("campaign", campaign)
.put("systemList", systems)
Expand All @@ -478,7 +477,8 @@ private JSONObject createJsonCampaignStat(String campaign, JSONArray systems, JS
.put("maxDateEnd", maxDateEnd)
.put("avgOK", avgOK)
.put("avgReliability",avgReliability)
.put("avgNbExeUsefull", avgNbExeUsefull);
.put("avgNbExeUsefull", avgNbExeUsefull)
.put("numberCampaignExecutions", numberCampaignExecutions);
}

private String setKeyAccordingToAggregateType(String aggregateType, TagStatistic tagStatistic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2912,8 +2912,10 @@ public ArrayList<String> getSqlDocumentation() {
b.append(",('page_campaignstatistics','avgDuration_col','','en','Average duration','',NULL)");
b.append(",('page_campaignstatistics','avgReliability_col','','fr','Fiabilité moyenne','',NULL)");
b.append(",('page_campaignstatistics','avgReliability_col','','en','Average reliability','',NULL)");
b.append(",('page_campaignstatistics','avgNbExeUsefull_col','','fr','Nombre moyen d\\'exécutions utiles','',NULL)");
b.append(",('page_campaignstatistics','avgNbExeUsefull_col','','en','Average number of usefull executions','',NULL)");
b.append(",('page_campaignstatistics','avgNbExeUseful_col','','fr','Nombre moyen d\\'exécutions utiles','',NULL)");
b.append(",('page_campaignstatistics','avgNbExeUseful_col','','en','Average number of useful executions','',NULL)");
b.append(",('page_campaignstatistics','numberCampaignExecutions_col','','fr','Nombre d\\'exécutions de la campagne','',NULL)");
b.append(",('page_campaignstatistics','numberCampaignExecutions_col','','en','Number of campaign executions','',NULL)");
b.append(",('page_robot','button_create','','en','Create new Robot','',NULL)");
b.append(",('page_robot','button_create','','fa','ایجاد ربات جدید','',NULL)");
b.append(",('page_robot','button_create','','fr','Créer un nouveau Robot','',NULL)");
Expand Down
28 changes: 20 additions & 8 deletions source/src/main/webapp/js/pages/ReportingCampaignStatistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ $.when($.getScript("js/global/global.js")).then(function () {
}

//Hide the columns header search bar (searchable activated on specific columns to allow the global search on datatable, but not useful to show the header filter search bar on each column)
$('#tagStatisticTable').on('draw.dt', function () {
$(".filterHeader span").hide();
});
$('#tagStatisticDetailTable').on('draw.dt', function () {
$(".filterHeader span").hide();
});
hideColumnSearchBar();

$('[data-toggle="popover"]').popover({
'placement': 'auto',
Expand Down Expand Up @@ -395,7 +390,14 @@ function aoColumnsFunc(tableId) {
"name": "avgNbExeUsefull",
"searchable": false,
"width": "130px",
"title": doc.getDocLabel("page_campaignstatistics", "avgNbExeUsefull_col")
"title": doc.getDocLabel("page_campaignstatistics", "avgNbExeUseful_col")
},
{
"data": "numberCampaignExecutions",
"name": "numberCampaignExecutions",
"searchable": false,
"width": "130px",
"title": doc.getDocLabel("page_campaignstatistics", "numberCampaignExecutions_col")
},
];
return aoColumns;
Expand Down Expand Up @@ -501,7 +503,7 @@ function aoColumnsDetailFunc(tableId) {
"name": "avgNbExeUsefull",
"searchable": false,
"width": "130px",
"title": doc.getDocLabel("page_campaignstatistics", "avgNbExeUsefull_col")
"title": doc.getDocLabel("page_campaignstatistics", "avgNbExeUseful_col")
},
];
return aoColumns;
Expand All @@ -512,3 +514,13 @@ function getGreenToRed(percent) {
g = percent > 50 ? 255 : Math.floor((percent * 2) * 255 / 100);
return 'rgb(' + r + ',' + g + ',0)';
}

function hideColumnSearchBar() {
$(".filterHeader span").hide();
$('#tagStatisticTable').on('draw.dt', function () {
$(".filterHeader span").hide();
});
$('#tagStatisticDetailTable').on('draw.dt', function () {
$(".filterHeader span").hide();
});
}

0 comments on commit 5735de7

Please sign in to comment.