Esempio n. 1
0
    def load(self):
        from v2.database import session

        loaded_user_ids = [item["user_id"] for item in self.data]
        qs = session.query(User.id).filter(User.id.in_(loaded_user_ids))
        current_user_ids = [item[0] for item in qs]

        loaded_ids = [
            item["id"] for item in self.data if item["user_id"] in current_user_ids
        ]

        log.info(f"Session| Removendo {len(loaded_ids)} registros existentes...")
        session.execute(
            PageView.__table__.delete().where(PageView.session_id.in_(loaded_ids))
        )
        session.execute(Session.__table__.delete().where(Session.id.in_(loaded_ids)))

        items_to_add = [
            Session(**item) for item in self.data if item["user_id"] in current_user_ids
        ]
        log.info(
            f"Session| Inserindo {len(items_to_add)} novos registros no analytics..."
        )
        session.bulk_save_objects(items_to_add)
        session.commit()
    def load(self):
        from v2.database import session

        loaded_ids = [item["tid"] for item in self.data]
        log.info(
            f"Transaction| Removendo {len(loaded_ids)} registros existentes..."
        )
        session.execute(Transaction.__table__.delete().where(
            Transaction.tid.in_(loaded_ids)))

        items_to_add = [Transaction(**item) for item in self.data]
        log.info(
            f"Transaction| Inserindo {len(items_to_add)} novos registros no analytics..."
        )
        session.bulk_save_objects(items_to_add)
        session.commit()
Esempio n. 3
0
    def load_google(self):
        from v2.database import session

        loaded_ids = [item["campaign_id"] for item in self.google_data]
        log.info(
            f"CampaignPerformance| Removendo {len(loaded_ids)} registros existentes do Google Ads..."
        )
        session.execute(CampaignPerformance.__table__.delete().where(
            db.and_(
                CampaignPerformance.campaign_id.in_(loaded_ids),
                CampaignPerformance.source_id == self.GOOGLE_ID,
            )))

        items_to_add = [
            CampaignPerformance(**item) for item in self.google_data
        ]
        log.info(
            f"CampaignPerformance| Inserindo {len(items_to_add)} novos registros do Google Ads no analytics..."
        )
        session.bulk_save_objects(items_to_add)
        session.commit()
Esempio n. 4
0
    def load(self):
        from v2.database import session

        users = [item for item in self.data]
        loaded_ids = [item["id"] for item in users]

        log.info(
            f"Verificando quais dos {len(users)} usuários existem no analytics..."
        )
        qs = session.query(User.id).filter(User.id.in_(loaded_ids))
        existing_ids = [id[0] for id in qs.all()]

        log.info(f"Ignorando {len(existing_ids)} registros existentes...")
        items_to_add = []
        for item in users:
            if item["id"] not in existing_ids:
                items_to_add.append(User(id=item["id"], email=item["email"]))

        log.info(
            f"Inserindo {len(items_to_add)} novos usuários no analytics...")
        session.bulk_save_objects(items_to_add)
        session.commit()