| 2244 | |
| 2245 | |
| 2246 | def task_exam_stats(task, |
| 2247 | instance_list): |
| 2248 | # careful instance_list is a dict here not python object yet |
| 2249 | # (so need to call .get() instead of .attribute |
| 2250 | # Not sure if this is right place to put it |
| 2251 | |
| 2252 | task.review_star_rating_average = 0.0 |
| 2253 | |
| 2254 | # gold standard file is a cached dict |
| 2255 | # careful to use those methods instead ".attribute" |
| 2256 | if task.gold_standard_file['instance_list']: |
| 2257 | |
| 2258 | task.gold_standard_missing = 0 |
| 2259 | |
| 2260 | for instance in task.gold_standard_file['instance_list']: |
| 2261 | |
| 2262 | missing = instance.get('missing', None) |
| 2263 | if missing == True: |
| 2264 | task.gold_standard_missing += 1 |
| 2265 | |
| 2266 | sum_ratings = 0 |
| 2267 | count_ratings = 0 |
| 2268 | # What about soft deletes? |
| 2269 | |
| 2270 | if len(instance_list) > 0: |
| 2271 | |
| 2272 | for instance in instance_list: |
| 2273 | |
| 2274 | rating = instance.get('rating', None) |
| 2275 | if rating: |
| 2276 | sum_ratings += rating |
| 2277 | count_ratings += 1 |
| 2278 | |
| 2279 | task.review_star_rating_average = sum_ratings / count_ratings |
| 2280 | |
| 2281 | |
| 2282 | # From STUDIO |