mirror of
https://github.com/Expand-sys/ccashfrontend
synced 2025-12-17 07:12:12 +11:00
changes to how the graphs are done + propper update for v2
This commit is contained in:
parent
2c62a9a40b
commit
0711cd944b
2 changed files with 94 additions and 67 deletions
100
index.js
100
index.js
|
|
@ -155,48 +155,70 @@ fastify.get(
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
log = JSON.parse(log.body);
|
console.log(log.body)
|
||||||
console.log(log);
|
|
||||||
let graphlog = log;
|
|
||||||
if (graphlog != null) {
|
|
||||||
graphlog = graphlog.reverse();
|
|
||||||
}
|
|
||||||
let graphdata = "";
|
|
||||||
let currentbal = balance;
|
|
||||||
if (graphlog) {
|
|
||||||
for (i = graphlog.length - 1; i > -1; i--) {
|
|
||||||
currentbal = parseInt(currentbal) + parseInt(graphlog[i].amount);
|
|
||||||
graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
graphlog = undefined;
|
|
||||||
}
|
|
||||||
if (graphdata != "") {
|
|
||||||
graphdata =
|
|
||||||
", [" + parseInt(graphlog.length) + "," + balance + "]" + graphdata;
|
|
||||||
graphdata = '["transaction", "balance"]' + graphdata;
|
|
||||||
}
|
|
||||||
let transactionlog = []
|
let transactionlog = []
|
||||||
for(i = 0; i < log.length; i++){
|
let currentbal = balance;
|
||||||
if(log[i].amount > 0){
|
let graphlog = log;
|
||||||
let absol = Math.abs(log[i].amount)
|
let graphdata = []
|
||||||
console.log(absol)
|
if(log.body != "null"){
|
||||||
let date = Date(log[i].time)
|
log = JSON.parse(log.body);
|
||||||
console.log(date)
|
let graphlog = log;
|
||||||
transactionlog.push(`You sent ${log[i].counterparty} ${absol} at ${date}`);
|
if (graphlog != null) {
|
||||||
|
graphlog = graphlog.reverse();
|
||||||
} else {
|
|
||||||
|
|
||||||
transactionlog.push(`${log[i].counterparty} sent you ${log[i].amount} at ${log[i].time}`);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
console.log(graphlog)
|
||||||
|
console.log("here fuckwit")
|
||||||
|
|
||||||
console.log(transactionlog)
|
|
||||||
let maxgraph = balance + 1000;
|
|
||||||
console.log(graphdata)
|
|
||||||
console.log("begin render " + Date.now());
|
if (graphlog) {
|
||||||
|
for (i = 0; i < graphlog.length; i++) {
|
||||||
|
console.log(i)
|
||||||
|
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 {
|
||||||
|
graphlog = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(i = 0; i < log.length; i++){
|
||||||
|
console.log(log[i])
|
||||||
|
if(log[i].amount < 0){
|
||||||
|
let absol = Math.abs(log[i].amount)
|
||||||
|
console.log(absol)
|
||||||
|
let date = new Date(log[i].time * 1000)
|
||||||
|
console.log(date)
|
||||||
|
transactionlog.push(`You sent ${log[i].counterparty} ${absol} at ${date}`);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let date = new Date(log[i].time * 1000)
|
||||||
|
|
||||||
|
transactionlog.push(`${log[i].counterparty} sent you ${log[i].amount} at ${date}`);
|
||||||
|
|
||||||
|
}
|
||||||
|
console.log(transactionlog)
|
||||||
|
|
||||||
|
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: {
|
||||||
|
|
|
||||||
|
|
@ -51,39 +51,44 @@ 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.load('current', {'packages':['corechart', 'line']});
|
google.charts.setOnLoadCallback(drawBasic);
|
||||||
google.charts.setOnLoadCallback(drawChart);
|
|
||||||
function drawChart() {
|
|
||||||
var data = google.visualization.arrayToDataTable([!{graphdata}]);
|
|
||||||
|
|
||||||
var options = {
|
function drawBasic() {
|
||||||
title: 'Balance',
|
|
||||||
hAxis: {
|
var data = google.visualization.arrayToDataTable([!{graphdata}]);
|
||||||
title: 'Transaction',
|
|
||||||
textPosition: 'out',
|
|
||||||
},
|
var options = {
|
||||||
vAxis: {
|
hAxis: {
|
||||||
title: 'Balance',
|
title: 'Transactions'
|
||||||
format: 'currency',
|
},
|
||||||
textPosition: 'out',
|
vAxis: {
|
||||||
},
|
title: 'Current Balance'
|
||||||
trendlines: {
|
},
|
||||||
0: {type: 'exponential', color: '#333', opacity: .5},
|
trendlines: {
|
||||||
1: {type: 'linear', color: '#111', opacity: .3}
|
0: {type: 'exponential', color: '#333', opacity: .5},
|
||||||
},
|
1: {type: 'linear', color: '#111', opacity: .3}
|
||||||
|
},
|
||||||
width: 680,
|
width: 680,
|
||||||
height: 350,
|
height: 350,
|
||||||
};
|
};
|
||||||
function resize () {
|
|
||||||
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
|
|
||||||
chart.draw(data, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.onload = resize;
|
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
|
||||||
window.onresize = resize;
|
|
||||||
|
chart.draw(data, options);
|
||||||
}
|
|
||||||
|
window.onload = 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'));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue