Skip to content

Commit

Permalink
Add turbine names to postgres gui (#33)
Browse files Browse the repository at this point in the history
* add turbine names option to gui

* add an option to sort the cols so appear in order
  • Loading branch information
paulf81 authored Oct 25, 2022
1 parent 53d4d7a commit aa19969
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions flasc/raw_data_handling/sqldatabase_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ def print_properties(self):
print(" N.o. columns: %d." % len(cols))
print("")

def launch_gui(self):
def launch_gui(self, turbine_names=None, sort_columns=False):
root = tk.Tk()
sql_db_explorer_gui(master=root, dbc=self)

sql_db_explorer_gui(master=root, dbc=self, turbine_names=turbine_names, sort_columns=sort_columns)
root.mainloop()

def get_column_names(self, table_name):
Expand Down Expand Up @@ -256,7 +257,7 @@ def send_data(


class sql_db_explorer_gui:
def __init__(self, master, dbc):
def __init__(self, master, dbc, turbine_names = None, sort_columns=False):

# Create the options container
frame_1 = tk.Frame(master)
Expand Down Expand Up @@ -408,6 +409,12 @@ def mapper_func(evt):
# Set up the database connection
self.dbc = dbc

# Save the turbine names
self.turbine_names = turbine_names

# Save the sort columns
self.sort_columns = sort_columns

def channel_add(self):
if self.N_channels < self.N_channels_max:
ci = self.N_channels # New channel
Expand Down Expand Up @@ -463,11 +470,23 @@ def load_data(self):
]
col_mapping = dict(zip(old_col_names, new_col_names))
df = df.rename(columns=col_mapping)

# If specific turbine names are supplied apply them here
if self.turbine_names is not None:
columns = df.columns
for t in range(len(self.turbine_names)):
columns = [c.replace('%03d' % t,self.turbine_names[t]) for c in columns]
df.columns = columns

df_array.append(df)

# Merge dataframes
self.df = pd.concat(df_array, axis=1).reset_index(drop=False)

# If sorting the columns do it now
if self.sort_columns:
self.df = self.df[sorted(self.df.columns)]

self.update_channel_cols()
self.create_figures()
# # Clear all axes
Expand Down

0 comments on commit aa19969

Please sign in to comment.