def get_contracts_by_entity(self, entity_id="", date=""):
        """
        Return all contracts for a Single Entity for a date. Date filter is applied at publish Date.
        Args:
            entity_id: (str) ID number of the Entity
            date: (str) date format YYYYMM
        """
        logging.debug("Geting Contracts for " + entity_id + " filtering by " + date)

        if not self.db_connection:
            self.__connect_mongo_db()

        query_filter = {
            "Código Órgão": str(entity_id)
        }

        if not date:
            logging.warning("Didn't receive a date to filter... Returning no contracts.")
            return []

        date_formated = date[4:6] + "/" + date[0:4]

        query_filter["Data Publicação DOU"] = {"$regex": str(date_formated)}

        result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=result, key_field="", remove_duplicated=False)
Beispiel #2
0
    def get_all_entities(self, entity_type=None, date=None):
        """
        Get all entities names and IDs.
        Args:
            entity_type: (str) "Superior" or "Subordinado"
        """
        if not entity_type:
            logging.warning(
                "Superior ou Subordinado not select! Return empty list.")
            return []

        query_filter = {}

        if date:
            filter_date = self.__parse_date(date)
            query_filter = {"Ano e mês do lançamento": filter_date}

        key_field = "Código Órgão " + entity_type

        query_fields = {
            "Código Órgão " + entity_type: 1,
            "Nome Órgão " + entity_type: 1
        }
        result = self.db_connector.query(filter=query_filter,
                                         fields=query_fields)
        return transform_data_in_list(query_result=result,
                                      key_field=key_field,
                                      remove_duplicated=True)
Beispiel #3
0
    def get_entity_data(self,
                        entity_id="",
                        entity_type=None,
                        date="",
                        date_regex=False):
        """
        Get all data from an entity within a specific date.
        Args:
            entity_id = Entity ID.
            entity_type: (str) "Superior" or "Subordinado"
            date: (str) "YYYYMM"
        """
        if not entity_type:
            logging.warning(
                "Superior ou Subordinado not select! Return empty list.")
            return []

        query_filter = {"Código Órgão " + entity_type: str(entity_id)}

        if date:
            if date_regex:
                query_filter["Ano e mês do lançamento"] = {"$regex": str(date)}
            else:
                query_filter["Ano e mês do lançamento"] = self.__parse_date(
                    date)

        logging.debug(query_filter)

        result = self.db_connector.query(filter=query_filter)
        return transform_data_in_list(query_result=result,
                                      key_field="",
                                      remove_duplicated=False)
    def get_all_contracts(self):
        """
        Return all Contracts inside the DB.
        """
        logging.debug("Geting ALL Contracts. No filtering")

        if not self.db_connection:
            self.__connect_mongo_db()

        query_filter = {}

        result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=result, key_field="", remove_duplicated=False)
    def get_all_companies(self):
        """
        Get all Companies IDs in the Companies Bidding Database.
        Return:
            (list) List of dicts with the Ids and Names of the Companies.
        """

        self.__connect_mongo_db(BIDDINGS_COMPANIES_DB_NAME)

        query_fields = {"Código Participante": 1, "Nome Participante": 1}

        result = self.db_connection.query(filter={}, fields=query_fields)
        return transform_data_in_list(query_result=result,
                                      key_field="Código Participante",
                                      remove_duplicated=True)
    def get_bidding_by_company(self, company_id):
        """
        Get the Biddings that a Company participated.
        Args:
            (str) Company ID.
        Return:
            (list) List of Dicts with the data requested.
        """
        logging.debug("Geting Company '{}' Bidding IDs... ".format(company_id))

        if not self.db_connection:
            self.__connect_mongo_db(BIDDINGS_COMPANIES_DB_NAME)

        query_filter = {"Código Participante": str(company_id)}

        result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=result)
    def get_bidding(self,
                    bidding_id=None,
                    ug_id=None,
                    process_id=None,
                    entity_id=None):
        """
        Get a Bidding using some filed to filtering.
        OBS.: Filtering by the process_id will give you a unique Bidding.
        Args:
            bidding_id: (str) Bidding ID in Database.
            ug_id: (str) "Código UG" in Database.
            process_id: (str) Number of the Bidding Process in Databse.
            entity_id: (str) "Código Órgão" in Databse.
        Return:
            (list) of Dicts with all the Biddings that match the filtering.
        """

        if not self.db_connection:
            self.__connect_mongo_db(BIDDINGS_DB_NAME)

        query_filter = {}

        if bidding_id:
            query_filter["Número Licitação"] = str(bidding_id)

        if ug_id:
            query_filter["Código UG"] = str(ug_id)

        if process_id:
            query_filter["Número Processo"] = str(process_id)

        if entity_id:
            query_filter["Código Órgão"] = str(entity_id)

        if not query_filter:
            return []

        logging.debug("Geting specific Bid details. Filters: {}".format(
            str(query_filter)))

        result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=result)
    def get_contracts_by_cnpj(self, company_cnpj):
        """
        Get all Contracts filtering by Company CNPJ.
        Args:
            company_name: (str) Company CNPJ.
        Return:
            (list) of (dicts) with all data.
        """
        logging.debug("Searching all contracts filtering by Company CNPJ (" + company_cnpj + ").")

        if not self.db_connection:
            self.__connect_mongo_db()

        query_filter = {
            "Código Contratado": str(company_cnpj)
        }

        query_result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=query_result, key_field="", remove_duplicated=False)
    def get_contracts_by_year(self, field_to_filter="Data Publicação DOU", date_year=2020):
        """
        Return all contracts for a year. Contracts have some fields related to date. This method
        will use the 'field_to_filter' field.
        Args:
            date_year: (int) Year to filter the Contracts.
            field_to_filter: (str) Contract field used to filter the Contracts.
        """
        logging.debug("Geting Contracts by Year: " + str(date_year) + ". Filtering by field " + field_to_filter)

        if not self.db_connection:
            self.__connect_mongo_db()

        query_filter = {
            field_to_filter: {"$regex": str(date_year)}
        }

        result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=result, key_field="", remove_duplicated=False)
