From 6c198557c16fa8b4c0ed6d8a0eacd625f3c26d78 Mon Sep 17 00:00:00 2001 From: darkwizard5 <36392311+darkwizard5@users.noreply.github.com> Date: Tue, 25 Feb 2020 13:23:25 -0800 Subject: [PATCH 1/4] Add MaxMohammadi to contributors list --- Entity/RPILogs.py | 22 ++++++++++++++++++++++ database_wrapper.py | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Entity/RPILogs.py diff --git a/Entity/RPILogs.py b/Entity/RPILogs.py new file mode 100644 index 0000000..c2b9228 --- /dev/null +++ b/Entity/RPILogs.py @@ -0,0 +1,22 @@ +from sqlalchemy import Column, Integer, Text, Enum, Boolean +from sqlalchemy.ext.declarative import declarative_base +import enum + +# This is the way SQLAlchemy initializes their special classes +Base = declarative_base() + + +class RPILogs(Base): + __tablename__ = "RPILogs" + id = Column(Integer, primary_key=True) + normalized_question = Column(String(255)) + entity = Column(String(225)) + input_question = Column(String(225)) + prediction = Column(String(225)) + + +class RPILogsProperties(enum.Enum): + normalized_question = RPILogs.normalized_question + entity = RPILogs.entity + input_question = RPILogs.input_question + prediction = RPILogs.prediction diff --git a/database_wrapper.py b/database_wrapper.py index 250ef41..4311319 100755 --- a/database_wrapper.py +++ b/database_wrapper.py @@ -23,6 +23,7 @@ from Entity.Locations import Locations from Entity.QuestionAnswerPair import QuestionAnswerPair from Entity.Professors import Professors, ProfessorsProperties +from Entity.RPILogs import RPILogs, RPILogsProperties UNION_ENTITIES = Union[ @@ -138,7 +139,7 @@ def get_property_from_entity( condition_field: (optional) string representing the column name. condition_value: (optional) string representing the cell value. - Returns: + Returns: adam is coos The list of prop of the entity (e.g. firstName of Professor) """ pass @@ -270,6 +271,7 @@ def __init__(self, config_file: str = "config.json") -> None: self.AudioSampleMetaData = AudioSampleMetaData self.Locations = Locations self.QuestionAnswerPair = QuestionAnswerPair + self.RPILogs = RPILogs with open(config_file) as json_data_file: config = json.load(json_data_file) @@ -337,6 +339,7 @@ def __safe_create(SQLAlchemy_object): __safe_create(self.AudioSampleMetaData) __safe_create(self.Locations) __safe_create(self.QuestionAnswerPair) + __safe_create(self.RPILogs) def _create_database_session(self): Session = sessionmaker(bind=self.engine) @@ -689,6 +692,42 @@ def save_faculty(self, professor: dict) -> bool: self.session.commit() return True + def save_rpi_logs(self, rpi_logs: dict) -> bool: + """ + Save the given Rasperry PI logs into the database" + + Example input: + { + "normalized_question": "Where is [PROF]'s office?", + "entity": "Khosmood", + "input_question": "Where is Khosmood's office?", + "prediction": "Where is the office of [PROF]?" + } + + Args: + rpi_logs: a dictionary that corresponds to the fields in RPILogs + + Raises: + BadDictionaryKeyError - ... + BadDictionaryValueError - ... + + Returns: + True if all is good, else False + """ + + rpi_data = RPILogs() + rpi_data.id = rpi_logs["id"] + rpi_data.normalized_question = rpi_logs["normalized_question"] + rpi_data.entity = rpi_logs["entity"] + rpi_data.input_question = rpi_logs["input_question"] + rpi_data.prediction = rpi_logs["prediction"] + + # insert this new rpi_data object into the RPILogs table + self.session.add(rpi_data) + self.session.commit() + return True + + def _execute(self, query: str): return self.engine.execute(query) From 04712b10c5e1aff129abad5fda01b99de25a92ae Mon Sep 17 00:00:00 2001 From: darkwizard5 <36392311+darkwizard5@users.noreply.github.com> Date: Tue, 25 Feb 2020 13:26:13 -0800 Subject: [PATCH 2/4] Added SQLAlchemy RPILogs object to database --- database_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database_wrapper.py b/database_wrapper.py index 4311319..fcdea37 100755 --- a/database_wrapper.py +++ b/database_wrapper.py @@ -649,7 +649,7 @@ def save_calendar(self, calendar_data: dict): calendar.month = calendar_data["month"] calendar.year = calendar_data["year"] calendar.raw_events_text = calendar_data["raw_events_text"] - + self.session.add(calendar) self.session.commit() return True From 70a05988bd804a0d430edcd92a807241f3fb763b Mon Sep 17 00:00:00 2001 From: darkwizard5 <36392311+darkwizard5@users.noreply.github.com> Date: Tue, 25 Feb 2020 13:29:48 -0800 Subject: [PATCH 3/4] Added SQLAlchemy RPILogs object to database --- database_wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database_wrapper.py b/database_wrapper.py index fcdea37..57e49ed 100755 --- a/database_wrapper.py +++ b/database_wrapper.py @@ -139,7 +139,7 @@ def get_property_from_entity( condition_field: (optional) string representing the column name. condition_value: (optional) string representing the cell value. - Returns: adam is coos + Returns: The list of prop of the entity (e.g. firstName of Professor) """ pass From a3c29bc5f4fdb70236ce2bf098fb20a14b8c1b7d Mon Sep 17 00:00:00 2001 From: darkwizard5 <36392311+darkwizard5@users.noreply.github.com> Date: Fri, 28 Feb 2020 21:29:19 -0800 Subject: [PATCH 4/4] Added a TODO --- database_wrapper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/database_wrapper.py b/database_wrapper.py index 1f33835..abe3743 100755 --- a/database_wrapper.py +++ b/database_wrapper.py @@ -815,6 +815,7 @@ def save_rpi_logs(self, rpi_logs: dict) -> bool: True if all is good, else False """ + # TODO: Add a "tag" rpi_data = RPILogs() rpi_data.id = rpi_logs["id"] rpi_data.normalized_question = rpi_logs["normalized_question"]