Repository: learningequality/kolibri

Issue:
Progress bar on topics in Learn not reflecting actual progress
<!--
Instructions:
 * Fill out the sections below, replace …'s with information about your issue
 * Use the 'preview' function above this text box to verify formatting before submitting
-->

### Observed behavior
<!--
Description of the behavior that was observed, including screenshots or other references when applicable
-->

Even if all items within a topic are completed, it will sometimes display as incomplete
<img width="1027" alt="screen shot 2018-06-21 at 3 07 55 pm" src="https://user-images.githubusercontent.com/6668144/41749211-0ac6d940-756a-11e8-942b-4232d335fb97.png">


### Expected behavior
<!--
Description of what behavior was expected but did not occur
-->

The topic should have a full yellow bar with a complete icon

### User-facing consequences
<!--
Implications and real-world consequences for learners, coaches, admins, and other users of the application
-->

Learner will be confused and sad or think something is missing from the topic


### Steps to reproduce
<!--
Precise steps that someone else can follow in order to see this behavior
-->

1. Log in as a facility user
2. Complete/master all items in a topic
3. Look at the parent topic

### Context
<!--
Tell us about your environment, including:
 * Kolibri version
 * Operating system
 * Browser
-->

0.10.0
MacOS
Chrome



Discussion:
@jonboiser mind looking at this?
I think the problem is that the percentage used on the "Early Math > Counting >Counting" topic card is 

2 (mastered resources) / 5 (total resources)

Whereas, based on this installation it should be

2 (mastered resources) / 2 (available resources)
We should probably be excluding unavailable content when getting these leaf_ids here: https://github.com/learningequality/kolibri/blob/release-v0.10.x/kolibri/content/serializers.py#L177
(this will also stop us from counting completed, but unavailable content from being included in progress calculations - the inverse of this)

Resolving patch:
diff --git a/kolibri/content/serializers.py b/kolibri/content/serializers.py
--- a/kolibri/content/serializers.py
+++ b/kolibri/content/serializers.py
@@ -174,21 +174,31 @@ def get_topic_and_content_progress_fraction(node, user):
 
 
 def get_topic_and_content_progress_fractions(nodes, user):
-    leaf_ids = nodes.get_descendants(include_self=True).order_by().exclude(
-        kind=content_kinds.TOPIC).values_list("content_id", flat=True)
+    leaf_ids = nodes.get_descendants(include_self=True) \
+        .order_by() \
+        .exclude(available=False) \
+        .exclude(kind=content_kinds.TOPIC) \
+        .values_list('content_id', flat=True)
 
-    summary_logs = get_summary_logs(leaf_ids, user)
+    leaf_node_logs = get_summary_logs(leaf_ids, user)
 
-    overall_progress = {log['content_id']: round(log['progress'], 4) for log in summary_logs.values('content_id', 'progress')}
+    overall_progress = {}
+
+    for log in leaf_node_logs.values('content_id', 'progress'):
+        overall_progress[log['content_id']] = round(log['progress'], 4)
 
     for node in nodes:
         if node.kind == content_kinds.TOPIC:
-            leaf_ids = node.get_descendants(include_self=True).order_by().exclude(
-                kind=content_kinds.TOPIC).values_list("content_id", flat=True)
+            topic_leaf_ids = node.get_descendants(include_self=True) \
+                .order_by() \
+                .exclude(available=False) \
+                .exclude(kind=content_kinds.TOPIC) \
+                .values_list('content_id', flat=True)
+
             overall_progress[node.content_id] = round(
-                sum(overall_progress.get(leaf_id, 0) for leaf_id in leaf_ids) / len(leaf_ids),
+                sum(overall_progress.get(leaf_id, 0) for leaf_id in topic_leaf_ids) / len(topic_leaf_ids),
                 4
-            ) if leaf_ids else 0.0
+            ) if topic_leaf_ids else 0.0
 
     return overall_progress
 


Test patch: