Beispiel #1
0
def get_subordinado_rank(date_year):
    db.connect(EXPENSES_DB_NAME)
    di = entity_inspector.EntityInspector(db)
    return {
        "data":
        di.get_entity_rank(entity_type="Subordinado",
                           rank_size=20,
                           date_year=date_year)
    }
Beispiel #2
0
 def __get_data_for_single_spender(self,
                                   spender_id,
                                   entity_type,
                                   date="",
                                   date_regex=False):
     """
     Get from MongoDB data of a single Receiver Entity.
     Args:
         spender_id: (int OR str) Entity ID ('ID Órgão Suberdinado')
     """
     di = entity_inspector.EntityInspector(self.db_connector)
     return di.get_entity_data(entity_id=spender_id,
                               entity_type=entity_type,
                               date=date,
                               date_regex=date_regex)
Beispiel #3
0
    def create_entities_list(self, entity_type=None):
        """
        Create a list with all Entities (name, ID), removing duplicated.
        Save this list inside a RedisDB (db=1) to be used as a cache system
        by the API.
        """
        self.__connect_mongo(EXPENSES_DB_NAME)

        if not entity_type:
            logging.warning(
                "No entity type selected at 'create_entities_list'. Returning..."
            )
            return

        logging.debug("Creating Entities list...")
        di = entity_inspector.EntityInspector(self.db_connector)
        all_entities = di.get_all_entities(entity_type=entity_type, date=None)
        self.__connect_redis(db=1)

        base_name = "all_" + entity_type + "_list"
        key_name = self.__build_key_name(base_name)

        return self.redis_connector.set(key_name, json.dumps(all_entities))
Beispiel #4
0
def get_subordinado_data(date, id):
    db.connect(EXPENSES_DB_NAME)
    di = entity_inspector.EntityInspector(db)
    return {"data": di.get_entity_data(id, "Subordinado", date)}
Beispiel #5
0
def get_superior_data(date, id):
    db.connect(EXPENSES_DB_NAME)
    di = entity_inspector.EntityInspector(db)
    response = {"data": di.get_entity_data(id, "Superior", date)}
    return response
Beispiel #6
0
def get_all_subordinado(date):
    db.connect(EXPENSES_DB_NAME)
    di = entity_inspector.EntityInspector(db)
    response = {"data": di.get_all_entities_from_redis("Subordinado", date)}
    return response
Beispiel #7
0
def get_all_superior(date):
    db.connect(EXPENSES_DB_NAME)
    di = entity_inspector.EntityInspector(db)
    response = {"data": di.get_all_entities("Superior", date)}
    return response