コード例 #1
0
ファイル: main.py プロジェクト: clubby2/ICT1002-Team-23
    def displayPlot(self):
        """Displays Visualisation of Data using MatPlotLib"""
        try:
            # retrieve combobox values
            graphtype = str(self.typeBox.currentText())
            xaxis = str(self.xBox.currentText())
            yaxis = str(self.yBox.currentText())
            plotType = str(self.plotBox.currentText())
            xval = int(xaxis[0])
            yval = int(yaxis[0])
            plotNone = None

            def defineplot(x):
                if x == "None":
                    return plotNone
                else:
                    a = int(x[0])
                    return a

            plotval = defineplot(plotType)
            # generates the plot (plot func is under modules)
            mod.plot(self.table, graphtype, xval, yval, plotval)
            plt.show()

        except Exception as e:
            mod.errorGUI(str(e))
            print e
コード例 #2
0
ファイル: main.py プロジェクト: clubby2/ICT1002-Team-23
    def importCSV(self):
        """Imports CSV and displays as table in GUI"""
        try:
            fileName = mod.openFileLocation(self)
            self.table = mod.fileUpload(fileName)
            self.csvTable.setSortingEnabled(True)
            # self.csvTable.setHorizontalHeaderLabels()
            self.csvTable.setModel(PandasModel(self.table))
            self.csvTable.resizeColumnsToContents()
            self.csvTable.show()

            # clears comboboxes to avoid repeat values when another CSV is imported
            self.xBox.clear()
            self.yBox.clear()
            self.plotBox.clear()

            # populate combobox values
            colVal = 0
            self.plotBox.addItem("None")
            for i in self.table.columns:
                colName = str(colVal) + ". " + i
                self.xBox.addItem(colName)
                self.yBox.addItem(colName)
                self.plotBox.addItem(colName)
                colVal += 1

        except Exception as e:
            # Display error message
            mod.errorGUI(str(e))
コード例 #3
0
ファイル: main.py プロジェクト: clubby2/ICT1002-Team-23
    def mergeCSV(self):
        """Merges another CSV with the currently open Pandas Dataframe"""
        try:
            fileName = mod.openFileLocation(self)
            table2 = mod.fileUpload(fileName)

            if collections.Counter(
                    self.table.columns.values) == collections.Counter(
                        table2.columns.values):
                newTable = pd.concat([self.table, table2])
                newTable = newTable.reset_index(drop=True)
            else:
                return ValueError("No matching columns found!")
                # newTable = pd.concat([self.table, table2], axis=1)

            self.table = newTable

            self.csvTable.setSortingEnabled(True)
            self.csvTable.setModel(PandasModel(self.table))
            self.csvTable.resizeColumnsToContents()
            self.csvTable.show()

        except Exception as e:
            # Display error message
            mod.errorGUI(str(e))
コード例 #4
0
    def exportPDF(self):
        """Exports the current Pandas Dataframe as a PDF File (No modifications is made)"""
        dateTimeFormat = time.strftime(
            "%Y%m%d-%H%M%S")  # Date and Time Format (YYYYMMDD-HHMMSS)
        config = pdf.configuration(
            wkhtmltopdf="wkhtmltopdf\\bin\\wkhtmltopdf.exe"
        )  # where the config file is located at

        try:
            if self.table.empty:
                raise ValueError("There is no data!")
            else:
                self.table.to_html(
                    'exportPDF.html')  # convert table data to html

                pdfFileName = 'tablePDF-' + dateTimeFormat + ".pdf"  # name file of the pdf file
                pdf.from_file('exportPDF.html',
                              pdfFileName,
                              configuration=config)  # convert html to pdf file

                os.remove('exportPDF.html')  # delete the html file
                mod.successGUI()  # prompt file downloaded

        except Exception as e:
            mod.errorGUI(str(e))
