Compare commits
7 Commits
master
...
market-cap
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a6659c3f7 | |||
| 92e630f24f | |||
| e40cc80ec2 | |||
| cefe56cd11 | |||
| 57c4bf2c38 | |||
| 1ffcd56342 | |||
| 93a811fb08 |
19
backend/README.md
Normal file
19
backend/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# 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.
|
||||||
|
No database needed. Mock data is used.
|
||||||
|
You can only login with the credentials "test" "test".
|
||||||
|
|
||||||
|
The server reloads on changes you still need to refresh your browserpage yourself.
|
||||||
@@ -199,7 +199,7 @@ app.delete("/API/user/logout", function (req, res) {
|
|||||||
return res.status(status.OK).send("logout success");
|
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);
|
const kind = parseInt(req.query.kind);
|
||||||
if (Number.isInteger(kind)) {
|
if (Number.isInteger(kind)) {
|
||||||
//Mock Data:
|
//Mock Data:
|
||||||
@@ -226,7 +226,34 @@ app.get('/API/day', function (req, res) {
|
|||||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
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(mockDataDay);
|
||||||
|
|
||||||
|
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);
|
const kind = parseInt(req.query.kind);
|
||||||
if (Number.isInteger(kind)) {
|
if (Number.isInteger(kind)) {
|
||||||
//Mock Data:
|
//Mock Data:
|
||||||
@@ -259,7 +286,40 @@ app.get('/API/week', function (req, res) {
|
|||||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
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(mockDataWeek);
|
||||||
|
|
||||||
|
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);
|
const kind = parseInt(req.query.kind);
|
||||||
if (Number.isInteger(kind)) {
|
if (Number.isInteger(kind)) {
|
||||||
//Mock Data:
|
//Mock Data:
|
||||||
@@ -289,6 +349,36 @@ app.get('/API/month', function (req, res) {
|
|||||||
return res.status(status.BAD_REQUEST).send("invalid data provided");
|
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:
|
||||||
|
if (kind === -1 || DEBUG) return res.send(mockDataMonth);
|
||||||
|
|
||||||
|
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(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) {
|
||||||
|
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/resourcelist', function (req, res) {
|
app.get('/API/resourcelist', function (req, res) {
|
||||||
return res.send(resourceList);
|
return res.send(resourceList);
|
||||||
});
|
});
|
||||||
|
|||||||
1761
backend/package-lock.json
generated
1761
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -45,7 +45,7 @@ export default function ResourceChart(props) {
|
|||||||
if (loading === null) {
|
if (loading === null) {
|
||||||
setLoading(<LinearProgress />)
|
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 dataWithDate = await dayData.json();
|
||||||
let qualitySortedData = [];
|
let qualitySortedData = [];
|
||||||
for (let i = 0; i < dataWithDate.length; i++) {
|
for (let i = 0; i < dataWithDate.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user