Skip to content

Commit

Permalink
Merge branch 'development' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
varun2948 authored Sep 7, 2023
2 parents 034903d + 6f88d57 commit ff93f51
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
12 changes: 6 additions & 6 deletions src/backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Settings(BaseSettings):
FRONTEND_MAIN_URL: Optional[str]
FRONTEND_MAP_URL: Optional[str]

EXTRA_CORS_ORIGINS: Optional[Union[str, list[AnyUrl]]] = []
EXTRA_CORS_ORIGINS: Optional[Union[str, list[str]]] = []

@field_validator("EXTRA_CORS_ORIGINS", mode="before")
@classmethod
Expand All @@ -53,8 +53,8 @@ def assemble_cors_origins(

# Build default origins from env vars
url_scheme = info.data.get("URL_SCHEME")
main_url = info.data.get("URL_SCHEME")
map_url = info.data.get("URL_SCHEME")
main_url = info.data.get("FRONTEND_MAIN_URL")
map_url = info.data.get("FRONTEND_MAP_URL")
if url_scheme and main_url and map_url:
default_origins = [
f"{url_scheme}://{main_url}",
Expand Down Expand Up @@ -99,9 +99,9 @@ def assemble_db_connection(cls, v: Optional[str], info: FieldValidationInfo) ->
# Convert Url type to string
return str(pg_url)

ODK_CENTRAL_URL: Optional[AnyUrl]
ODK_CENTRAL_USER: Optional[str]
ODK_CENTRAL_PASSWD: Optional[str]
ODK_CENTRAL_URL: Optional[AnyUrl] = None
ODK_CENTRAL_USER: Optional[str] = ""
ODK_CENTRAL_PASSWD: Optional[str] = ""

OSM_CLIENT_ID: str
OSM_CLIENT_SECRET: str
Expand Down
15 changes: 11 additions & 4 deletions src/backend/app/projects/project_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import segno
import shapely.wkb as wkblib
import sqlalchemy
import pkg_resources
from fastapi import File, HTTPException, UploadFile
from geoalchemy2.shape import from_shape
from geojson import dump
Expand Down Expand Up @@ -700,15 +701,15 @@ def process_polygon(db:Session, project_id:uuid.UUID, boundary_data:str, no_of_b
db.commit()
else:
# Remove the polygons outside of the project AOI using a parameterized query
query = f"""
query = text(f"""
DELETE FROM ways_poly
WHERE NOT ST_Within(ST_Centroid(ways_poly.geom), (SELECT geom FROM project_aoi WHERE project_id = '{project_id}'));
"""
""")
result = db.execute(query)
db.commit()
with open('app/db/split_algorithm.sql', 'r') as sql_file:
query = sql_file.read()
result = db.execute(query, params={'num_buildings': no_of_buildings})
result = db.execute(text(query), params={'num_buildings': no_of_buildings})
result = result.fetchall()
db.query(db_models.DbBuildings).delete()
db.query(db_models.DbOsmLines).delete()
Expand Down Expand Up @@ -1044,9 +1045,15 @@ def read_xlsforms(
):
"""Read the list of XLSForms from the disk."""
xlsforms = list()
package_name = "osm_fieldwork"
for xls in os.listdir(directory):
if xls.endswith(".xls") or xls.endswith(".xlsx"):
xlsforms.append(xls)
file_name = xls.split(".")[0]
yaml_file_name = f"data_models/{file_name}.yaml"
if pkg_resources.resource_exists(package_name,yaml_file_name):
xlsforms.append(xls)
else:
continue
log.info(xls)
inspect(db_models.DbXForm)
forms = table(
Expand Down
34 changes: 17 additions & 17 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,33 @@ class BETAProjectUpload(BaseModel):
xform_title: Union[str, None]
odk_central: ODKCentral
hashtags: Union[List[str], None]
organisation_id: Optional[int]
organisation_id: Optional[int] = None
# city: str
# country: str


class Feature(BaseModel):
id: int
project_id: int
task_id: Optional[int]
geometry: Optional[Feature]
task_id: Optional[int] = None
geometry: Optional[Feature] = None


class ProjectSummary(BaseModel):
id: int = -1
priority: ProjectPriority = ProjectPriority.MEDIUM
priority_str: str = priority.name
title: Optional[str]
location_str: Optional[str]
description: Optional[str]
total_tasks: Optional[int]
tasks_mapped: Optional[int]
num_contributors: Optional[int]
tasks_validated: Optional[int]
tasks_bad: Optional[int]
hashtags: Optional[List[str]]
organisation_id: Optional[int]
organisation_logo: Optional[str]
title: Optional[str] = None
location_str: Optional[str] = None
description: Optional[str] = None
total_tasks: Optional[int] = None
tasks_mapped: Optional[int] = None
num_contributors: Optional[int] = None
tasks_validated: Optional[int] = None
tasks_bad: Optional[int] = None
hashtags: Optional[List[str]] = None
organisation_id: Optional[int] = None
organisation_logo: Optional[str] = None


class ProjectBase(BaseModel):
Expand All @@ -88,9 +88,9 @@ class ProjectBase(BaseModel):
# location_str: str
# outline_geojson: Optional[Feature]
project_tasks: Optional[List[tasks_schemas.Task]]
xform_title: Optional[str]
hashtags: Optional[List[str]]
organisation_id: Optional[int]
xform_title: Optional[str] = None
hashtags: Optional[List[str]] = None
organisation_id: Optional[int] = None


class ProjectOut(ProjectBase):
Expand Down
8 changes: 4 additions & 4 deletions src/backend/app/tasks/tasks_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ async def task_features_count(
)

def process_task(task):
feature_count_query = f"""
select count(*) from features where project_id = {project_id} and task_id = {task}
"""
feature_count_query = text(f"""
select count(*)from features where project_id = {project_id} and task_id = {task}
""")
result = db.execute(feature_count_query)
feature_count = result.fetchone()

Expand All @@ -190,7 +190,7 @@ def process_task(task):
# form_details = central_crud.get_form_full_details(project.odkid, task, odk_credentials)
return {
"task_id": task,
"feature_count": feature_count["count"],
"feature_count": feature_count[0],
# 'submission_count': form_details['submissions'],
"submission_count": len(submission_list)
if isinstance(submission_list, list)
Expand Down
32 changes: 18 additions & 14 deletions src/frontend/main/src/views/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ const Home = () => {
totalProjectCount={stateHome.homeProjectSummary.length}
/>
{stateHome.homeProjectLoading == false ? (
filteredProjectCards.length > 0 ? (
<div>
<div className="fmtm-flex fmtm-flex-col lg:fmtm-flex-row fmtm-gap-5">
<div className={`fmtm-w-full ${showMapStatus ? 'lg:fmtm-w-[50%]' : ''} `}>
<div className="fmtm-flex fmtm-flex-col lg:fmtm-flex-row fmtm-gap-5">
<div className={`fmtm-w-full ${showMapStatus ? 'lg:fmtm-w-[50%]' : ''} `}>
{filteredProjectCards.length > 0 ? (
<div>
<div
className={`fmtm-px-[1rem] fmtm-grid fmtm-gap-5 ${
!showMapStatus
Expand All @@ -74,17 +74,21 @@ const Home = () => {
))}
</div>
</div>
{/* fmtm-w-[41.8rem] */}
{showMapStatus && (
<ProjectListMap/>
)}
</div>
) : (
<CoreModules.Typography
variant="h2"
color="error"
sx={{ p: 2, textAlign: 'center' }}
className="fmtm-h-full fmtm-flex fmtm-justify-center fmtm-items-center"
>
No projects found.
</CoreModules.Typography>
)}
</div>
) : (
<CoreModules.Typography variant="h2" color="error" sx={{ p: 2, textAlign: 'center' }}>
No projects found.
</CoreModules.Typography>
)
{showMapStatus && (
<ProjectListMap/>
)}
</div>
) : (
<CoreModules.Stack
sx={{
Expand Down

0 comments on commit ff93f51

Please sign in to comment.