diff options
Diffstat (limited to 'src/argaze.test')
-rw-r--r-- | src/argaze.test/GazeFeatures.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/argaze.test/GazeFeatures.py b/src/argaze.test/GazeFeatures.py index f73eefe..8cd2e56 100644 --- a/src/argaze.test/GazeFeatures.py +++ b/src/argaze.test/GazeFeatures.py @@ -13,6 +13,7 @@ from dataclasses import dataclass from argaze import GazeFeatures import numpy +import pandas def random_gaze_positions(size, screen_dimension: tuple[float, float] = (1, 1)): """ Generate random TimeStampedGazePsoitions for testing purpose. @@ -209,6 +210,52 @@ class TestTimeStampedGazePositionsClass(unittest.TestCase): self.assertEqual(repr(ts_gaze_positions), "{\"0\": {\"message\": null, \"value\": [null, null], \"precision\": null}}") + def test_from_dataframe(self): + """Test from_dataframe classmethod.""" + + data = {'Specific timestamp label': [0, 1, 2, 3, 4], + 'Specific gaze position x label': [0, 10, numpy.nan, 30, 40], + 'Specific gaze position y label': [0, 100, numpy.nan, 300, 400] + } + dataframe = pandas.DataFrame().from_dict(data) + + ts_gaze_positions = GazeFeatures.TimeStampedGazePositions.from_dataframe(dataframe, timestamp='Specific timestamp label', x='Specific gaze position x label', y='Specific gaze position y label') + + # Check buffer length + self.assertEqual(len(ts_gaze_positions), 5) + + # Check first gaze position is correctly stored and accessible as a GazePosition + self.assertIsInstance(ts_gaze_positions[0], GazeFeatures.GazePosition) + self.assertEqual(ts_gaze_positions[0].precision, 0) + self.assertEqual(ts_gaze_positions[0].valid, True) + + # Check third gaze position is correctly stored and accessible as a UnvalidGazePosition + self.assertIsInstance(ts_gaze_positions[2], GazeFeatures.UnvalidGazePosition) + self.assertEqual(ts_gaze_positions[2].precision, None) + self.assertEqual(ts_gaze_positions[2].valid, False) + + data = {'Specific timestamp label': [0, 1, 2, 3, 4], + 'Specific gaze position x label': [0, 10, numpy.nan, 30, 40], + 'Specific gaze position y label': [0, 100, numpy.nan, 300, 400], + 'Specific precisison label': [15, 15, numpy.nan, 15, 15] + } + dataframe = pandas.DataFrame().from_dict(data) + + ts_gaze_positions = GazeFeatures.TimeStampedGazePositions.from_dataframe(dataframe, timestamp='Specific timestamp label', x='Specific gaze position x label', y='Specific gaze position y label', precision='Specific precisison label') + + # Check buffer length + self.assertEqual(len(ts_gaze_positions), 5) + + # Check first gaze position is correctly stored and accessible as a GazePosition + self.assertIsInstance(ts_gaze_positions[0], GazeFeatures.GazePosition) + self.assertEqual(ts_gaze_positions[0].precision, 15) + self.assertEqual(ts_gaze_positions[0].valid, True) + + # Check third gaze position is correctly stored and accessible as a UnvalidGazePosition + self.assertIsInstance(ts_gaze_positions[2], GazeFeatures.UnvalidGazePosition) + self.assertEqual(ts_gaze_positions[2].precision, None) + self.assertEqual(ts_gaze_positions[2].valid, False) + def test_as_dataframe(self): """Test inherited as_dataframe method.""" |