Beispiel #1
0
def category(request, name):
    from data_categories import CATEGORIES
    
    name = CATEGORY_NAME_PREFIX + name
    category = CATEGORIES.get(name)
    if not category:
        raise Http404
    #print category.get_absolute_url()
    
    parents = category.parents.order_by('display')
    children = category.children.order_by('display')
    try:
        changes = []
        annotations = []
        for chao in category.chao.all():
            for change in chao.changes.filter(Change.relevant_filter).order_by('-timestamp'):
                changes.append(change)
            for annotation in chao.annotations.filter(Annotation.relevant_filter).order_by('-created'):
                annotations.append(annotation)
        #print changes
        #print annotations
    except OntologyComponent.DoesNotExist:
        changes = annotations = []
    
    timeline_changes = get_weekly(changes, lambda c: c.timestamp.date() if c.timestamp else None, to_ordinal=True,
        min_date=MIN_CHANGES_DATE, max_date=MAX_CHANGES_DATE)
    timeline_annotations = get_weekly(annotations, lambda a: a.created.date() if a.created else None, to_ordinal=True,
        min_date=MIN_CHANGES_DATE, max_date=MAX_CHANGES_DATE)
    
    authors = counts(change.author_id for change in changes + annotations)
    authors = [{'label': name[len(settings.INSTANCE):], 'data': count} for name, count in sorted(authors.iteritems(),
        key=lambda (n, c): c, reverse=True)]
    
    #x, y = GRAPH_POSITIONS[settings.DEFAULT_LAYOUT][category.name]
    x, y = category.get_pos(settings.DEFAULT_LAYOUT)
    network_url = reverse('icd.views.network') + '#x=%f&y=%f&z=2' % (x, y)
    
    return render_to_response('category.html', {
        'category': category,
        'parents': parents,
        'children': children,
        'changes': changes,
        'annotations': annotations,
        'network_url': network_url,
        'timeline_changes': timeline_changes,
        'timeline_annotations': timeline_annotations,
        'authors': authors,
    }, context_instance=RequestContext(request))
Beispiel #2
0
def category(request, name):
    INSTANCE = get_instance(request)
    #from data_categories import CATEGORIES
    test = ""
    if name.startswith("http:/") and not name.startswith("http://"):
        test = "i do parse wrong"
        name = name.replace("http:/", "http://", 1)
    print name
    category = data_categories.CATEGORIES[INSTANCE].get(name)
    if not category:
        raise Http404
    #print category.get_absolute_url()
    
    parents = category.parents.order_by('display')
    children = category.children.order_by('display')
    try:
        changes = []
        annotations = []
        for chao in category.chao.all():
            for change in chao.changes.filter(relevant_filter(INSTANCE)).order_by('-timestamp'):
                changes.append(change)
            for annotation in chao.annotations.filter(Annotation.relevant_filter).order_by('-created'):
                annotations.append(annotation)
        #print changes
        #print annotations
    except OntologyComponent.DoesNotExist:
        changes = annotations = []
    
    tag_activity = [{'label': 'Primary Community Changes', 'data': category.metrics.primary_tag_changes}, 
                    {'label': 'Secondary Community Changes', 'data': category.metrics.secondary_tag_changes}, 
                    {'label': 'Involved Community Changes', 'data': category.metrics.involved_tag_changes}, 
                    {'label': 'WHO Team Community Changes', 'data': category.metrics.who_tag_changes},
                    {'label': 'Outside Community Changes', 'data': category.metrics.outside_tag_changes}]
    
    
    timeline_changes = get_weekly(changes, lambda c: c.timestamp.date() if c.timestamp else None, to_ordinal=True,
        min_date=data.MIN_CHANGES_DATE[INSTANCE], max_date=data.MAX_CHANGES_DATE[INSTANCE])
    timeline_annotations = get_weekly(annotations, lambda a: a.created.date() if a.created else None, to_ordinal=True,
        min_date=data.MIN_CHANGES_DATE[INSTANCE], max_date=data.MAX_CHANGES_DATE[INSTANCE])
    
    authors = counts(change.author_id for change in changes + annotations)
    authors = [{'label': name[len(INSTANCE):], 'data': count} for name, count in sorted(authors.iteritems(),
        key=lambda (n, c): c, reverse=True)]
    
    titles = category.category_titles.all()
    definitions = category.category_definitions.all()
    involved_tags = category.involved_tags.all()
    
    #x, y = GRAPH_POSITIONS[settings.DEFAULT_LAYOUT][category.name]
    x, y = category.get_pos(settings.DEFAULT_LAYOUT)
    network_url = reverse('icd.views.network') + '#x=%f&y=%f&z=2' % (x, y)
    #reCoIndations = [x.reCoInd for x in category.similarity_reCoIndations.all().order_by("-tag_similarity")[:10]]
    #coeditor_reCoIndations = [x.reCoInd for x in category.amazon_reCoIndations.all().order_by("-tag_similarity")]
    return render_to_response('category.html', {
        'instance': INSTANCE,
        #'instances': settings.INSTANCES,
        'name': name,
        'test': test,
        'category': category,
        'parents': parents,
        'children': children,
        'changes': changes,
        'annotations': annotations,
        'network_url': network_url,
        'timeline_changes': timeline_changes,
        'timeline_annotations': timeline_annotations,
        'authors': authors,
        'titles': titles,
        'tag_activity': tag_activity,
        #'reCoIndations': reCoIndations,
        'definitions': definitions,
        'involved_tags': involved_tags,
        #'coeditor_reCoIndations': coeditor_reCoIndations,
    }, context_instance=RequestContext(request))