Inherit from AWARESensor correctly.

Two additional tests to check getting a participant and some data.
communication
junos 2020-12-31 14:29:35 +01:00
parent 30bae2c1f9
commit f542a37955
4 changed files with 30 additions and 9 deletions

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (straw2analysis)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (straw2analysis)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="false" />
</component>
</project> </project>

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/config/.ipynb_checkpoints" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (straw2analysis)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.9 (straw2analysis)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>

View File

@ -37,27 +37,27 @@ class Participant(Base):
return '<Participant {}>'.format(self.username) return '<Participant {}>'.format(self.username)
class AWAREsensor(Base): class AWAREsensor(object):
id = Column(BigInteger, primary_key=True, nullable=False) id = Column(BigInteger, primary_key=True, nullable=False)
_id = Column(BigInteger, nullable=False) _id = Column(BigInteger, nullable=False)
timestamp = Column(BigInteger, nullable=False) timestamp = Column(BigInteger, nullable=False)
device_id = Column(String(length=36), nullable=False) device_id = Column(String(length=36), nullable=False)
@declared_attr @declared_attr
def __tablename__(cls): def __tablename__(self):
return cls.__name__.lower() return self.__name__.lower()
@declared_attr @declared_attr
def participant_id(cls): def participant_id(self):
return Column(Integer, ForeignKey('participants.id'), nullable=False, index=True) return Column(Integer, ForeignKey('participants.id'), nullable=False, index=True)
@declared_attr @declared_attr
def participants(cls): def participant(self):
return relationship('Participant', lazy="select", backref=cls.__tablename__) return relationship('Participant', lazy="select", backref=self.__tablename__)
@declared_attr @declared_attr
def __table_args__(cls): def __table_args__(self):
return UniqueConstraint('device_id', '_id', name=cls.__tablename__ + "_twice"), return UniqueConstraint('device_id', '_id', name=self.__tablename__ + "_twice"),
# I think it makes more sense to create a Constraint on device_id and _id rather than relate it to participant_id. # I think it makes more sense to create a Constraint on device_id and _id rather than relate it to participant_id.
# _id is a primary key, auto incremented by AWARE. # _id is a primary key, auto incremented by AWARE.
# However, I would expect it to reset back to 1 if the application was reinstalled, # However, I would expect it to reset back to 1 if the application was reinstalled,
@ -145,6 +145,7 @@ class ESM(Base, AWAREsensor):
class Imperfection(Base): class Imperfection(Base):
__tablename__ = "imperfection"
id = Column(BigInteger, primary_key=True, nullable=False) id = Column(BigInteger, primary_key=True, nullable=False)
timestamp = Column(BigInteger, nullable=False) timestamp = Column(BigInteger, nullable=False)
error = Column(String) error = Column(String)

View File

@ -1,18 +1,33 @@
import unittest import unittest
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from config.models import Participant, LightSensor
from setup import db_uri from setup import db_uri
class DatabaseConnection(unittest.TestCase): class DatabaseConnection(unittest.TestCase):
def setUp(self): def setUp(self):
self.engine = create_engine(db_uri, echo=True) self.engine = create_engine(db_uri, echo=True)
Session = sessionmaker(bind=self.engine)
self.session = Session()
def tearDown(self): def tearDown(self):
self.engine.dispose() self.engine.dispose()
self.session.close()
def test_connection(self): def test_connection(self):
with self.engine.connect() as connection: with self.engine.connect() as connection:
self.assertIsNotNone(connection) self.assertIsNotNone(connection)
connection.close() connection.close()
def test_get_participant(self):
self.participant_0 = self.session.query(Participant).first()
self.assertIsNotNone(self.participant_0)
print(self.participant_0)
def test_get_light_data(self):
light_0 = self.session.query(Participant).join(LightSensor).first()
self.assertIsNotNone(light_0)
print(light_0)