Skip to content
Snippets Groups Projects
Commit abbbc903 authored by Éloïs's avatar Éloïs
Browse files

[enh] membersCount : Personalize the maximum number of shown points and the...

[enh] membersCount : Personalize the maximum number of shown points and the choice of the parameter on which to play to respect this limit
parent 11b0feb0
No related branches found
No related tags found
1 merge request!62Dev2
......@@ -109,11 +109,34 @@ module.exports = (req, res, next) => co(function *() {
}
else { cache.beginBlock = yield duniterServer.dal.peerDAL.query('SELECT `medianTime`,`number` FROM block WHERE `fork`=0 AND `number`='+req.query.begin+' LIMIT 1 '); }
// Apply STEP_COUNT_MAX and calculate stepTime
if ( Math.ceil((cache.endBlock[0].medianTime-cache.beginBlock[0].medianTime)/(cache.step*unitTime)) > constants.STEP_COUNT_MAX )
// Define nbMaxPoints and adaptMaxPoints
if ( typeof(req.query.nbMaxPoints) != 'undefined' && req.query.nbMaxPoints > 0 ) {
cache.nbMaxPoints = req.query.nbMaxPoints;
} else {
cache.nbMaxPoints = constants.STEP_COUNT_MAX;
}
if ( typeof(req.query.adaptMaxPoints) != 'undefined' && (req.query.adaptMaxPoints == "step" || req.query.adaptMaxPoints == "end")) {
cache.adaptMaxPoints = req.query.adaptMaxPoints;
} else {
cache.adaptMaxPoints = "begin";
}
// Apply nbMaxPoints and adaptMaxPoints
if (cache.adaptMaxPoints == "begin")
{
if ( Math.ceil((cache.endBlock[0].medianTime-cache.beginBlock[0].medianTime)/(cache.step*unitTime)) > cache.nbMaxPoints )
{
let newBeginTime = cache.endBlock[0].medianTime-cache.step*cache.nbMaxPoints*unitTime;
cache.beginBlock = yield duniterServer.dal.peerDAL.query('SELECT `medianTime`,`number` FROM block WHERE `fork`=0 AND `medianTime` >= \''+newBeginTime+'\' ORDER BY `medianTime` ASC LIMIT 1 ');
}
} else if (cache.adaptMaxPoints == "step") {
cache.step = Math.ceil((cache.endBlock[0].medianTime-cache.beginBlock[0].medianTime)/(constants.STEP_COUNT_MAX*unitTime));
} else {
let newEndTime = cache.beginBlock[0].medianTime+cache.step*cache.nbMaxPoints*unitTime;
cache.endBlock = yield duniterServer.dal.peerDAL.query('SELECT `medianTime`,`number` FROM block WHERE `fork`=0 AND `medianTime` <= \''+newEndTime+'\' ORDER BY `medianTime` DESC LIMIT 1 ');
}
// Calculate stepTime
cache.stepTime = parseInt(cache.step)*unitTime;
// if new blocks and MIN_CACHE_UPDATE_FREQ pass, update cache
......
......@@ -3,8 +3,9 @@
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;
//const STEP_COUNT_MAX = 150;
module.exports = (req, res, next) => co(function *() {
......@@ -32,7 +33,7 @@ module.exports = (req, res, next) => co(function *() {
// Traiter le cas stepUnit == "blocks"
if (cache.stepUnit == "blocks")
{
if ( Math.ceil((cache.endBlock[0].number-cache.beginBlock[0].number)/cache.step) > STEP_COUNT_MAX ) { cache.step = Math.ceil((cache.endBlock[0].number-cache.beginBlock[0].number)/STEP_COUNT_MAX); }
if ( Math.ceil((cache.endBlock[0].number-cache.beginBlock[0].number)/cache.step) > constants.STEP_COUNT_MAX ) { cache.step = Math.ceil((cache.endBlock[0].number-cache.beginBlock[0].number)/constants.STEP_COUNT_MAX); }
}
// Initialize nextStepTime, stepIssuerCount and bStep
......@@ -185,7 +186,7 @@ module.exports = (req, res, next) => co(function *() {
tabMembersCount,
begin: cache.beginBlock[0].number,
end: cache.endBlock[0].number,
form: `${LANG["BEGIN"]} #<input type="number" name="begin" value="${cache.beginBlock[0].number}" min="0"> - ${LANG["END"]} #<input type="number" name="end" value="${cache.endBlock[0].number}" > - ${LANG["STEP"]} <input type="number" name="step" value="${cache.step}" min="1">
form: `${LANG["BEGIN"]} #<input type="number" name="begin" value="${cache.beginBlock[0].number}" min="0" size="7" style="width:60px;"> - ${LANG["END"]} #<input type="number" name="end" value="${cache.endBlock[0].number}" size="7" style="width:60px;"> - ${LANG["STEP"]} <input type="number" name="step" value="${cache.step}" min="1" size="4" style="width:50px;">
<select name="stepUnit">
<option name="stepUnit" value ="blocks" ${cache.stepUnit == 'blocks' ? 'selected' : ''}>${LANG["BLOCKS"]}
<option name="stepUnit" value ="hours" ${cache.stepUnit == 'hours' ? 'selected' : ''}>${LANG["HOURS"]}
......@@ -193,9 +194,15 @@ module.exports = (req, res, next) => co(function *() {
<option name="stepUnit" value ="weeks" ${cache.stepUnit == 'weeks' ? 'selected' : ''}>${LANG["WEEKS"]}
<option name="stepUnit" value ="months" ${cache.stepUnit == 'months' ? 'selected' : ''}>${LANG["MONTHS"]}
<option name="stepUnit" value ="years" ${cache.stepUnit == 'years' ? 'selected' : ''}>${LANG["YEARS"]}
</select>`,
</select> - max <input type="number" name="nbMaxPoints" value="${cache.nbMaxPoints}" min="1" size="4" style="width:50px;"> points (réguler en adaptant
<select name="adaptMaxPoints">
<option name="adaptMaxPoints" value ="begin"> ${LANG["BEGIN"]}
<option name="adaptMaxPoints" value ="step" ${cache.adaptMaxPoints == 'step' ? 'selected' : ''}> ${LANG["STEP"]}
<option name="adaptMaxPoints" value ="end" ${cache.adaptMaxPoints == 'end' ? 'selected' : ''}> ${LANG["END"]}
</select>)`,
description: `${LANG["DESCRIPTION1"]+'<br>'+LANG["DESCRIPTION2"]+'<b>'+cache.Yn+'</b>.'}`,
form2: `<input type="checkbox" name="pow" value="yes" ${pow == 'yes' ? 'checked' : ''}> ${LANG["SHOW_POW_MIN"]}`,
form2: `
<input type="checkbox" name="pow" value="yes" ${pow == 'yes' ? 'checked' : ''}> ${LANG["SHOW_POW_MIN"]}`,
chart: {
type: 'line',
data: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment