In [25]:
from django.db.models import Count
from django.db.models import Q
In [26]:
## total batch
Batch.objects.all().count()
Out[26]:
In [27]:
## total images
Image.objects.all().count()
Out[27]:
In [28]:
## count images that has any label
Image.objects.annotate(label_count=Count('label')).filter(label_count__gt=0).count()
Out[28]:
In [29]:
## total images labelled by "labeller1"
Image.objects.annotate( label_count=Count('label', distinct=True) )\
.filter(
Q(label_count__gt=0) &
Q(batch__labeller__user__username="labeller1")
).count()
Out[29]:
In [57]:
# list of total images labelled by all user
msg=""
for u in MyUser.objects.all().order_by('user__username'):
n=Image.objects.annotate( label_count=Count('label', distinct=True) )\
.filter(
Q(label_count__gt=0) &
Q(batch__labeller__user__username=u.user.username)
).count()
m=Image.objects.annotate( label_count=Count('label', distinct=True) )\
.filter(
Q(label_count__gt=0) &
Q(batch__labeller__user__username=u.user.username)
).count()
msg+= "%15s: labelled %05d, reviewed %05d\n"%(u,n,m)
print msg
In [61]:
# list of total images labelled by all user
msg=""
for u in MyUser.objects.all().order_by('user__username'):
n=Image.objects.annotate( label_count=Count('label', distinct=True) )\
.filter(
Q(label_count__gt=0) &
Q(batch__labeller__user__username=u.user.username)
).count()
m=Image.objects.annotate( label_count=Count('label', distinct=True) )\
.filter(
Q(label_count__gt=0) &
Q(batch__labeller__user__username=u.user.username)
).count()
msg+= "+%15s labelled: %5d, reviewed: %5d\n"%(u,n,m)
print msg
In [6]:
for i in Image.objects.annotate(label_count=Count('label')).filter(Q(label_count__gt=0)&Q(batch__labeller__isnull=False)):
print "%s did %s label(s) on %s"%(i.batch.labeller, i.label_count, i.raw_path)
In [7]:
Image.objects.annotate(label_count=Count('label', distinct=True))\
.filter(Q(label_count__gt=0)&Q(batch__labeller__isnull=False))\
.values("batch__labeller").annotate(job_count=Count('batch__labeller', distinct=True))
Out[7]:
In [8]:
Batch.objects.all().values('labeller').annotate(total=Count('labeller')).order_by('total')
Out[8]:
In [14]:
for i in MyUser.objects.annotate(review_done_count=Count('reviewer_batch')):
print "%s reviewed %s batches"%(i,i.review_done_count)
In [16]:
for i in MyUser.objects.annotate(review_done_count=Count('labeller_batch')):
print "%s reviewed %s batches"%(i,i.review_done_count)
In [30]:
for i in MyUser.objects.annotate(x=Count('labeller_batch__image')):
print "%s, %s"%(i,i.x)
In [40]:
MyUser.comment_set
Out[40]:
In [41]:
Out[41]:
In [ ]: