Compare commits
8 Commits
enablePWA
...
new-mockda
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c174948f8 | |||
| 92e630f24f | |||
| e40cc80ec2 | |||
| cefe56cd11 | |||
| 57c4bf2c38 | |||
| 1ffcd56342 | |||
| 93a811fb08 | |||
| 7d1a9ff86e |
18
backend/README.md
Normal file
18
backend/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Backend for the Simcompanies-Dashboard
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the production mode.<br />
|
||||
Access the API and frontend files on [http://localhost:3001](http://localhost:3001) to view it in the browser.
|
||||
|
||||
### `npm run debug`
|
||||
|
||||
Runs the app in the developement mode.<br />
|
||||
Access the API and frontend files on [http://localhost:3001](http://localhost:3001) to view it in the browser.
|
||||
You can only login with the credentials "test" "test".
|
||||
|
||||
The server reloads on changes you still need to refresh your browserpage yourself.
|
||||
101
backend/index.js
101
backend/index.js
@@ -33,6 +33,9 @@ var sessionStore = new MySQLStore({
|
||||
const mockDataDay = require('./mockdata-test/day.json');
|
||||
const mockDataWeek = require('./mockdata-test/week.json');
|
||||
const mockDataMonth = require('./mockdata-test/month.json');
|
||||
//const mockAmountDataDay = require('./mockdata-test/amountDay.json');
|
||||
//const mockAmountDataWeek = require('./mockdata-test/amountWeek.json');
|
||||
//const mockAmountDataMonth = require('./mockdata-test/amountMonth.json');
|
||||
var resourceList;
|
||||
const saltRounds = 13;
|
||||
|
||||
@@ -199,7 +202,7 @@ app.delete("/API/user/logout", function (req, res) {
|
||||
return res.status(status.OK).send("logout success");
|
||||
});
|
||||
|
||||
app.get('/API/day', function (req, res) {
|
||||
app.get('/API/price/day', function (req, res) {
|
||||
const kind = parseInt(req.query.kind);
|
||||
if (Number.isInteger(kind)) {
|
||||
//Mock Data:
|
||||
@@ -226,7 +229,34 @@ app.get('/API/day', function (req, res) {
|
||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
});
|
||||
|
||||
app.get('/API/week', function (req, res) {
|
||||
app.get('/API/amount/day', function (req, res) {
|
||||
const kind = parseInt(req.query.kind);
|
||||
if (Number.isInteger(kind)) {
|
||||
//Mock Data:
|
||||
if (kind === -1 || DEBUG) return res.send(mockAmountDataDay);
|
||||
|
||||
if (kind >= 1 && kind <= 113) {
|
||||
var dayend = new Date().toMysqlFormat();
|
||||
var daybegin = new Date();
|
||||
daybegin.setDate(daybegin.getDate() - 1);
|
||||
daybegin = daybegin.toMysqlFormat();
|
||||
const querystring = `SELECT time, quality, amount FROM marketcap WHERE kind = ${kind} AND time > "${daybegin}" AND time < "${dayend}" ORDER BY time, quality`;
|
||||
connection.query(querystring, function (error, results, fields) {
|
||||
if (error) {
|
||||
return res.status(status.INTERNAL_SERVER_ERROR).send("database connection failed");
|
||||
}
|
||||
return res.send(results);
|
||||
});
|
||||
}
|
||||
else
|
||||
return res.status(status.BAD_REQUEST).send("invalid data range provided");
|
||||
|
||||
}
|
||||
else
|
||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
});
|
||||
|
||||
app.get('/API/price/week', function (req, res) {
|
||||
const kind = parseInt(req.query.kind);
|
||||
if (Number.isInteger(kind)) {
|
||||
//Mock Data:
|
||||
@@ -259,7 +289,70 @@ app.get('/API/week', function (req, res) {
|
||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
});
|
||||
|
||||
app.get('/API/month', function (req, res) {
|
||||
app.get('/API/amount/week', function (req, res) {
|
||||
const kind = parseInt(req.query.kind);
|
||||
if (Number.isInteger(kind)) {
|
||||
//Mock Data:
|
||||
if (kind === -1 || DEBUG) return res.send(mockAmountDataWeek);
|
||||
|
||||
if (kind >= 1 && kind <= 113) {
|
||||
var day = new Date();
|
||||
day.setDate(day.getDate() - 6)
|
||||
var querying = "";
|
||||
for (let i = 0; i < 7; i++) {
|
||||
let currentday = day.toMysqlFormat().split(" ")[0];
|
||||
querying += `SELECT "${currentday + " 3:00:00"}" as time,kind,quality,AVG(amount) as amount FROM marketcap WHERE kind = ${kind} AND TIME > "${currentday} 00:00:00" AND TIME <= "${currentday} 05:59:59" GROUP BY kind,quality UNION `;
|
||||
querying += `SELECT "${currentday + " 09:00:00"}" as time,kind,quality,AVG(amount) as amount FROM marketcap WHERE kind = ${kind} AND TIME > "${currentday} 6:00:00" AND TIME <= "${currentday} 11:59:59" GROUP BY kind,quality UNION `;
|
||||
querying += `SELECT "${currentday + " 15:00:00"}" as time,kind,quality,AVG(amount) as amount FROM marketcap WHERE kind = ${kind} AND TIME > "${currentday} 12:00:00" AND TIME <= "${currentday} 17:59:59" GROUP BY kind,quality UNION `;
|
||||
querying += `SELECT "${currentday + " 21:00:00"}" as time,kind,quality,AVG(amount) as amount FROM marketcap WHERE kind = ${kind} AND TIME > "${currentday} 18:00:00" AND TIME <= "${currentday} 23:59:59" GROUP BY kind,quality ${i === 6 ? "" : "UNION"} `;
|
||||
day.setDate(day.getDate() + 1);
|
||||
}
|
||||
connection.query(querying, function (error, results, fields) {
|
||||
if (error) {
|
||||
return res.status(status.INTERNAL_SERVER_ERROR).send("database connection failed");
|
||||
}
|
||||
return res.send(results);
|
||||
});
|
||||
}
|
||||
else
|
||||
return res.status(status.BAD_REQUEST).send("invalid data range provided");
|
||||
|
||||
}
|
||||
else
|
||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
});
|
||||
|
||||
app.get('/API/price/month', function (req, res) {
|
||||
const kind = parseInt(req.query.kind);
|
||||
if (Number.isInteger(kind)) {
|
||||
//Mock Data:
|
||||
if (kind === -1 || DEBUG) return res.send(mockAmountDataMonth);
|
||||
|
||||
if (kind >= 1 && kind <= 113) {
|
||||
var day = new Date();
|
||||
day.setDate(day.getDate() - 29);
|
||||
var querying = "";
|
||||
for (let i = 0; i < 30; i++) {
|
||||
let currentday = day.toMysqlFormat().split(" ")[0];
|
||||
querying += `SELECT "${currentday}" as time,kind,quality,AVG(price) as price FROM marketv2 WHERE kind = ${kind} AND TIME >= "${currentday} 00:00:00" AND TIME <= "${currentday} 23:59:59" GROUP BY kind,quality ${i === 29 ? "" : "UNION"} `;
|
||||
day.setDate(day.getDate() + 1);
|
||||
}
|
||||
connection.query(querying, function (error, results, fields) {
|
||||
if (error) {
|
||||
return res.status(status.INTERNAL_SERVER_ERROR).send("database connection failed");
|
||||
}
|
||||
return res.send(results);
|
||||
});
|
||||
}
|
||||
else
|
||||
return res.status(status.BAD_REQUEST).send("invalid data range provided");
|
||||
|
||||
}
|
||||
else
|
||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
||||
});
|
||||
|
||||
app.get('/API/amount/month', function (req, res) {
|
||||
const kind = parseInt(req.query.kind);
|
||||
if (Number.isInteger(kind)) {
|
||||
//Mock Data:
|
||||
@@ -271,7 +364,7 @@ app.get('/API/month', function (req, res) {
|
||||
var querying = "";
|
||||
for (let i = 0; i < 30; i++) {
|
||||
let currentday = day.toMysqlFormat().split(" ")[0];
|
||||
querying += `SELECT "${currentday}" as time,kind,quality,AVG(price) as price FROM marketv2 WHERE kind = ${kind} AND TIME >= "${currentday} 00:00:00" AND TIME <= "${currentday} 23:59:59" GROUP BY kind,quality ${i === 29 ? "" : "UNION"} `;
|
||||
querying += `SELECT "${currentday}" as time,kind,quality,AVG(amount) as amount FROM marketcap WHERE kind = ${kind} AND TIME >= "${currentday} 00:00:00" AND TIME <= "${currentday} 23:59:59" GROUP BY kind,quality ${i === 29 ? "" : "UNION"} `;
|
||||
day.setDate(day.getDate() + 1);
|
||||
}
|
||||
connection.query(querying, function (error, results, fields) {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 53 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
@@ -3,11 +3,7 @@
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" sizes="64x64" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/apple-icon-180x180.png">
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="%PUBLIC_URL%/android-icon-192x192.png">
|
||||
<link rel="icon" type="image/png" sizes="512x512" href="%PUBLIC_URL%/android-chrome-512x512.png">
|
||||
<meta name="theme-color" content="#0B1929" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" />
|
||||
<meta name="description" content="This is the dashboard for sim companies ">
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
|
||||
@@ -2,25 +2,12 @@
|
||||
"short_name": "SC Dashboard",
|
||||
"name": "Sim Companies Dashboard",
|
||||
"icons": [{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "android-icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"density": "4.0"
|
||||
},
|
||||
{
|
||||
"src": "android-chrome-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"density": "4.0"
|
||||
}
|
||||
],
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
}],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#0B1929",
|
||||
"background_color": "#0B1929"
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@@ -45,7 +45,7 @@ export default function ResourceChart(props) {
|
||||
if (loading === null) {
|
||||
setLoading(<LinearProgress />)
|
||||
}
|
||||
let dayData = await fetch(`/simcompanies/API/${interval}?kind=${id}`);
|
||||
let dayData = await fetch(`/simcompanies/API/price/${interval}?kind=${id}`);
|
||||
let dataWithDate = await dayData.json();
|
||||
let qualitySortedData = [];
|
||||
for (let i = 0; i < dataWithDate.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user