Save block predictions results in db and show results in a chart

This commit is contained in:
nymkappa
2022-07-06 22:27:45 +02:00
parent 8040abaec4
commit 0887428066
21 changed files with 576 additions and 224 deletions

View File

@@ -27,6 +27,7 @@ import BlocksRepository from './repositories/BlocksRepository';
import HashratesRepository from './repositories/HashratesRepository';
import difficultyAdjustment from './api/difficulty-adjustment';
import DifficultyAdjustmentsRepository from './repositories/DifficultyAdjustmentsRepository';
import BlocksAuditsRepository from './repositories/BlocksAuditsRepository';
class Routes {
constructor() {}
@@ -743,6 +744,20 @@ class Routes {
}
}
public async $getHistoricalBlockPrediction(req: Request, res: Response) {
try {
const blockPredictions = await mining.$getBlockPredictionsHistory(req.params.interval);
const blockCount = await BlocksAuditsRepository.$getPredictionsCount();
res.header('Pragma', 'public');
res.header('Cache-control', 'public');
res.header('X-total-count', blockCount.toString());
res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
res.json(blockPredictions.map(prediction => [prediction.time, prediction.height, prediction.match_rate]));
} catch (e) {
res.status(500).send(e instanceof Error ? e.message : e);
}
}
public async getBlock(req: Request, res: Response) {
try {
const block = await blocks.$getBlock(req.params.hash);