Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI #2753

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open

GUI #2753

Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6144e25
added gui example
arminm22 Aug 1, 2024
801cb47
added text
arminm22 Aug 2, 2024
603142c
Added docstring
arminm22 Aug 3, 2024
1cf880d
Added documentation
arminm22 Aug 4, 2024
5b3677f
Update start.py
arminm22 Aug 5, 2024
b26a11b
Update start.py
arminm22 Aug 6, 2024
b86581e
Update start.py
arminm22 Aug 7, 2024
eb585a8
Update start.py
arminm22 Aug 8, 2024
e9a8905
Update start.py
arminm22 Aug 9, 2024
a1a185f
Update start.py
arminm22 Aug 10, 2024
563091f
Update start.py
arminm22 Aug 11, 2024
0e635b4
Update start.py
arminm22 Aug 12, 2024
88981c3
Update start.py
arminm22 Aug 13, 2024
33333b3
Update start.py
arminm22 Aug 14, 2024
a2851c0
Update start.py
arminm22 Aug 15, 2024
1179938
Update start.py
arminm22 Aug 16, 2024
7692bc8
Update start.py
arminm22 Aug 17, 2024
3efad87
Update start.py
arminm22 Aug 18, 2024
1eca1bc
Update start.py
arminm22 Aug 19, 2024
ee5169c
Update start.py
arminm22 Aug 21, 2024
631101d
Update start.py
arminm22 Aug 22, 2024
92c35cf
Update start.py
arminm22 Aug 23, 2024
951f2e7
Update start.py
arminm22 Aug 24, 2024
8b4cfcb
Update start.py
arminm22 Aug 25, 2024
27177f1
Update start.py
arminm22 Aug 26, 2024
fdcee47
Update start.py
arminm22 Aug 27, 2024
d2fee0c
Update start.py
arminm22 Aug 28, 2024
810589b
Update start.py
arminm22 Aug 29, 2024
4db386c
Update start.py
arminm22 Aug 30, 2024
aa865f6
Update start.py
arminm22 Aug 31, 2024
3995d8f
Update start.py
arminm22 Sep 1, 2024
6e301c7
Update start.py
arminm22 Sep 2, 2024
ac9e91e
Update start.py
arminm22 Sep 3, 2024
c3f5797
Update start.py
arminm22 Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update start.py
arminm22 authored Sep 4, 2024
commit c3f5797d079da90be3e940ea7f8cc1344a1a6f7a
206 changes: 163 additions & 43 deletions featuretools/gui/start.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,176 @@
"""
This module provides a GUI to merge 2 CSV-files containing data-sets into one
using deep feature sythesis.
"""

import wx
import pandas as pd
import featuretools as ft
import warnings

# Disable all warnings
warnings.filterwarnings("ignore")


VERT_SPACE = 40
LEFT_MARGIN = 10


class Frame(wx.Frame):

"""
This class contains all the GUI-functions
"""

def __init__(self, parent, title):
super().__init__(parent, title=title, size=(400, 300))
#Create panels
self.panel1 = wx.Panel(self)
super().__init__(parent, title=title, size=(600, 800))

# Create panel
self.panel = wx.Panel(self)

# List of chosen files
self.chosen_files = []
# Create variables
self.filepath_1 = ""
self.filepath_2 = ""

# Primary key
self.primary_key = ""
# Directory to save csv-file
self.directory = ""

# Text area for primary key
self.text_area = wx.TextCtrl(self.panel1)

# Create file picker
self.file_picker = wx.FilePickerCtrl(self.panel1, style=wx.FLP_DEFAULT_STYLE)
# Text area for primary keys
self.text_area_1 = wx.TextCtrl(self.panel)
self.text_area_2 = wx.TextCtrl(self.panel)

# Create description labels
self.description_label_1 = wx.StaticText(self.panel1, label="Choose multiple files:")
description_1 = "Select 2 CSV-files and merge them into 1 using deep feature synthesis\n"
description_2 = "The primary key of file 1 must be also present in file 2"

# Description labels
self.general_description = wx.StaticText(
self.panel, label=description_1+description_2)
self.user_information = wx.StaticText(self.panel, label="")
self.path_1_label = wx.StaticText(self.panel, label="")
self.key_1_label = wx.StaticText(
self.panel, label="Primary key of file 1:")
self.path_2_label = wx.StaticText(self.panel, label="")
self.key_2_label = wx.StaticText(
self.panel, label="Primary key of file 2:")

self.description_label_2 = wx.StaticText(self.panel1, label="Choose a primary key:")

# Create static text control
self.file_name_label = wx.StaticText(self.panel1, label="")

