def generate_session(self, user_key: str, level: Level, difficulty_score: float) -> str: # Variable intended to store the key # that will be created within the function. session_id: int = 0 # Fetches the ids of all previously played sessions. session_ids: [int] = self.get_session_ids(user_key) # Checks whether at least a single session has been # stored before for a given user. if len(session_ids) > 0: # Sets the id for the session that should be # created next to one higher than previous # session id. session_id = max(session_ids) + 1 # Generates a key that corresponds to the previously # created id like 'session_042' if the session's id # is '42' session_key: str = Helper().generate_key('session', session_id) # Defines a new performance object which values are # initialized with zeros. performance: Performance = Performance(0, 0, 0, 0, 0, 0, 0, difficulty_score) # Creates a new session object based on the previously # defined key and id pair. session: Session = Session(session_key, session_id, 'created', server_timestamp, performance) # Defines a new database reference pointing towards # the place at which the new session sould be stored. ref = db.document(f'users/{user_key}/sessions/{session_key}') # Writes the generated session to Firestore. ref.set(session.to_dict()) # Defines a new database reference at which the session's # performance should be stored. ref = db.document( f'users/{user_key}/sessions/{session_key}/data/performance') # Stores the session's performance. ref.set(performance.to_dict()) # Defines a new database reference pointing to the place at # which the level for the generated session should be stored. ref = db.document( f'users/{user_key}/sessions/{session_key}/data/level') # Stores the session's level at Firestore. ref.set(level.to_dict()) # Returns the key of the generated session. return session_key
def store_level(self, user_key: str, session_key: str, level: Level) -> None: # Defines are reference to a Firebase level document. ref: str = f'users/{user_key}/sessions/{session_key}/data/level' # Stores the level to the level document. db.document(ref).set(level.to_dict())
def initialize_level_prototype(self, level: Level) -> None: # db.document(f'level_prototypes/{level.key}').set(level.to_dict())
def store_initial_level(self, level: Level) -> None: # Creates a new level document at Firestore. db.document(f'levels/{level.key}').set(level.to_dict())
def store_tutorial(self, level: Level) -> None: # Creates a new turorial at Firestore. db.document(f'tutorials/{level.key}').set(level.to_dict())
def store_level_prototype(self, level: Level) -> None: # Creates a new level prototype document at Firestore. db.document(f'level_prototypes/{level.key}').set(level.to_dict())