Skip to content

Commit

Permalink
Updated the orgunit to use asyc wait
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsMurumba committed Jul 8, 2022
1 parent a68cb84 commit 8be8ff4
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 64 deletions.
99 changes: 53 additions & 46 deletions %deAvaliaçõesRealizadas.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$("#total").html(json.rows[3][2]);
$("#validEvaluations").html(json.rows[4][2]);
$("#orgUnit4").html(orgUnit.name);
validEvaluationsPercentage = ( parseInt(json.rows[5][2]) / parseInt(json.rows[4][2]))*100 || 0;
validEvaluationsPercentage = (parseInt(json.rows[5][2]) / parseInt(json.rows[4][2])) * 100 || 0;
$("#validEvaluationsPercentage").html(validEvaluationsPercentage);

});
Expand All @@ -85,17 +85,18 @@
}
}
function getOrgUnit(orgUnitId) {
let results = [];
let orgUnit = {};
$.getJSON("../api/organisationUnits/" + orgUnitId + ".json?fields=id,name,level,children", function (data) {
orgUnit.id = data.id;
orgUnit.name = data.name;
orgUnit.level = data.level;
orgUnit.children = data.children;
results.push(orgUnit);
console.log(results);
});
return results;
const orgUnitDetails = fetch("../api/organisationUnits/" + orgUnitId + ".json?fields=id,name")
.then((response) => response.json())
.then((data) => {
return data;
});

const printOrgUnitDetails = async () => {
const a = await orgUnitDetails;
// console.log(a.name);
};

return printOrgUnitDetails();
}

