Skip to content

Commit

Permalink
Merge pull request #2688 from goat-community/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
EPajares authored Oct 11, 2023
2 parents 45089b9 + 5600b6a commit 396e712
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
13 changes: 11 additions & 2 deletions app/api/src/core/opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read_population_sql(table_to_aggregate: str, group_by_column: str, obj_in):

modified_buildings = []
scenario_result = {}
if obj_in.scenario.id != 0 and obj_in.scenario.modus != 'default':
if obj_in.scenario.id != 0 and obj_in.scenario.modus.value != 'default':
modified_buildings = legacy_engine.execute(
f"SELECT * FROM basic.modified_buildings({obj_in.scenario.id})",
legacy_engine,
Expand Down Expand Up @@ -50,6 +50,7 @@ def read_population_sql(table_to_aggregate: str, group_by_column: str, obj_in):
base_result = legacy_engine.execute(sql_base_population)
base_result = base_result.fetchall()[0][0]

if obj_in.scenario.id != 0:
sql_scenario_population = f"""
SELECT basic.aggregate_points_by_polygon(
'customer.population_modified',
Expand All @@ -62,6 +63,9 @@ def read_population_sql(table_to_aggregate: str, group_by_column: str, obj_in):
"""
scenario_result = legacy_engine.execute(sql_scenario_population)
scenario_result = scenario_result.fetchall()[0][0]

if scenario_result is None:
scenario_result = {}

result = {}
# Loop through all keys in both dictionaries
Expand All @@ -71,7 +75,12 @@ def read_population_sql(table_to_aggregate: str, group_by_column: str, obj_in):
else:
scenario_value = 0
result[key] = {}
result[key]["population"] = base_result.get(key, 0).get("population", 0) + scenario_value
base_value = base_result.get(key)
if isinstance(base_value, dict):
base_population = base_value.get("population", 0)
else:
base_population = 0
result[key]["population"] = base_population + scenario_value

return result

Expand Down
2 changes: 2 additions & 0 deletions app/api/src/endpoints/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from src.db import models
from src.endpoints import deps
from src.utils import send_test_email
from urllib.parse import unquote

router = APIRouter()

Expand All @@ -23,6 +24,7 @@ async def reverse_proxy(
"""
Reverse proxy to another server.
"""
url = unquote(url)
if not url:
raise HTTPException(status_code=400, detail="URL is required")
if (
Expand Down
28 changes: 27 additions & 1 deletion app/client/src/factory/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import mapStore from "../store/modules/map";
import indicators from "../store/modules/indicators";
import axios from "axios";
import store from "../store";
import JwtService from "../services/jwt.service";

/**
*
Expand Down Expand Up @@ -204,7 +205,32 @@ export const LayerFactory = {
const layer = new ImageLayer({
...this.baseConf(lConf).lOpts,
source: new ImageWMS({
...this.baseConf(lConf).sOpts
...this.baseConf(lConf).sOpts,
imageLoadFunction: function(image, src) {
let reqUrl = src;
let headers = new Headers();
if (src.includes("reverse-proxy")) {
const split = src.split("?url=");
const proxyUrl = split[1];
const encodedUrl = encodeURIComponent(proxyUrl);
reqUrl = `${split[0]}?url=${encodedUrl}`;
headers = new Headers({
Authorization: `Bearer ${JwtService.getToken()}`
});
}

fetch(reqUrl, { headers })
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
const img = image.getImage();
img.addEventListener("load", function() {
URL.revokeObjectURL(url);
});
img.src = url;
})
.catch(error => console.error(error));
}
})
});
return layer;
Expand Down

0 comments on commit 396e712

Please sign in to comment.