Commit 32d74685 authored by Cédric Moreau's avatar Cédric Moreau

[refact] constants.js ==> constants.ts

parent 28abbf67
"use strict";
module.exports = {
export const MonitConstants = {
USE_WOTB6: false,
DEFAULT_LANGUAGE: "fr",
MIN_WILLMEMBERS_UPDATE_FREQ: 180,
......@@ -16,4 +14,4 @@ module.exports = {
GET_SENTRIES_COUNT: 3,
GET_D_SEN: 3
}
};
\ No newline at end of file
};
......@@ -2,9 +2,9 @@
import {DataFinder} from "./DataFinder";
import {DBBlock} from "duniter/app/lib/db/DBBlock";
import {MonitConstants} from "./constants2";
const co = require('co');
const constants = require(__dirname + '/constants')
/**
* updateCache
......@@ -24,7 +24,7 @@ module.exports = async (req:any, res:any, next:any) => {
let upgradeCache = false;
// Cacluler s'il faut mettre à jour le cache ou pas
upgradeCache = (Math.floor(Date.now() / 1000) > (cache.lastUptime + constants.MIN_CACHE_UPDATE_FREQ));
upgradeCache = (Math.floor(Date.now() / 1000) > (cache.lastUptime + MonitConstants.MIN_CACHE_UPDATE_FREQ));
// Si le cache membersCount est dévérouillé, le vérouiller, sinon ne pas réinitialiser le cache
if (upgradeCache && !cache.lockMembersCount)
......@@ -109,7 +109,7 @@ module.exports = async (req:any, res:any, next:any) => {
{ cache.beginBlock = [await dataFinder.getBlock(0)]; }
else if (req.query.begin > cache.endBlock[0].number)
{
let beginTime = cache.endBlock[0].medianTime-(parseInt(cache.step)*unitTime*constants.STEP_COUNT_MIN);
let beginTime = cache.endBlock[0].medianTime-(parseInt(cache.step)*unitTime*MonitConstants.STEP_COUNT_MIN);
cache.beginBlock = [await dataFinder.getBlockWhereMedianTimeGte(beginTime)];
}
else { cache.beginBlock = [await dataFinder.getBlock(req.query.begin)]; }
......@@ -118,7 +118,7 @@ module.exports = async (req:any, res:any, next:any) => {
if ( typeof(req.query.nbMaxPoints) != 'undefined' && req.query.nbMaxPoints > 0 ) {
cache.nbMaxPoints = req.query.nbMaxPoints;
} else {
cache.nbMaxPoints = constants.STEP_COUNT_MAX;
cache.nbMaxPoints = MonitConstants.STEP_COUNT_MAX;
}
if ( typeof(req.query.adaptMaxPoints) != 'undefined' && (req.query.adaptMaxPoints == "step" || req.query.adaptMaxPoints == "end")) {
cache.adaptMaxPoints = req.query.adaptMaxPoints;
......@@ -135,7 +135,7 @@ module.exports = async (req:any, res:any, next:any) => {
cache.beginBlock = [await dataFinder.getBlockWhereMedianTimeGte(newBeginTime)];
}
} else if (cache.adaptMaxPoints == "step") {
cache.step = Math.ceil((cache.endBlock[0].medianTime-cache.beginBlock[0].medianTime)/(constants.STEP_COUNT_MAX*unitTime));
cache.step = Math.ceil((cache.endBlock[0].medianTime-cache.beginBlock[0].medianTime)/(MonitConstants.STEP_COUNT_MAX*unitTime));
} else {
let newEndTime = cache.beginBlock[0].medianTime+cache.step*cache.nbMaxPoints*unitTime;
cache.endBlock = [await dataFinder.getBlockWhereMedianTimeLte(newEndTime)];
......@@ -145,7 +145,7 @@ module.exports = async (req:any, res:any, next:any) => {
cache.stepTime = parseInt(cache.step)*unitTime;
// if new blocks and MIN_CACHE_UPDATE_FREQ pass, update cache
if ( parseInt(cache.endBlock[0].number) >= cache.currentBlockNumber && Math.floor(Date.now() / 1000) > (cache.lastUptime + constants.MIN_CACHE_UPDATE_FREQ))
if ( parseInt(cache.endBlock[0].number) >= cache.currentBlockNumber && Math.floor(Date.now() / 1000) > (cache.lastUptime + MonitConstants.MIN_CACHE_UPDATE_FREQ))
{
// let previousCacheTime = (cache.blockchain.length > 0) ? cache.blockchain[cache.blockchain.length-1].medianTime:0;
var newBlocks = await dataFinder.getBlockWhereMedianTimeLteAndGtNoLimit(cache.currentBlockTime, cache.endBlock[0].medianTime);
......
import {DBBlock} from 'duniter/app/lib/db/DBBlock'
import {DataFinder} from '../lib/DataFinder'
import {showExecutionTimes} from '../lib/MonitorExecutionTime'
import {MonitConstants} from "../lib/constants2";
const fs = require('fs')
const timestampToDatetime = require(__dirname + '/../lib/timestampToDatetime')
const colorScale = require(__dirname + '/../lib/colorScale')
const getLang = require(__dirname + '/../lib/getLang')
const constants = require(__dirname + '/../lib/constants')
// Garder l'index des blocs en mémoire vive
var blockchain: DBBlock[] = [];
......@@ -30,7 +30,7 @@ module.exports = async (req: any, res: any, next: any) => {
var significantPercent = req.query.significantPercent || 3;
// get lg file
const LANG = getLang(`${__dirname}/../lg/blockCount_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`);
const LANG = getLang(`${__dirname}/../lg/blockCount_${req.query.lg||MonitConstants.DEFAULT_LANGUAGE}.txt`);
// detect fork
if ( blockchain.length > 0 )
......
"use strict";
import {DataFinder} from "../lib/DataFinder";
import {MonitConstants} from "../lib/constants2";
const co = require('co')
const constants = require(__dirname + '/../lib/constants')
const membersQuality = require(__dirname + '/tools/membersQuality')
const getLang = require(__dirname + '/../lib/getLang')
......@@ -25,14 +21,14 @@ module.exports = async (req:any, res:any, next:any) => {
const nextYn = (req.query.nextYn=="yes") ? "yes":"no";
// get lg file
const LANG = getLang(`${__dirname}/../lg/gaussianWotQuality_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`);
const LANG = getLang(`${__dirname}/../lg/gaussianWotQuality_${req.query.lg||MonitConstants.DEFAULT_LANGUAGE}.txt`);
// Définition des contantes
const conf = duniterServer.conf;
const qualityMax = (1/conf.xpercent);
// Définition des variables
let lastUpgradeTimeDatas = membersQuality(constants.QUALITY_CACHE_ACTION.INIT);
let lastUpgradeTimeDatas = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.INIT);
let tabUidIndex = [];
let tabMembersQuality= [];
let tabMembersQualitySorted = [];
......@@ -44,7 +40,7 @@ module.exports = async (req:any, res:any, next:any) => {
let membersList = await dataFinder.getMembers();
// Si les données de qualité n'ont jamais été calculés, le faire
if (lastUpgradeTimeDatas == 0 || (lastUpgradeTimeDatas+constants.MIN_WOT_QUALITY_CACHE_UPDATE_FREQ) < (Math.floor(Date.now() / 1000)) || (previousNextYn != nextYn))
if (lastUpgradeTimeDatas == 0 || (lastUpgradeTimeDatas+MonitConstants.MIN_WOT_QUALITY_CACHE_UPDATE_FREQ) < (Math.floor(Date.now() / 1000)) || (previousNextYn != nextYn))
{
// Calculer dSen
var dSen = Math.ceil(Math.pow(membersList.length, 1 / conf.stepMax));
......@@ -54,14 +50,14 @@ module.exports = async (req:any, res:any, next:any) => {
const wot = duniterServer.dal.wotb;
// Initialiser le cache des données de qualité
membersQuality(constants.QUALITY_CACHE_ACTION.INIT, 0, dSen, conf.stepMax, conf.xpercent, wot.memCopy());
membersQuality(MonitConstants.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(constants.QUALITY_CACHE_ACTION.GET_SENTRIES_COUNT);
const nbSentries = (sentries=="no") ? membersList.length:membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_SENTRIES_COUNT);
let limit1 = 1;
let label = LANG['QUALITY'];
switch (unit)
......@@ -80,15 +76,15 @@ module.exports = async (req:any, res:any, next:any) => {
// Récupérer le tableau de qualité des membres
tabMembersQuality= [];
for (let i=0;membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, i) >= 0;i++)
for (let i=0;membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_QUALITY, i) >= 0;i++)
{
if (sentries == "no")
{
tabMembersQuality[i] = membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, i, -1);
tabMembersQuality[i] = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_QUALITY, i, -1);
}
else
{
tabMembersQuality[i] = membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, i);
tabMembersQuality[i] = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_QUALITY, i);
}
}
......
const fs = require('fs')
const express = require('express')
const constants = require(__dirname + '/../lib/constants')
const constants = require(__dirname + '/../lib/constants2').MonitConstants
const getLang = require(__dirname + '/../lib/getLang')
const printMenu = require(__dirname + '/../views/printMenu')
......
import {DataFinder} from '../lib/DataFinder'
import {MonitConstants} from "../lib/constants2";
const constants = require(__dirname + '/../lib/constants')
const randomInt = require(__dirname + '/../lib/randomInt')
const timestampToDatetime = require(__dirname + '/../lib/timestampToDatetime')
const membersQuality = require(__dirname + '/tools/membersQuality')
......@@ -74,15 +74,15 @@ module.exports = async (req: any, res: any, next: any) => {
let numberOfRandomMembers = req.query.randomCounts || 10
// Vérifier la valeur de nextYn dans le cache
let lastUpgradeTimeDatas = membersQuality(constants.QUALITY_CACHE_ACTION.INIT);
let dSenCache = membersQuality(constants.QUALITY_CACHE_ACTION.GET_D_SEN);
let lastUpgradeTimeDatas = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.INIT);
let dSenCache = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_D_SEN);
if (lastUpgradeTimeDatas > 0 && dSenCache > dSen) { previousNextYn == "yes"; }
// Alimenter wotb avec la toile actuelle
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));
let reinitCache = (Math.floor(Date.now() / 1000) > (membersLastUptime + MonitConstants.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 || previousRandomList != randomList || numberOfRandomMembers != previousRandomCounts)
......@@ -145,7 +145,7 @@ module.exports = async (req: any, res: any, next: any) => {
if (nextYn=="yes") { dSen++; }
// réinitialiser le cache des données de qualité
membersQuality(constants.QUALITY_CACHE_ACTION.INIT, 0, dSen, conf.stepMax, conf.xpercent, wotbInstance.memCopy());
membersQuality(MonitConstants.QUALITY_CACHE_ACTION.INIT, 0, dSen, conf.stepMax, conf.xpercent, wotbInstance.memCopy());
// Réinitialiser le cache des données de centralité
if (centrality=='yes')
......@@ -229,14 +229,14 @@ module.exports = async (req: any, res: any, next: any) => {
membersNbSentriesUnreached[membersList[m].uid] = parseInt(detailedDistance.nbSentries) - parseInt(detailedDistance.nbSuccess);
// Calculer la qualité du membre courant
if (membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, membersList[m].wotb_id, (currentMemberIsSentry) ? 1 : 0) >= 1.0) {
if (membersQuality(MonitConstants.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(constants.QUALITY_CACHE_ACTION.GET_QUALITY, membersList[m].wotb_id, -1) >= 1.0) {
if (membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_QUALITY, membersList[m].wotb_id, -1) >= 1.0) {
proportionMembersWithQualityUpper1IfNoSentries++;
}
......@@ -474,7 +474,7 @@ module.exports = async (req: any, res: any, next: any) => {
{
for (const member of membersList)
{
tabSort.push(membersQuality(constants.QUALITY_CACHE_ACTION.GET_QUALITY, member.wotb_id));
tabSort.push(membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_QUALITY, member.wotb_id));
}
}
else if (sort_by == "sigCount")
......@@ -574,7 +574,7 @@ module.exports = async (req: any, res: any, next: any) => {
// Sinon, printer le tableau html
else
{
let meansMembersQuality = membersQuality(constants.QUALITY_CACHE_ACTION.GET_MEANS);
let meansMembersQuality = membersQuality(MonitConstants.QUALITY_CACHE_ACTION.GET_MEANS);
res.locals = {
host: req.headers.host.toString(),
......
"use strict";
import {DataFinder} from "../lib/DataFinder";
import {MonitConstants} from "../lib/constants2";
const co = require('co')
const timestampToDatetime = require(__dirname + '/../lib/timestampToDatetime')
const getLang = require(__dirname + '/../lib/getLang')
const constants = require(__dirname + '/../lib/constants.js')
//const STEP_COUNT_MAX = 150;
......@@ -21,7 +21,7 @@ module.exports = async (req: any, res: any, next: any) => {
var pow = req.query.pow || 'no';
// get lg file
const LANG = getLang(`${__dirname}/../lg/membersCount_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`);
const LANG = getLang(`${__dirname}/../lg/membersCount_${req.query.lg||MonitConstants.DEFAULT_LANGUAGE}.txt`);
// get blockchain
var blockchain = await dataFinder.getBlockWhereMedianTimeLteNoLimit(cache.endBlock[0].medianTime);
......
"use strict";
import {DataFinder} from "../lib/DataFinder";
import {MonitConstants} from "../lib/constants2";
const co = require('co')
const timestampToDatetime = require(__dirname + '/../lib/timestampToDatetime')
const getLang = require(__dirname + '/../lib/getLang')
const constants = require(__dirname + '/../lib/constants.js')
module.exports = async (req:any, res:any, next:any) => {
......@@ -21,14 +19,14 @@ module.exports = async (req:any, res:any, next:any) => {
var format = req.query.format || 'HTML';
// get lg file
const LANG = getLang(`${__dirname}/../lg/monetaryMass_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`);
const LANG = getLang(`${__dirname}/../lg/monetaryMass_${req.query.lg||MonitConstants.DEFAULT_LANGUAGE}.txt`);
// calculate meanMonetaryMassAtFullCurrency
const meanMonetaryMassAtFullCurrency = Math.ceil((1/duniterServer.conf.c)*(duniterServer.conf.dtReeval / duniterServer.conf.dt));
// get beginBlock and endBlock
var beginBlock = [await dataFinder.getBlock(begin)];
var endBlock = null;
var endBlock: any = null;
if (end > 0)
{
endBlock = [await dataFinder.getBlock(end)];
......
const constants = require(__dirname + '/../../lib/constants')
const constants = require(__dirname + '/../../lib/constants2').MonitConstants
// membersQuality cache
var lastUpgradeTime = 0;
......
......@@ -3,8 +3,8 @@ import {DBMembership} from 'duniter/app/lib/dal/sqliteDAL/MembershipDAL'
import {DBIdentity} from 'duniter/app/lib/dal/sqliteDAL/IdentityDAL'
import {showExecutionTimes} from '../lib/MonitorExecutionTime'
import {DataFinder} from '../lib/DataFinder'
import {MonitConstants} from "../lib/constants2";
const constants = require(__dirname + '/../lib/constants')
const timestampToDatetime = require(__dirname + '/../lib/timestampToDatetime')
// Préserver les résultats en cache
......@@ -31,7 +31,7 @@ module.exports = async (req: any, res: any, next: any) => {
try {
// get blockchain timestamp
let resultQueryCurrentBlock = await dataFinder.getCurrentBlockOrNull();
let resultQueryCurrentBlock: any = await dataFinder.getCurrentBlockOrNull();
const currentBlockchainTimestamp = resultQueryCurrentBlock.medianTime;
const currentMembersCount = resultQueryCurrentBlock.membersCount;
const currentBlockNumber = resultQueryCurrentBlock.number;
......@@ -60,7 +60,7 @@ module.exports = async (req: any, res: any, next: any) => {
// Vérifier si le cache doit être Réinitialiser
let reinitCache = (Math.floor(Date.now() / 1000) > (willMembersLastUptime + constants.MIN_WILLMEMBERS_UPDATE_FREQ));
let reinitCache = (Math.floor(Date.now() / 1000) > (willMembersLastUptime + MonitConstants.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) {
......@@ -360,7 +360,7 @@ module.exports = async (req: any, res: any, next: any) => {
{
// Tester la présence de l'adhésion
let membership: DBMembership|null = null
const pendingMembershipsOfIdty: DBMembership[] = await duniterServer.dal.msDAL.getPendingINOfTarget(identitiesList[idMax].hash);
const pendingMembershipsOfIdty: DBMembership[] = await duniterServer.dal.msDAL.getPendingINOfTarget(identitiesList[idMax].hash as string);
for (const ms of pendingMembershipsOfIdty)
{
if (!membership && ms.expires_on > currentBlockchainTimestamp)
......
"use strict";
import {DataFinder} from "../lib/DataFinder";
import {MonitConstants} from "../lib/constants2";
const _ = require('underscore')
const getLang = require(__dirname + '/../lib/getLang')
const constants = require(__dirname + '/../lib/constants.js')
const MAX_STEP_LOOK = 7
......@@ -20,7 +18,7 @@ module.exports = async (req:any, res:any, next:any) => {
var help = req.query.help || 'yes';
// get lg file
const LANG = getLang(`${__dirname}/../lg/wotex_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`);
const LANG = getLang(`${__dirname}/../lg/wotex_${req.query.lg||MonitConstants.DEFAULT_LANGUAGE}.txt`);
// Trouve les points de contrôle efficacement grâce au module C (nommé "wotb")
const wotb = duniterServer.dal.wotb.memCopy();
......
const constants = require(__dirname + '/../lib/constants')
const constants = require(__dirname + '/../lib/constants2').MonitConstants
module.exports = function printMenu(lang, help, location) {
let htmlMenu = '<ul class="menu">';//'<table align="center" width="100%"><tr>';
......
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