コード例 #5
0
    def importCSV(self):
        """Imports CSV and displays as table in GUI"""
        try:
            #prompts user for file location
            fileName = mod.openFileLocation(self)

            #populates dataframe with CSV data
            self.table = mod.fileUpload(fileName)

            #enables sorting for table by pressing the headers
            self.csvTable.setSortingEnabled(True)

            #sets and shows the table in GUI
            self.csvTable.setModel(PandasModel(self.table))
            self.csvTable.resizeColumnsToContents()
            self.csvTable.show()

            # clears comboboxes to avoid repeat values when another CSV is imported
            self.xBox.clear()
            self.yBox.clear()
            self.plotBox.clear()

            # populate combobox values in visualisation
            colVal = 0
            self.plotBox.addItem("None")
            for i in self.table.columns:
                colName = str(colVal) + ". " + i
                self.xBox.addItem(colName)
                self.yBox.addItem(colName)
                self.plotBox.addItem(colName)
                colVal += 1

        except Exception as e:
            # Display error message
            mod.errorGUI(str(e))
コード例 #6
0
    def mergeCSV(self):
        """Merges another CSV with the currently open Pandas Dataframe"""
        try:
            #prompts user for 2nd dataset and stores it as a separate dataframe
            fileName = mod.openFileLocation(self)
            table2 = mod.fileUpload(fileName)

            #if same columns are present, then it will merge with the existing dataframe. otherwise will not allow merging
            if collections.Counter(
                    self.table.columns.values) == collections.Counter(
                        table2.columns.values):
                newTable = pd.concat([self.table, table2])
                newTable = newTable.reset_index(drop=True)
            else:
                return ValueError("No matching columns found!")

            #initialises table
            self.table = newTable
            self.csvTable.setSortingEnabled(True)
            self.csvTable.setModel(PandasModel(self.table))
            self.csvTable.resizeColumnsToContents()
            self.csvTable.show()

        except Exception as e:
            # Display error message
            mod.errorGUI(str(e))
コード例 #7
0
ファイル: main.py プロジェクト: clubby2/ICT1002-Team-23
 def exportCSV(self):
     """Exports the current Pandas Dataframe (after merges and modifications) as a CSV File"""
     try:
         fileName = mod.saveFileLocation(self)
         self.table.to_csv(fileName, encoding='utf-8', index=False)
     except Exception as e:
         # Display error message
         mod.errorGUI(str(e))
コード例 #8
0
    def searchTable(self):
        """Searches the table and presents the search results as a view"""
        try:
            self.view = self.view.iloc[0:0]
            # search table and generates view
            searchQuery = str(self.search.text())

            #throws an error if there is no search value
            if searchQuery == "":
                raise ValueError("Please enter a search query!")

            # creates dictionary to hold the float, int and str values of the query
            queryDict = {'string': searchQuery}

            #if value can be an integer or float, it will convert accordingly. else it will set a default value of 0.
            try:
                queryDict['int'] = int(searchQuery)
                queryDict['float'] = float(searchQuery)
            except:
                queryDict['int'] = 0
                queryDict['float'] = 0.0

            # initialises the view dataframe
            for i in self.table.columns:
                loopQ = ""
                # sets the query datatype according to the type in the column
                if is_numeric_dtype(self.table[i].dtype):
                    loopQ = queryDict['int']
                    queryBool = self.table[i] == loopQ
                elif is_string_dtype(self.table[i].dtype):
                    loopQ = queryDict['string']
                    queryBool = self.table[i].str.contains(loopQ,
                                                           case=False,
                                                           regex=True)
                elif is_float_dtype(self.table[i].dtype):
                    loopQ = queryDict['float']
                    queryBool = self.table[i] == loopQ

                # if there are matches, add the rows to the view otherwise will show no result.
                if self.table[queryBool].empty is False:
                    self.view = pd.concat(
                        [self.view, self.table.loc[queryBool]])
                else:
                    continue
            # displays view
            if not self.view.empty:
                self.csvTable.setSortingEnabled(True)
                self.csvTable.setModel(PandasModel(self.view))
                self.csvTable.resizeColumnsToContents()
                self.csvTable.show()
            else:
                raise ValueError("No Value Found!")

        except Exception as e:
            mod.errorGUI(str(e))
