Changeset fb1c047 for asadb/groups


Ignore:
Timestamp:
Jan 22, 2012, 12:16:44 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage
Children:
5e2645b
Parents:
7ef7143
git-author:
Alex Dehnert <adehnert@…> (01/22/12 12:16:44)
git-committer:
Alex Dehnert <adehnert@…> (01/22/12 12:16:44)
Message:

Gather statistics on return codes

Location:
asadb/groups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/gather_constitutions.py

    r7ef7143 rfb1c047  
    99    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    1010
     11import collections
    1112import datetime
    1213import subprocess
     
    4950    subprocess.check_call(['git', 'commit', '--allow-empty', '-a', '-m', msg, ], cwd=git_dir, )
    5051
     52def webstat():
     53    constitutions = groups.models.GroupConstitution.objects.all()
     54    codes = collections.defaultdict(list)
     55    count = 0
     56    for const in constitutions:
     57        if count % 10 == 0: print count,
     58        code = const.webstat()
     59        codes[code].append(const)
     60        count += 1
     61    for code, gs in codes.items():
     62        print "\nCode: %s (count: %d)" % (code, len(gs), )
     63        for const in gs:
     64            print const.group
     65    for code, gs in codes.items():
     66        print "\nCode: %s (count: %d)" % (code, len(gs), )
     67        for const in gs:
     68            print const.source_url
     69    print "\n\n"
     70    for code, gs in codes.items():
     71        print "%4d\t%s" % (len(gs), code, )
     72
    5173if __name__ == '__main__':
    52     additions, changed = gather_constitutions()
    53     update_repo(additions, changed)
     74    if len(sys.argv) == 1 or sys.argv[1] == "gather":
     75        additions, changed = gather_constitutions()
     76        update_repo(additions, changed)
     77    elif sys.argv[1] == "webstat":
     78        webstat()
     79    else:
     80        raise NotImplementedError
  • asadb/groups/models.py

    r7ef7143 rfb1c047  
    201201        return path
    202202
     203    def webstat(self, ):
     204        url = self.source_url
     205        if url:
     206            try:
     207                stream = urllib.urlopen(self.source_url)
     208                return stream.getcode()
     209            except:
     210                return "IOError"
     211        else:
     212            return "no-url"
     213
    203214reversion.register(GroupConstitution)
    204215
Note: See TracChangeset for help on using the changeset viewer.