Commit e4778081 authored by Éloïs's avatar Éloïs

[fix] type quality cache actions

parent ba5c69c8
Pipeline #404 passed with stage
in 19 seconds
......@@ -7,5 +7,12 @@ module.exports = {
STEP_COUNT_MIN: 4,
STEP_COUNT_MAX: 150,
MIN_CACHE_UPDATE_FREQ: 150, // 2 min 30 (150 sec)
MIN_WOT_QUALITY_CACHE_UPDATE_FREQ: 300
MIN_WOT_QUALITY_CACHE_UPDATE_FREQ: 300,
QUALITY_CACHE_ACTION : {
GET_QUALITY: 0,
GET_MEANS: 1,
INIT: 2,
GET_SENTRIES_COUNT: 3,
GET_D_SEN: 3
}
};
\ No newline at end of file
......@@ -28,7 +28,7 @@ module.exports = (req, res, next) => co(function *() {
const qualityMax = (1/conf.xpercent);
// Définition des variables
let lastUpgradeTimeDatas = membersQuality(-1);
let lastUpgradeTimeDatas = membersQuality(constants.QUALITY_CACHE_ACTION.INIT);
let tabUidIndex = [];
let tabMembersQuality= [];
let tabMembersQualitySorted = [];
......@@ -50,14 +50,14 @@ module.exports = (req, res, next) => co(function *() {
const wot = duniterServer.dal.wotb;
// Initialiser le cache des données de qualité
membersQuality(-1, dSen, conf.stepMax, conf.xpercent, wot.memCopy());
membersQuality(constants.QUALITY_CACHE_ACTION.INIT, 0, dSen, conf.stepMax, conf.xpercent, wot.memCopy());
}
// Mettre a jour previousNextYn
previousNextYn = (nextYn=="yes") ? "yes":"no";
// Calculer nbSentries, limit1 and label
const nbSentries = (sentries=="no") ? membersList.length:membersQuality(-2);
const nbSentries = (sentries=="no") ? membersList.length:membersQuality(constants.QUALITY_CACHE_ACTION.GET_SENTRIES_COUNT);
let limit1 = 1;
let label = LANG['QUALITY'];
switch (unit)
......@@ -76,15 +76,15 @@ module.exports = (req, res, next) => co(function *() {
// Récupérer le tableau de qualité des membres
tabMembersQuality= [];
for (let i=0;membersQuality(i) >= 0;i++)
for (let i=0;membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, i) >= 0;i++)
{
if (sentries == "no")
{
tabMembersQuality[i] = membersQuality(i, -1);
tabMembersQuality[i] = membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, i, -1);
}
else
{
tabMembersQuality[i] = membersQuality(i);
tabMembersQuality[i] = membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, i);
}
}
......
......@@ -75,9 +75,9 @@ module.exports = (req, res, next) => co(function *() {
const numberOfRandomMembers = req.query.randomCounts || 10
// Vérifier la valeur de nextYn dans le cache
let lastUpgradeTimeDatas = membersQuality(-1);
let dSenCache = membersQuality(-3);
if (lastUpgradeTimeDatas > 0 && dSenCache > dSen) { previousNextYn=="yes"; }
let lastUpgradeTimeDatas = membersQuality(constants.QUALITY_CACHE_ACTION.INIT);
let dSenCache = membersQuality(constants.QUALITY_CACHE_ACTION.GET_D_SEN);
if (lastUpgradeTimeDatas > 0 && dSenCache > dSen) { previousNextYn == "yes"; }
// Alimenter wotb avec la toile actuelle
const wotbInstance = duniterServer.dal.wotb;
......@@ -145,7 +145,7 @@ module.exports = (req, res, next) => co(function *() {
if (nextYn=="yes") { dSen++; }
// réinitialiser le cache des données de qualité
membersQuality(-1, dSen, conf.stepMax, conf.xpercent, wotbInstance.memCopy());
membersQuality(constants.QUALITY_CACHE_ACTION.INIT, 0, dSen, conf.stepMax, conf.xpercent, wotbInstance.memCopy());
// Réinitialiser le cache des données de centralité
if (centrality=='yes')
......@@ -231,14 +231,14 @@ module.exports = (req, res, next) => co(function *() {
membersNbSentriesUnreached[membersList[m].uid] = parseInt(detailedDistance.nbSentries) - parseInt(detailedDistance.nbSuccess);
// Calculer la qualité du membre courant
if (membersQuality(membersList[m].wotb_id, (currentMemberIsSentry) ? 1 : 0) >= 1.0) {
if (membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, membersList[m].wotb_id, (currentMemberIsSentry) ? 1 : 0) >= 1.0) {
proportionMembersWithQualityUpper1++;
}
// Calculer la qualité du membre courant s'il n'y avait pas de référents (autrement di si tout les membres était référents)
//let membersQualityIfNoSentries = ((detailedDistanceQualityExt.nbReached/membersList.length)/conf.xpercent).toFixed(2);
//console.log("membersQualityIfNoSentries[%s] = %s", membersList[m].uid, membersQualityIfNoSentries);
if (membersQuality(membersList[m].wotb_id, -1) >= 1.0) {
if (membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, membersList[m].wotb_id, -1) >= 1.0) {
proportionMembersWithQualityUpper1IfNoSentries++;
}
......@@ -481,7 +481,7 @@ module.exports = (req, res, next) => co(function *() {
{
for (const member of membersList)
{
tabSort.push(membersQuality(member.wotb_id));
tabSort.push(membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, member.wotb_id));
}
}
else if (sort_by == "sigCount")
......@@ -575,7 +575,7 @@ module.exports = (req, res, next) => co(function *() {
// Sinon, printer le tableau html
else
{
let meansMembersQuality = membersQuality(-1, -1);
let meansMembersQuality = membersQuality(constants.QUALITY_CACHE_ACTION.GET_MEANS);
res.locals = {
host: req.headers.host.toString(),
......
const constants = require(__dirname + '/../../lib/constants')
// membersQuality cache
var lastUpgradeTime = 0;
......@@ -21,10 +21,9 @@ var means = {
meanMembersReachedByMembers: 0
};
module.exports = function membersQuality(wotb_id, dSen = 0, stepMax = 0, xpercent = 0, wotCopy = null) {
module.exports = function membersQuality(action, wotb_id = 0, dSen = 0, stepMax = 0, xpercent = 0, wotCopy = null) {
if (wotb_id >= 0)
{
if (action == constants.QUALITY_CACHE_ACTION.GET_QUALITY) {
if (typeof(tabMembersQuality[wotb_id])=='undefined')
{
// Si le wotb_id n'existe pas, renvoyer -1
......@@ -57,8 +56,7 @@ module.exports = function membersQuality(wotb_id, dSen = 0, stepMax = 0, xpercen
return tabMembersQuality[wotb_id];
}
}
else if (dSen < 0)
{
else if (action == constants.QUALITY_CACHE_ACTION.GET_MEANS) {
if (!meansCalculate)
{
// Calculate mean Members/Sentries ReachedBy Members/Sentries
......@@ -77,15 +75,16 @@ module.exports = function membersQuality(wotb_id, dSen = 0, stepMax = 0, xpercen
return means;
}
else if (wotb_id == -1)
{
else if (action == constants.QUALITY_CACHE_ACTION.INIT) {
if (wot != null)
{
wot.clear();
wot = null
}
if (wotCopy != null)
{
lastUpgradeTime = Math.floor(Date.now() / 1000);
if (wot != null)
{
wot.clear();
}
wot = wotCopy;
membersCount = wot.getWoTSize()-wot.getDisabled().length;
sentriesCount = wot.getSentries(dSen).length;
......@@ -105,12 +104,10 @@ module.exports = function membersQuality(wotb_id, dSen = 0, stepMax = 0, xpercen
return lastUpgradeTime;
}
else if (wotb_id == -2)
{
else if (action == constants.QUALITY_CACHE_ACTION.GET_SENTRIES_COUNT) {
return sentriesCount;
}
else if (wotb_id == -3)
{
else if (action == constants.QUALITY_CACHE_ACTION.GET_D_SEN) {
return conf.dSen;
}
}
......@@ -56,34 +56,31 @@ module.exports = (req, res, next) => co(function *() {
let limitTimestamp = currentBlockchainTimestamp + (days*86400);
// Alimenter wotb avec la toile de confiance
const wotbInstance = duniterServer.dal.wotb;
const wotbInstance = duniterServer.dal.wotb;
// Vérifier si le cache doit être Réinitialiser
let reinitCache = (Math.floor(Date.now() / 1000) > (willMembersLastUptime + constants.MIN_WILLMEMBERS_UPDATE_FREQ));
// Vérifier si le cache doit être Réinitialiser
let reinitCache = (Math.floor(Date.now() / 1000) > (willMembersLastUptime + constants.MIN_WILLMEMBERS_UPDATE_FREQ));
// Si le cache willMembers est dévérouillé, le vérouiller, sinon ne pas réinitialiser le cache
if (reinitCache && !lockWillMembers)
{
lockWillMembers = true;
}
else if(lockWillMembers)
{
reinitCache = false;
}
// Si le cache willMembers est dévérouillé, le vérouiller, sinon ne pas réinitialiser le cache
if (reinitCache && !lockWillMembers) {
lockWillMembers = true;
} else if(lockWillMembers) {
reinitCache = false;
}
if (reinitCache)
if (reinitCache)
{
// Réinitialiser le cache
identitiesList = [];
idtysPendingCertifsList = [];
nbMaxCertifs = 0;
countMembersWithSigQtyValidCert = 0;
sentries = [];
sentriesIndex = [];
wotbIdIndex = [];
membersQualityExt = [];
willMembersLastUptime = Math.floor(Date.now() / 1000);
// Réinitialiser le cache
identitiesList = [];
idtysPendingCertifsList = [];
nbMaxCertifs = 0;
countMembersWithSigQtyValidCert = 0;
sentries = [];
sentriesIndex = [];
wotbIdIndex = [];
membersQualityExt = [];
willMembersLastUptime = Math.floor(Date.now() / 1000);
// Récupérer la liste des membres référents
sentries = wotbInstance.getSentries(dSen);
......
......@@ -7,7 +7,7 @@ ${(host.substr(host.length-6,6) == '.onion') ? HTML_TOR_HEAD:HTML_HEAD}
${printMenu(MENU_LANG, help, "ABOUT")}
</form>
<div align="left">${LANG['VERSION']} : <a href="https://git.duniter.org/nodes/typescript/modules/duniter-currency-monit/tree/v0.4.10">0.4.10</a></div><br>
<div align="left">${LANG['VERSION']} : <a href="https://git.duniter.org/nodes/typescript/modules/duniter-currency-monit/tree/v0.4.11">0.4.11</a></div><br>
<div align="left">${LANG['AUTHOR']} : <a href="https://github.com/librelois">Éloïs Librelois</a></div><br>
<div align="left"><small>${LANG['CONTRIBUTORS']}: <a href="https://github.com/jytou">jytou</a> (translator), <a href="https://github.com/devingfx">devingfx</a> (frontend), <a href="https://github.com/c-geek">cgeek</a> (willMembers and wotex),<a href="https://github.com/M5oul">M5oul</a> (adjustments)</small></div><br>
<div align="left">
......
......@@ -125,7 +125,7 @@ ${LANG["MEMBER_FILTER"]} : <input type="text" name="filter" id="filter" value=""
<td align="center" style="background:hsla(${member.proportion}, 100%, 50%, 1)"><b>${member.uid}</b><br>
${(member.isSentry) ? `<font color="blue">${LANG['REFERRING_MEMBER']} : ${LANG['YES']}</font>`:`${LANG['REFERRING_MEMBER']} : ${LANG['NO']}`}<br>
${LANG['QUALITY_EXT']} : <b>${(typeof(membersQuality(member.wotb_id))=='undefined') ? `0.00`:membersQuality(member.wotb_id)}</b><br>
${LANG['QUALITY_EXT']} : <b>${(typeof(membersQuality(0, member.wotb_id))=='undefined') ? `0.00`:membersQuality(0, member.wotb_id)}</b><br>
<b>${(membersLastCentralityCalcTime==0) ? `${LANG['CENTRALITY']} : ?`:`
${LANG['CENTRALITY']} : <b>${(typeof(membersCentrality[member.wotb_id])=='undefined') ? `0`:membersCentrality[member.wotb_id]}
`}</b><br>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment