Example #1
0
    def __init__(self, argv):
        """ Construct the object graph for GazeStatsAnalyzer """
        super(GazeStatsRunner, self).__init__()
        op = GazeStatisticsOptionParser(argv)
        # Read and parse the gazestream

        ar = AutoScanpathReader()
        self.scanpath = ar.read_scanpath(filename=op.gaze_file)

        self.timeline = None
        
        if op.options.stim_file is not None:
            self.timeline = self.__build_timeline(op.options.stim_file)
            if op.options.object_dir is not None:
                r = shapes.ShapeReader(path = op.options.object_dir)
                dec = shapes.TimelineDecorator(r)
                self.timeline = dec.find_shape_files_and_add_to_timeline(
                    self.timeline
                )
            if op.options.recenter_on is not None:
                #TODO: Make these sepeficiable on the command line
                rx = 400
                ry = 300
                limiter = shapes.Rectangle(300, 200, 500, 400)
                self.timeline = self.timeline.recenter_on(
                    op.options.recenter_on, rx, ry, limiter
                )
            
        # And build the analyzer
        self.analyzer = GazeStatisticsAnalyzer(
            scanpath = self.scanpath,
            timeline = self.timeline
        )
class TestAutoScanpath(object):
    
    def __init__(self):
        pass
        
    def setup(self):
        # Woo woo woo
        p = path.abspath(path.dirname(__file__))
        
        self.iview_2_file = path.join(
            p, "../examples/iview_normal.txt")
        self.iview_3_file = path.join(
            p, "../examples/iview_3_small.txt")
        self.event_file = path.join(
            p, "../examples/pres_tiny.txt")
            
        self.ar2 = AutoScanpathReader([IView2ScanpathReader])
        self.ar3 = AutoScanpathReader([IView3ScanpathReader])
        self.ar_multi = AutoScanpathReader([
            IView2ScanpathReader, IView3ScanpathReader
        ])
    
    def test_version_2_reader_gets_scanpath(self):
        app = self.ar2.read_scanpath(filename=self.iview_2_file)
        mpp = IView2ScanpathReader(filename=self.iview_2_file).scanpath()
        eq_(len(mpp), len(app))

    def test_version_2_reader_sets_success_class(self):
        app = self.ar2.read_scanpath(filename=self.iview_2_file)
        eq_(IView2ScanpathReader, self.ar2.success_class)
        
    def test_reader_returns_none_on_failure(self):
        app = self.ar2.read_scanpath(filename=self.iview_3_file)
        assert app is None
    
    def test_reader_records_failures(self):
        app = self.ar2.read_scanpath(filename=self.iview_3_file)
        eq_(1, len(self.ar2.failures))
        eq_(IView2ScanpathReader, self.ar2.failures[0][0])
    
    def test_multi_reader_succeeds(self):
        app = self.ar_multi.read_scanpath(self.iview_3_file)
        mpp = IView3ScanpathReader(filename=self.iview_3_file)
        eq_(len(mpp), len(app))

    def test_multi_reader_records_failures(self):
        app = self.ar_multi.read_scanpath(self.iview_3_file)
        mpp = IView3ScanpathReader(filename=self.iview_3_file)
        eq_(1, len(self.ar_multi.failures))
        eq_(IView2ScanpathReader, self.ar_multi.failures[0][0])
    
    def test_multi_reader_returns_none_on_fail(self):
        app = self.ar_multi.read_scanpath(self.event_file)
        eq_(2, len(self.ar_multi.failures))
        
    def test_multi_reader_has_no_success_class_on_fail(self):
        app = self.ar_multi.read_scanpath(self.event_file)
        assert self.ar_multi.success_class is None
 def setup(self):
     # Woo woo woo
     p = path.abspath(path.dirname(__file__))
     
     self.iview_2_file = path.join(
         p, "../examples/iview_normal.txt")
     self.iview_3_file = path.join(
         p, "../examples/iview_3_small.txt")
     self.event_file = path.join(
         p, "../examples/pres_tiny.txt")
         
     self.ar2 = AutoScanpathReader([IView2ScanpathReader])
     self.ar3 = AutoScanpathReader([IView3ScanpathReader])
     self.ar_multi = AutoScanpathReader([
         IView2ScanpathReader, IView3ScanpathReader
     ])