Skip to content

Commit

Permalink
Merge pull request #39 from KaartGroup/kaart-stage
Browse files Browse the repository at this point in the history
v3.4.5 Release
  • Loading branch information
Zack LaVergne authored Dec 9, 2019
2 parents 34e7b4e + a47d0d5 commit cf4d5e2
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ client/yarn.lock
server/web/static/dist
server/web/static/dist/

# Ignore project files #
server/project-files

# Ignore local logs
logs/
*.log
Expand Down Expand Up @@ -43,3 +46,7 @@ ehthumbs.db
Thumbs.db
.elasticbeanstalk/
venv_aws/

# emacs files #
\#*\#
*~
17 changes: 17 additions & 0 deletions client/app/project/project-dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ <h2>{{ 'Contributions' | translate }}</h2>
<tr>
<th>{{ 'User' | translate }}</th>
<th>{{ 'Mapped' | translate }}</th>
<!-- <th>{{ '% of Mapped' | translate }}</th> -->
<th>{{ 'Validated' | translate }}</th>
<!-- <th>{{ '% of Validated' | translate }}</th> -->
</tr>
</thead>
<tbody>
<tr ng-repeat="item in projectDashboardCtrl.projectContributions | orderBy: '-mapped'">
<td><a ng-href="/user/{{ item.username }}">{{ item.username }}</a></td>
<td>{{ item.mapped }}</td>
<!-- <td>{{ item.project_percent_mapped }}%</td> -->
<td>{{ item.validated }}</td>
<!-- <td>{{ item.project_percent_validated }}%</td> -->
</tr>
</tbody>
</table>
Expand All @@ -97,13 +101,26 @@ <h2>{{ 'Contributions' | translate }}</h2>
<div class="inner">
<div class="dashboard-container">
<h2>{{ 'Stats' | translate }}</h2>
<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 }} <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>
<span class="label">{{ projectDashboardCtrl.project.percentValidated }}{{ '% Validated' | translate }}</span>
<uib-progressbar value="projectDashboardCtrl.project.percentValidated"></uib-progressbar>
</div>
<h3>Area Completion</h3>
<div class="section__project-dashboard--stats">
<span class="label">{{ projectDashboardCtrl.project.areaPercentMapped }}{{ '% Mapped' | translate }}</span>
<uib-progressbar value="projectDashboardCtrl.project.areaPercentMapped"></uib-progressbar>
<span class="label">{{ projectDashboardCtrl.project.areaPercentValidated }}{{ '% Validated' | translate }}</span>
<uib-progressbar value="projectDashboardCtrl.project.areaPercentValidated"></uib-progressbar>
<span class="important-message">{{ 'NOTE: This percentage may be greater than 100 if the tasks aren\'t clipped to the project AOI' | translate }}</span>
</div>
</div>
<div class="right">
<div id="map" class="map-container"></div>
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
5 changes: 5 additions & 0 deletions server/models/dtos/project_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ class ProjectStatsDTO(Model):
percent_validated = IntType(serialized_name='percentValidated')
percent_bad_imagery = IntType(serialized_name='percentBadImagery')
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')


class ProjectUserStatsDTO(Model):
Expand Down
2 changes: 2 additions & 0 deletions server/models/dtos/stats_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class UserContribution(Model):
username = StringType()
mapped = IntType()
validated = IntType()
project_percent_mapped = IntType()
project_percent_validated = IntType()


class ProjectContributionsDTO(Model):
Expand Down
58 changes: 58 additions & 0 deletions server/models/postgis/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,57 @@ def get_project_user_stats(self, user_id: int) -> ProjectUserStatsDTO:

return stats_dto

def get_mapped_area(project_id: int):
""" Get all tasks that are mapped """
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 IN (2,4)) 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_validated_area(project_id: int):
""" Get all tasks that are validated """
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 = 4) s;
'''

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_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 @@ -412,6 +463,9 @@ def get_project_stats(self) -> ProjectStatsDTO:
project_stats.area = area
project_stats.total_mappers = db.session.query(User).filter(User.projects_mapped.any(self.id)).count()
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 @@ -464,6 +518,10 @@ def get_project_stats(self) -> ProjectStatsDTO:
average_validation_time = total_validation_seconds/unique_validators
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 - 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

def get_project_summary(self, preferred_locale) -> ProjectSummary:
Expand Down
5 changes: 5 additions & 0 deletions server/services/stats_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def get_user_contributions(project_id: int) -> ProjectContributionsDTO:
user_contrib.username = row[1] if row[1] else row[4]
user_contrib.mapped = row[2] if row[2] else 0
user_contrib.validated = row[5] if row[5] else 0

# Calculate user's contribution percentages
project = Project.get(project_id)
user_contrib.project_percent_mapped = (user_contrib.mapped / (project.tasks_mapped or 1)) * 100
user_contrib.project_percent_validated = (user_contrib.validated / (project.tasks_validated or 1)) * 100
contrib_dto.user_contributions.append(user_contrib)
return contrib_dto

Expand Down

0 comments on commit cf4d5e2

Please sign in to comment.