def get_snapshot_chronology_for_study_id(study, study_id): """Get the snapshots for a child sorted in reverse chronological order. Get the snapshots for a child sorted in reverse chronological order given the study / study ID of that child. @param study: The name of the study to find the child in. @type study: str @param study_id: The ID of the child within the study. @type study_id: str @return: List of snapshots. @rtype: List of models.SnapshotMetadata """ study_filter = models.Filter( 'study', 'eq', study ) id_filter = models.Filter( 'study_id', 'eq', study_id ) results = filter_util.run_search_query( [study_filter, id_filter], 'snapshots' ) results.sort(key=lambda x: x.session_date, reverse=True) return results
def test_run_search_query(self): fake_cursor = TestDBCursor() fake_connection = TestDBConnection(fake_cursor) self.mox.StubOutWithMock(db_util, 'get_db_connection') db_util.get_db_connection().AndReturn(fake_connection) self.mox.ReplayAll() filters = [ models.Filter('study', 'eq', 'study1,study2') ] filter_util.run_search_query(filters, 'test') query = fake_cursor.queries[0] query_str ='SELECT * FROM test WHERE (study == ? OR study == ?) AND '\ '(deleted == ?)' self.assertEqual(query, query_str) operands = fake_cursor.operands[0] self.assertEqual(len(operands), 3) self.assertEqual(operands[0], 'study1') self.assertEqual(operands[1], 'study2') self.assertEqual(operands[2], 0)
def get_snapshot_chronology_for_db_id(db_id): """Get snapshots for a child sorted in reverse chronological order. Get snapshots for a child sorted in reverse choronological order given the database ID of that child. @param db_id: The database ID of the child to get the snapshot chronology for. @type db_id: str @return: List of snapshots. @rtype: List of models.SnapshotMetadata """ child_id_filter = models.Filter( 'child_id', 'eq', db_id ) results = filter_util.run_search_query([child_id_filter], 'snapshots') results.sort(key=lambda x: x.session_date, reverse=True) return results
def set_global_id(self, new_global_id): """Set the global ID of the child to load missing form values from. @param new_global_id: The global ID of the child to start loading form values from. @type new_global_id: int """ if not self.is_valid_value(new_global_id): return try: new_global_id = int(new_global_id) except ValueError: return child_id_filter = models.Filter('child_id', 'eq', new_global_id) results = filter_util.run_search_query([child_id_filter], 'snapshots') if len(results) == 0: return results.sort(key=lambda x: x.session_date, reverse=True) self.__target_user = results[0]
def set_study_id(self, study, study_id): """Set the child to load missing values from using study information. Set the child to load missing form values from by finding the reference child using a study id and study name. @param study: The name of the study to find the child in. @type study: str @param study_id: The id of the child within the study to use as a reference to load missing form values from. @type study_id: str """ if not self.is_valid_value(study) or not self.is_valid_value(study_id): return study_filter = models.Filter('study', 'eq', study) study_id_filter = models.Filter('study_id', 'eq', study_id) results = filter_util.run_search_query([study_filter, study_id_filter], 'snapshots') if len(results) == 0: return results.sort(key=lambda x: x.session_date, reverse=True) self.__target_user = results[0]
def get_session_number(study, study_id): study_filter = models.Filter('study', 'eq', study) study_id_filter = models.Filter('study_id', 'eq', study_id) results = filter_util.run_search_query([study_filter, study_id_filter], 'snapshots') return len(results) + 1