Skip to content

Commit

Permalink
Changing name of results SQL database table.
Browse files Browse the repository at this point in the history
  • Loading branch information
astronomerritt committed Apr 9, 2024
1 parent dd43d86 commit c9a38e3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/sorcha/modules/PPOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ def PPOutWriteSqlite3(pp_results, outf):
None.
"""
pplogger = logging.getLogger(__name__)

pp_results = pp_results.drop("level_0", axis=1, errors="ignore")

cnx = sqlite3.connect(outf)

pp_results.to_sql("pp_results", con=cnx, if_exists="append", index=False)
pp_results.to_sql("sorcha_results", con=cnx, if_exists="append", index=False)

pplogger.info("SQL results saved in table sorcha_results in database {}.".format(outf))


def PPWriteOutput(cmd_args, configs, observations_in, endChunk=0, verbose=False):
Expand Down
10 changes: 5 additions & 5 deletions src/sorcha/utilities/createResultsSQLDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sorcha.modules.PPConfigParser import PPFindDirectoryOrExit


def create_results_table(cnx_out, filename, output_path, output_stem, table_name="pp_results"):
def create_results_table(cnx_out, filename, output_path, output_stem, table_name="sorcha_results"):
"""
Creates a table in a SQLite database from SSPP results.
Expand All @@ -35,7 +35,7 @@ def create_results_table(cnx_out, filename, output_path, output_stem, table_name
stem filename for SSPP outputs.
table_name : string, optional
name of table of for storing sorcha results. Default ="pp_results"
name of table of for storing sorcha results. Default ="sorcha_results"
Returns
-----------
Expand Down Expand Up @@ -71,7 +71,7 @@ def create_results_table(cnx_out, filename, output_path, output_stem, table_name
con = sqlite3.connect(filename)
cur = con.cursor()

cur.execute("SELECT * FROM pp_results")
cur.execute("SELECT * FROM sorcha_results")
output = cur.fetchall()

for row in output:
Expand Down Expand Up @@ -156,7 +156,7 @@ def create_results_database(args):
create_inputs_table(cnx_out, "comet")


def get_column_names(filename, table_name="pp_results"):
def get_column_names(filename, table_name="sorcha_results"):
"""
Obtains column names from a table in a SQLite database.
Expand All @@ -166,7 +166,7 @@ def get_column_names(filename, table_name="pp_results"):
Filepath/name of sqlite3 database.
table_name : string, optional
Name of table. Default = "pp_results"
Name of table. Default = "sorcha_results"
Returns
-----------
Expand Down
Binary file modified tests/data/sqlresults.db
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/sorcha/test_PPOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_PPOutWriteSqlite3(setup_and_teardown_for_PPOutWriteSqlite3):

cnx = sqlite3.connect(os.path.join(tmp_path, "test_sql_out.db"))
cur = cnx.cursor()
cur.execute("select * from pp_results")
cur.execute("select * from sorcha_results")
col_names = list(map(lambda x: x[0], cur.description))

test_in = pd.DataFrame(cur.fetchall(), columns=col_names)
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_PPWriteOutput(setup_and_teardown_for_PPWriteOutput):
PPWriteOutput(args, configs, observations, 10)
cnx = sqlite3.connect(os.path.join(tmp_path, "PPOutput_test_out.db"))
cur = cnx.cursor()
cur.execute("select * from pp_results")
cur.execute("select * from sorcha_results")
col_names = list(map(lambda x: x[0], cur.description))
sql_test_in = pd.DataFrame(cur.fetchall(), columns=col_names)

Expand Down
4 changes: 2 additions & 2 deletions tests/sorcha/test_createResultsSQLDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_create_results_table(tmp_path):

cnx_in = sqlite3.connect(os.path.join(tmp_path, "test_results_table.db"))
cur = cnx_in.cursor()
cur.execute("select * from pp_results")
cur.execute("select * from sorcha_results")
col_names = list(map(lambda x: x[0], cur.description))
test_inputs = pd.DataFrame(cur.fetchall(), columns=col_names)
cnx_out.close()
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_create_results_database(tmp_path):
col_names = list(map(lambda x: x[0], cur.description))
test_orbits = pd.DataFrame(cur.fetchall(), columns=col_names)

cur.execute("select * from pp_results")
cur.execute("select * from sorcha_results")
col_names = list(map(lambda x: x[0], cur.description))
test_results = pd.DataFrame(cur.fetchall(), columns=col_names)

Expand Down

0 comments on commit c9a38e3

Please sign in to comment.