Skip to content

Commit

Permalink
Merge pull request #38 from KaartGroup/feature/more_project_stats
Browse files Browse the repository at this point in the history
account for bad imagery tasks
  • Loading branch information
Zack LaVergne authored Dec 9, 2019
2 parents ad222fc + 3dbca6d commit a47d0d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion client/app/project/project-dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ <h3>Task Completion</h3>
<div class="left">
<span><b>{{ ' Total Tasks' | translate }}:</b> {{ projectDashboardCtrl.project.totalTasks }} <b>|</b></span>
<span><b>{{ 'Tasks Mapped' | translate }}:</b> {{ projectDashboardCtrl.project.tasksMapped }} <b>|</b></span>
<span><b>{{ ' Tasks Validated' | translate }}:</b> {{ projectDashboardCtrl.project.tasksValidated }}</span>
<span><b>{{ ' Tasks Validated' | translate }}:</b> {{ projectDashboardCtrl.project.tasksValidated }} <b>|</b></span>
<span><b>{{ ' Bad Imagery' | translate }}:</b> {{ projectDashboardCtrl.project.tasksBadImagery }}</span>
<div class="section__project-dashboard--stats">
<span class="label">{{ projectDashboardCtrl.project.percentMapped }}{{ '% Mapped' | translate }}</span>
<uib-progressbar value="projectDashboardCtrl.project.percentMapped"></uib-progressbar>
Expand Down
2 changes: 2 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ <h2 class="toggle-menu">
<script src="app/services/httpInterceptor.service.js"></script>
<script src="app/services/settings.service.js"></script>
<script src="app/services/userPreferences.service.js"></script>
<script src="app/services/mapping_issue.service.js"></script>
<script src="app/services/osmcha.service.js"></script>

<script src="app/components/add-layer/add-layer.directive.js"></script>
<script src="app/components/account-nav/account-nav.directive.js"></script>
Expand Down
1 change: 1 addition & 0 deletions server/models/dtos/project_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class ProjectStatsDTO(Model):
aoi_centroid = BaseType(serialized_name='aoiCentroid')
tasks_mapped = IntType(serialized_name='tasksMapped')
tasks_validated = IntType(serialized_name='tasksValidated')
tasks_bad_imagery = IntType(serialized_name='tasksBadImagery')
area_percent_mapped = IntType(serialized_name='areaPercentMapped')
area_percent_validated = IntType(serialized_name='areaPercentValidated')

Expand Down
22 changes: 20 additions & 2 deletions server/models/postgis/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,23 @@ def get_validated_area(project_id: int):
result.close()
return area or 0

def get_bad_imagery_area(project_id: int):
""" Get all tasks that are marked as bad imagery """
sql = '''SELECT sum(ST_Area(geom))
FROM (
SELECT t.geometry :: geometry geom
FROM tasks t
WHERE t.project_id = :project_id AND t.task_status = 6) sub;
'''

result = db.engine.execute(text(sql), project_id=project_id)
if result.rowcount == 0:
raise NotFound()

area = result.next()[0]
result.close()
return area or 0

def get_project_stats(self) -> ProjectStatsDTO:
""" Create Project Summary model for postgis project object"""
project_stats = ProjectStatsDTO()
Expand All @@ -448,6 +465,7 @@ def get_project_stats(self) -> ProjectStatsDTO:
project_stats.total_tasks = self.total_tasks
project_stats.tasks_mapped = self.tasks_mapped + self.tasks_validated
project_stats.tasks_validated = self.tasks_validated
project_stats.tasks_bad_imagery = self.tasks_bad_imagery
project_stats.total_comments = db.session.query(ProjectChat).filter(ProjectChat.project_id == self.id).count()
project_stats.percent_mapped = Project.calculate_tasks_percent('mapped', self.total_tasks,
self.tasks_mapped, self.tasks_validated,
Expand Down Expand Up @@ -501,8 +519,8 @@ def get_project_stats(self) -> ProjectStatsDTO:
project_stats.average_validation_time = average_validation_time

# Calculate area_percent_complete to get completion percentage by state according to area
project_stats.area_percent_mapped = int((Project.get_mapped_area(self.id) / polygon.area) * 100)
project_stats.area_percent_validated = int((Project.get_validated_area(self.id) / polygon.area) * 100)
project_stats.area_percent_mapped = int((Project.get_mapped_area(self.id) / (polygon.area - Project.get_bad_imagery_area(self.id))) * 100)
project_stats.area_percent_validated = int((Project.get_validated_area(self.id) / (polygon.area - Project.get_bad_imagery_area(self.id))) * 100)

return project_stats

Expand Down

0 comments on commit a47d0d5

Please sign in to comment.