function getReportDetails(orgUnits, period, count) {
Expand All @@ -114,41 +115,47 @@
let exepectedEvaluationSumPercentage = 0;
let validEvaluationsSum = 0;
let validEvaluationSumPercentage = 0;

$.each(orgUnits, function (index, value) {
$.get("../api/organisationUnits/" + value.id + ".json?fields=id,name", function (json) {
orgUnitName = json.name;
});

$.get("../api/analytics?dimension=dx:yOR81tRBWIw;u7P0opGH3c9;lD2YLTZ8NOe;QYYFkIdTTDY;vA3Y0Bzy4sU;hV52rtgvgEI&dimension=pe:" + period + "&filter=ou:" + value.id, function (json) {
if (Array.isArray(json.rows) && json.rows.length > 0) {
baseline = json.rows[0][2];
internal = json.rows[1][2];
external = json.rows[2][2];
total = json.rows[3][2];
validEvaluations = json.rows[4][2];
validEvaluationsPercentage = ( parseInt(json.rows[5][2]) / parseInt(validEvaluations))*100 || 0;

}
baselineSum = parseInt(baselineSum) + parseInt(baseline);
internalSum = parseInt(internalSum) + parseInt(internal);
externalSum = parseInt(externalSum) + parseInt(external);
totalSum = parseInt(totalSum) + parseInt(total);
exepectedEvaluationSum = parseInt(exepectedEvaluationSum) + parseInt(1)
exepectedEvaluationSumPercentage = '100%';
validEvaluationsSum = parseInt(validEvaluationsSum) + parseInt(validEvaluations);
validEvaluationSumPercentage =parseFloat(validEvaluationSumPercentage) + ((parseFloat(validEvaluationsPercentage)) / parseFloat(count));
$("#baselineSum").html(baselineSum);
$("#internalSum").html(internalSum);
$("#externalSum").html(externalSum);
$("#totalSum").html(totalSum);
$("#exepectedEvaluationSum").html(exepectedEvaluationSum);
$("#exepectedEvaluationSumPercentage").html(exepectedEvaluationSumPercentage);
$("#validEvaluationsSum").html(validEvaluationsSum);
$("#validEvaluationSumPercentage").html(validEvaluationSumPercentage);
$('#tblOrgainzationUnits').append('<tr><td>' + orgUnitName + '</td><td>' + baseline + '</td> <td>' + internal + '</td><td>' + external + '</td> <td>' + total + '</td> <td>1</td> <td>100%</td> <td>' + validEvaluations + '</td> <td>' + validEvaluationsPercentage + '%</td></tr>');

});
$.each(orgUnits, function (index, value) {
const orgUnitDetails = fetch("../api/organisationUnits/" + value.id + ".json?fields=id,name")
.then((response) => response.json())
.then((data) => {
return data;
});

const printOrgUnitDetails = async () => {
const a = await orgUnitDetails;
$.get("../api/analytics?dimension=dx:yOR81tRBWIw;u7P0opGH3c9;lD2YLTZ8NOe;QYYFkIdTTDY;vA3Y0Bzy4sU;hV52rtgvgEI&dimension=pe:" + period + "&filter=ou:" + value.id, function (json) {
if (Array.isArray(json.rows) && json.rows.length > 0) {
baseline = json.rows[0][2];
internal = json.rows[1][2];
external = json.rows[2][2];
total = json.rows[3][2];
validEvaluations = json.rows[4][2];
validEvaluationsPercentage = (parseInt(json.rows[5][2]) / parseInt(validEvaluations)) * 100 || 0;

}
baselineSum = parseInt(baselineSum) + parseInt(baseline);
internalSum = parseInt(internalSum) + parseInt(internal);
externalSum = parseInt(externalSum) + parseInt(external);
totalSum = parseInt(totalSum) + parseInt(total);
exepectedEvaluationSum = parseInt(exepectedEvaluationSum) + parseInt(1)
exepectedEvaluationSumPercentage = '100%';
validEvaluationsSum = parseInt(validEvaluationsSum) + parseInt(validEvaluations);
validEvaluationSumPercentage = parseFloat(validEvaluationSumPercentage) + ((parseFloat(validEvaluationsPercentage)) / parseFloat(count));
$("#baselineSum").html(baselineSum);
$("#internalSum").html(internalSum);
$("#externalSum").html(externalSum);
$("#totalSum").html(totalSum);
$("#exepectedEvaluationSum").html(exepectedEvaluationSum);
$("#exepectedEvaluationSumPercentage").html(exepectedEvaluationSumPercentage);
$("#validEvaluationsSum").html(validEvaluationsSum);
$("#validEvaluationSumPercentage").html(validEvaluationSumPercentage);
$('#tblOrgainzationUnits').append('<tr><td>' + a.name + '</td><td>' + baseline + '</td> <td>' + internal + '</td><td>' + external + '</td> <td>' + total + '</td> <td>1</td> <td>100%</td> <td>' + validEvaluations + '</td> <td>' + validEvaluationsPercentage + '%</td></tr>');

});
};
printOrgUnitDetails();
});
$('#tblTotal').append('<tr><td>Total</td><td><span id="baselineSum"></span></td><td><span id="internalSum"></span></td><td><span id="externalSum"></span></td> <td><span id="totalSum"></span></td> <td><span id="exepectedEvaluationSum"></span></td> <td>100%</td> <td><span id="validEvaluationsSum"></span></td> <td><span id="validEvaluationSumPercentage"></span>%</td></tr>');
}
Expand Down
58 changes: 40 additions & 18 deletions performanceSummaryReport.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@

// area1(period);
// area2(criteria2,"s8e95DectKU",period);
area('N1sUx4ndd1b',"s8e95DectKU",period,1);
area('N1sUx4ndd1b',"s8e95DectKU",period,2);
area('N1sUx4ndd1b',"s8e95DectKU",period,3);
area('N1sUx4ndd1b',"s8e95DectKU",period,4);
area('N1sUx4ndd1b',"s8e95DectKU",period,5);
area('N1sUx4ndd1b',"s8e95DectKU",period,6);
area('N1sUx4ndd1b',"s8e95DectKU",period,7);
area('N1sUx4ndd1b',"s8e95DectKU",period,8);
area('N1sUx4ndd1b',"s8e95DectKU",period,9);
area('N1sUx4ndd1b',"s8e95DectKU",period,10);
area(['N1sUx4ndd1b'], orgUnit.id, period, 1);
area(['kOMhWASTEub', 'xHyRsdOrdBF'], orgUnit.id, period, 2);
area(['N1sUx4ndd1b'], orgUnit.id, period, 3);
area(['N1sUx4ndd1b'], orgUnit.id, period, 4);
area(['N1sUx4ndd1b'], orgUnit.id, period, 5);
area(['N1sUx4ndd1b'], orgUnit.id, period, 6);
area(['N1sUx4ndd1b'], orgUnit.id, period, 7);
area(['N1sUx4ndd1b'], orgUnit.id, period, 8);
area(['N1sUx4ndd1b'], orgUnit.id, period, 9);
area(['N1sUx4ndd1b'], orgUnit.id, period, 10);



Expand Down Expand Up @@ -125,24 +125,46 @@
let areaObserved = 0;
let areaReached = 0;
let rate = 0;
$.get("../api/analytics?dimension=dx:"+criteria+"&dimension=pe:" + period + "&filter=ou:"+ orgUnitId, function (data) {
if (criteria.length > 1) {
$.each(criteria, function (index, value) {
$.get("../api/analytics?dimension=dx:" + value + "&dimension=pe:" + period + "&filter=ou:" + orgUnitId, function (data) {
var results = data.rows[0][2];
if (results >= 1) {
$("#area" + area + "Observed").html(1);
$("#area" + area + "Reached").html(1);
areaObserved = 1;
areaReached = 1;
} else {
$("#area" + area + "Observed").html(1);
$("#area" + area + "Reached").html(0);
areaObserved = 1;
areaReached = 0;
}

rate = (areaReached / areaObserved) * 100;
$("#area" + area + "Rate").html(rate);
});
});
} else {
$.get("../api/analytics?dimension=dx:" + criteria + "&dimension=pe:" + period + "&filter=ou:" + orgUnitId, function (data) {
var results = data.rows[0][2];
if (results >= 1) {
$("#area"+area+"Observed").html(1);
$("#area"+area+"Reached").html(1);
$("#area" + area + "Observed").html(1);
$("#area" + area + "Reached").html(1);
areaObserved = 1;
areaReached = 1;
} else {
$("#area"+area+"Observed").html(1);
$("#area"+area+"Reached").html(0);
$("#area" + area + "Observed").html(1);
$("#area" + area + "Reached").html(0);
areaObserved = 1;
areaReached = 0;
}

rate = (areaReached / areaObserved) * 100;
$("#area"+area+"Rate").html(rate);
});

$("#area" + area + "Rate").html(rate);
});
}

}
function getCriteriaDetails(criteriaId, period, orgUnitId) {
$.get("../api/analytics?dimension=dx:" + criteriaId + "&dimension=pe:" + period + "&filter=ou:" + orgUnitId, function (data) {
Expand Down

0 comments on commit 8be8ff4

Please sign in to comment.