Change behavior of the percentage done
cover Change behavior of the percentage done
From: Mariano Lopez <[email protected]>
This patches changes the behavior of the percentage done to display the percentage of out to date recipes that were updated in the period.
models.py: Added SQL queriesviews.py: Changed the behavior
base_toplevel.html: Changed format of the webpage
Mariano Lopez (3):
models.py: Added Raw SQL for percentage updated views.py: Changed the behavior of percentage done base_toplevel.html: Changed format of percentage done
rrs/models.py | 44 ++++++++++++++++++++++++++++++++++++++++ rrs/views.py | 33 ++++++++++++++++++++++-------- templates/rrs/base_toplevel.html | 2 +- 3 files changed, 69 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/3 models.py: Added Raw SQL for percentage updated
From: Mariano Lopez <[email protected]>
This adds SQL queries that will be used for the
percentage of recipes updated in a period.
--- rrs/models.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
rrs/models.py +44 -0
@@ -235,6 +235,16 @@ class RecipeUpstreamHistory(models.Model): return None @staticmethod + def get_first_by_date_range(start, end): + history = RecipeUpstreamHistory.objects.filter(start_date__gte = start, + start_date__lte = end).order_by('start_date') + + if history: + return history[0] + else: + return None + + @staticmethod def get_last(): history = RecipeUpstreamHistory.objects.filter().order_by('-start_date')
@@ -475,6 +485,40 @@ class Raw(): return Raw.dictfetchall(cur) @staticmethod + def get_reup_by_date(date_id): + cur = connection.cursor() + cur.execute("""SELECT DISTINCT recipe_id + FROM rrs_RecipeUpstream + WHERE status = 'N' + AND history_id = %s + """, [date_id]) + return [i[0] for i in cur.fetchall()] + + @staticmethod + def get_reupg_by_dates(start_date, end_date): + cur = connection.cursor() + cur.execute("""SELECT id, recipe_id, maintainer_id, author_date, commit_date + FROM rrs_recipeupgrade + WHERE commit_date >= %s + AND commit_date <= %s + ORDER BY commit_date DESC; + """, [start_date, end_date]) + return Raw.dictfetchall(cur) + + @staticmethod + def get_reupg_by_dates_and_recipes(start_date, end_date, recipes_id): + recipes = str(recipes_id).strip('[]') + + cur = connection.cursor() + qry = """SELECT DISTINCT recipe_id + FROM rrs_RecipeUpgrade""" + qry += "\nWHERE commit_date >= '%s'" % str(start_date) + qry += "\nAND commit_date <= '%s'" % str(end_date) + qry += "\nAND recipe_id IN (%s);" % recipes + cur.execute(qry) + return Raw.dictfetchall(cur) + + @staticmethod def dictfetchall(cursor): "Returns all rows from a cursor as a dict" desc = cursor.description
Signature · 1 line
1.9.1
PATCH 2/3 views.py: Changed the behavior of percentage done
In reply to [email protected]From: Mariano Lopez <[email protected]>
This changes the percetage done from recipes up to date in the period to percentage of not updated recipes that were updated in the period.
--- rrs/views.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
rrs/views.py +24 -9
@@ -40,10 +40,26 @@ def _get_milestone_statistics(milestone, maintainer_name=None): milestone.start_date, milestone.end_date ) + recipe_upstream_history_first = \ + RecipeUpstreamHistory.get_first_by_date_range( + milestone.start_date, + milestone.end_date, + ) if maintainer_name is None: - milestone_statistics['all'] = \ - RecipeUpstream.get_all_recipes(recipe_upstream_history).count() + if recipe_upstream_history_first: + recipes_not_upgraded = \ + Raw.get_reup_by_date(recipe_upstream_history_first.id) + recipes_upgraded = \ + Raw.get_reupg_by_dates_and_recipes( + milestone.start_date, milestone.end_date, recipes_not_upgraded) + milestone_statistics['all'] = \ + float(len(recipes_upgraded))/float(len(recipes_not_upgraded)) + else: + milestone_statistics['all'] = 0 + + milestone_statistics['percentage'] = "%.0f" % \ + (float(milestone_statistics['all']) * 100.0) milestone_statistics['up_to_date'] = \ RecipeUpstream.get_recipes_up_to_date(recipe_upstream_history).count() milestone_statistics['not_updated'] = \
@@ -79,13 +95,12 @@ def _get_milestone_statistics(milestone, maintainer_name=None): milestone_statistics['cant_be_updated'] += 1 else: milestone_statistics['unknown'] += 1 - - if milestone_statistics['all'] == 0: - milestone_statistics['percentage'] = 0 - else: - milestone_statistics['percentage'] = "%.0f" % \ - ((float(milestone_statistics['up_to_date']) / - float(milestone_statistics['all'])) * 100) + if milestone_statistics['all'] == 0: + milestone_statistics['percentage'] = '0' + else: + milestone_statistics['percentage'] = "%.0f" % \ + ((float(milestone_statistics['up_to_date']) / + float(milestone_statistics['all'])) * 100) return milestone_statistics
Signature · 1 line
1.9.1
PATCH 3/3 base_toplevel.html: Changed format of percentage done
In reply to [email protected]From: Mariano Lopez <[email protected]>
Changed the text of percentage done to updated. Also added a tooltip that shows how this percentage is calculated.
--- templates/rrs/base_toplevel.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
templates/rrs/base_toplevel.html +1 -1
@@ -66,7 +66,7 @@ </span> <ul class="nav"> <li class="divider-vertical"></li> - <li class="lead" id="percentage"><strong>{{ recipes_percentage }}%</strong> done</li> + <li class="lead" id="percentage" data-toggle="tooltip" title="Upgrades done in the period divided by recipes not updated at the beginning of the period"><strong>{{ recipes_percentage }}%</strong> Updated</li> <li class="divider-vertical"></li> <li class="lead" id="up-to-date-recipes">Up-to-date: <span class="text-success">{{ recipes_up_to_date }}</strong></li> <li class="divider-vertical"></li>
Signature · 1 line
1.9.1