Skip to content

Commit

Permalink
Add dummy data route
Browse files Browse the repository at this point in the history
  • Loading branch information
karanikiotis committed Oct 22, 2024
1 parent b650e43 commit 892e19b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/routes/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import express from "express";
import Sentry from "@sentry/node";

const router = express.Router({ mergeParams: true });

const generateRandomData = (min = 0, max = 10) => Math.random() * (max - min) + min;

router.get("/", async (req, res) => {
try {
const localFoodCropProduction = {
March: Array.from({ length: 100 }, () => generateRandomData(0, 10)),
April: Array.from({ length: 100 }, () => generateRandomData(0, 10)),
May: Array.from({ length: 100 }, () => generateRandomData(0, 10)),
};

const comparisonOfIrrigationWaterVsNeeds = {
March: { etc: generateRandomData(0, 100), irrigation: generateRandomData(0, 100), rainfall: generateRandomData(0, 100) },
April: { etc: generateRandomData(0, 100), irrigation: generateRandomData(0, 100), rainfall: generateRandomData(0, 100) },
May: { etc: generateRandomData(0, 100), irrigation: generateRandomData(0, 100), rainfall: generateRandomData(0, 100) },
June: { etc: generateRandomData(0, 100), irrigation: generateRandomData(0, 100), rainfall: generateRandomData(0, 100) },
July: { etc: generateRandomData(0, 100), irrigation: generateRandomData(0, 100), rainfall: generateRandomData(0, 100) },
August: { etc: generateRandomData(0, 100), irrigation: generateRandomData(0, 100), rainfall: generateRandomData(0, 100) },
};

const timePlot = {
meteo: Array.from({ length: 20 }, () => generateRandomData(0, 100)),
inSitu: Array.from({ length: 20 }, () => generateRandomData(0, 100)),
generated: Array.from({ length: 20 }, () => generateRandomData(0, 100)),
};

return res.json({
success: true,
localFoodCropProduction,
comparisonOfIrrigationWaterVsNeeds,
timePlot,
});
} catch (error) {
Sentry.captureException(error);
return res.status(500).json({ message: "Something went wrong." });
}
});

export default router;
3 changes: 3 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { attachUser } from "../utils/index.js";
import publicRoutes from "./public.js";
import userSystemRoutes from "./user-system.js";
import userRoutes from "./user.js";
import dataRoutes from "./data.js";

const router = express.Router({ mergeParams: true });

Expand All @@ -20,6 +21,8 @@ router.use(attachUser);
// Handlers for user routes
router.use("/user/", userRoutes);

router.use("/data/", dataRoutes);

router.get("/test/", (req, res) => {
const { user } = res.locals;
console.log(user);
Expand Down

0 comments on commit 892e19b

Please sign in to comment.