Exemplo n.º 1
0
    def test_season_end(self):
        default_end = "10/20"
        Ekans.update_season_end_date(default_end)
        season_end=\
         DatabaseInteractor.read_database_query(("select DefaultValue from SystemInputTags where description =\"BatSeasonEndDate\""))
        self.assertTrue(default_end == str(season_end))

        season_end = \
         DatabaseInteractor.read_database_query(("select EndTimePeriod from MultipleSeasonDefaultValues where EnableForPeriod =\"True\""))
        self.assertTrue(default_end == str(season_end))

        season_end_row_id = \
         DatabaseInteractor.read_database_query(("select rowid from MultipleSeasonDefaultValues where EnableForPeriod =\"True\""))+1
        next_season_start = DatabaseInteractor.read_database_query((
            f"select StartTimePeriod from MultipleSeasonDefaultValues where rowid=\"{(season_end_row_id)}\""
        ))
        test_ed = f"10/20/{datetime.datetime.now().year}"
        format = "%m/%d/%Y"
        end_dt = datetime.datetime.strptime(test_ed, format)
        t = datetime.timedelta(days=1)
        expected_start = (end_dt + t).strftime("%m/%d")
        self.assertTrue(
            next_season_start == expected_start,
            f"next_season_start {next_season_start} expected start {expected_start}"
        )
Exemplo n.º 2
0
    def test_tuple_list_insert(self):
        query = 'INSERT INTO TurbineINputTags VALUES (?,?,?,?,?,?,?,?,?,?)'
        rows = [
            ('T300', 'Zubat.T300.Participation', 'T300.WTUR.TURST.ACTST',
             'T300.WNAC.ExTmp', 'T300.WNAC.WdSpd', '',
             'T300.WTUR.SetTurOp.ActSt.Stop', 'T300.WTUR.SetTurOp.ActSt.Str',
             'Zubat.T300.PauseTimeOut', 'Met'),
            ('T300', 'Zubat.T300.Participation', 'T300.WTUR.TURST.ACTST',
             'T300.WNAC.ExTmp', 'T300.WNAC.WdSpd', '',
             'T300.WTUR.SetTurOp.ActSt.Stop', 'T300.WTUR.SetTurOp.ActSt.Str',
             'Zubat.T300.PauseTimeOut', 'Met'),
            ('T300', 'Zubat.T300.Participation', 'T300.WTUR.TURST.ACTST',
             'T300.WNAC.ExTmp', 'T300.WNAC.WdSpd', '',
             'T300.WTUR.SetTurOp.ActSt.Stop', 'T300.WTUR.SetTurOp.ActSt.Str',
             'Zubat.T300.PauseTimeOut', 'Met')
        ]
        DatabaseInteractor.execute_many_database_query(query, rows)

        read_query = "SELECT * from TurbineInputTags where TurbineId=='T300'"
        connection = DatabaseInteractor.connect_to_database()
        result = connection.cursor().execute(read_query).fetchall()
        self.assertIsNotNone(result)
        self.assertTrue(len(result) == 3)
        delete_query = "DELETE from TurbineInputTags where TurbineId=='T300'"
        DatabaseInteractor.execute_database_query(delete_query)
        connection.close()
Exemplo n.º 3
0
def insert_to_turbine_input_table(csv_map):
    table = "TurbineInputTags"
    num_turbines_in_csv = int(
        CsvInteractor.get_number_of_turbines_in_csv(csv_map))
    cut_off_turbine_num = int(
        re.search('\d+', CsvInteractor.get_met_backup(csv_map)).group(0))
    num_met_tower = int(CsvInteractor.get_num_met_tower(csv_map))
    list_of_backup_turbines = CsvInteractor.get_turbine_backup(csv_map).split(
        ',')
    print(list_of_backup_turbines)

    #Starts from 2 because T001 is already in the DB
    insert_rows = []
    for i in range(2, num_turbines_in_csv + 1):
        met_id = "Met"
        if (i > cut_off_turbine_num) and (num_met_tower > 1):
            met_id = "Met2"
        turbine_id = build_turbine_id(i)
        row = get_default_row(table)
        backup_flag = ""
        new_turbine_tuple = generate_new_input_tag_row(
            list(row[0]), turbine_id, met_id, list_of_backup_turbines)
        insert_rows.append(new_turbine_tuple)
    query = f"INSERT INTO {table} VALUES (?,?,?,?,?,?,?,?,?,?)"
    DatabaseInteractor.execute_many_database_query(query, insert_rows)
    return
