def test_sql_to_csv():
    """Checks the function that writes the SQL database to a CSV file."""
    csv_outfile = 'optwrf_database.csv'
    db_conn = conn_to_db('optwrf.db')
    sql_to_csv(csv_outfile, db_conn)
    close_conn_to_db(db_conn)
    assert os.path.exists(csv_outfile) == 1
def test_update_sim():
    """Checks to make sure that entries in the database can be updated."""
    # Generate a random set of parameters, a random start date, and a Chromosome
    r_start_date, r_end_date = sga.generate_random_dates()
    r_param_ids = wp.flexible_generate()
    individual = sga.Chromosome(r_param_ids,
                                fitness=100,
                                start_date=r_start_date,
                                end_date=r_end_date)
    # Put individual in the database
    db_conn = conn_to_db('optwrf_repeat.db')
    owp.insert_sim(individual, db_conn)
    print_database(db_conn)
    # Generate a new random start date and a Chromosome
    r_start_date, r_end_date = sga.generate_random_dates()
    individual = sga.Chromosome(r_param_ids,
                                fitness=50,
                                start_date=r_start_date,
                                end_date=r_end_date)
    # Update the individual in the database database
    owp.update_sim(individual, db_conn)
    print_database(db_conn)
def test_print_database():
    """Checks to see if the contnts of a database can be successfully printed to the screen."""
    db_conn = conn_to_db('optwrf.db')
    print_database(db_conn)
    close_conn_to_db(db_conn)
Exemplo n.º 4
0
"""
Write Contents of SQL Datatbase to CSV
======================================

This example shows how to dump the contents of the SQL optwrf database (optwrf.db)
to a CSV file, so it can be easily read.

"""
import optwrf.optimize_wrf_physics as owp

# Name of the csv file and optwrf database
#csv_outfile = 'optwrf_database.csv'
csv_outfile = 'optwrf_database_final_run_01.csv'
#sql_database = 'optwrf.db'
sql_database = 'optwrf.db'

# Connect to the sql database
db_conn = owp.conn_to_db(sql_database)

# Write the database contents to CSV
owp.sql_to_csv(csv_outfile, db_conn)

# Close connection to the sql database
owp.close_conn_to_db(db_conn)