Esempio n. 1
0
 def randomdata(self):
     dummy = Dummy(self._storage)
     rand = int(random.random() * 10) + 1
     for i in range(rand):
         rand_start = random.random() * 60
         rand_end = random.random() * 60
         dummy.create_hits_linear(
             u'http://www.mysite.com/page' + str(rand),
             start_hits_per_hour=rand_start, end_hits_per_hour=rand_end,
             referrer='http://www.google.com?q=page' + str(rand))
     return Response('done')
Esempio n. 2
0
    def dummydata(self):
        dummy = Dummy(self._conf, self._storage, True)

        dummy.create_hits_linear(u'http://www.mysite.com/page',
                                 start_time=0, end_time=10000,
                                 start_hits_per_hour=0, end_hits_per_hour=50,
                                 referrer='http://google.com?q=cool%20page')
        dummy.create_hits_linear(u'http://www.mysite.com/page',
                                 start_time=5000, end_time=10000,
                                 start_hits_per_hour=0, end_hits_per_hour=50,
                                 referrer='http://www.google.com?q=cool')
        dummy.create_hits_linear(u'http://www.mysite.com/page2',
                                 start_time=0, end_time=10000,
                                 start_hits_per_hour=20, end_hits_per_hour=80)
        dummy.create_hits_linear(u'http://www.mysite.com/page3',
                                 start_time=0, end_time=10000,
                                 start_hits_per_hour=0, end_hits_per_hour=75)
        dummy.create_hits_linear(u'http://www.mysite.com/page4',
                                 start_time=0, end_time=10000,
                                 start_hits_per_hour=200, end_hits_per_hour=0)

        rand_start = random.random() * 60
        rand_end = random.random() * 60
        dummy.create_hits_linear(u'http://www.mysite.com/page2',
                                 start_time=0, end_time=10000,
                                 start_hits_per_hour=rand_start,
                                 end_hits_per_hour=rand_end,
                                 referrer='http://www.google.com?q=page2')
        return Response('done')
Esempio n. 3
0
class TestAnalyzer(TestBase):

    def setUp(self):
        super(TestAnalyzer, self).setUp()
        self.analyzer = Analyzer(self._storage)
        self.dummy = Dummy(self._conf, self._storage, clear=True)
    
    def test_deviators_stable(self):
        """Test listing of top deviators - stable"""
        self.dummy.create_hits_linear(u'http://mysite.com/page1',
            start_hits_per_hour=5000, end_hits_per_hour=5000,
            start_time=0, end_time=10000)
        self.assertEqual(self.analyzer.get_top_deviators(qfield='hit_url', 
            start_time=0, boundary_time=7500, end_time=10000), 
            [{'name': u'http://mysite.com/page1', 'pct': 0, 
                'hph_recent': 5001, 'hph_historic': 4999,
                'num_recent': 3473, 'num_historic': 10416}])
    
    def test_deviators_increasing(self):
        """Test listing of top deviators - increasing"""
        self.dummy.create_hits_linear(u'http://mysite.com/page2',
            start_hits_per_hour=0, end_hits_per_hour=8000,
            start_time=0, end_time=10000)
        self.assertEqual(self.analyzer.get_top_deviators(qfield='hit_url', 
            start_time=0, boundary_time=7500, end_time=10000), 
            [{'name': u'http://mysite.com/page2', 'pct': 133, 
                'hph_recent': 6999, 'hph_historic': 2999,
                'num_recent': 4861, 'num_historic': 6249}])
    
    def test_deviators_decreasing(self):
        """Test listing of top deviators - decreasing"""
        self.dummy.create_hits_linear(u'http://mysite.com/page3',
            start_hits_per_hour=8000, end_hits_per_hour=0,
            start_time=0, end_time=10000)
        self.assertEqual(self.analyzer.get_top_deviators(qfield='hit_url', 
            start_time=0, boundary_time=7500, end_time=10000), 
            [{'name': u'http://mysite.com/page3', 'pct': -80, 
                'hph_recent': 1000, 'hph_historic': 5000,
                'num_recent': 695, 'num_historic': 10417}])

    def test_toppages_basic(self):
        """Test listing of top pages - basic"""
        self.dummy.create_hits_linear(u'http://mysite.com/page',
            start_hits_per_hour=50, end_hits_per_hour=50,
            start_time=0, end_time=3600)
        self.assertEqual(self.analyzer.get_top_pages(qfield='hit_url',
            start_time=0, end_time=3600), [
                {'name': u'http://mysite.com/page', 'count': 50, 'hph': 50.0}
            ])

    def test_toppages_strings(self):
        """Test listing of top pages - timestamps as string"""
        self.dummy.create_hits_linear(u'http://mysite.com/page',
            start_hits_per_hour=50, end_hits_per_hour=50,
            start_time=0, end_time=3600)
        self.assertEqual(self.analyzer.get_top_pages(qfield='hit_url',
            start_time='0', end_time='3600'), [
                {'name': u'http://mysite.com/page', 'count': 50, 'hph': 50.0}
            ])
    
    def test_toppages_timespan(self):
        """Test listing of top pages - using timespan"""
        self.dummy.create_hits_linear(u'http://mysite.com/page',
            start_hits_per_hour=50, end_hits_per_hour=50,
            start_time=time.time() - 3600, end_time=time.time())
        self.assertEqual(self.analyzer.get_top_pages(qfield='hit_url',
            timespan='3600'), [
                {'name': u'http://mysite.com/page', 'count': 50, 'hph': 50.0}
            ])
    
    def test_keywordcloud_basic(self):
        """Test generation of keyword cloud - basic"""
        tests = []
        # Regular search, single word
        tests.append({
            'ref': u'http://google.com?q=cool', 
            'expect': [(u'cool', 100.0)]
        })
        # Regular search, phrase
        tests.append({
            'ref': u'http://google.com?q=cool page', 
            'expect': [(u'cool', 50.0), (u'page', 50.0)]
        })
        # Empty search query
        tests.append({
            'ref': u'http://google.com?q=', 
            'expect': []
        })
        # No search query
        tests.append({
            'ref': u'http://google.com', 
            'expect': []
        })
        # With query, but no searchengine
        tests.append({
            'ref': u'http://mysite.com?q=test', 
            'expect': []
        })

        for test in tests:
            self._storage.clear_hits(0)
            hit = Hit(self._conf, u'http://mysite.com/page',
                      referrer=test['ref'])
            self._storage.add_hit(hit)
            self.assertEqual(self.analyzer.get_keyword_cloud(), test['expect'])
    
    def test_keywordcloud_multi(self):
        """Test generation of keyword cloud - multiple hits"""
        searches = [
            'cool page',
            'funny test',
            'cool',
            'page',
            'cool',
            'test page test',
            'cool test page',
            'page',
            'cool page',
            'very cool funny test page'
        ]
        
        for query in searches:
            hit = Hit(self._conf, u'http://mysite.com/page',
                      referrer=u'http://google.com?q='+query)
            self._storage.add_hit(hit)

        self.assertEqual(sorted(self.analyzer.get_keyword_cloud()), 
            sorted([
                ('cool', 30.0), ('page', 35.0), ('funny', 10.0),
                ('test', 20.0), ('very', 5.0)
            ]))

    def test_keywordcloud_specialchars(self):
        """Test generation of keyword cloud - special characters"""
        hit = Hit(self._conf, u'http://mysite.com/page',
            referrer=u'http://google.com?q=éäüòñрусском')
        self._storage.add_hit(hit)
        self.assertEqual(self.analyzer.get_keyword_cloud(), 
            [(u'éäüòñрусском', 100.0)])