Exemplo n.º 4
0
    def test_insert_to_db(self):

        query = f"INSERT into TurbineInputTags VALUES ('Test','Test','Test','Test','Test','Test','Test','Test','Test','Test')"
        DatabaseInteractor.execute_database_query(query)
        number_of_turbines = DatabaseInteractor.get_number_of_turbines_in_database(
        )
        self.assertTrue(number_of_turbines >= 104)
Exemplo n.º 5
0
 def test_update_evaluation_time(self):
     Ekans.update_evaluation_time()
     result = DatabaseInteractor.read_database_query(
         f"select defaultvalue from systeminputtags where description = 'EvaluationPeriod'"
     )
     print(result)
     self.assertTrue(result == '10')
Exemplo n.º 6
0
 def test_update_longitude(self):
     default_lon = -122.60917
     Ekans.update_longtitude(default_lon)
     lon = DatabaseInteractor.read_database_query(
         "select DefaultValue from SystemInputTags where description = \"Lon\""
     )
     self.assertTrue(lon == str(default_lon))
Exemplo n.º 7
0
 def test_update_UTC(self):
     default_UTC = -8
     Ekans.update_utc(default_UTC)
     lon = DatabaseInteractor.read_database_query(
         "select DefaultValue from SystemInputTags where description = \"UTCOffset\""
     )
     self.assertTrue(lon == str(default_UTC))
Exemplo n.º 8
0
 def test_update_site_name(self):
     site_prefix = "DESER"
     Ekans.update_site_name(site_prefix)
     site_name = DatabaseInteractor.read_database_query(
         "select DefaultValue from SystemInputTags where description = \"SitePrefix\""
     )
     self.assertTrue(site_name == site_prefix)
Exemplo n.º 9
0
 def test_update_latitude(self):
     default_lat = 45.59578
     Ekans.update_latitude(default_lat)
     lat = DatabaseInteractor.read_database_query(
         "select DefaultValue from SystemInputTags where description = \"Lat\""
     )
     self.assertTrue(str(lat) == str(default_lat))
Exemplo n.º 10
0
def insert_to_turbine_output_table(csv_map):
    table = "TurbineOutputTags"
    num_turbines_in_csv = int(
        CsvInteractor.get_number_of_turbines_in_csv(csv_map))
    #You'll also have to deal wit hthe met tower, but do this later
    #Starts from 2 because T001 is already in the DB
    insert_rows = []
    for i in range(2, num_turbines_in_csv + 1):
        turbine_id = build_turbine_id(i)
        row = get_default_row(table)
        new_turbine_tuple = generate_new_output_tag_row(
            list(row[0]), turbine_id)
        insert_rows.append(new_turbine_tuple)
    query = f"INSERT INTO {table} VALUES (?,?,?,?,?,?,?,?,?,?,?)"
    DatabaseInteractor.execute_many_database_query(query, insert_rows)
    return
Exemplo n.º 11
0
 def test_backup_turbine_update(self):
     dummy_row = "T001,Zubat.T001.Participation,T001.WTUR.TURST.ACTST," \
                  "T001.WNAC.ExTmp,T001.WNAC.WdSpd,,T001.WTUR.SetTurOp.ActSt.Stop," \
                  "T001.WTUR.SetTurOp.ActSt.Str,Zubat.T001.PauseTimeOut,Met".split(',')
     backup_turbines = "T001,T003,T049,T099".split(',')
     self.assertTrue(Ekans.is_backup_turbine(dummy_row[0], backup_turbines))
     self.assertFalse(Ekans.is_backup_turbine(dummy_row[0], ''))
     if (Ekans.is_backup_turbine(dummy_row[0], backup_turbines)):
         Ekans.make_turbine_backup(dummy_row[0])
     result = DatabaseInteractor.read_database_query(
         f"select isbackupturbine from TurbineInputTags where TurbineId = '{dummy_row[0]}'"
     )
     self.assertTrue(result)
     DatabaseInteractor.execute_database_query(
         f"Update Turbineinputtags set isbackupturbine='' where TurbineId='{dummy_row[0]}'"
     )
