Inherit from AWARESensor correctly.
Two additional tests to check getting a participant and some data.communication
parent
30bae2c1f9
commit
f542a37955
|
@ -1,4 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<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>
|
|
@ -1,7 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<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="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
|
|
|
@ -37,27 +37,27 @@ class Participant(Base):
|
|||
return '<Participant {}>'.format(self.username)
|
||||
|
||||
|
||||
class AWAREsensor(Base):
|
||||
class AWAREsensor(object):
|
||||
id = Column(BigInteger, primary_key=True, nullable=False)
|
||||
_id = Column(BigInteger, nullable=False)
|
||||
timestamp = Column(BigInteger, nullable=False)
|
||||
device_id = Column(String(length=36), nullable=False)
|
||||
|
||||
@declared_attr
|
||||
def __tablename__(cls):
|
||||
return cls.__name__.lower()
|
||||
def __tablename__(self):
|
||||
return self.__name__.lower()
|
||||
|
||||
@declared_attr
|
||||
def participant_id(cls):
|
||||
def participant_id(self):
|
||||
return Column(Integer, ForeignKey('participants.id'), nullable=False, index=True)
|
||||
|
||||
@declared_attr
|
||||
def participants(cls):
|
||||
return relationship('Participant', lazy="select", backref=cls.__tablename__)
|
||||
def participant(self):
|
||||
return relationship('Participant', lazy="select", backref=self.__tablename__)
|
||||
|
||||
@declared_attr
|
||||
def __table_args__(cls):
|
||||
return UniqueConstraint('device_id', '_id', name=cls.__tablename__ + "_twice"),
|
||||
def __table_args__(self):
|
||||
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.
|
||||
# _id is a primary key, auto incremented by AWARE.
|
||||
# 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):
|
||||
__tablename__ = "imperfection"
|
||||
id = Column(BigInteger, primary_key=True, nullable=False)
|
||||
timestamp = Column(BigInteger, nullable=False)
|
||||
error = Column(String)
|
||||
|
|
|
@ -1,18 +1,33 @@
|
|||
import unittest
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from config.models import Participant, LightSensor
|
||||
from setup import db_uri
|
||||
|
||||
|
||||
class DatabaseConnection(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.engine = create_engine(db_uri, echo=True)
|
||||
Session = sessionmaker(bind=self.engine)
|
||||
self.session = Session()
|
||||
|
||||
def tearDown(self):
|
||||
self.engine.dispose()
|
||||
self.session.close()
|
||||
|
||||
def test_connection(self):
|
||||
with self.engine.connect() as connection:
|
||||
self.assertIsNotNone(connection)
|
||||
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)
|
Loading…
Reference in New Issue