def get_session(self, user_key: str, session_key: str) -> Session: # Sets up a document reference to a specified session. ref = db.document(f'users/{user_key}/sessions/{session_key}') # Converts the entries stored within the referenced document # into a dictionary. session_dict: dict = ref.get().to_dict() # Builds up a reference to the performance document of a # specified session. ref = db.document( f'users/{user_key}/sessions/{session_key}/data/performance') # Adds the performance entries to the session dictionary, # enabling the convertion from a dictionary to a Session # object. performance: Performance = Performance.from_dict(ref.get().to_dict()) # Creates a session which is based on the entries within the # previously updated dictionary. session: Session = Session.from_dict(session_dict, performance) # Return the newly created session. return session
def test_from_dict(self): # Should create a new Performance object result: Performance = Performance.from_dict( Samples.sample_performance_dict) # Expected Result expected_result: Performance = Samples.sample_performance # self.assertEqual(result.to_dict(), expected_result.to_dict())
def get_average_performance(self, user_key: str) -> Performance: # Creates a reference to the 'performance' Firestore document. ref = db.document(f'users/{user_key}/properties/average_performance') # Stores all datapoints stored at the document # to a dictionary. dict = ref.get().to_dict() # Returns a Performance object created from the # values stored in the dictionary. return Performance.from_dict(dict)