Skip to content

Commit

Permalink
Merge pull request #489 from pgiraud/issue457
Browse files Browse the repository at this point in the history
Done/validated are stored as floats in db
  • Loading branch information
Pierre GIRAUD committed Dec 16, 2014
2 parents 8509c25 + a4d2f51 commit e2ab5ea
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def run_migrations_online():
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
target_metadata=target_metadata,
compare_type=True
)

try:
Expand Down
36 changes: 36 additions & 0 deletions alembic/versions/336f4518e8e6_change_integer_to_float_for_done_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Change integer to float for done/validated
Revision ID: 336f4518e8e6
Revises: 3f282468e66e
Create Date: 2014-12-12 22:14:06.904066
"""

# revision identifiers, used by Alembic.
revision = '336f4518e8e6'
down_revision = '3f282468e66e'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.alter_column('project', 'done',
existing_type=sa.INTEGER(),
type_=sa.Float(),
existing_nullable=True)
op.alter_column('project', 'validated',
existing_type=sa.INTEGER(),
type_=sa.Float(),
existing_nullable=True)


def downgrade():
op.alter_column('project', 'validated',
existing_type=sa.Float(),
type_=sa.INTEGER(),
existing_nullable=True)
op.alter_column('project', 'done',
existing_type=sa.Float(),
type_=sa.INTEGER(),
existing_nullable=True)
11 changes: 5 additions & 6 deletions osmtm/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import math

from sqlalchemy import (
Table,
Column,
Float,
Integer,
BigInteger,
Unicode,
Expand Down Expand Up @@ -453,9 +452,9 @@ class Project(Base, Translatable):
priority = Column(Integer, default=2)

# percentage of done tasks
done = Column(Integer, default=0)
done = Column(Float, default=0)
# percentage of validated tasks
validated = Column(Integer, default=0)
validated = Column(Float, default=0)

__table_args__ = (CheckConstraint(priority.in_(range(0, 4))), )

Expand Down Expand Up @@ -530,7 +529,7 @@ def get_done(self):
if not done:
done = 0

return math.floor(done * 100 / total) if total != 0 else 0
return round(done * 100 / total, 2) if total != 0 else 0

def get_validated(self):
total = DBSession.query(func.sum(ST_Area(Task.geometry))) \
Expand All @@ -551,7 +550,7 @@ def get_validated(self):
if not validated:
validated = 0

return math.floor(validated * 100 / total) if total != 0 else 0
return round(validated * 100 / total, 2) if total != 0 else 0

def to_bbox(self):
return shape.to_shape(self.area.geometry).bounds
Expand Down
3 changes: 2 additions & 1 deletion osmtm/templates/home.mako
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ sorts = [('priority', 'asc', _('High priority first')),
<%
import markdown
import bleach
import math
if request.locale_name:
project.locale = request.locale_name
priority = priorities[project.priority]
Expand Down Expand Up @@ -143,7 +144,7 @@ sorts = [('priority', 'asc', _('High priority first')),
<div style="width: ${project.validated}%;" class="progress-bar progress-bar-success"></div>
</div>
</td>
<td>&nbsp;${project.done + project.validated}%</td>
<td>&nbsp;${int(math.floor(project.done + project.validated))}%</td>
</tr>
</table>
</li>
Expand Down

0 comments on commit e2ab5ea

Please sign in to comment.