Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into deployment-to-cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
anaiscalza committed Jan 19, 2024
2 parents 25a1808 + b9b2d3e commit ef95457
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
6 changes: 3 additions & 3 deletions docker-compose.yml

Large diffs are not rendered by default.

Binary file added frontend/public/adac-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/default-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<v-app-bar :elevation="16" :color="tenantBackgroundColor">
<img
alt="logo-black"
:src="`${TENANT_LOGO}`"
:src="TENANT_LOGO"
width="200"
class="d-inline-block align-top ml-2"
style="cursor: pointer"
Expand Down Expand Up @@ -50,7 +50,7 @@ let username = computed(() => {
let tenantBackgroundColor = ref(TENANT_BACKGROUNDCOLOR || '#ffffff')
console.log('TENANT: ' + TENANT + ' PATH: ' + PATH, 'TENANT_BACKGROUNDCOLOR: ' + TENANT_BACKGROUNDCOLOR)
console.log('TENANT: ' + TENANT + ' PATH: ' + PATH, 'TENANT_BACKGROUNDCOLOR: ' + TENANT_BACKGROUNDCOLOR, 'TENANT_LOGO: ' + TENANT_LOGO)
console.log(document.cookie)
</script>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const BACKEND_URL = import.meta.env.VITE_BACKEND_URL;
const TENANT = import.meta.env.VITE_TENANT || 'default';
const TENANT_CLIENT_ID = import.meta.env.VITE_TENANT_CLIENT_ID;

const TENANT_LOGO = import.meta.env.VITE_TENANT_LOGO;
const TENANT_LOGO = import.meta.env.VITE_TENANT_LOGO || '/default-logo.png';
const TENANT_BACKGROUNDCOLOR = import.meta.env.VITE_TENANT_BACKGROUNDCOLOR;

const PATH = TENANT == 'default' ? '' : `/${TENANT}`;
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/js/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export async function createPin(pin) {
"tenant": TENANT
}
});

console.log(response);

