Merge remote-tracking branch 'origin/master' into login
This commit is contained in:
@@ -24,9 +24,7 @@ export default function Content() {
|
||||
<div className={classes.root}>
|
||||
<Route exact path="/" component={Overview} />
|
||||
<Route path="/resources" component={SelectResource} />
|
||||
|
||||
<Route path="/resourcechart/:id" render={() => <ResourceChart day={new Date().toUTCString()}></ResourceChart>} />
|
||||
|
||||
<Route path="/resourcechart/:id" render={() => <ResourceChart />} />
|
||||
</div>
|
||||
|
||||
);
|
||||
|
||||
@@ -38,7 +38,14 @@ const output = (data) => {
|
||||
<YAxis domain={['datamin', 'datamax']} />
|
||||
<Tooltip />
|
||||
<Legend />
|
||||
<Line type="monotone" dataKey="price" stroke="#8884d8" dot={false} />
|
||||
<Line type="monotone" dataKey="q0" stroke="#8884d8" dot={false} />
|
||||
<Line type="monotone" dataKey="q1" stroke="#000000" dot={false} />
|
||||
<Line type="monotone" dataKey="q2" stroke="#82ca9d" dot={false} />
|
||||
<Line type="monotone" dataKey="q3" stroke="#ff0066" dot={false} />
|
||||
<Line type="monotone" dataKey="q4" stroke="#660066" dot={false} />
|
||||
<Line type="monotone" dataKey="q5" stroke="#99cc00" dot={false} />
|
||||
<Line type="monotone" dataKey="q6" stroke="#669999" dot={false} />
|
||||
<Line type="monotone" dataKey="q7" stroke="#996633" dot={false} />
|
||||
</LineChart>
|
||||
)
|
||||
}
|
||||
@@ -49,13 +56,49 @@ export default function ResourceChart(props) {
|
||||
const [data, setData] = React.useState(null);
|
||||
let { id } = useParams();
|
||||
const loadData = async () => {
|
||||
let nextData = await fetch(`/simcompanies/API/day?date=${props["day"]}&kind=${id}`);
|
||||
nextData = await nextData.json();
|
||||
for (let i = 0; i < nextData.length; i++) {
|
||||
nextData[i]["time"] = new Date(nextData[i]["time"]);
|
||||
nextData[i]["time"] = nextData[i]["time"].toLocaleTimeString();
|
||||
let dayData = await fetch(`/simcompanies/API/day?kind=${id}`);
|
||||
let dataWithDate = await dayData.json();
|
||||
let qualitySortedData = [];
|
||||
for (let i = 0; i < dataWithDate.length; i++) {
|
||||
if (i === 0) qualitySortedData.push(dataWithDate[i]);
|
||||
else {
|
||||
if (dataWithDate[i]["time"] === qualitySortedData[qualitySortedData.length - 1]["time"]) {
|
||||
switch (dataWithDate[i].quality) {
|
||||
case 0: break;
|
||||
case 1:
|
||||
qualitySortedData[qualitySortedData.length - 1]["q1"] = dataWithDate[i]["price"];
|
||||
break;
|
||||
case 2:
|
||||
qualitySortedData[qualitySortedData.length - 1]["q2"] = dataWithDate[i]["price"];
|
||||
break;
|
||||
case 3:
|
||||
qualitySortedData[qualitySortedData.length - 1]["q3"] = dataWithDate[i]["price"];
|
||||
break;
|
||||
case 4:
|
||||
qualitySortedData[qualitySortedData.length - 1]["q4"] = dataWithDate[i]["price"];
|
||||
break;
|
||||
case 5:
|
||||
qualitySortedData[qualitySortedData.length - 1]["q5"] = dataWithDate[i]["price"];
|
||||
break;
|
||||
case 6:
|
||||
qualitySortedData[qualitySortedData.length - 1]["q6"] = dataWithDate[i]["price"];
|
||||
break;
|
||||
case 7:
|
||||
qualitySortedData[qualitySortedData.length - 1]["q7"] = dataWithDate[i]["price"];
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
qualitySortedData.push(dataWithDate[i]);
|
||||
qualitySortedData[qualitySortedData.length - 1]["q0"] = qualitySortedData[qualitySortedData.length - 1]["price"];
|
||||
}
|
||||
}
|
||||
}
|
||||
setData(nextData)
|
||||
for (let i = 0; i < qualitySortedData.length; i++) {
|
||||
qualitySortedData[i]["time"] = new Date(qualitySortedData[i]["time"]);
|
||||
qualitySortedData[i]["time"] = qualitySortedData[i]["time"].toLocaleTimeString();
|
||||
}
|
||||
console.log(qualitySortedData);
|
||||
setData(qualitySortedData)
|
||||
}
|
||||
|
||||
if (data === null) {
|
||||
@@ -82,7 +125,5 @@ export default function ResourceChart(props) {
|
||||
</Grid>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user