1 from django.core.management.base import BaseCommand |
1 from django.core.management.base import BaseCommand |
2 from ldt.ldt_utils.models import Content |
2 from ldt.ldt_utils.models import Content, Project |
3 from ldt.ldt_utils.stat import update_stat_content |
3 from ldt.ldt_utils.stat import update_stat_content, update_stat_project |
4 from optparse import make_option |
|
5 |
4 |
6 class Command(BaseCommand): |
5 class Command(BaseCommand): |
7 help = 'Computes annotation volume for a given content' |
6 help = 'Computes annotation for all contents and all projects' |
8 |
7 |
9 option_list = BaseCommand.option_list + ( |
|
10 make_option("-c", "--content", |
|
11 dest="content", |
|
12 action="store", |
|
13 help="The id of the content we want to compute annotation volume on"), |
|
14 ) |
|
15 |
8 |
16 def handle(self, *args, **options): |
9 def handle(self, *args, **options): |
17 parser = self.create_parser("statannotation", "") |
|
18 options, args = parser.parse_args() |
|
19 |
|
20 verbose = (options.verbosity == "2") |
|
21 |
10 |
22 id_content = options.content |
11 for proj in Project.objects.all(): |
23 if id_content: |
12 print "Stat for project %s" % proj |
24 contents = Content.objects.filter(iri_id=id_content) |
13 update_stat_project(proj) |
25 if not len(contents): |
|
26 print "No content found with iri_id %s" % id_content |
|
27 return None |
|
28 else: |
|
29 contents = Content.objects.all() |
|
30 print "analysing all contents" |
|
31 |
14 |
32 |
15 # Sets fields nb_annotation and stat_annotation to 0 and 0,0,...,0 |
33 for content in contents: |
16 # for contents that do not have annotations |
34 update_stat_content(content) |
17 for content in Content.objects.all(): |
|
18 if not content.stat_annotation: |
|
19 print "Stat for content %s" % content |
|
20 update_stat_content(content) |
35 |
21 |
36 return None |
22 return None |
37 |
23 |