Ejemplo n.º 1
0
    def collect_codes_administrative_level(self):

        paese = self.box_value_adm0.get()
        self.area_messaggi.delete(1.0, END)

        aree_amministrative = completeDrought.ManagePostgresDBDrought(
            self.dbname, self.user, self.password)
        lista_admin2 = aree_amministrative.admin_2nd_level_list(paese)

        #print lista_admin2

        for aministrazione in lista_admin2[1].iteritems():

            code_admin = aministrazione[0]
            nome_admin = aministrazione[1]['name_clean']

            all_codes = aree_amministrative.administrative_level_0_1_fetch(
                code_admin)
            #self.area_messaggi.insert(INSERT, all_codes)

            aree_amministrative.file_structure_creation(nome_admin, code_admin)
            newDroughtAssessment = completeDrought.HazardAssessmentDrought(
                self.dbname, self.user, self.password)
            newDroughtAssessment.extract_poly2_admin(paese, nome_admin,
                                                     code_admin)

            section_pop_raster_cut = newDroughtAssessment.cut_rasters_drought(
                paese, nome_admin, code_admin)

            if section_pop_raster_cut == "sipop":
                print "Population clipped...."
            elif section_pop_raster_cut == "nopop":
                print "Population raster not available...."
                sys.exit()
Ejemplo n.º 2
0
    def national_calc_drought(self):

        paese = self.box_value_adm0.get()

        db_conn_drought = completeDrought.ManagePostgresDBDrought(
            self.dbname, self.user, self.password)
        lista_admin2 = db_conn_drought.admin_2nd_level_list(paese)

        for aministrazione in lista_admin2[1].iteritems():

            code_admin = aministrazione[0]
            nome_admin = aministrazione[1]['name_clean']

            #all_codes = aree_amministrative.livelli_amministrativi_0_1(code_admin)
            #self.area_messaggi.insert(INSERT, all_codes)

            db_conn_drought.file_structure_creation(nome_admin, code_admin)
            newDroughtAssessment = completeDrought.HazardAssessmentDrought(
                self.dbname, self.user, self.password)
            newDroughtAssessment.extract_poly2_admin(paese, nome_admin,
                                                     code_admin)

            section_pop_raster_cut = newDroughtAssessment.cut_rasters_drought(
                paese, nome_admin, code_admin)

            if section_pop_raster_cut == "sipop":
                print "Population clipped...."
            elif section_pop_raster_cut == "nopop":
                print "Population raster not available...."
                sys.exit()

        dizio_drought = db_conn_drought.collect_drought_population_frequencies_frm_dbfs(
        )
        self.area_messaggi.insert(INSERT, "Data Collected\n")
        adms = set()
        for chiave, valori in sorted(dizio_drought.iteritems()):
            adms.add(chiave.split("-")[1])
        insert_list = db_conn_drought.prepare_insert_statements_drought_monthly_values(
            adms, dizio_drought)[2]
        self.area_messaggi.insert(INSERT, "Data Ready for Upload in DB\n")

        if db_conn_drought.check_if_monthly_table_drought_exists() == '42P01':
            db_conn_drought.create_sparc_drought_population_month()
            db_conn_drought.insert_drought_in_postgresql(insert_list)

        if db_conn_drought.check_if_monthly_table_drought_exists() == 'exists':
            db_conn_drought.insert_drought_in_postgresql(insert_list)

        db_conn_drought.save_changes()
        db_conn_drought.close_connection()
        self.area_messaggi.insert(INSERT,
                                  "Data for " + paese + " Uploaded in DB")
Ejemplo n.º 3
0
    def scrittura_dati(self, paese):

        wfp_countries = 'sparc_wfp_countries'
        wfp_areas = 'sparc_wfp_areas'
        gaul_wfp_iso = 'sparc_gaul_wfp_iso'  #THIS IS THE GIS TABLE CONTAINING ALL POLYGONS
        nome_admin = ''
        code_admin = ''
        scrittura_tabelle = completeDrought.ManagePostgresDBDrought(
            paese, nome_admin, code_admin, dbname, user, password)

        if scrittura_tabelle.check_tabella() == '42P01':
            scrittura_tabelle.create_sparc_drought_population_month()
            #scrittura_tabelle.fetch_results()
            #scrittura_tabelle.inserisci_valori_calcolati()
        if scrittura_tabelle.check_tabella() == 'exists':
            scrittura_tabelle.fetch_results_drought_montly_from_txt_file()
            scrittura_tabelle.insert_monthly_calulated_drought_values()
        scrittura_tabelle.save_changes()
        scrittura_tabelle.close_connection()
Ejemplo n.º 4
0
    def collect_codes_country_level(self):

        paesi = completeDrought.ManagePostgresDBDrought(
            self.dbname, self.user, self.password)
        self.lista_paesi = paesi.all_country_db()
Ejemplo n.º 5
0
    def national_calc_drought(self):

        paese = self.box_value_adm0.get()
        completeDrought.processo_dati(paese)
        completeDrought.scrittura_dati(paese)
Ejemplo n.º 6
0
    def national_calc_drought(self):

        paese = self.box_value_adm0.get()
        completeDrought.processo_dati(paese)
        completeDrought.scrittura_dati(paese)