Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 8, 2024
1 parent 27c6e51 commit e7555f1
Show file tree
Hide file tree
Showing 12 changed files with 2,508 additions and 1,538 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- added alchemy text on centroid api
- map Component added to main
- add script to generate openapi.json
- Added a new function to perform the conversion of task_boundary from GeoJSON to .osm format.
- Added a new function to perform the conversion of task_boundary from GeoJSON to .osm format.
- download button for data extract on project details fix Add option to download the data extract fix #779
- api for download data extract
- added download data extract loading
Expand All @@ -30,7 +30,7 @@
- use loguru stdout + json file logging
- form validation added on custom form
- added organisation_id on create project frontend
- organisation Id on create project api
- organisation Id on create project api
- added api to centroid logo
- added projectId on projectbyid
- Tailwindcss integrated
Expand Down Expand Up @@ -220,7 +220,7 @@
- minimum 5 of splitting algorithm
- Project name should accept other characters too. #754
- organization_id none case handled
- task splitted is not shown in map, although the number of tasks are determined and generated #750
- task splitted is not shown in map, although the number of tasks are determined and generated #750
- previous button wrong route issue
- project_id added in the tile_instance
- set tile_path_instance outside try, ref before assign
Expand Down Expand Up @@ -261,7 +261,7 @@
- pwa fixes for icon
- merge conflicts
- data Cleaning fix
- removed api listing static content
- removed api listing static content
- projects can be filter based on user_id and hashtags present in the project
- filtering by hashtags check if project hashtags overlap with requested hashtags
- task spliting for geojson with polygons instead of features
Expand Down Expand Up @@ -322,7 +322,7 @@
- osm-fieldwork import
- osm-fieldwork imports
- Fixes Create Project Section : The input file name has design issues. #452
- Create Project Section - Upload Area subsection : Alignment of the map elements need to be maintained. #451
- Create Project Section - Upload Area subsection : Alignment of the map elements need to be maintained. #451
- handle click outside issue
- organization post
- adjusted map page of home
Expand Down Expand Up @@ -435,7 +435,7 @@
- move app backend server files to app dir
- move backend code out of app dir for rebase
- add additional logging to odkcentral connection
- update __version__.py path in pyproject.toml
- update **version**.py path in pyproject.toml
- remove FMTM_TEST_DB_NAME, DB_URL --> FMTM_DB_URL
- ignore osm-fieldwork local dir
- remove tests dir in root (under src dirs)
Expand Down
10 changes: 7 additions & 3 deletions src/backend/app/auth/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from loguru import logger as log
from sqlalchemy.orm import Session

from app.auth.osm import AuthUser, init_osm_auth, login_required
from app.db import database
from app.db.db_models import DbUser
from app.users import user_crud
from app.auth.osm import AuthUser, init_osm_auth, login_required

router = APIRouter(
prefix="/auth",
Expand Down Expand Up @@ -108,9 +108,13 @@ async def my_data(
"Please contact the administrator."
),
)