Exemplo n.º 12
0
    def test_season_start(self):
        default_start = "07/20"
        Ekans.update_season_start_date(default_start)
        season_start=\
         DatabaseInteractor.read_database_query(("select DefaultValue from SystemInputTags where description =\"BatSeasonStartDate\""))
        self.assertTrue(default_start == str(season_start))
        season_start=\
         DatabaseInteractor.read_database_query(("select StartTimePeriod from MultipleSeasonDefaultValues where EnableForPeriod =\"True\""))
        self.assertTrue(default_start == str(season_start), )

        season_start_row_id = \
         DatabaseInteractor.read_database_query(("select rowid from MultipleSeasonDefaultValues where EnableForPeriod =\"True\""))-1
        prev_end_date = DatabaseInteractor.read_database_query((
            f"select EndTimePeriod from MultipleSeasonDefaultValues where rowid=\"{(season_start_row_id)}\""
        ))
        test_ed = f"07/20/{datetime.datetime.now().year}"
        format = "%m/%d/%Y"
        end_dt = datetime.datetime.strptime(test_ed, format)
        t = datetime.timedelta(days=-1)
        expected_end_date = (end_dt + t).strftime("%m/%d")
        self.assertTrue(
            prev_end_date == expected_end_date,
            f"previous end date {prev_end_date} expected end date {expected_end_date}"
        )
Exemplo n.º 13
0
def update_season_end_date(end_date):
    query = f"Update SystemInputTags set DefaultValue = \"{end_date}\" where Description=\"BatSeasonEndDate\""
    execute_database_query(query)

    query = f"Update MultipleSeasonDefaultValues set EndTimePeriod = \"{end_date}\" where EnableForPeriod=\"True\""
    execute_database_query(query)

    end_date_datetime = datetime.datetime.strptime(
        f"{end_date}/{datetime.datetime.now().year}", "%m/%d/%Y")
    timedelta = datetime.timedelta(days=1)
    row = DatabaseInteractor.read_database_query((
        "select rowid from MultipleSeasonDefaultValues where EnableForPeriod =\"True\""
    )) + 1
    next_start_date = (end_date_datetime + timedelta).strftime("%m/%d")
    query = f"Update MultipleSeasonDefaultValues set StartTimePeriod = \"{next_start_date}\" where rowid=\"{row}\""
    execute_database_query(query)
Exemplo n.º 14
0
def insert_new_met_tower_row(met_id):
    table = "MetTowerInputTags"
    default_met_row = DatabaseInteractor.read_database_row(
        f"Select * from {table} Where MetId='Met'")
    new_row = [
        tuple([item.replace("Met", met_id) for item in default_met_row[0]])
    ]
    print(new_row)
    query = f"Insert into {table} Values (?,?,?,?)"
    DatabaseInteractor.execute_many_database_query(query, new_row)

    table = "MetTowerOutputTags"
    default_met_row = DatabaseInteractor.read_database_row(
        f"Select * from {table} Where MetId='Met'")
    new_row = [
        tuple([item.replace("Met", met_id) for item in default_met_row[0]])
    ]
    print(new_row)
    query = f"Insert into {table} Values (?,?,?,?,?,?,?,?)"
    DatabaseInteractor.execute_many_database_query(query, new_row)
Exemplo n.º 15
0
def update_evaluation_time():
    DatabaseInteractor.execute_database_query(
        f"Update SYsteminputTags set defaultvalue = '10' where description = 'EvaluationPeriod'"
    )
Exemplo n.º 16
0
 def test_remove_from_db(self):
     query = f"Delete from TurbineInputTags WHERE TurbineId=\"Test\""
     DatabaseInteractor.execute_database_query(query)
     number_of_turbines = DatabaseInteractor.get_number_of_turbines_in_database(
     )
     self.assertTrue(number_of_turbines == 104)
Exemplo n.º 17
0
def update_met_tower_temp_tag(met_id, tag):
    table = "MetTowerInputTags"
    modified_tag = tag.replace("Met", met_id)
    query = f"Update {table} set TempValueTag='{modified_tag}' where MetId='{met_id}'"
    DatabaseInteractor.execute_database_query(query)
Exemplo n.º 18
0
 def test_read_from_sql(self):
     number_of_turbines = DatabaseInteractor.get_number_of_turbines_in_database(
     )
     self.assertTrue(number_of_turbines == 104)
Exemplo n.º 19
0
 def test_database_connection(self):
     self.assertIsNotNone(DatabaseInteractor.connect_to_database())
Exemplo n.º 20
0
 def test_configuration_DB_exists(self):
     fileExists = DatabaseInteractor.configuration_db_exists()
     self.assertTrue(fileExists)
Exemplo n.º 21
0
def make_turbine_backup(turbine_Id):
    DatabaseInteractor.execute_database_query(
        f"Update TurbineInputTags set IsBackupTurbine = 'true' where TurbineId = '{turbine_Id}'"
    )
Exemplo n.º 22
0
def get_default_row(turbine_table):
    return DatabaseInteractor.read_database_row(
        f"SELECT * from {turbine_table} WHERE TurbineId=='T001'")