Beispiel #10
0
    def search_entity(self, search_term=None, entity_type=None, date=None):
        """
        Search for an entity, 'Subirdonado' ou 'Superior' in DB.
        Args:
            search_term: (str) search term for entity name
            entity_type: (str) "Superior" or "Subordinado"
            date: (str) "YYYYMM"
        """
        query_filter = {
            str("Nome Órgão " + entity_type): {
                "$regex": search_term
            }
        }

        if date:
            filter_date = self.__parse_date(date)
            query_filter["Ano e mês do lançamento"] = filter_date

        result = self.db_connector.query(filter=query_filter)
        return transform_data_in_list(query_result=result)
Beispiel #11
0
    def get_bidding_companies(self, bidding_id, entity_id, process_id):
        """
        Get the Companies that took part in a Bidding process.
        Args:
            bidding_id: (str) Bidding ID.
            entity_id: (str) Entity ID.
            process_id: (str) Process ID.
        """

        logging.debug("Geting Companies for Bidding " + bidding_id)

        if not self.db_connection:
            self.__connect_mongo_db(BIDDINGS_COMPANIES_DB_NAME)

        query_filter = {
            "Código Órgão": str(entity_id),
            "Número Licitação": str(bidding_id),
            "Número Processo": str(process_id),
        }

        result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=result)
Beispiel #12
0
    def get_biddings_by_entity(self,
                               entity_id="",
                               open_date="",
                               close_date=""):
        """
        Return all Biddings for a Single Entity for a date. If any of the data params are
        passed as empty, they are not considered.
        Args:
            entity_id: (str) ID number of the Entity
            open_date: (str) date format YYYYMM. Date which the bidding process was opened.
            close_date: (str) date format YYYYMM. Date which the bidding process was closed.
        """
        logging.debug("Geting Biddings for " + entity_id)

        if not self.db_connection:
            self.__connect_mongo_db(BIDDINGS_DB_NAME)

        query_filter = {"Código Órgão": str(entity_id)}

        # If open_date is passed ar arg, use it as filter condition. Format: MM/YYYY.
        if open_date != "":
            opened_date_formated = open_date[4:6] + "/" + open_date[0:4]
            query_filter["Data Abertura"] = {
                "$regex": str(opened_date_formated)
            }

        # If close_date is passed ar arg, use it as filter condition. Format: MM/YYYY.
        if close_date != "":
            closed_date_formated = close_date[4:6] + "/" + close_date[0:4]
            query_filter["Data Resultado Compra"] = {
                "$regex": str(closed_date_formated)
            }

        result = self.db_connection.query(filter=query_filter)

        return transform_data_in_list(query_result=result)