# Add user to database
db_user = DbUser(id=user_data["id"], username=user_data["username"], profile_img = user_data["img_url"])
db_user = DbUser(
id=user_data["id"],
username=user_data["username"],
profile_img=user_data["img_url"],
)
db.add(db_user)
db.commit()
else:
Expand Down
4 changes: 3 additions & 1 deletion src/backend/app/central/central_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ async def get_submission(
for entry in range(1, len(data)):
submissions.append(json.loads(data[entry]))
else:
data = central_crud.download_submissions(first.odkid, xmlFormId, None, True, odk_credentials)
data = central_crud.download_submissions(
first.odkid, xmlFormId, None, True, odk_credentials
)
submissions.append(json.loads(data[0]))
if len(data) >= 2:
for entry in range(1, len(data)):
Expand Down
14 changes: 8 additions & 6 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,14 +1171,15 @@ async def get_template_file(
)


@router.get("/project_dashboard/{project_id}", response_model=project_schemas.ProjectDashboard)
@router.get(
"/project_dashboard/{project_id}", response_model=project_schemas.ProjectDashboard
)
async def project_dashboard(
project_id: int,
project_id: int,
background_tasks: BackgroundTasks,
db: Session = Depends(database.get_db)
db: Session = Depends(database.get_db),
):
"""
Get the project dashboard details.
"""Get the project dashboard details.
Args:
project_id (int): The ID of the project.
Expand All @@ -1197,6 +1198,7 @@ async def project_dashboard(
)
return data


@router.get("/contributors/{project_id}")
async def get_contributors(project_id: int, db: Session = Depends(database.get_db)):
"""Get contributors of a project.
Expand All @@ -1208,4 +1210,4 @@ async def get_contributors(project_id: int, db: Session = Depends(database.get_d
list[project_schemas.ProjectUser]: List of project users.
"""
project_users = await project_crud.get_project_users(db, project_id)
return project_users
return project_users
1 change: 0 additions & 1 deletion src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from app.models.enums import ProjectPriority, ProjectStatus, TaskSplitType
from app.tasks import tasks_schemas
from app.users.user_schemas import User
from pydantic.functional_validators import field_validator


class ODKCentral(BaseModel):
Expand Down
35 changes: 20 additions & 15 deletions src/backend/app/submission/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import threading
import uuid
from asyncio import gather
from datetime import datetime
from io import BytesIO
from pathlib import Path
from collections import Counter
from datetime import datetime, timedelta
from io import BytesIO
from pathlib import Path

import sozipfile.sozipfile as zipfile
from asgiref.sync import async_to_sync
Expand Down Expand Up @@ -821,9 +820,10 @@ async def get_submission_count_of_a_project(db: Session, project_id: int):
return len(files)


async def get_submissions_by_date(db: Session, project_id: int, days: int, planned_task: int):
"""
Get submissions by date.
async def get_submissions_by_date(
db: Session, project_id: int, days: int, planned_task: int
):
"""Get submissions by date.
Fetches the submissions for a given project within a specified number of days.
Expand All @@ -839,31 +839,37 @@ async def get_submissions_by_date(db: Session, project_id: int, days: int, plann
# Fetch submissions for project with ID 1 within the last 7 days
submissions = await get_submissions_by_date(db, 1, 7)
"""

project = await project_crud.get_project(db, project_id)
s3_project_path = f"/{project.organisation_id}/{project_id}"
s3_submission_path = f"/{s3_project_path}/submission.zip"

try:
file = get_obj_from_bucket(settings.S3_BUCKET_NAME, s3_submission_path)
except ValueError as e:
except ValueError:
return []

with zipfile.ZipFile(file, "r") as zip_ref:
with zip_ref.open("submissions.json") as file_in_zip:
content = file_in_zip.read()

content = json.loads(content)
end_dates = [datetime.fromisoformat(entry["end"].split('+')[0]) for entry in content if entry.get("end")]

dates = [date.strftime('%m/%d') for date in end_dates if datetime.now() - date <= timedelta(days=days)]
end_dates = [
datetime.fromisoformat(entry["end"].split("+")[0])
for entry in content
if entry.get("end")
]

dates = [
date.strftime("%m/%d")
for date in end_dates
if datetime.now() - date <= timedelta(days=days)
]

submission_counts = Counter(sorted(dates))

response = [
{"date": key, "count": value}
for key, value in submission_counts.items()
]
{"date": key, "count": value} for key, value in submission_counts.items()
]
if planned_task:
count_dict = {}
cummulative_count = 0
Expand All @@ -876,4 +882,3 @@ async def get_submissions_by_date(db: Session, project_id: int, days: int, plann
]

return response

23 changes: 11 additions & 12 deletions src/backend/app/submission/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
from osm_fieldwork.osmfile import OsmFile
from sqlalchemy.orm import Session

from app.central import central_crud
from app.config import settings
from app.db import database
from app.projects import project_crud, project_schemas
from app.central import central_crud
from app.tasks import tasks_crud

from app.submission import submission_crud
from app.tasks import tasks_crud

router = APIRouter(
prefix="/submission",
Expand Down Expand Up @@ -317,13 +316,13 @@ async def get_submission_page(
planned_task: Optional[int] = None,
db: Session = Depends(database.get_db),
):
"""
This api returns the submission page of a project.
"""This api returns the submission page of a project.
It takes one parameter: project_id.
project_id: The ID of the project. This endpoint returns the submission page of this project.
"""

data = await submission_crud.get_submissions_by_date(db, project_id, days, planned_task)
data = await submission_crud.get_submissions_by_date(
db, project_id, days, planned_task
)

# Update submission cache in the background
background_task_id = await project_crud.insert_background_task_into_database(
Expand All @@ -338,9 +337,10 @@ async def get_submission_page(


@router.get("/submission_form_fields/{project_id}")
async def get_submission_form_fields(project_id: int, db: Session = Depends(database.get_db)):
"""
Retrieves the submission form for a specific project.
async def get_submission_form_fields(
project_id: int, db: Session = Depends(database.get_db)
):
"""Retrieves the submission form for a specific project.
Args:
project_id (int): The ID of the project.
Expand All @@ -349,9 +349,8 @@ async def get_submission_form_fields(project_id: int, db: Session = Depends(data
Returns:
Any: The response from the submission form API.
"""

project = await project_crud.get_project(db, project_id)
task_list = await tasks_crud.get_task_id_list(db, project_id)
odk_form = central_crud.get_odk_form(project)
response = odk_form.form_fields(project.odkid, str(task_list[0]))
return response
return response
16 changes: 10 additions & 6 deletions src/backend/app/tasks/tasks_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import base64
from typing import List

from fastapi import HTTPException, Depends
from fastapi import Depends, HTTPException
from geoalchemy2.shape import from_shape
from geojson import dump
from loguru import logger as log
Expand All @@ -27,15 +27,15 @@
from sqlalchemy.orm import Session
from sqlalchemy.sql import text

from app.tasks import tasks_schemas
from app.central import central_crud
from app.db import db_models, database
from app.db import database, db_models
from app.models.enums import (
TaskStatus,
get_action_for_status_change,
verify_valid_status_update,
)
from app.projects import project_crud
from app.tasks import tasks_schemas
from app.users import user_crud


Expand Down Expand Up @@ -321,13 +321,17 @@ async def edit_task_boundary(db: Session, task_id: int, boundary: str):
return True


async def update_task_history(tasks: List[tasks_schemas.TaskBase], db: Session = Depends(database.get_db)):
async def update_task_history(
tasks: List[tasks_schemas.TaskBase], db: Session = Depends(database.get_db)
):
def process_history_entry(history_entry):
status = history_entry.action_text.split()
history_entry.status = status[5]

if history_entry.user_id:
user = db.query(db_models.DbUser).filter_by(id=history_entry.user_id).first()
user = (
db.query(db_models.DbUser).filter_by(id=history_entry.user_id).first()
)
if user:
history_entry.username = user.username
history_entry.profile_img = user.profile_img
Expand All @@ -338,4 +342,4 @@ def process_history_entry(history_entry):
for history_entry in task_history:
process_history_entry(history_entry)

return tasks
return tasks
6 changes: 5 additions & 1 deletion src/backend/app/tasks/tasks_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from app.models.enums import TaskStatus
from app.projects import project_crud, project_schemas
from app.users import user_schemas

from . import tasks_crud, tasks_schemas

router = APIRouter(
Expand All @@ -37,6 +38,7 @@
responses={404: {"description": "Not found"}},
)


@router.get("/task-list", response_model=List[tasks_schemas.ReadTask])
async def read_task_list(
project_id: int,
Expand Down Expand Up @@ -109,7 +111,9 @@ async def read_tasks(task_id: int, db: Session = Depends(database.get_db)):
return task


@router.post("/{task_id}/new_status/{new_status}", response_model=tasks_schemas.ReadTask)
@router.post(
"/{task_id}/new_status/{new_status}", response_model=tasks_schemas.ReadTask
)
async def update_task_status(
user: user_schemas.User,
task_id: int,
Expand Down

0 comments on commit e7555f1

Please sign in to comment.