summaryrefslogtreecommitdiff
path: root/linaro_metrics/teamcredit.py
blob: a8f5c8b3da64fb1429b2fc2ca65cfd8ca1731be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import datetime
from linaro_metrics.models import Team, TeamMembership, TeamCredit
from patchwork.models import Patch
from bin import django_setup
import logging
import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
django_setup()  # must be called to get sys.path and django settings in place

dateb = datetime.datetime.now() - datetime.timedelta(days=180)

log = logging.getLogger('teamcredit')

"""
This is a thrown together script to fix the teamcredit statistics. It should
not often be needed, but at times a ldap team can change and the team lead
forgets to inform patches of this change. Hence the teamcredit will go out of
sync.

The script runs in a default of 180 days.

"""

team = 'team-ldcg'
t = Team.objects.get(name=team)
tm = TeamMembership.objects.filter(team=t)

for p in tm:
    logging.info("#### %s %s", p.user, p.id)
    # get all patches to that user
    patchu = Patch.objects.filter(submitter__user=p.user)
    for pa in patchu:
        if dateb < pa.date:
            tcs = TeamCredit.objects.filter(patch=pa)
            if not tcs:
                logging.info("No Patch: %s, %s", pa, tcs)
                new_values = {
                    'patch': pa, 'team': t, 'last_state_change': pa.date
                }
                tcs = TeamCredit(**new_values)
                tcs.save()
            else:
                tcsno = TeamCredit.objects.filter(patch=pa,
                                                  team__name='no-team'
                                                  )
                if tcsno:
                    logging.info("No Credit: %s, %s", tcsno, pa.date)
                    TeamCredit.objects.filter(patch=pa).update(team=t)