Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max mohammadi #68

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Entity/RPILogs.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 41 additions & 1 deletion database_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from Entity.Clubs import Clubs
from Entity.Sections import Sections, SectionType

Expand Down Expand Up @@ -274,6 +275,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)
Expand Down Expand Up @@ -343,6 +345,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)
Expand Down Expand Up @@ -746,7 +749,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
Expand Down Expand Up @@ -789,6 +792,43 @@ 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
"""

# TODO: Add a "tag"
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)

Expand Down