# Create and bind button
self.button1 = wx.Button(self.panel1, label="Continue")
self.Bind(wx.EVT_BUTTON, self.button_pressed, self.button1)

# Layout controls manually
self.description_label_1.SetPosition((10,10))
self.file_picker.SetPosition((10, 40))
self.button1.SetPosition((150,40))
self.description_label_2.SetPosition((10,80))
self.text_area.SetPosition((10,120))
self.file_name_label.SetPosition((10, 160))

# Bind file picker change event
self.file_picker.Bind(wx.EVT_FILEPICKER_CHANGED, self.on_file_changed)


def on_file_changed(self, event):
file_path = self.file_picker.GetPath()
self.chosen_files.append(file_path)
self.file_name_label.SetLabel('\n'.join(self.chosen_files))

def button_pressed(self,event):
self.primary_key = self.text_area.GetValue()

self.file_name_label = wx.StaticText(self.panel, label="")

# Create and bind buttons
self.pick_1_button = wx.Button(self.panel, label='Pick file 1:')
self.Bind(wx.EVT_BUTTON, self.on_pick_file_1, self.pick_1_button)

self.pick_2_button = wx.Button(self.panel, label='Pick file 2:')
self.Bind(wx.EVT_BUTTON, self.on_pick_file_2, self.pick_2_button)

self.continue_button = wx.Button(self.panel, label="Continue")
self.Bind(wx.EVT_BUTTON, self.continue_pressed, self.continue_button)

# Layout control
self.general_description.SetPosition((LEFT_MARGIN, VERT_SPACE*1))

self.pick_1_button.SetPosition((LEFT_MARGIN, VERT_SPACE*4))
self.path_1_label.SetPosition((LEFT_MARGIN, VERT_SPACE*5))
self.key_1_label.SetPosition((LEFT_MARGIN, VERT_SPACE*6))
self.text_area_1.SetPosition((LEFT_MARGIN, VERT_SPACE*7))

self.pick_2_button.SetPosition((LEFT_MARGIN, VERT_SPACE*9))
self.path_2_label.SetPosition((LEFT_MARGIN, VERT_SPACE*10))
self.key_2_label.SetPosition((LEFT_MARGIN, VERT_SPACE*11))
self.text_area_2.SetPosition((LEFT_MARGIN, VERT_SPACE*12))

self.continue_button.SetPosition((LEFT_MARGIN, VERT_SPACE*14))
self.user_information.SetPosition((LEFT_MARGIN, VERT_SPACE*16))

def continue_pressed(self, event):
"""
Action when continue-button is pressed
First asks for a directory to save the result,
then the data-processing starts
"""

if not self.check_fields():
self.user_information.SetLabel("Error: Missing values")
return False

with wx.DirDialog(self, "Choose a directory to save the new file", style=wx.DD_DEFAULT_STYLE) as dialog:
if dialog.ShowModal() == wx.ID_OK:
self.directory = dialog.GetPath()

# Error handling
try:
self.process_data()
self.user_information.SetLabel(
"File result.csv has been generated")
except:
self.user_information.SetLabel(
" Error: Wrong information \n Check keys and dataset")

def process_data(self):
"""The acutal data processing and saving"""

# Load the data into dataframes
df1 = pd.read_csv(self.filepath_1)
df2 = pd.read_csv(self.filepath_2)

# Load primary keys:
pk1 = self.text_area_1.GetValue()
pk2 = self.text_area_2.GetValue()

# Create a new EntitySet
entities = {
"data1": (df1, pk1),
"data2": (df2, pk2),
}

# Add a relationship between datasets
relationships = [("data1", pk1, "data2", pk1)]

# Run deep feature synthesis to automatically generate features
feature_matrix, features_defs = ft.dfs(
dataframes=entities,
relationships=relationships,
target_dataframe_name="data1",
)

print(feature_matrix)

dir_and_filename = self.directory+'result.csv'

feature_matrix.to_csv(dir_and_filename)

def on_pick_file_1(self, event):
self.pick_file(1)

def on_pick_file_2(self, event):
self.pick_file(2)

def pick_file(self, filenumber):
"""File dialog"""

with wx.FileDialog(self, "Open a file", wildcard="CSV files (*.csv)|*.csv",
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_OK:
# Get the selected file path
filepath = fileDialog.GetPath()

if filenumber == 1:
self.filepath_1 = filepath
self.path_1_label.SetLabel(filepath)
else:
self.filepath_2 = filepath
self.path_2_label.SetLabel(filepath)

def check_fields(self):
"""Checks if necessary fields are empty"""

if self.text_area_1 == "" or self.text_area_2 == "":
return False
if self.filepath_1 == "" or self.filepath_2 == "":
return False

return True


if __name__ == '__main__':
app = wx.App()