-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new active projects api for export tool #6153
Merged
kshitijrajsharma
merged 6 commits into
develop
from
feat/active-projects-api-for-export-tool
Jan 8, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
348de44
feat: new active projects api for export tool
kaditya97 0a3e152
fix: interval validation and datetime in utc timezone
kaditya97 c9fb313
Fix: restrict user to extract more than 24 hour active projects
kaditya97 3aee592
Trigger Builds
kshitijrajsharma 4d59f9c
Revert typo space
kshitijrajsharma c3f5aca
Merge remote-tracking branch 'origin/develop' into feat/active-projec…
kshitijrajsharma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import threading | ||
from cachetools import TTLCache, cached | ||
from flask import current_app | ||
import geojson | ||
from datetime import datetime, timedelta, timezone | ||
|
||
from backend.exceptions import NotFound | ||
from backend.models.dtos.mapping_dto import TaskDTOs | ||
|
@@ -615,3 +617,37 @@ def send_email_on_project_progress(project_id): | |
project_completion, | ||
), | ||
).start() | ||
|
||
@staticmethod | ||
def get_active_projects(interval): | ||
action_date = datetime.now(timezone.utc) - timedelta(hours=interval) | ||
result = ( | ||
TaskHistory.query.with_entities(TaskHistory.project_id) | ||
.distinct() | ||
.filter(TaskHistory.action_date >= action_date) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using this , test this query with dump of production database , you might need action_date btree timestamp index |
||
.all() | ||
) | ||
project_ids = [row.project_id for row in result] | ||
projects = ( | ||
Project.query.with_entities( | ||
Project.id, | ||
Project.mapping_types, | ||
Project.geometry.ST_AsGeoJSON().label("geometry"), | ||
) | ||
.filter( | ||
Project.status == ProjectStatus.PUBLISHED.value, | ||
Project.id.in_(project_ids), | ||
) | ||
.all() | ||
) | ||
features = [] | ||
for project in projects: | ||
properties = { | ||
"project_id": project.id, | ||
"mapping_types": project.mapping_types, | ||
} | ||
feature = geojson.Feature( | ||
geometry=geojson.loads(project.geometry), properties=properties | ||
) | ||
features.append(feature) | ||
return geojson.FeatureCollection(features) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.