def get_chart1_data(user_id=None, set=None, tag=None): ''' Fetch raw data to present in first user profile chart. This function is isolated so that it can be called directly from ajax controls on the chart itself, as well as programmatically from info(). Returns: dict: ''' # def milliseconds(dt): # return (dt-datetime.datetime(1970,1,1)).total_seconds() * 1000 user_id = user_id if user_id else auth.user_id stats = Stats(user_id) badge_set_milestones = stats.get_badge_set_milestones() answer_counts = stats.get_answer_counts(set=set, tag=tag) chart1_data = {'badge_set_reached': [{'date': dict['my_date'], 'set': dict['badge_set']} for dict in badge_set_milestones], 'answer_counts': [{'date': dict['my_date'], 'total': dict['right'] + dict['wrong'], 'ys': [{'class': 'right', 'y0': 0, 'y1': dict['right']}, {'class': 'wrong', 'y0': dict['right'], 'y1': dict['right'] + dict['wrong']} ], 'ids': dict['ids'] } for dict in answer_counts], # above includes y values for stacked bar graph # and 'ids' for modal presentation of daily attempts } return {'chart1_data': chart1_data, 'badge_set_milestones': badge_set_milestones, 'answer_counts': answer_counts}