if (!response.ok) throw new Error(`HTTP error! status: ${response.status}, ${response.statusText}`);
const createdPin = await response.json();
Expand All @@ -65,7 +67,7 @@ export async function createPin(pin) {
*/
export async function getHeatmapData() {
try {
const response = await fetch(`${BACKEND_URL}/heatmap`, {
const response = await fetch(`${BACKEND_URL}/heatmap/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/HeatmapView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
style="cursor: crosshair"
>
<l-tile-layer
url="https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png"
url="http://tile.openstreetmap.org/{z}/{x}/{y}.png"
min-zoom="1"
max-zoom="14"
inertia-max-speed="500"
attribution='&copy; <a href="https://stadiamaps.com/">Stadia Maps</a>, &copy; <a href="https://openmaptiles.org/">OpenMapTiles</a> &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
attribution='&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
/>
<l-polygon
v-for="polygon in polygons"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/PinView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
style="cursor: crosshair"
>
<l-tile-layer
url="https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png"
url="http://tile.openstreetmap.org/{z}/{x}/{y}.png"
min-zoom="1"
max-zoom="14"
inertia-max-speed="500"
attribution='&copy; <a href="https://stadiamaps.com/">Stadia Maps</a>, &copy; <a href="https://openmaptiles.org/">OpenMapTiles</a> &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
attribution='&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
/>
<l-polygon
v-for="marker in markers"
Expand Down
2 changes: 1 addition & 1 deletion frontend/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.1
v1.0.3
73 changes: 29 additions & 44 deletions services/heatmap-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import dotenv from "dotenv";
import path from "path";
import { fileURLToPath } from "url";
dotenv.config({ path: path.join(path.dirname(fileURLToPath(import.meta.url)), "../.env") });
const debug = (...args) => { console.log(...args); };

const MONDODB_URI = process.env.MONGODB_URI || "mongodb://localhost:27017";

debug("heatmap-service: connecting to MongoDB: ", MONDODB_URI);

// connect to MongoDB
const client = new MongoClient(MONDODB_URI);
await client.connect();
Expand All @@ -21,66 +25,47 @@ const polygonCollection = database.collection("polygon");
// heatRegionsState = { timestamp: string, heatRegions: [{ polygonname: string, density: number (0-1), count: number }] }
const heatRegionStateCollection = database.collection("heatRegionState");

// create a view that joins the heatRegion and polygon collections
await database.command({ drop: "heatRegionStateWithPolygonView" });
// polygon: {polygonname: string, polygon: []}
// heatRegionWithPolygonView: { timestamp: string, heatRegions: [{ polygonname: string, density: number (0-1), count: number, polygon: [] }] }
await database.command({
create: "heatRegionStateWithPolygonView",
viewOn: "heatRegionState",
pipeline: [
{
$lookup: {
from: "polygon",
localField: "heatRegions.polygonname",
foreignField: "polygonname",
as: "polygondata",
},
},
{
$project: {
_id: 0,
timestamp: 1,
heatRegions: {
polygonname: 1,
density: 1,
count: 1,
polygon: "$polygondata.polygon",
},
},
},
{
$unwind: "$heatRegions.polygon"
}
],
});
const heatRegionStateWithPolygonView = database.collection("heatRegionStateWithPolygonView");

// start express server
const app = express();
const port = 3003;
app.use(express.json());
app.use(cookieParser());
app.use(auth);
// app.use(auth);


// define routes
app.get("/", async (req, res) => {

debug("heatmap-service: GET /");

// get the current heat region state
const heatRegionState = await heatRegionStateCollection.find({}).sort({ timestamp: -1 }).limit(1).next();
const heatRegionState = await heatRegionStateCollection.find({}).sort({ "timestamp": -1 }).limit(1).next();
if (!heatRegionState) {
debug("heatmap-service: no heat region state found");
res.status(400).send("No heat region state found");
return;
}

// TEMP: add polygon data to the heat region state (later this should be done in the view)
for (let i = 0; i < heatRegionState.heatRegions.length; i++) {
const heatRegion = heatRegionState.heatRegions[i];
const polygon = await polygonCollection.findOne({ polygonname: heatRegion.polygonname });
if (polygon) {
heatRegion.polygon = polygon.polygon;
debug("heatmap-service: heat region state: ", heatRegionState);

const polygonNames = heatRegionState.heatRegions.map(heatRegion => heatRegion.polygonname);

debug("heatmap-service: polygon names: ", polygonNames);

const polygons = await polygonCollection.find({ polygonname: { $in: polygonNames } }).toArray();

debug("heatmap-service: polygons: ", polygons);

heatRegionState.heatRegions.forEach(heatRegion => {
const polygon = polygons.find(polygon => polygon.polygonname === heatRegion.polygonname);
if (!polygon) {
console.error(`Could not find polygon ${heatRegion.polygonname}`);
return;
}
}
heatRegion.polygon = polygon.polygon;
});

debug("heatmap-service: sending heat region state: ", heatRegionState);

// send the heat region state
res.status(200).send(heatRegionState);
Expand Down
2 changes: 1 addition & 1 deletion services/heatmap-service/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.1
v1.0.3
86 changes: 20 additions & 66 deletions services/pin-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,23 @@ const pinCollection = database.collection("pin");
const polygonCollection = database.collection("polygon");
const heatRegionCollection = database.collection("heatRegion");

// create a view that joins the pin and polygon collections
await database.command({ drop: "pinWithPolygonView" });
await database.command({
create: "pinWithPolygonView",
viewOn: "pin",
pipeline: [
{
$lookup: {
from: "polygon",
localField: "polygonname",
foreignField: "polygonname",
as: "polygondata",
},
},
{
$project: {
_id: 0,
id: 1,
username: 1,
longitude: 1,
latitude: 1,
name: 1,
description: 1,
date: 1,
companions: 1,
duration: 1,
budget: 1,
polygon: "$polygondata.polygon",
polygonname: 1,
},
},
{
$unwind: {
path: "$polygon",
preserveNullAndEmptyArrays: true,
},
},
],
});
const pinWithPolygonView = database.collection("pinWithPolygonView");

// start express server
const app = express();
const port = 3002;
app.use(express.json());
app.use(cookieParser());
app.use(auth);

const debug = (...args) => { console.log(...args); };

app.post("/", async (req, res) => {
let pin = req.body;

debug("pin-service: received pin: ", pin);

pin.username = req.user.username;

debug("pin-service: username in request: ", req.user.username);

const { polygon, polygonname } = await getPolygonAndName(pin.latitude, pin.longitude);
if (!polygon) {
res.status(400).send("Could not find polygon");
Expand All @@ -96,36 +60,26 @@ app.post("/", async (req, res) => {

app.get("/", async (req, res) => {
const user = req.user;
const pins = await pinWithPolygonView.find({ username: user.username }).toArray();
res.send(pins);
});

app.post("/region", async (req, res) => {
debug("pin-service: username in get request: ", req.user.username);

// takes in a lat and lng and returns a polygon that is the region around that point
// it also stores the polygon in the database so that it does not have to be fetched again
// it replaces the getPolygonAndName function (but uses it)

const { lat, lng } = req.body;

// fetch the polygon outline from nominatim
const { polygon, polygonname } = await getPolygonAndName(lat, lng);
if (!polygon) {
res.status(400).send("Could not find polygon");
return;
}
const pins = await pinCollection.find({ "username": req.user.username }).toArray();

// save the polygon outline to the database to not have to fetch it again if it is not already there
const existingPolygon = await polygonCollection.findOne({ polygonname });
if (!existingPolygon) {
await polygonCollection.insertOne({ polygonname, polygon });
}
// add the polygon outlines to the pins
const polygonnames = pins.map(pin => pin.polygonname);
const polygons = await polygonCollection.find({ polygonname: { $in: polygonnames } }).toArray();
const pinsWithPolygons = pins.map(pin => {
const polygon = polygons.find(polygon => polygon.polygonname === pin.polygonname);
if (!polygon) return pin;
pin.polygon = polygon.polygon;
return pin;
});

res.send({ polygonname, polygon });
debug("pin-service: received pins from database: ", pinsWithPolygons);

res.send(pinsWithPolygons);
});


app.listen(port, () => console.log(`Example app listening on http://localhost:${port}`));


Expand Down Expand Up @@ -167,7 +121,7 @@ const getPolygonAndName = async (lat, lng) => {
let maxZoom = 10;
let minZoom = 5;

for (let tryIndex = 0; tryIndex < 10; tryIndex++) {
for (let tryIndex = 0; tryIndex < 5; tryIndex++) {

// prepare the reverse geocoding request options
let reverseRequestOptions = {
Expand Down
2 changes: 1 addition & 1 deletion services/pin-service/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.1
v1.0.5
2 changes: 1 addition & 1 deletion services/update-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const app = express();
const port = 3005;
app.use(express.json());
app.use(cookieParser());
app.use(auth);
// app.use(auth);

// define routes
app.get("/", (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion services/update-service/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.1
v1.0.2

0 comments on commit ef95457

Please sign in to comment.