(session, job_id = None, user_id = None, project_id = None)
| 735 | |
| 736 | @staticmethod |
| 737 | def stats(session, job_id = None, user_id = None, project_id = None): |
| 738 | from shared.database.user import User |
| 739 | |
| 740 | query = session.query(Task) |
| 741 | filter_tasks = Task.job_id == job_id |
| 742 | if job_id: |
| 743 | filter_tasks = Task.job_id == job_id |
| 744 | |
| 745 | if project_id: |
| 746 | filter_tasks = Task.project_id == project_id |
| 747 | |
| 748 | total = query.filter(filter_tasks).count() |
| 749 | completed = query.filter(filter_tasks, Task.status == 'complete').count() |
| 750 | in_review = query.filter(filter_tasks, Task.status == 'in_review').count() |
| 751 | requires_changes = query.filter(filter_tasks, Task.status == 'requires_changes').count() |
| 752 | in_progress = query.filter(filter_tasks, Task.status == 'in_progress').count() |
| 753 | instances_created = 0 |
| 754 | if user_id: |
| 755 | query = query.filter(Task.assignee_user_id == user_id) |
| 756 | |
| 757 | if user_id is None: |
| 758 | if job_id: |
| 759 | all_the_tasks = query.filter(Task.job_id == job_id).all() |
| 760 | task_id_list = [task.id for task in all_the_tasks] |
| 761 | # Get all the instances created on the tasks. No user filter |
| 762 | instances_created = session.query(Instance).filter( |
| 763 | Instance.task_id.in_(task_id_list), |
| 764 | Instance.soft_delete == False |
| 765 | ).count() |
| 766 | if project_id: |
| 767 | # Get all the instances created on the tasks. No user filter |
| 768 | instances_created = session.query(Instance).filter( |
| 769 | Instance.project_id == project_id, |
| 770 | Instance.soft_delete == False |
| 771 | ).count() |
| 772 | |
| 773 | else: |
| 774 | # Get all the instances created by the given user |
| 775 | user = User.get_by_id(session, user_id = user_id) |
| 776 | if job_id: |
| 777 | all_the_tasks = query.filter(Task.job_id == job_id).all() |
| 778 | task_id_list = [task.id for task in all_the_tasks] |
| 779 | |
| 780 | instances_created = session.query(Instance).filter( |
| 781 | Instance.task_id.in_(task_id_list), |
| 782 | Instance.soft_delete == False, |
| 783 | Instance.member_created_id == user.member_id |
| 784 | ).count() |
| 785 | if project_id: |
| 786 | # Get all the instances created on the tasks. No user filter |
| 787 | instances_created = session.query(Instance).filter( |
| 788 | Instance.project_id == project_id, |
| 789 | Instance.soft_delete == False, |
| 790 | Instance.member_created_id == user.member_id |
| 791 | ).count() |
| 792 | |
| 793 | tasks_stats = { |
| 794 | "total": total, |
no test coverage detected