def fillAddStocksComboBox(self):
        allStocksIDs = clientNetwork.clientNetwork().getAllStocksIDs()
        if allStocksIDs:
            allStocksIDs = list(allStocksIDs)

            myStocksIDs = clientNetwork.clientNetwork().getMyStocksIDs(
                self.userID)

            StocksList = []
            if myStocksIDs or isinstance(myStocksIDs, tuple):  ##
                # Remove myStocks from allStocks
                for myStockID in myStocksIDs:
                    for i, allStockID in enumerate(allStocksIDs):
                        if myStockID[0] == allStockID[0]:
                            del allStocksIDs[i]
                            break

            stocksListForComboBox = []
            for allStockID in allStocksIDs:
                stock = clientNetwork.clientNetwork().getStockByID(
                    allStockID[0])[0]
                stocksListForComboBox.append(
                    str(stock[0]) + ", \t" + str(stock[1]))

            self.addStocks_comboBox.clear()
            self.addStocks_comboBox.addItems(stocksListForComboBox)
        else:
            self.addStocks_comboBox.clear()
Exemple #2
0
    def __init__(self):

        clientNetwork.clientNetwork()
        isSignInAndID = signUpInGUILogic.start()
        isSignIn = isSignInAndID[0]
        if isSignIn:
            self.ID = isSignInAndID[1][0]
            ClientGUILogic.start(self.ID[0])
 def getMyStocks(self, ID):
     myStocksIDs = clientNetwork.clientNetwork().getMyStocksIDs(ID)
     if myStocksIDs:
         myStocksList = []
         for stockID in myStocksIDs:
             stockID = stockID[0]
             myStocksList.append(
                 clientNetwork.clientNetwork().getStockByID(stockID)[0])
         return tuple(myStocksList)
     else:
         print("Could not retrieve myStocksIDs, or is empty.")
    def addStockToUser(self):
        # Get symbol from combobox
        comboText = self.addStocks_comboBox.currentText()
        symbol = comboText.split(",")[1].lstrip()

        stockID = clientNetwork.clientNetwork().getStockIDBySymbol(symbol)

        if stockID:
            if clientNetwork.clientNetwork().addStockToUser(
                    self.userID, stockID[0][0]):
                # Update GUI
                self.fillMyStocks()
                self.fillAddStocksComboBox()
 def deleteStocks_pushButton_clicked(self):
     stockID = clientNetwork.clientNetwork().getStockIDBySymbol(
         self.selectedSymbolFromMyStocks)
     if stockID:
         isDelete = clientNetwork.clientNetwork().deleteStockByIDs(
             self.userID, stockID[0][0])
         if isDelete:
             # Update GUI
             self.fillMyStocks()
             self.fillAddStocksComboBox()
         else:
             print("Can not delete stock.")
     else:
         print("Can not delete stock.")
 def fillMyMessages(self):
     allMessages = clientNetwork.clientNetwork().getAllMessagesByUserID(
         self.userID)
     if allMessages:
         self.fillTable(self.myMessages_tableWidget, allMessages)
     else:
         self.myMessages_tableWidget.setRowCount(0)
    def getAllStocks(self):
        allStocks = clientNetwork.clientNetwork().getAllStocks()

        if isinstance(allStocks, bool) and allStocks == False:
            print("Could not retrieve all stocks.")
            return False

        return allStocks
    def fillStockInfo(self):
        # Fill info tab
        explanation = clientNetwork.clientNetwork().getExplanationBysymbol(
            self.selectedSymbolFromAllStocks)
        if explanation:
            self.explanation_textBrowser.setText(explanation[0][0])
        else:
            self.explanation_textBrowser.setText("")

        # Fill tweets tab
        stockID = clientNetwork.clientNetwork().getStockIDBySymbol(
            self.selectedSymbolFromAllStocks)
        if stockID:
            allTweets = clientNetwork.clientNetwork().getAllTweetsByStockID(
                stockID[0][0])
            if allTweets:
                self.fillTable(self.tweets_tableWidget, allTweets)
            else:
                self.tweets_tableWidget.setRowCount(0)
        else:
            self.tweets_tableWidget.setRowCount(0)
Exemple #9
0
    def signIn(self):
        # Get values
        email = self.email_lineEdit_2.text()
        password = self.password_lineEdit_2.text()

        arg = (email, password)

        response = clientNetwork.clientNetwork().signIn(arg)
        if isinstance(response, bool) and response == True:
            return True
        else:
            return response
