Example #1
0
 def test_add_task_concept(self):
     self.assertTrue(
         self.client.login(username=self.user.username,
                           password=self.password))
     task = Task()
     concept = Concept()
     contrast = Contrast()
     tsk = task.create('test_add_task_concept', {'prop': 'prop'})
     con = concept.create('test_add_task_concept', {'prop': 'prop'})
     cont = contrast.create('test_add_task_concept', {'prop': 'prop'})
     concept.link(con.properties['id'],
                  cont.properties['id'],
                  "HASCONTRAST",
                  endnode_type='contrast')
     response = self.client.post(
         reverse('add_task_concept', kwargs={'uid': tsk.properties['id']}),
         {'concept_selection': con.properties['id']})
     self.assertEqual(response.status_code, 200)
     response = self.client.get(
         reverse('task', kwargs={'uid': tsk.properties['id']}))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.context['task']['relations']['ASSERTS']),
                      1)
     self.assertEqual(
         response.context['task']['relations']['ASSERTS'][0]['id'],
         con.properties['id'])
     tsk.delete_related()
     con.delete_related()
     tsk.delete()
     con.delete()
     cont.delete()
Example #2
0
 def test_contrast_get_conditions(self):
     contrast = Contrast()
     conditions = contrast.get_conditions(self.cont.properties['id'])
     self.assertEqual(len(conditions), 1)
     self.assertEqual(
         conditions[0]['condition_id'],
         self.cond.properties['id'])
Example #3
0
 def setUp(self):
     self.task = Task()
     self.node_name = "test_name"
     self.node_properties = {'test_key': 'test_value'}
     self.graph = Graph("http://graphdb:7474/db/data/")
     self.task1 = self.task.create(
         name=self.node_name,
         properties=self.node_properties)
     self.task2 = self.task.create(
         name=self.node_name,
         properties=self.node_properties)
     condition = Condition()
     self.cond = condition.create(
         name=self.node_name,
         properties=self.node_properties)
     contrast = Contrast()
     self.cont = contrast.create(
         name=self.node_name,
         properties=self.node_properties)
     concept = Concept()
     self.con = concept.create(
         name=self.node_name,
         properties=self.node_properties)
     self.task.link(
         self.task1.properties['id'],
         self.cond.properties['id'],
         "HASCONDITION",
         endnode_type='condition')
     self.task.link(
         self.task1.properties['id'],
         self.con.properties['id'],
         "ASSERTS",
         endnode_type='concept')
     condition.link(
         self.cond.properties['id'],
         self.cont.properties['id'],
         "HASCONTRAST",
         endnode_type='contrast')
     concept.link(
         self.con.properties['id'],
         self.cont.properties['id'],
         "MEASUREDBY",
         endnode_type='contrast')
Example #4
0
 def test_contrast_get_tasks(self):
     contrast = Contrast()
     tasks = contrast.get_tasks(self.cont.properties['id'])
     self.assertEqual(len(tasks), 1)
     self.assertEqual(tasks[0]['task_id'], self.task1.properties['id'])
Example #5
0
 def test_contrast_get_concepts(self):
     contrast = Contrast()
     concepts = contrast.get_concepts(self.cont.properties['id'])
     self.assertEqual(len(concepts), 1)
     self.assertEqual(concepts[0]['concept_id'], self.con.properties['id'])
Example #6
0
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.template import loader, Context

from cognitive.apps.atlas.query import Concept, Condition, Contrast, Task
from cognitive.apps.atlas.utils import merge_cypher

Task = Task()
Concept = Concept()
Condition = Condition()
Contrast = Contrast()

# Return full graph visualizations


def graph_view(request, label, uid):
    query = "MATCH (n:{}) where n.id = '{}' OPTIONAL MATCH (n)-[]-(r) return n, r"
    query = query.format(label, uid)
    return render(request, "graph/graph.html", {'query': query})


def task_graph(request, uid):
    nodes = Task.get_graph(uid)
    context = {"graph": nodes}
    return render(request, "graph/task.html", context)


def concept_graph(request, uid):
    nodes = Concept.get_graph(uid)
    context = {"graph": nodes}
    return render(request, "graph/task.html", context)