Exemplo n.º 1
0
 def get_items(self, date):
     """Returns all rows with given added date.
     """
     return db.query(
         "SELECT * FROM import_item" +
         " WHERE added_time::date = $date",
         vars=locals())
Exemplo n.º 2
0
 def get_books_imported_per_day(self):
     rows = db.query(
         "SELECT import_time::date as date, count(*) as count"
         " FROM import_item" +
         " WHERE status='created'"
         " GROUP BY 1" +
         " ORDER BY 1")
     return [[self.date2millis(row.date), row.count] for row in rows]
Exemplo n.º 3
0
 def get_items_summary(self, date):
     """Returns all rows with given added date.
     """
     rows = db.query("SELECT status, count(*) as count" +
                     " FROM import_item" + " WHERE added_date::date = $date"
                     " GROUP BY status",
                     vars=locals())
     return {"counts": dict([(row.status, row.count) for row in rows])}
Exemplo n.º 4
0
 def get_count_by_date_status(self, ndays=10):
     result = db.query(
         "SELECT added_time::date as date, status, count(*)" +
         " FROM import_item " +
         " WHERE added_time > current_date - interval '$ndays' day"
         " GROUP BY 1, 2" + " ORDER BY 1 desc",
         vars=locals())
     d = defaultdict(dict)
     for row in result:
         d[row.date][row.status] = row.count
     return sorted(d.items(), reverse=True)
Exemplo n.º 5
0
 def get_count_by_date_status(self, ndays=10):
     result = db.query(
         "SELECT added_time::date as date, status, count(*)" +
         " FROM import_item " +
         " WHERE added_time > current_date - interval '$ndays' day"
         " GROUP BY 1, 2" + 
         " ORDER BY 1 desc",
         vars=locals())
     d = defaultdict(dict)
     for row in result:
         d[row.date][row.status] = row.count
     return sorted(d.items(), reverse=True)
Exemplo n.º 6
0
 def get_items_summary(self, date):
     """Returns all rows with given added date.
     """
     rows = db.query(
             "SELECT status, count(*) as count" +
             " FROM import_item" +
             " WHERE added_date::date = $date"
             " GROUP BY status",
             vars=locals())
     return {
         "counts": dict([(row.status, row.count) for row in rows])
     }
Exemplo n.º 7
0
    def add_items(self, items):
        if not items:
            return
        logger.info("batch %s: adding %d items", self.name, len(items))
        already_present = [row.ia_id for row in db.query("SELECT ia_id FROM import_item WHERE ia_id IN $items", vars=locals())]
        # ignore already present
        items = list(set(items) - set(already_present))

        logger.info("batch %s: %d items are already present, ignoring...", self.name, len(already_present))
        if items:
            values = [dict(batch_id=self.id, ia_id=item) for item in items]
            db.get_db().multiple_insert("import_item", values)        
            logger.info("batch %s: added %d items", self.name, len(items))
Exemplo n.º 8
0
 def setup_method(self, method):
     web.config.db_parameters = dict(dbn='postgres', db='oltest')
     db.query("TRUNCATE waitingloan")
Exemplo n.º 9
0
 def find(name):
     result = db.query("SELECT * FROM import_batch where name=$name", vars=locals())
     return result and Batch(result[0]) or None
Exemplo n.º 10
0
 def get_count_by_status(self, date=None):
     rows = db.query("SELECT status, count(*) FROM import_item GROUP BY status")
     return dict([(row.status, row.count) for row in rows])
Exemplo n.º 11
0
 def get_count_by_status(self, date=None):
     rows = db.query(
         "SELECT status, count(*) FROM import_item GROUP BY status")
     return dict([(row.status, row.count) for row in rows])
Exemplo n.º 12
0
 def get_items(self, date):
     """Returns all rows with given added date.
     """
     return db.query("SELECT * FROM import_item" +
                     " WHERE added_time::date = $date",
                     vars=locals())
Exemplo n.º 13
0
 def get_books_imported_per_day(self):
     rows = db.query("SELECT import_time::date as date, count(*) as count"
                     " FROM import_item" + " WHERE status='created'"
                     " GROUP BY 1" + " ORDER BY 1")
     return [[self.date2millis(row.date), row.count] for row in rows]