Example #1
0
    public Sentiments getSentiment(int sentiment_id)
    {
        Sentiments mySentiment = new Sentiments();

        SqlConnection connection = new SqlConnection(connectionString);
        string        query      = "SELECT * FROM Sentiments WHERE sentiment_id = @id";
        SqlCommand    command    = new SqlCommand(query);

        command.Parameters.Add("@id", SqlDbType.Int);
        command.Parameters["@id"].Value = sentiment_id;
        command.Connection  = connection;
        command.CommandType = CommandType.Text;

        try
        {
            command.Connection.Open();
            command.Prepare();
            SqlDataReader reader = command.ExecuteReader();
            //Coloumns Index
            int sentiment_idIndex     = reader.GetOrdinal("sentiment_id");
            int sentiment_totalIndex  = reader.GetOrdinal("sentiment_total");
            int category_primaryIndex = reader.GetOrdinal("category_primary");
            int key_phrasesIndex      = reader.GetOrdinal("key_phrases");
            int tweet_idIndex         = reader.GetOrdinal("tweet_id");

            if (reader.HasRows)
            {
                reader.Read();
                mySentiment.sentiment_id     = reader.GetInt32(sentiment_idIndex);
                mySentiment.sentiment_total  = reader.GetDouble(sentiment_totalIndex);
                mySentiment.category_primary = reader.GetString(category_primaryIndex);
                mySentiment.key_phrases      = reader.GetString(key_phrasesIndex);
                mySentiment.tweet_id         = reader.GetInt32(tweet_idIndex);
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
        }
        command.Connection.Close();
        command.Dispose();
        connection.Dispose();
        return(mySentiment);
    }
Example #2
0
    public int setSentiment(Sentiments sentiment)
    {
        int statusCode = -1;

        SqlConnection connection = new SqlConnection(connectionString);
        string        query      = "UPDATE Sentiments " +
                                   "SET sentiment_total = @sentiment_total, " +
                                   "category_primary = @category_primary, " +
                                   "key_phrases = @key_phrases, " +
                                   "tweet_id = @tweet_id " +
                                   "WHERE sentiment_id = @id;";
        SqlCommand command = new SqlCommand(query);

        command.Parameters.Add("@id", SqlDbType.Int).Value = sentiment.sentiment_id;

        command.Parameters.Add("@sentiment_total", SqlDbType.Decimal);
        command.Parameters["@sentiment_total"].Precision = 38;
        command.Parameters["@sentiment_total"].Scale     = 19;
        command.Parameters["@sentiment_total"].Value     = sentiment.sentiment_total;

        command.Parameters.Add("@category_primary", SqlDbType.VarChar, -1).Value = sentiment.category_primary;
        command.Parameters.Add("@key_phrases", SqlDbType.VarChar, -1).Value      = sentiment.key_phrases;
        command.Parameters.Add("@tweet_id", SqlDbType.Int).Value = sentiment.tweet_id;

        command.Connection  = connection;
        command.CommandType = CommandType.Text;

        try
        {
            command.Connection.Open();
            command.Prepare();
            statusCode = command.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
        }
        command.Connection.Close();
        command.Dispose();
        connection.Dispose();

        return(statusCode);
    }
Example #3
0
    public List <Sentiments> getSentiments()
    {
        List <Sentiments> sentiments = new List <Sentiments>();

        SqlConnection connection = new SqlConnection(connectionString);
        string        query      = "SELECT * FROM Sentiments";
        SqlCommand    command    = new SqlCommand(query);

        command.Connection  = connection;
        command.CommandType = CommandType.Text;

        try
        {
            command.Connection.Open();
            command.Prepare();
            SqlDataReader reader = command.ExecuteReader();
            //Column Indexs
            int sentiment_idIndex     = reader.GetOrdinal("sentiment_id");
            int sentiment_totalIndex  = reader.GetOrdinal("sentiment_total");
            int category_primaryIndex = reader.GetOrdinal("category_primary");
            int key_phrasesIndex      = reader.GetOrdinal("key_phrases");
            int tweet_idIndex         = reader.GetOrdinal("tweet_id");

            while (reader.Read())
            {
                Sentiments sentiment = new Sentiments();
                sentiment.sentiment_id     = reader.GetInt32(sentiment_idIndex);
                sentiment.sentiment_total  = (double)reader.GetDecimal(sentiment_totalIndex);
                sentiment.category_primary = reader.GetString(category_primaryIndex);
                sentiment.key_phrases      = reader.GetString(key_phrasesIndex);
                sentiment.tweet_id         = reader.GetInt32(tweet_idIndex);
                sentiments.Add(sentiment);
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
        }
        command.Connection.Close();
        command.Dispose();
        connection.Dispose();
        return(sentiments);
    }
Example #4
0
    public int getTextAnalyticsStartPoint()
    {//Get the last record ID which was
        Sentiments mySentiment = new Sentiments();

        SqlConnection connection = new SqlConnection(connectionString);
        string        query      = "SELECT TOP 1 * FROM Sentiments ORDER BY sentiment_id DESC";
        SqlCommand    command    = new SqlCommand(query);

        command.Connection  = connection;
        command.CommandType = CommandType.Text;

        try
        {
            command.Connection.Open();
            command.Prepare();
            SqlDataReader reader = command.ExecuteReader();
            //Coloumns Index
            int tweet_idIndex = reader.GetOrdinal("tweet_id");

            if (reader.HasRows)
            {
                reader.Read();
                mySentiment.tweet_id = reader.GetInt32(tweet_idIndex);
            }
        }
        catch (SqlException ex)
        {
            Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
        }
        command.Connection.Close();
        command.Dispose();
        connection.Dispose();

        if (mySentiment.tweet_id == null || mySentiment.tweet_id < 0)
        {
            mySentiment.tweet_id = 0;
        }

        return(mySentiment.tweet_id);
    }
Example #5
0
    public int addSentiment(Sentiments sentiment)
    {
        int statusCode = -1;

        SqlConnection connection = new SqlConnection(connectionString);
        string        query      = "INSERT INTO Sentiments (sentiment_total, category_primary, key_phrases, tweet_id) " +
                                   "OUTPUT INSERTED.sentiment_id " +
                                   "VALUES (@sentiment_total, @category_primary, @key_phrases, @tweet_id);";

        SqlCommand command = new SqlCommand(query);

        command.Parameters.Add("@sentiment_total", SqlDbType.Decimal);
        command.Parameters["@sentiment_total"].Precision = 38;
        command.Parameters["@sentiment_total"].Scale     = 19;
        command.Parameters["@sentiment_total"].Value     = sentiment.sentiment_total;

        command.Parameters.Add("@category_primary", SqlDbType.VarChar, -1).Value = sentiment.category_primary;
        command.Parameters.Add("@key_phrases", SqlDbType.VarChar, -1).Value      = sentiment.key_phrases;
        command.Parameters.Add("@tweet_id", SqlDbType.Int).Value = sentiment.tweet_id;
        command.Connection  = connection;
        command.CommandType = CommandType.Text;

        try
        {
            command.Connection.Open();
            command.Prepare();
            statusCode = (Int32)command.ExecuteScalar();
        }
        catch (SqlException ex)
        {
            Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
        }
        command.Connection.Close();
        command.Dispose();
        connection.Dispose();
        return(statusCode);
    }
Example #6
0
        public bool ProcessRules(StockInfo stockInfo, StockExchange stockExchange)//int ruleType, symbol, ruleXML
        {
            bool        result_TaLib               = false;
            bool        result_PriceBar            = false;
            bool        result_PrevioudDayPriceBar = false;
            bool        result_CurrentDayPriceBar  = false;
            bool        result_Indices             = false;
            bool        result_Sentiments          = false;
            bool        result_NASDAQindicator     = false;
            MarketQuote marketQoute = new MarketQuote();

            //create Stock object which is the feed for Codefeects rule engine
            Stock e_stock = new Stock();

            e_stock.Symbol          = stockInfo.stock_symbol;
            e_stock.StockID         = stockInfo.stock_ID;
            e_stock.StockExchangeID = stockExchange.stockExchange_ID;

            try
            {
                // fill with market data - open close high low

                marketQoute = APIReader.GetCurrentMarketData(stockInfo.stock_symbol, stockExchange);
            }
            catch (Exception)
            {
                Console.WriteLine("ERR in GetCurrentMarketData()");
            }

            result_CurrentDayPriceBar = MarketData.UpdateStockObjectWithMarketData(marketQoute, ref e_stock);

            //get History data
            List <Candle> candles = new List <Candle>();

            try
            {
                candles = APIReader.GetPriceHistory(stockInfo.stock_symbol, stockExchange);
            }
            catch (Exception)
            {
                Console.WriteLine("ERR in GetPriceHistory()");
            }


            //build a stock qoute object which will be used for all other calculations. this is holding data which needs for other analysis
            StockQuote stockQuote = new StockQuote();

            stockQuote.stock_candles = candles;

            //fill with previous day market data
            result_PrevioudDayPriceBar = MarketData.UpdateStockObjectWithPreviousDayData(stockQuote, ref e_stock);

            //fill with Talib values
            //   result_TaLib = TaLib.UpdateStockObjectWithTechnicalAnalysisData(stockQuote, ref e_stock);


            //get volatality factor)
            result_Indices = Indices.UpdateStockObjectWithIndicesData(stockQuote, ref e_stock);


            //Get sentinments)
            result_Sentiments = Sentiments.UpdateStockObjectWithSentimentData(ref e_stock);



            //get rule xml

            //if (ruleType == 1) //execute
            //{
            //    ///execute rule xml
            /// //// Get the rule XML


            //// Load Rule XML from the storage as a string
            List <CERule> rules = new List <CERule>();

            rules = ShareBook.App.Engine.Common.Data.DB.LoadRuleXml(1);
            foreach (CERule rule in rules)
            {
                Evaluator <Stock> evaluator = new Evaluator <Stock>(rule.RuleXml);

                try
                {
                    e_stock.RuleID = rule.RuleID;
                    // Evaluate the rule against the patient
                    bool success = evaluator.Evaluate(e_stock);
                }
                catch (DivideByZeroException)
                {
                    Console.WriteLine("ERR at rule evaluation-DivideByZeroException");
                    return(false);
                }
                catch (FormatException)
                {
                    Console.WriteLine("ERR at rule evaluation-FormatException");
                    return(false);
                }
            }
            return(true);
        }