feat(backend): Added concrete example data for stats

parent 277d16d8
......@@ -53,31 +53,210 @@ def stats(request):
dataset = request.GET.get("dataset")
if dataset == "1":
stats_data = [
{ 'a': 1, 'b': 1, 'c': 1 },
{ 'a': 4, 'b': 2, 'c': 1 },
{ 'a': 1, 'b': 3, 'c': 1 },
{ 'a': 3, 'b': 4, 'c': 5 },
{ 'a': 2, 'b': 3, 'c': 2 },
{ 'a': 1, 'b': 3, 'c': 1 },
{ 'a': 4, 'b': 3, 'c': 3 },
{ 'a': 2, 'b': 1, 'c': 1 }
raw_data = [
{"date": "2020-06-06", "nb_connections": 5},
{"date": "2020-06-05", "nb_connections": 25},
{"date": "2020-06-04", "nb_connections": 1},
{"date": "2020-06-03", "nb_connections": 1},
{"date": "2020-06-02", "nb_connections": 4},
{"date": "2020-06-01", "nb_connections": 1},
{"date": "2020-05-31", "nb_connections": 0},
{"date": "2020-05-30", "nb_connections": 2},
{"date": "2020-05-29", "nb_connections": 1},
{"date": "2020-05-28", "nb_connections": 0},
{"date": "2020-05-27", "nb_connections": 1},
{"date": "2020-05-26", "nb_connections": 0},
{"date": "2020-05-25", "nb_connections": 0},
{"date": "2020-05-25", "nb_connections": 0},
{"date": "2020-05-24", "nb_connections": 3},
{"date": "2020-05-23", "nb_connections": 2},
{"date": "2020-05-22", "nb_connections": 2},
{"date": "2020-05-22", "nb_connections": 2},
{"date": "2020-05-21", "nb_connections": 2},
{"date": "2020-05-20", "nb_connections": 1},
]
cols = ["date", "nb_connections"]
stats_data = {c: [d[c] for d in raw_data] for c in cols}
elif dataset == "2":
stats_data = [
{ 'f': 1, 'g': 1, 'h': 1 },
{ 'f': 4, 'g': 2, 'h': 1 },
{ 'f': 1, 'g': 3, 'h': 1 },
{ 'f': 3, 'g': 4, 'h': 5 },
{ 'f': 2, 'g': 3, 'h': 2 },
{ 'f': 1, 'g': 3, 'h': 1 },
{ 'f': 4, 'g': 3, 'h': 3 },
{ 'f': 2, 'g': 1, 'h': 1 }
raw_data = [
{
"date": "2020-06-04",
"university": "337 - Universidad Autónoma de Aguascalientes",
"major": "GU",
"minor": "SR",
"exchange_semester": "A2019",
"nb_contributions": 1,
},
{
"date": "2020-05-30",
"university": "26 - Cranfield University",
"major": "IM",
"minor": "MARS",
"exchange_semester": "A2019",
"nb_contributions": 1,
},
{
"date": "2020-05-24",
"university": "343 - Universidad Pontificia Comillas",
"major": "TC",
"minor": "",
"exchange_semester": "A2018",
"nb_contributions": 1,
},
{
"date": "2020-04-26",
"university": "344 - Technical University of Košice",
"major": "TC",
"minor": "",
"exchange_semester": "P2020",
"nb_contributions": 1,
},
{
"date": "2020-04-10",
"university": "221 - École nationale supérieure des mines de Rabat",
"major": "IM",
"minor": "PIL",
"exchange_semester": "A2019",
"nb_contributions": 7,
},
{
"date": "2020-03-24",
"university": "51 - University of Glasgow",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 6,
},
{
"date": "2020-03-22",
"university": "53 - Technische Universität Braunschweig",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 4,
},
{
"date": "2020-03-14",
"university": "53 - Technische Universität Braunschweig",
"major": "TC",
"minor": "",
"exchange_semester": "A2017",
"nb_contributions": 7,
},
{
"date": "2020-03-14",
"university": "39 - Université du Québec à Chicoutimi",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 3,
},
{
"date": "2020-03-11",
"university": "405 - National Chiao Tung University",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 6,
},
{
"date": "2020-03-11",
"university": "200 - University of Science and Technology",
"major": "IM",
"minor": "MARS",
"exchange_semester": "A2019",
"nb_contributions": 3,
},
{
"date": "2020-03-11",
"university": "170 - Silesian University of Technology",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 1,
},
{
"date": "2020-03-11",
"university": "71 - Polytechnique Montréal",
"major": "IM",
"minor": "MARS",
"exchange_semester": "A2019",
"nb_contributions": 5,
},
{
"date": "2020-03-10",
"university": "375 - Politechnika Wrocławska",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 5,
},
{
"date": "2020-02-19",
"university": "376 - Warsaw University of Life Sciences",
"major": "GB",
"minor": "IAA",
"exchange_semester": "P2019",
"nb_contributions": 1,
},
{
"date": "2020-02-12",
"university": "301 - Université de technologie sino-européenne de l'université de Shanghai",
"major": "HuTech",
"minor": "Spe-GI",
"exchange_semester": "P2019",
"nb_contributions": 1,
},
{
"date": "2020-02-10",
"university": "57 - Technische Universität Graz",
"major": "TC",
"minor": "",
"exchange_semester": "P2018",
"nb_contributions": 9,
},
{
"date": "2020-02-05",
"university": "71 - Polytechnique Montréal",
"major": "IM",
"minor": "SIM",
"exchange_semester": "A2019",
"nb_contributions": 2,
},
{
"date": "2020-02-02",
"university": "51 - University of Glasgow",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 6,
},
{
"date": "2020-01-31",
"university": "375 - Politechnika Wrocławska",
"major": "IM",
"minor": "CMI",
"exchange_semester": "A2019",
"nb_contributions": 1,
},
]
cols = [
"date",
"university",
"major",
"minor",
"exchange_semester",
"nb_contributions",
]
stats_data = {c: [d[c] for d in raw_data] for c in cols}
else:
return HttpResponseRedirect("/stats/?dataset=1")
return render(request, "stats.html", dict(stats_data=json.dumps(stats_data)))
......
......@@ -7,10 +7,15 @@ import TableFromData from "./Table";
import { makeStyles } from "@material-ui/styles";
import { Line } from "react-chartjs-2";
const data = __StatsData;
/* SELECT a, COUNT(*) AS c FROM ? GROUP BY a
SELECT a as x, COUNT(*) AS y FROM ? GROUP BY a */
const cols = Object.keys(__StatsData);
const data = [];
for (let i = 0; i < __StatsData[cols[0]].length; i++) {
const elem = {};
for (let col of cols) {
elem[col] = __StatsData[col][i];
}
data.push(elem);
}
const useStyles = makeStyles({});
......@@ -31,15 +36,15 @@ function PlotResult({ result }) {
<div>
<Line
data={{
labels: result.map(r => r.x),
labels: result.map((r) => r.x),
datasets: [
{
label: "My First dataset", //séparer par cat
backgroundColor: "rgb(255, 99, 132)",
borderColor: "rgb(255, 99, 132)",
data: result.map(r => r.y)
}
]
data: result.map((r) => r.y),
},
],
}}
/>
</div>
......@@ -80,7 +85,12 @@ function SqlRequestResult({ result }) {
);
}
const defaultRequest = "SELECT a as x, COUNT(*) AS y FROM ? GROUP BY a;";
const defaultRequest = `SELECT
date AS x,
nb_connections AS y
FROM ?
ORDER BY x ASC;
`;
function getRequestFromUrl() {
const getParamsInUrl = new URL(document.location).searchParams;
......@@ -104,7 +114,7 @@ function getRequestFromUrl() {
function setRequestInUrl(request) {
const requestInfo = {
request,
version: 1.0
version: 1.0,
};
const requestInfoAsString = btoa(JSON.stringify(requestInfo));
......@@ -139,7 +149,7 @@ function SqlInterface() {
rows={5}
placeholder="Entrez la requête SQL"
value={sqlRequest}
onChange={event => setSqlRequest(event.target.value)}
onChange={(event) => setSqlRequest(event.target.value)}
/>
{requestError !== "" && (
<>
......@@ -156,10 +166,10 @@ function SqlInterface() {
setRequestError("");
setRequestResult([]);
executeRequest(sqlRequest, data)
.then(res => {
.then((res) => {
setRequestResult(res);
})
.catch(err => {
.catch((err) => {
setRequestError(err);
});
}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment