Пример #1
0
    def _logs(self):
        logs = []
        for i, a in enumerate(self.articles):
            ts = self.timestamps[i % len(self.timestamps)]
            wiki_ts = self.wiki_timestamps[i % len(self.wiki_timestamps)]
            if len(a) == 6:
                ns = a[5]
            else:
                ns = 0

            if len(a) >= 3:
                if a[1] is not None and a[2] is not None:
                    l = Log(l_project=self.project,
                            l_article=a[0],
                            l_action=b'quality',
                            l_old=a[1],
                            l_new=a[2],
                            l_namespace=ns,
                            l_timestamp=ts,
                            l_revision_timestamp=wiki_ts)
                    logs.append(l)
            if len(a) == 5:
                l = Log(l_project=self.project,
                        l_article=a[0],
                        l_action=b'importance',
                        l_old=a[2],
                        l_new=a[3],
                        l_namespace=ns,
                        l_timestamp=ts,
                        l_revision_timestamp=wiki_ts)
                logs.append(l)
        return logs
Пример #2
0
    def test_add_log_for_importance_rating(self):
        rating = Rating(r_project=b'Test Project',
                        r_namespace=0,
                        r_article=b'Testing Stuff',
                        r_importance=b'Mid-Class',
                        r_importance_timestamp=b'2018-04-01T12:30:00Z')
        logic_rating.add_log_for_rating(self.wp10db, rating,
                                        AssessmentKind.IMPORTANCE,
                                        b'NotA-Class')

        with self.wp10db.cursor() as cursor:
            cursor.execute(
                '''
        SELECT * FROM ''' + Log.table_name + '''
        WHERE l_article = %s
      ''', (b'Testing Stuff', ))
            db_log = cursor.fetchone()
            self.assertIsNotNone(db_log)
            log = Log(**db_log)
        self.assertEqual(b'Test Project', log.l_project)
        self.assertEqual(0, log.l_namespace)
        self.assertEqual(b'Testing Stuff', log.l_article)
        self.assertEqual(b'Mid-Class', log.l_new)
        self.assertEqual(b'NotA-Class', log.l_old)
        self.assertEqual(b'importance', log.l_action)
Пример #3
0
def get_logs(wp10db, project_name, start_dt):
    wp10db.ping()
    with wp10db.cursor() as cursor:
        cursor.execute(
            'SELECT * FROM logging WHERE l_project = %s AND l_timestamp > %s',
            (project_name, start_dt.strftime(TS_FORMAT_WP10)))
        return [Log(**db_log) for db_log in cursor.fetchall()]
Пример #4
0
def update_page_moved(wp10db, project, old_ns, old_title, new_ns, new_title,
                      move_timestamp_dt):
    logger.debug('Updating moves table for %s -> %s',
                 old_title.decode('utf-8'), new_title.decode('utf-8'))
    db_timestamp = move_timestamp_dt.strftime(TS_FORMAT).encode('utf-8')

    existing_move = logic_move.get_move(wp10db, db_timestamp, old_ns,
                                        old_title)
    if existing_move is not None:
        logger.debug('Move already recorded: %r', existing_move)
    else:
        new_move = Move(m_timestamp=db_timestamp,
                        m_old_namespace=old_ns,
                        m_old_article=old_title,
                        m_new_namespace=new_ns,
                        m_new_article=new_title)
        logic_move.insert(wp10db, new_move)

    new_log = Log(l_project=project.p_project,
                  l_namespace=old_ns,
                  l_article=old_title,
                  l_action=b'moved',
                  l_timestamp=GLOBAL_TIMESTAMP,
                  l_old=b'',
                  l_new=b'',
                  l_revision_timestamp=db_timestamp)
    logic_log.insert_or_update(wp10db, new_log)
Пример #5
0
 def setUp(self):
     super().setUp()
     self.project_name = b'My test project'
     self.ns = 0
     self.article = b'The Art of Testing (book)'
     self.action = b'quality'
     self.timestamp = b'20180401123000'
     self.log = Log(l_project=self.project_name,
                    l_namespace=self.ns,
                    l_article=self.article,
                    l_action=self.action,
                    l_timestamp=self.timestamp,
                    l_old=b'NotA-Class',
                    l_new=b'Mid-Class',
                    l_revision_timestamp=b'2018-01-01T12:00:00Z')
     logic_log.insert_or_update(self.wp10db, self.log)
Пример #6
0
    def _move_logs(self):
        logs = []
        for i, m in enumerate(self.moves):
            ts = self.timestamps[i % len(self.timestamps)]
            wiki_ts = self.wiki_timestamps[i % len(self.wiki_timestamps)]

            l = Log(l_project=self.project,
                    l_article=m[0],
                    l_action=b'moved',
                    l_old=None,
                    l_new=None,
                    l_namespace=0,
                    l_timestamp=ts,
                    l_revision_timestamp=wiki_ts)
            logs.append(l)
        return logs
Пример #7
0
    def test_new_move_log(self):
        logic_page.update_page_moved(self.wp10db, self.project, self.old_ns,
                                     self.old_article, self.new_ns,
                                     self.new_article, self.dt)

        with self.wp10db.cursor() as cursor:
            cursor.execute(
                '''
          SELECT * FROM logging
          WHERE l_article = %(old_article)s
      ''', {'old_article': self.old_article})
            log = Log(**cursor.fetchone())

        self.assertIsNotNone(log)
        self.assertEqual(self.old_ns, log.l_namespace)
        self.assertEqual(self.old_article, log.l_article)
        self.assertEqual(b'moved', log.l_action)
        self.assertEqual(b'', log.l_old)
        self.assertEqual(b'', log.l_new)
        self.assertEqual(self.timestamp_db, log.l_revision_timestamp)
Пример #8
0
def add_log_for_rating(wp10db, new_rating, kind, old_rating_value):
    if kind == AssessmentKind.QUALITY:
        action = b'quality'
        timestamp = new_rating.r_quality_timestamp
        new = new_rating.r_quality
    elif kind == AssessmentKind.IMPORTANCE:
        action = b'importance'
        timestamp = new_rating.r_importance_timestamp
        new = new_rating.r_importance
    else:
        raise ValueError('Unrecognized value for kind: %s', kind)

    log = Log(l_project=new_rating.r_project,
              l_namespace=new_rating.r_namespace,
              l_article=new_rating.r_article,
              l_timestamp=GLOBAL_TIMESTAMP,
              l_action=action,
              l_old=old_rating_value,
              l_new=new,
              l_revision_timestamp=timestamp)
    logic_log.insert_or_update(wp10db, log)
Пример #9
0
def get_all_logs(wp10db):
    with wp10db.cursor() as cursor:
        cursor.execute('SELECT * FROM ' + Log.table_name)
        return [Log(**db_log) for db_log in cursor.fetchall()]