Esempio n. 4
0
class TestDummy(TestBase):
    
    def setUp(self):
        super(TestDummy, self).setUp()
        self.dummy = Dummy(self._conf, self._storage, clear=True)
    
    def test_create_linear_regular(self):
        """Test the linear creation of dummy hits - regular"""
        url = u'http://abc.nl/page'
        self.dummy.create_hits_linear(url,
            referrer=u'http://example.com/page?id=123',
            start_hits_per_hour=0, end_hits_per_hour=100,
            start_time=0, end_time=3600)
        hitcount = self._storage.get_hitcount(url)
        self.assertEqual(hitcount, 50)

    def test_create_linear_search(self):
        """Test the linear creation of dummy hits - searchengine"""
        url = u'http://abc.nl/page'
        self.dummy.create_hits_linear(url,
            referrer=u'http://google.com?q=my search query',
            start_hits_per_hour=0, end_hits_per_hour=100,
            start_time=0, end_time=3600)
        hitcount = self._storage.get_hitcount(url)
        self.assertEqual(hitcount, 50)

    def test_create_linear_specialchars(self):
        """Test the linear creation of dummy hits - special chars"""
        url = u'http://abc.nl/page?x=éäüòñ'
        self.dummy.create_hits_linear(url,
            referrer=u'http://example.com/page/éäüòñ',
            start_hits_per_hour=0, end_hits_per_hour=100,
            start_time=0, end_time=3600)
        hitcount = self._storage.get_hitcount(url)
        self.assertEqual(hitcount, 50)

    def test_create_linear_cyrillic(self):
        """Test the linear creation of dummy hits - cyrillic"""
        url = u'http://abc.nl/page?x=миниатю'
        self.dummy.create_hits_linear(url,
            referrer=u'http://example.com/page/миниатю',
            start_hits_per_hour=0, end_hits_per_hour=100,
            start_time=0, end_time=3600)
        hitcount = self._storage.get_hitcount(url)
        self.assertEqual(hitcount, 50)

    def test_create_linear_no_timestamp(self):
        """Test the linear creation of dummy hits - no timestamp"""
        url = u'http://abc.nl/page'
        self.dummy.create_hits_linear(url,
            referrer=None,
            start_hits_per_hour=0, end_hits_per_hour=100,
            start_time=None, end_time=None)
        hitcount = self._storage.get_hitcount(url)
        self.assertEqual(hitcount, 1200)

    def test_create_linear_decreasing(self):
        """Test the linear creation of dummy hits - decreasing"""
        url = u'http://abc.nl/page'
        self.dummy.create_hits_linear(url,
            referrer=None,
            start_hits_per_hour=100, end_hits_per_hour=0,
            start_time=0, end_time=3600)
        hitcount = self._storage.get_hitcount(url)
        self.assertEqual(hitcount, 50)

    def test_create_linear_stable(self):
        """Test the linear creation of dummy hits - stable"""
        url = u'http://abc.nl/page'
        self.dummy.create_hits_linear(url,
            referrer=None,
            start_hits_per_hour=50, end_hits_per_hour=50,
            start_time=0,end_time=3600)
        hitcount = self._storage.get_hitcount(url)
        self.assertEqual(hitcount, 50)