Exemple #10
0
    def signUp(self):
        # Get values
        firstName = self.firstName_lineEdit.text()
        lastName = self.lastName_lineEdit.text()
        email = self.email_lineEdit.text()
        phoneNumber = self.phoneNumber_lineEdit.text()
        password = self.password_lineEdit.text()

        arg = (firstName, lastName, email, phoneNumber, password)

        response = clientNetwork.clientNetwork().signUp(arg)
        if isinstance(response, bool) and response == True:
            return True
        else:
            return response
Exemple #11
0
    def signIn_pushButton_clicked(self):
        # Check values
        isValid = self.checkSignInVlues()
        if isinstance(isValid, bool) and isValid == True:
            # Try signin
            isSignin = self.signIn()
            if isinstance(isSignin, bool) and isSignin == True:
                # Update flag
                self.isSignInn = True

                # Save userID
                self.userID = clientNetwork.clientNetwork().getIDByEmail(self.email_lineEdit_2.text())

                # Close signin window
                self.close()
            else:
                self.error_label_2.setText(str(isSignin))
        else:
            self.error_label_2.setText(str(isValid))
    def prepareGUI(self):
        # Full name
        fullName = clientNetwork.clientNetwork().getFullNameByID(self.userID)
        if fullName:
            firstName = fullName[0][0]
            lastName = fullName[0][1]
            self.helloUser_label.setText("Hello %s %s" % (firstName, lastName))

        # All stocks
        allStocks = self.getAllStocks()
        if allStocks:
            self.fillTable(self.allStocks_tableWidget, allStocks)

        # My stocks
        self.fillMyStocks()

        # Add stocks ComboBox
        self.fillAddStocksComboBox()

        # My messages
        self.fillMyMessages()
 def closeEvent(self, QCloseEvent):
     super().closeEvent(QCloseEvent)
     clientNetwork.clientNetwork().exit()
    def openGraphWindow(self):
        # Close if open
        plt.close()

        # Get x and y (The samples)
        xy = clientNetwork.clientNetwork().getXYForGraphByID(
            self.selectedSymbolFromAllStocks)
        X = np.array(xy[1])
        y = np.array(xy[0])

        if len(X) == 0 or len(y) == 0:
            return

        # Linear Regression with OLS algorithm
        linearReg = linear_model.LinearRegression()
        linearReg.fit(X, y)
        lineYLinearRegression = linearReg.predict(X)
        linearR2 = linearReg.score(X, y)
        print("Linear R^2=", linearR2)

        # Robust linear regression with RANSAC algorithm
        ransac = linear_model.RANSACRegressor()
        ransac.fit(X, y)
        inlier_mask = ransac.inlier_mask_
        outlier_mask = np.logical_not(inlier_mask)
        lineYRansac = ransac.predict(X)
        ransacR2 = ransac.score(X[inlier_mask], y[inlier_mask])
        print("RANSAC R^2=", ransacR2)

        # Polynomial regression with Ridge algorithm
        lw = 2
        for count, degree in enumerate([5, 6]):
            model = make_pipeline(PolynomialFeatures(degree),
                                  linear_model.Ridge())
            model.fit(X, y)
            curveYPolynomial = model.predict(X)
            plt.plot(X,
                     curveYPolynomial,
                     label="Polynomial degree %d" % degree)
            print("Polynomial R^2= %f (degree:%d)" %
                  (model.score(X, y), degree))

        # Draw plot
        # Inlier points
        plt.scatter(X[inlier_mask],
                    y[inlier_mask],
                    label='Inliers',
                    color='black',
                    linewidth=4)
        # Outlier points
        plt.scatter(X[outlier_mask],
                    y[outlier_mask],
                    label='Outliers',
                    color='black',
                    linewidth=2)
        # Lines
        plt.plot(X, lineYLinearRegression, label='Linear regressor')
        plt.plot(X, lineYRansac, label='RANSAC regressor')
        # Title, Labels and legend
        plt.title("Linear, Robust and Polynomial Regression \nFor %s" %
                  (self.selectedSymbolFromAllStocks))
        plt.xlabel("Sentiment")
        plt.ylabel("ChangClosePrice")
        plt.legend()  ##loc='lower right')

        plt.show()
Exemple #15
0
 def closeEvent(self, QCloseEvent):
     super().closeEvent(QCloseEvent)
     if not self.isSignInn:
         clientNetwork.clientNetwork().exit()