From 1bd705860add20da992f1ac648f235f82cce8cd6 Mon Sep 17 00:00:00 2001 From: Kirsten Winther Date: Fri, 11 Jan 2019 09:46:21 -0800 Subject: [PATCH 1/3] log interface --- api.py | 10 +++++++++- models.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/api.py b/api.py index 2a81edb3..7851fc5a 100644 --- a/api.py +++ b/api.py @@ -240,6 +240,12 @@ class Meta: # name = graphene.InputField() # systems = graphene.List('api.Systems') +class Log(CustomSQLAlchemyObjectType): + + class Meta: + model = models.Log + interfaces = (graphene.relay.Node, ) + class System(CustomSQLAlchemyObjectType): @@ -613,8 +619,10 @@ class Query(graphene.ObjectType): ReactionSystem, **get_filter_fields(models.ReactionSystem)) publications = FilteringConnectionField( Publication, **get_filter_fields(models.Publication)) + logs = FilteringConnectionField( + Log, **get_filter_fields(models.Log)) schema = graphene.Schema( - query=Query, types=[System, Species, TextKeyValue, NumberKeyValue, Key, Reaction, ReactionSystem, Publication + query=Query, types=[System, Species, TextKeyValue, NumberKeyValue, Key, Reaction, ReactionSystem, Publication, Log ]) diff --git a/models.py b/models.py index c63f6a40..6c21e1ff 100644 --- a/models.py +++ b/models.py @@ -5,7 +5,7 @@ import sqlalchemy.types import sqlalchemy.ext.declarative from sqlalchemy import or_ -from sqlalchemy.dialects.postgresql import JSONB, TSVECTOR +from sqlalchemy.dialects.postgresql import JSONB, TSVECTOR, BYTEA from sqlalchemy import String, Float, Integer from sqlalchemy.types import ARRAY from sqlalchemy.ext.associationproxy import association_proxy @@ -97,6 +97,16 @@ class ReactionSystem(Base): id = sqlalchemy.Column(sqlalchemy.Integer, sqlalchemy.ForeignKey('{}.reaction.id'.format(SCHEMA)), primary_key=True) + +class Log(Base): + __tablename__ = 'log' + __table_args__ = ({'schema': SCHEMA}) + + ase_id = sqlalchemy.Column(sqlalchemy.String, + sqlalchemy.ForeignKey('{}.systems.unique_id'.format(SCHEMA)), + primary_key=True) + logfile = sqlalchemy.Column(BYTEA, ) + class Reaction(Base): __tablename__ = 'reaction' @@ -222,6 +232,11 @@ class System(Base): backref="systems", uselist=True) + log = sqlalchemy.orm.relationship( + "Log", + backref="systems", + uselist=True) + #reaction = sqlalchemy.orm.relationship("ReactionSystems", backref='systems', uselist=True) publication = sqlalchemy.orm.relationship("Publication", From 1e90ea29c4f13bc9ebe73f4f840108e21ac445da Mon Sep 17 00:00:00 2001 From: Kirsten Winther Date: Fri, 11 Jan 2019 11:12:46 -0800 Subject: [PATCH 2/3] decoded Logtext --- models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/models.py b/models.py index 6c21e1ff..bfc51552 100644 --- a/models.py +++ b/models.py @@ -105,7 +105,11 @@ class Log(Base): ase_id = sqlalchemy.Column(sqlalchemy.String, sqlalchemy.ForeignKey('{}.systems.unique_id'.format(SCHEMA)), primary_key=True) - logfile = sqlalchemy.Column(BYTEA, ) + logfile = sqlalchemy.Column(sqlalchemy.String, ) + + @hybrid_property + def _logtext(self): + return bytes(self.logfile).decode('utf-8') class Reaction(Base): @@ -408,7 +412,8 @@ def hybrid_prop_parameters(key): 'Ctime': ['id', 'ctime'], 'Mtime': ['id', 'mtime'], 'Pbc': ['id', 'pbc'], - 'Trajdata': ['all']} + 'Trajdata': ['all'], + 'Logtext': ['logfile']} if key not in h_parameters: return ['id', 'key_value_pairs'] From c886a5c5ddd9d94ce3342cfccfef3248c64bab80 Mon Sep 17 00:00:00 2001 From: Kirsten Winther Date: Fri, 11 Jan 2019 11:22:00 -0800 Subject: [PATCH 3/3] log list under systems --- api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/api.py b/api.py index 7851fc5a..0739896c 100644 --- a/api.py +++ b/api.py @@ -256,6 +256,7 @@ class Meta: interfaces = (graphene.relay.Node, ) publication = graphene.List('api.Publication') + log = graphene.List('api.Log') @staticmethod def resolve__input_file(self, info, format="py"):