changes to how the graphs are done + propper update for v2

This commit is contained in:
Expand-sys 2022-12-24 22:22:49 +11:00
parent 2c62a9a40b
commit 0711cd944b
2 changed files with 94 additions and 67 deletions

View file

@ -155,48 +155,70 @@ fastify.get(
Accept: "application/json", Accept: "application/json",
}, },
}); });
console.log(log.body)
let transactionlog = []
let currentbal = balance;
let graphlog = log;
let graphdata = []
if(log.body != "null"){
log = JSON.parse(log.body); log = JSON.parse(log.body);
console.log(log);
let graphlog = log; let graphlog = log;
if (graphlog != null) { if (graphlog != null) {
graphlog = graphlog.reverse(); graphlog = graphlog.reverse();
} }
let graphdata = ""; console.log(graphlog)
let currentbal = balance; console.log("here fuckwit")
if (graphlog) { if (graphlog) {
for (i = graphlog.length - 1; i > -1; i--) { for (i = 0; i < graphlog.length; i++) {
currentbal = parseInt(currentbal) + parseInt(graphlog[i].amount); console.log(i)
graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]"; console.log(graphlog[0])
currentbal = parseInt(currentbal) - parseInt(graphlog[i].amount);
if( i > 14)
break
graphdata.push([i+1, currentbal])
} }
const seconds = Math.floor(Date.now() / 1000);
graphdata.unshift([0 , balance])
graphdata.unshift(["Transaction", "Amount"])
console.log(graphdata)
} else { } else {
graphlog = undefined; graphlog = undefined;
} }
if (graphdata != "") {
graphdata =
", [" + parseInt(graphlog.length) + "," + balance + "]" + graphdata;
graphdata = '["transaction", "balance"]' + graphdata;
}
let transactionlog = []
for(i = 0; i < log.length; i++){ for(i = 0; i < log.length; i++){
if(log[i].amount > 0){ console.log(log[i])
if(log[i].amount < 0){
let absol = Math.abs(log[i].amount) let absol = Math.abs(log[i].amount)
console.log(absol) console.log(absol)
let date = Date(log[i].time) let date = new Date(log[i].time * 1000)
console.log(date) console.log(date)
transactionlog.push(`You sent ${log[i].counterparty} ${absol} at ${date}`); transactionlog.push(`You sent ${log[i].counterparty} ${absol} at ${date}`);
} else { } else {
let date = new Date(log[i].time * 1000)
transactionlog.push(`${log[i].counterparty} sent you ${log[i].amount} at ${log[i].time}`); transactionlog.push(`${log[i].counterparty} sent you ${log[i].amount} at ${date}`);
} }
}
console.log(transactionlog) console.log(transactionlog)
let maxgraph = balance + 1000;
console.log(graphdata)
console.log("begin render " + Date.now());
console.log(graphdata)
}
console.log("begin render " + Date.now());
}
let maxgraph = balance + 1000;
stringgraphdata = JSON.stringify(graphdata)
console.log(stringgraphdata)
graphdata = stringgraphdata.slice(1,stringgraphdata.length-1)
res.view("bankf", { res.view("bankf", {
transactionlog: transactionlog, transactionlog: transactionlog,
maxgraph: maxgraph, maxgraph: maxgraph,
@ -303,6 +325,7 @@ fastify.post("/login", async function (req, res) {
adminTest = JSON.parse(adminTest.statusCode); adminTest = JSON.parse(adminTest.statusCode);
} catch (e) { } catch (e) {
console.log(e.response.body); console.log(e.response.body);
console.log("yeet")
} }
console.log(adminTest); console.log(adminTest);
if (adminTest == 204) { if (adminTest == 204) {
@ -312,7 +335,6 @@ fastify.post("/login", async function (req, res) {
req.session.set("password", password); req.session.set("password", password);
} else { } else {
let verified; let verified;
//verified = await client.verifyPassword(name, password);
try { try {
verified = await got.post(`${api}/api/v1/user/verify_password`, { verified = await got.post(`${api}/api/v1/user/verify_password`, {
headers: { headers: {

View file

@ -51,22 +51,20 @@ block content
script(type='text/javascript' src='https://www.gstatic.com/charts/loader.js') script(type='text/javascript' src='https://www.gstatic.com/charts/loader.js')
script(type='text/javascript'). script(type='text/javascript').
google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawBasic);
function drawBasic() {
google.charts.load('current', {'packages':['corechart', 'line']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([!{graphdata}]); var data = google.visualization.arrayToDataTable([!{graphdata}]);
var options = { var options = {
title: 'Balance',
hAxis: { hAxis: {
title: 'Transaction', title: 'Transactions'
textPosition: 'out',
}, },
vAxis: { vAxis: {
title: 'Balance', title: 'Current Balance'
format: 'currency',
textPosition: 'out',
}, },
trendlines: { trendlines: {
0: {type: 'exponential', color: '#333', opacity: .5}, 0: {type: 'exponential', color: '#333', opacity: .5},
@ -75,15 +73,22 @@ block content
width: 680, width: 680,
height: 350, height: 350,
}; };
function resize () {
var chart = new google.visualization.LineChart(document.getElementById('chart_div')); var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options); chart.draw(data, options);
}
window.onload = resize; window.onload = resize;
window.onresize = resize; window.onresize = resize;
} }
script(type='text/javascript'). script(type='text/javascript').
function resize () { function resize () {
var chart = new google.visualization.LineChart(document.getElementById('chart_div')); var chart = new google.visualization.LineChart(document.getElementById('chart_div'));