diff --git a/dataacquisition/ExportToDatabase.py b/dataacquisition/ExportToDatabase.py index 2cb8cad308ba015469365af674bbb8e041d33efa..cb82bc08e728fa3342acfded95314af5fd854927 100644 --- a/dataacquisition/ExportToDatabase.py +++ b/dataacquisition/ExportToDatabase.py @@ -144,6 +144,7 @@ def create_matrix_data(cursor, amount_points): def createInsertStatement(station_list): # create INSERT INTO table (columns) VALUES('%s',...) station_list.columns.astype(str) + df_columns = list(station_list) station_list = station_list.round(decimals=3) values = "VALUES({})".format(",".join(["%s" for _ in df_columns])) @@ -166,8 +167,10 @@ def insert_data(station_list, cursor): # for column in df_columns: # columns.append('"' + column + '"') #columns = str(columns).replace('[', '').replace(']', '').replace("'", "").replace('\n', '').replace(' ', '') + + station_list["station_id"] = station_list.index station_list = station_list.round(decimals=3) - + # create VALUES('%s', '%s",...) one '%s' per column #values = "VALUES({})".format(",".join(["%s" for _ in df_columns])) diff --git a/dataacquisition/test_ExportToDatabase.py b/dataacquisition/test_ExportToDatabase.py index 9a54fa6e54d456b64cb40b98e95c86f9e94122f0..cd5f5f37227e486341d0822634da71d198f5c085 100644 --- a/dataacquisition/test_ExportToDatabase.py +++ b/dataacquisition/test_ExportToDatabase.py @@ -92,6 +92,7 @@ class TestExportToDatabase(unittest.TestCase): with open("./dataacquisition/pickle/stationList_with_temperature.pickle", "rb") as pickleFile: stationList = pickle.load(pickleFile) stationList = stationList.loc[stationList['country']=="Germany"] + stationList["station_id"] = stationList.index insert_stmt = cut.createInsertStatement(stationList)