Skip to content

Commit

Permalink
Merge pull request #139 from the-virtual-brain/TVB-2689
Browse files Browse the repository at this point in the history
TVB-2689: add summary_info to DataType indexes
  • Loading branch information
liadomide committed May 8, 2020
2 parents b18b41a + f400337 commit 5b158ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions framework_tvb/tvb/core/entities/model/model_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
.. moduleauthor:: Yann Gordon <yann@tvb.invalid>
"""
import json
import typing
from datetime import datetime
from copy import copy
from sqlalchemy.orm import relationship, backref
Expand Down Expand Up @@ -112,6 +113,38 @@ class DataType(HasTraitsIndex):
fk_from_operation = Column(Integer, ForeignKey('OPERATIONS.id', ondelete="CASCADE"))
parent_operation = relationship(Operation, backref=backref("DATA_TYPES", order_by=id, cascade="all,delete"))

@property
def summary_info(self):
# type: () -> typing.Dict[str, str]

ret = {}
if self.title:
ret['Title'] = str(self.title)

columns = self._get_table_columns()
for attr_name in columns:
try:
if attr_name.startswith("fk_") or "id" == attr_name:
continue
name = attr_name.title().replace("_", " ")
attr_value = getattr(self, attr_name)
ret[name] = str(attr_value)
except Exception:
pass
return ret

def _get_table_columns(self):
columns = self.__table__.columns.keys()
if type(self).__bases__[0] is DataType:
return columns
# Consider the immediate superclass only, as for now we have
# - most of *Index classes directly inheriting from DataType
# - except the ones with one intermediate: DataTypeMatrix or TimeSeriesIndex
base_table_columns = type(self).__bases__[0].__table__.columns.keys()
columns.extend(base_table_columns)
return columns


def __init__(self, gid=None, **kwargs):

# if gid is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,4 @@ def fill_from_datatype(self, datatype_result, parent_burst):

### Populate Scientific attributes
if hasattr(datatype_result, 'summary_info') and datatype_result.summary_info is not None:
self.add_scientific_fields(datatype_result.summary_info)
self.add_scientific_fields(datatype_result.summary_info)

0 comments on commit 5b158ce

Please sign in to comment.