[viz] Add a timeline for assessment
authorVincent Michel <vincent.michel@logilab.fr>
Fri, 20 Sep 2013 12:13:25 +0000
changeset 388 b3dfaba082e0
parent 387 1fadd043e96c
child 392 9866372aed84
[viz] Add a timeline for assessment
__pkginfo__.py
entities.py
importers/random.py
views/primary.py
views/tabs.py
--- a/__pkginfo__.py	Fri Sep 20 12:06:51 2013 +0000
+++ b/__pkginfo__.py	Fri Sep 20 12:13:25 2013 +0000
@@ -24,7 +24,9 @@
                 'cubicweb-registration': None,
                 'cubicweb-jqplot': None,
                 }
-__recommends__ = {'cubicweb-brainoviz': None}
+__recommends__ = {'cubicweb-brainoviz': None,
+                  'cubicweb-vtimeline': None,
+                  }
 
 
 from os import listdir as _listdir
--- a/entities.py	Fri Sep 20 12:06:51 2013 +0000
+++ b/entities.py	Fri Sep 20 12:13:25 2013 +0000
@@ -38,3 +38,20 @@
     @property
     def full_filepath(self):
         return compute_fullfilepath(self)
+
+
+##############################################################################
+from cubicweb.view import EntityAdapter
+from cubicweb.predicates import is_instance
+
+class AssessmentICalendarableAdapter(EntityAdapter):
+    __regid__ = 'ICalendarable'
+    __select__ = EntityAdapter.__select__ & is_instance('Assessment')
+
+    @property
+    def start(self):
+        return self.entity.datetime
+
+    @property
+    def end(self):
+        return self.entity.datetime
--- a/importers/random.py	Fri Sep 20 12:06:51 2013 +0000
+++ b/importers/random.py	Fri Sep 20 12:13:25 2013 +0000
@@ -170,12 +170,12 @@
 ###############################################################################
 ### DATA GENERATION CONFIGURATION #############################################
 ###############################################################################
-NB_SUBJECTS = 2000
-NB_SUBJECTS_GROUPS = 4
+NB_SUBJECTS = 10000
+NB_SUBJECTS_GROUPS = 5
 AGE_DATETIMES = (datetime.strptime('1/1/1930 1:30 PM', '%m/%d/%Y %I:%M %p'),
                  datetime.strptime('1/1/1990 4:50 AM', '%m/%d/%Y %I:%M %p'))
 PROJECT_DATETIMES = (datetime.strptime('1/1/2010 1:30 PM', '%m/%d/%Y %I:%M %p'),
-                     datetime.strptime('1/1/2011 4:50 AM', '%m/%d/%Y %I:%M %p'))
+                     datetime.strptime('1/1/2013 4:50 AM', '%m/%d/%Y %I:%M %p'))
 SEX = {0: u'male', 1: u'female'}
 HANDEDNESS = {0: u'right', 1: u'left', 2: u'ambidextrous', 3: u'mixed'}
 
--- a/views/primary.py	Fri Sep 20 12:06:51 2013 +0000
+++ b/views/primary.py	Fri Sep 20 12:13:25 2013 +0000
@@ -275,6 +275,7 @@
         subject = u'<a href="%s">%s</a>' % (subject.absolute_url(), subject.dc_title())
         return [(self._cw._('Identifier'), entity.identifier),
                 (self._cw._('Protocol'), entity.protocol),
+                (self._cw._('Date'), entity.datetime),
                 (self._cw._('Subject'), subject),
                 (self._cw._('Study'), entity.related_study[0].view('outofcontext')),
                 (self._cw._('Center'), entity.reverse_holds[0].view('outofcontext')),
--- a/views/tabs.py	Fri Sep 20 12:06:51 2013 +0000
+++ b/views/tabs.py	Fri Sep 20 12:13:25 2013 +0000
@@ -111,6 +111,28 @@
 
 
 ###############################################################################
+### TABBLABLE COMPONENTS - TIMELINE ###########################################
+###############################################################################
+class BrainomicsTabblableTimeline(AbstractBrainomicsTabblable):
+    """ Component used to display a tab with wiki. """
+    __select__ = AbstractBrainomicsTabblable.__select__ & is_instance('Subject')
+    __regid__ = 'entity-timeline-tab'
+
+    def get_title(self):
+        return self._cw._('Timeline')
+
+    def render_content(self, w, **kwargs):
+        entity = self.cw_rset.get_entity(0, 0)
+        assessments_rset = self._cw.execute('Any X, D WHERE S concerned_by X, X datetime D, S eid %(eid)s',
+                                            {'eid': entity.eid})
+        if assessments_rset:
+            w(self._cw.view('vtimeline', rset=assessments_rset,
+                            custom_settings={'width': '90%'}))
+        else:
+            w(u'<div>%s</div>' % self._cw._('No assessments available'))
+
+
+###############################################################################
 ### TABBLABLE COMPONENTS - JQPLOT #############################################
 ###############################################################################
 class BrainomicsTabblableJqplotQuestion(AbstractBrainomicsTabblable):
@@ -213,3 +235,15 @@
             w(entity.view('slices-view'))
         else:
             w(u'<h4>%s</h4>' % self._cw._('The brainoviz cube is required'))
+
+
+###############################################################################
+### REGISTRATION CALLBACK #####################################################
+###############################################################################
+def registration_callback(vreg):
+    vreg.register_all(globals().values(), __name__, (BrainomicsTabblableTimeline,))
+    try:
+        from cubes.vtimeline import views
+        vreg.register(BrainomicsTabblableTimeline)
+    except ImportError:
+        pass