Skip to content

Commit

Permalink
Merge pull request #86 from kirstenwinther/master
Browse files Browse the repository at this point in the history
Log file interface
  • Loading branch information
kirstenwinther authored Jan 11, 2019
2 parents 39d1830 + c886a5c commit 2e1f0de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
11 changes: 10 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -250,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"):
Expand Down Expand Up @@ -613,8 +620,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
])
24 changes: 22 additions & 2 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,6 +97,20 @@ 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(sqlalchemy.String, )

@hybrid_property
def _logtext(self):
return bytes(self.logfile).decode('utf-8')


class Reaction(Base):
__tablename__ = 'reaction'
Expand Down Expand Up @@ -222,6 +236,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",
Expand Down Expand Up @@ -393,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']
Expand Down

0 comments on commit 2e1f0de

Please sign in to comment.