Example #1
0
 def __init__(self, communityType):
     Bibliography = pd.read_excel(
         nfv.getPath(nfv.mainpath, "Bibliography_120220.xlsx"))
     Bibliography = nfv.fixBibliography(Bibliography)
     self.Bibliography = nfv.setDataByIndex(Bibliography, communityType)
     self.Entities = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA_1_0_Entities_Interview_results.csv"),
                     float_precision="high"), communityType)
     self.LocalLeaders = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(nfv.mainpath,
                                 "NAUTIA_1_0_Local_leaders_v3_results.csv"),
                     float_precision="high"), communityType)
     self.HouseHold = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA_1_0_Survey_household_v6_results.csv"),
                     float_precision="high"), communityType)
     self.WomenGroup = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA_1_0_Women_Focus_Group2_results.csv"),
                     float_precision="high"), communityType)
     self.SanitationInfra = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath,
             "NAUTIA_V1_0_Sanitation_Infrastructre_results.csv"),
                     float_precision="high"), communityType)
     self.Priorities = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(nfv.mainpath,
                                 "NAUTIA_1_0_Priorities_v3_results.csv"),
                     float_precision="high"), communityType)
     self.GeneralForm = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(nfv.mainpath,
                                 "NAUTIA_1_0_General_form_v3_results.csv"),
                     float_precision="high"), communityType)
     self.PublicSpace = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(nfv.mainpath,
                                 "NAUTIA_1_0_Public_Space_results.csv"),
                     float_precision="high"), communityType)
     self.WaterInf = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA_1_0_Water_Infrastructure_results.csv"),
                     float_precision="high"), communityType)
     self.SanitationInf = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath,
             "NAUTIA_V1_0_Sanitation_Infrastructre_results.csv"),
                     float_precision="high"), communityType)
     self.WasteManagementInf = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath,
             "NAUTIA_1_0_Waste_Management_Infrastructure_results.csv"),
                     float_precision="high"), communityType)
     self.EnergyINF = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA_1_0_Energy_Infrastructure_results.csv"),
                     float_precision="high"), communityType)
     self.Business = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA1_0_Business_surveys_v3_results.csv"),
                     float_precision="high"), communityType)
     self.MobilityINF = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath,
             "NAUTIA_1_0__Transport_servicesaccess_points_results.csv"),
                     float_precision="high"), communityType)
     self.ComunalServices = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA_1_0_Communal_Services_results.csv"),
                     float_precision="high"), communityType)
     self.GeneralCitizen = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath,
             "NAUTIA_1_0_General_Citizen_Focus_Group_results.csv"),
                     float_precision="high"), communityType)
     self.Shelter = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(nfv.mainpath,
                                 "NAUTIA_1_0_Shelter_results.csv"),
                     float_precision="high"), communityType)
     self.FarmyardCrop = nfv.setDataByIndex(
         pd.read_csv(nfv.getPath(
             nfv.mainpath, "NAUTIA_1_0_Farmyard_and_Crops_results.csv"),
                     float_precision="high"), communityType)
def writteExpanPlan(query, f, cursor, communityType):
    Entities = nfv.setDataByIndex(
        pd.read_csv(nfv.getPath(mainpath,
                                "NAUTIA_1_0_Entities_Interview_results.csv"),
                    float_precision="high"), communityType)
    inf_expandplanbeneficiaries = nfv.dfFix(Entities,
                                            "ENERGY:Covered_services",
                                            "ENERGY:Power_failure")
    inf_expandplanbeneficiaries = nt.separateValues(
        inf_expandplanbeneficiaries)
    cursor.execute("SELECT * FROM inf_expandplanbeneficiaries")
    array = np.array(cursor.fetchall())
    pk = np.array([])
    for row in array:
        for row2 in np.array(inf_expandplanbeneficiaries):
            for elem in row2:
                if (row[1] == elem):
                    pk = np.append(pk, elem)
    cursor.execute(
        "SELECT idINF_EnergyInfrastructure FROM INF_EnergyInfrastructure  ORDER BY idINF_EnergyInfrastructure DESC LIMIT 1"
    )
    pkInf = np.array(cursor.fetchall())
    cursor.execute(
        "SELECT Community_idCommunity FROM INF_EnergyInfrastructure  ORDER BY Community_idCommunity DESC LIMIT 1"
    )
    fkInf = np.array(cursor.fetchall())
    v1 = v2 = np.array([])
    for elem in pk:
        v1 = np.append(v1, pkInf)
        v2 = np.append(v2, fkInf)
    result = nt.concatDF(pd.DataFrame(pk),
                         nt.concatDF(pd.DataFrame(v1), pd.DataFrame(v2)))
    nt.mkCSV(result,
             "inf_expandplanbeneficiaries_has_inf_energyinfrastructure.csv")
    cursor.execute(
        "SHOW columns FROM inf_expandplanbeneficiaries_has_inf_energyinfrastructure"
    )
    columnList = cursor.fetchall()
    table = "inf_expandplanbeneficiaries_has_inf_energyinfrastructure"
    f.write(query.getquery1() + table + ".csv'\n" + query.getquery2() + " " +
            table + "\n" + query.getquery3() + "\n" + query.getquery4() + "\n")
    pk = True
    string = np.array([], dtype=str)
    for column in columnList:
        if (pk):
            pk = False
        else:
            string = np.append(string, column[0])
    f.write("    (")
    for column in string:
        if (column != string[-1]):
            f.write("@" + column + ",")
        else:
            f.write("@" + column + ")\n")
    f.write("SET ")
    for column in string:
        if (column != string[-1]):
            if (column == string[0]):
                f.write(column + " = NULLIF(@" + column + ",''),\n")
            else:
                f.write("    " + column + " = NULLIF(@" + column + ",''),\n")
        else:
            if (column == string[0]):
                f.write(column + " = NULLIF(@" + column + ",'');\n\n")
            else:
                f.write("    " + column + " = NULLIF(@" + column + ",'');\n\n")