Commit 7e3645d8 authored by Éloïs's avatar Éloïs

Merge branch 'dev2' into dev

parents 0d277183 e4778081
Pipeline #405 passed with stage
in 17 seconds
stages:
- github-sync
- deploy
push_to_github:
stage: github-sync
variables:
GIT_STRATEGY: none
tags:
- github
script:
- rm -rf ./*
- rm -rf .git
- git clone --mirror $CI_REPOSITORY_URL .
- git remote add github $GITHUB_URL_AND_KEY
- git config --global user.email "contact@duniter.org"
- git config --global user.name "Duniter"
# Job would fail if we don't remove refs about pull requests
- bash -c "cat packed-refs | grep -v 'refs/pull' > packed-refs-new; echo 'Removed pull refs.'"
- mv packed-refs-new packed-refs
- bash -c "git push --force --mirror github 2>&1 | grep -v duniter-gitlab; echo $?"
publish:
stage: deploy
image: node:6.12-alpine
tags:
- nodejs
only:
- tags
- triggers
script:
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
- npm publish
\ No newline at end of file
......@@ -3,7 +3,7 @@ VERSION Version
AUTHOR Author
CONTRIBUTORS Others Contributors
LICENSE license
GIT_REPOSITORY github repository
GIT_REPOSITORY git repository
IF_YOU_WANT If you want you can
DISABLE_HELP disable help
DONATE You can support the development of this module by a gift in Ğ1 at this pubkey
......
......@@ -3,7 +3,7 @@ VERSION Version
AUTHOR Auteur
CONTRIBUTORS Autres contributeurs
LICENSE licence
GIT_REPOSITORY dépôt github
GIT_REPOSITORY dépôt git
IF_YOU_WANT Si vous le souhaitez vous pouvez
DISABLE_HELP désactiver l'aide
DONATE Vous pouvez soutenir le développement de ce module par un don en Ğ1 à la clé publique suivante
......
......@@ -65,4 +65,6 @@ CERT_AVAILABLE available
MEMBERS members
NEXT_YN Feign the following Y[n] landing
MEMBER_FILTER search a member
EXPIRE_TIME expiration datetime
\ No newline at end of file
EXPIRE_TIME expiration datetime
RANDOM_LIST Draw lots
MEMBERS members
\ No newline at end of file
......@@ -65,4 +65,6 @@ CERT_AVAILABLE disponible
MEMBERS membres
NEXT_YN Simuler le palier Y[n] suivant
MEMBER_FILTER rechercher un membre
EXPIRE_TIME date et heure d'expiration
\ No newline at end of file
EXPIRE_TIME date et heure d'expiration
RANDOM_LIST Tirer au sort
MEMBERS membres
\ No newline at end of file
......@@ -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
module.exports = function randomInt (low, high) {
return Math.floor(Math.random() * (high - low) + low);
}
{
"name": "duniter-currency-monit",
"version": "0.4.5",
"version": "0.4.9",
"main": "index.js",
"license": "AGPLv3",
"dependencies": {
......
#!/bin/bash
current=`grep -P "version\": \"\d+.\d+.\d+(\w*)" package.json | grep -oP "\d+.\d+.\d+(\w*)"`
echo "Current version: $current"
if [[ $1 =~ ^[0-9]+.[0-9]+.[0-9]+((a|b)[0-9]+)?$ ]]; then
# Change the version in package.json and test file
sed -i "s/version\": \"$current/version\": \"$1/g" package.json
sed -i "s/$current/$1/g" views/about.html
# Commit
git reset HEAD
git add package.json views/about.html
git commit -m "v$1"
git tag "v$1"
else
echo "Wrong version format"
fi
......@@ -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);
}
}
......
......@@ -4,6 +4,7 @@ const co = require('co')
const constants = require(__dirname + '/../lib/constants')
const randomInt = require(__dirname + '/../lib/randomInt')
const timestampToDatetime = require(__dirname + '/../lib/timestampToDatetime')
const membersQuality = require(__dirname + '/tools/membersQuality')
......@@ -13,6 +14,8 @@ var membersLastUptime = 0;
var previousMode = null;
var previousCentrality = null;
var previousNextYn = "no";
var previousRandomList = "no"
var previousRandomCounts = 10
var membersList = [];
var membersIdentity = [];
var membersFirstCertifExpire = [];
......@@ -68,20 +71,22 @@ module.exports = (req, res, next) => co(function *() {
var centrality = req.query.centrality || "no"; // Valeur par défaut
var format = req.query.format || 'HTML'; // Valeur par défaut
const nextYn = (req.query.nextYn=="yes") ? "yes":"no";
const randomList = (req.query.randomList=="yes") ? "yes":"no";
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;
const wotbInstance = duniterServer.dal.wotb;
// Vérifier si le cache doit être Réinitialiser
let reinitCache = (Math.floor(Date.now() / 1000) > (membersLastUptime + constants.MIN_MEMBERS_UPDATE_FREQ));
// Vérifier si le cache doit être Réinitialiser
let reinitCache = (Math.floor(Date.now() / 1000) > (membersLastUptime + constants.MIN_MEMBERS_UPDATE_FREQ));
// Si changement de conditions, alors forcer le rechargement du cache s'il n'est pas, vérouillé, sinon forcer les conditions à celles en mémoire
if (previousMode != mode || previousCentrality != centrality || previousNextYn != nextYn)
// Si changement de conditions, alors forcer le rechargement du cache s'il n'est pas vérouillé, sinon forcer les conditions à celles en mémoire
if (previousMode != mode || previousCentrality != centrality || previousNextYn != nextYn || previousRandomList != randomList || numberOfRandomMembers != previousRandomCounts)
{
if (!lockMembers)
{
......@@ -92,7 +97,9 @@ module.exports = (req, res, next) => co(function *() {
{
mode = previousMode;
centrality = previousCentrality;
nextYn =previousNextYn;
nextYn = previousNextYn;
randomList = previousRandomList;
numberOfRandomMembers = previousRandomCounts;
}
}
// Sinon, si les conditions sont identiques :
......@@ -113,6 +120,8 @@ module.exports = (req, res, next) => co(function *() {
previousMode = mode;
previousCentrality = centrality;
previousNextYn = nextYn;
previousRandomList = randomList;
previousRandomCounts = numberOfRandomMembers;
membersList = [];
membersIdentity = [];
membersFirstCertifExpire = [];
......@@ -136,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')
......@@ -153,6 +162,19 @@ module.exports = (req, res, next) => co(function *() {
// Récupérer la liste des identités ayant actuellement le statut de membre
membersList = yield duniterServer.dal.peerDAL.query('SELECT `uid`,`pub`,`member`,`written_on`,`wotb_id` FROM i_index WHERE `member`=1');
if (randomList == "yes") {
// Tirer au sort randomCounts membres
const maxLengthRandomMembers = Math.min(numberOfRandomMembers,membersList.length)
let randomMembers = []
while (randomMembers.length < maxLengthRandomMembers) {
const randomInt_ = randomInt(0, membersList.length)
if (randomMembers.indexOf(membersList[randomInt_].uid) == -1) {
randomMembers.push(membersList[randomInt_])
}
}
membersList = randomMembers
}
// Récupérer pour chaque identité, le numéro du block d'écriture du dernier membership
// Ainsi que la première ou dernière certification
......@@ -209,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++;
}
......@@ -459,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")
......@@ -559,13 +581,14 @@ 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(),
// get parameters
days, mode, sort_by, order,
pendingSigs, centrality, nextYn,
numberOfRandomMembers, randomList,
// page data
currentBlockchainTimestamp,
......
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,12 +7,12 @@ ${(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://github.com/duniter/duniter-currency-monit/releases/tag/0.4.5">0.4.5</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">
${LANG['LICENSE']} : <a href="https://github.com/duniter/duniter-currency-monit/blob/master/LICENSE">AGPL V 3.0</a><br>
<a href="https://github.com/duniter/duniter-currency-monit/">${LANG['GIT_REPOSITORY']}</a>
<a href="https://git.duniter.org/nodes/typescript/modules/duniter-currency-monit">${LANG['GIT_REPOSITORY']}</a>
</div><br>
<div align="left">${LANG['IF_YOU_WANT']} <a href="?lg=${MENU_LANG['LG']}&help=no">${LANG['DISABLE_HELP']}</a>.</div><br>
<div align="left">${LANG['DONATE']} : GGUSkrw8csnV5uYXfL7Vdoy3qcM8fCD91v3NXHixWtKS<br>
......
......@@ -47,6 +47,8 @@ ${printMenu(MENU_LANG, help, "MEMBERS")}
<input type="checkbox" name="pendingSigs" value="yes" ${pendingSigs == 'yes' ? 'checked' : ''}>${LANG["CHECKBOX_PENDING_SIGS"]}.<br>
<input type="checkbox" name="mode" value="emitted" ${mode == 'emitted' ? 'checked' : ''}>${LANG["CHECKBOX_MODE_SIG"]}.<br>
<input type="checkbox" name="nextYn" value="yes" ${nextYn == 'yes' ? 'checked' : ''}> ${LANG["NEXT_YN"]}<br>
<input type="checkbox" name="randomList" value="yes" ${randomList == 'yes' ? 'checked' : ''}> ${LANG["RANDOM_LIST"]}
<input type="number" name="randomCounts" value="${numberOfRandomMembers}"/> ${LANG["MEMBERS"]}.<br>
<hr>
<!-- Afficher la légende et l'aide -->
......@@ -123,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