Example #1
0
 def get_estimated_population(self):
     table_name = DatabaseManager.camel_to_underscore(
         DatabaseManager.get_class_name(ZipCode(self.database_manager)))
     query = "SELECT sum(`estimated_population`) as `estimated_population` FROM `{}` WHERE `state_code`={};".format(
         table_name, self.database_manager.database.escape(self.code))
     results = self.__execute_sql_query(query)
     estimated_population = int(results[0]["estimated_population"])
     return estimated_population
Example #2
0
 def get_estimated_national_population(self):
     table_name = DatabaseManager.camel_to_underscore(
         DatabaseManager.get_class_name(self))
     query = "SELECT sum(`estimated_population`) as `estimated_population` FROM `{}`;".format(
         table_name)
     results = self.__execute_sql_query(query)
     estimated_population = int(results[0]["estimated_population"])
     return estimated_population
Example #3
0
 def get_city_area_km2(self):
     table_name = DatabaseManager.camel_to_underscore(
         DatabaseManager.get_class_name(self))
     query = "SELECT ROUND(sum(`area_m2`)/1000000) as `area_km2` FROM `{}` WHERE `city`={};".format(
         table_name, self.database_manager.database.escape(self.city))
     results = self.__execute_sql_query(query)
     area_km2 = int(results[0]["area_km2"])
     return area_km2
Example #4
0
    def get_mean_income(self):
        table_name = DatabaseManager.camel_to_underscore(
            DatabaseManager.get_class_name(ZipCode(self.database_manager)))
        query = "SELECT sum(`total_wages`) as `total_wages` FROM `{}` WHERE `state_code`={};".format(
            table_name, self.database_manager.database.escape(self.code))
        results = self.__execute_sql_query(query)
        total_wages = int(results[0]["total_wages"])

        query = "SELECT sum(`num_tax_returns`) as `total_returns` FROM `{}` WHERE `state_code`={};".format(
            table_name, self.database_manager.database.escape(self.code))
        results = self.__execute_sql_query(query)
        total_returns = int(results[0]["total_returns"])
        mean_city_income = int(total_wages / total_returns)
        return mean_city_income
Example #5
0
    def get_mean_national_income(self):
        table_name = DatabaseManager.camel_to_underscore(
            DatabaseManager.get_class_name(self))
        query = "SELECT sum(`total_wages`) as `total_wages` FROM `{}`;".format(
            table_name)
        results = self.__execute_sql_query(query)
        total_wages = int(results[0]["total_wages"])

        query = "SELECT sum(`num_tax_returns`) as `total_returns` FROM `{}`;".format(
            table_name)
        results = self.__execute_sql_query(query)
        total_returns = int(results[0]["total_returns"])
        mean_national_income = int(total_wages / total_returns)
        return mean_national_income
def get_database_connection(mysql_settings):
    database_manager = DatabaseManager(host=mysql_settings["server"],
                                       port=mysql_settings["port"],
                                       user=mysql_settings["username"],
                                       password=mysql_settings["password"],
                                       db=mysql_settings["schema"],
                                       charset=mysql_settings["charset"])
    return database_manager