コード例 #9
0
    def exportTXT(self):
        dateTimeFormat = time.strftime(
            "%Y%m%d-%H%M%S")  # Date and Time Format (YYYYMMDD-HHMMSS)
        try:
            if self.table.empty:
                raise ValueError("There is no data!")
            else:
                self.table.to_csv('tableTXT-' + dateTimeFormat + '.TXT',
                                  sep='\t')  # export data to TXT file
                mod.successGUI()  # prompt file downloaded

        except Exception as e:
            mod.errorGUI(str(e))
コード例 #10
0
 def exportCSV(self):
     """Exports the current Pandas Dataframe (after merges and modifications) as a CSV File"""
     try:
         fileName = mod.saveFileLocation(
             self)  # if search is valid export with the latest version
         if not self.view.empty:
             self.view.to_csv(fileName, encoding='utf-8', index=False)
             mod.successGUI()
         else:
             self.table.to_csv(fileName, encoding='utf-8', index=False)
             mod.successGUI()
     except Exception as e:
         # Display error message
         mod.errorGUI(str(e))
コード例 #11
0
    def displayLr(self):
        """Machine Learning - Linear Regression"""
        try:
            # retrieve combobox values
            xaxis = str(self.xBox.currentText())
            yaxis = str(self.yBox.currentText())
            plotType = str(self.plotBox.currentText())
            predictions = int(self.predictBox.currentText())
            x = int(xaxis[0])
            y = int(yaxis[0])
            z = str(self.plotBox_2.currentText())

            # generates the plot
            mod.plot_lr(self.table, x, y, z, plotType, predictions)

        except Exception as e:
            mod.errorGUI(str(e))
            print "mell"
コード例 #12
0
 def displayPlot(self):
     """Displays Visualisation of Data using MatPlotLib"""
     try:
         # retrieve combobox values
         graphtype = str(self.typeBox.currentText())
         xaxis = str(self.xBox.currentText())
         yaxis = str(self.yBox.currentText())
         plotType = str(self.plotBox.currentText())
         if xaxis == yaxis:
             raise ValueError("X and Y axis are the same")
         else:
             xval = int(xaxis[0])
             yval = int(yaxis[0])
         # set the plot value to be None if no columns are selected
         plotval = mod.defineplot(plotType)
         # generates the plot
         mod.plot(self.table, graphtype, xval, yval, plotval)
         #machine learning
         #Split the different graphs into section
         try:
             for i in yaxis:
                 if is_numeric_dtype(i):
                     if xaxis != yaxis:
                         self.plotBox_2.clear()
                         sections = []
                         for n in self.table[plotType[3:]]:
                             if n in sections:
                                 continue
                             else:
                                 sections.append(n)
                                 self.plotBox_2.addItem(n)
                         #load prediction options
                         x = self.table[self.table.columns[xval]].tail(1)
                         for a in range(1, 11):
                             next = int(x) + a
                             self.predictBox.addItem(str(next))
         except Exception as e:
             mod.errorGUI(
                 str(e) +
                 "\nMachine Learning will not work for this graph!")
             print e
     except Exception as e:
         mod.errorGUI(str(e))
         print e
コード例 #13
0
    def exportIMG_filter(self):
        """Exports the current Pandas Dataframe (after merges and modifications) as a IMG(.png) File"""
        dateTimeFormat = time.strftime(
            "%Y%m%d-%H%M%S")  # Date and Time Format (YYYYMMDD-HHMMSS)
        config = img.config(
            wkhtmltoimage="wkhtmltopdf\\bin\\wkhtmltoimage.exe")

        try:
            if self.view.empty:
                raise ValueError("There is no search data!")
            else:
                self.view.to_html('exportIMG_filter.html')
                img.from_file(
                    "exportIMG_filter.html",
                    "table_image_filter-" + dateTimeFormat + ".png",
                    config=config)  # from html change to img(.png) file
                os.remove('exportIMG_filter.html')  # delete html file
                mod.successGUI()  # prompt file downloaded

        except Exception as e:
            mod.errorGUI(str(e))