static void Main(string[] args) { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => SentimentPreProcess.Transform(tweet, keywords)).Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Topic = tweet.Topic, Text = tweet.Text}); //var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, // keywords)).Select(tweet => SentimentPreProcess.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Topic = tweet.Topic, SentimentScore = tweet.SentimentScore }); datum.ToObservable().Subscribe(myEventHubObserver); }
static void Main(string[] args) { ReadConfig(); //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); var thread = new Thread(new ThreadStart(Program.DoHeartbeat)); thread.Start(); var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)) .Select(tweet => Sentiment.ComputeScore(tweet)) .Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, UtcOffset = tweet.UtcOffset, UserName = tweet.UserName, SentimentScore = tweet.SentimentScore }); datum.ToObservable().Subscribe(myEventHubObserver); }
static void Main(string[] args) { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); try { var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Topic = tweet.Topic, SentimentScore = tweet.SentimentScore, Text = tweet.Text, Location = tweet.Location, sentiment = tweet.Sentiment, ProfileImageUrl = tweet.ProfileImageUrl, hashtags = tweet.hashtag }); datum.ToObservable().Subscribe(myEventHubObserver); } catch { } }
public void ApiCalls() { var observer = new EventHubObserver<ApiCall>("apicalls"); var random = new Random(); var calls = new string[] { "A", "B", "C", "D", "E" }; while (true) { var size = random.Next(500, 3000); var e = new ApiCall { CallTime = DateTime.Now.ToUniversalTime() , Deployment = _name , Url = "http://www.sqlsatexpo.com/api/" + calls[random.Next(0, 5)] , Size = size , Elapsed = size/10 + random.Next(50, 150) }; observer.OnNext(e); Task.Delay(e.Elapsed + random.Next(0, 1000)); } }
public void AnalyzeData(string UserId) { if (!string.IsNullOrWhiteSpace(UserId)) { userId = UserId; try { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)). Where(tweet => tweet.Topic != "Unknown" && (tweetTimeZone.ToUpper().Contains(tweet.TimeZone.ToUpper()) || string.Compare(tweetTimeZone, "All") == 0) && DateTime.Compare(DateTime.Now, tweetEndTime) <= 0). Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, UserId = UserId, Topic = tweet.Topic, SentimentScore = tweet.SentimentScore, PlaceTimeZone = tweet.TimeZone, TweetText = tweet.Text, Retweeted = tweet.Retweeted, RetweetCount = tweet.RetweetCount }); datum.ToObservable().Subscribe(myEventHubObserver); } catch (Exception ex) { logger.Log(ex.StackTrace, LOGLEVELS.ERROR); } } }
public void CpuLoads() { var observer = new EventHubObserver<CpuUsage>("cpuUsage"); var random = new Random(); while (true) { var e = new CpuUsage { LogTime = DateTime.Now.ToUniversalTime() , Deployment = _name , Load = random.Next(0, 1000) / 10 }; observer.OnNext(e); Task.Delay(30000); } }
static void Main(string[] args) { /* Get hashtag phrase that will be listened to / analysed by the Text Analytics API from user input. Basic use is to ask user: * Which hashtag do you want to listen to? * Which Event Hub do you want to send the sentiment score to? */ //string hashtag = "microsoft"; //string eventhubName = ""; //string eventhubConn = ""; //Console.WriteLine("Enter hashtag phrase (without the #): "); //hashtag = Console.ReadLine(); //ConfigurationManager.AppSettings["twitter_keywords"] = hashtag; //Console.WriteLine("Enter Event Hub Name: "); //eventhubName = Console.ReadLine(); //Console.WriteLine("Enter Event Hub Connection String: "); //eventhubConn = Console.ReadLine(); //var config = new EventHubConfig(); //config.ConnectionString = eventhubConn; //config.EventHubName = eventhubName; //var myEventHubObserver = new EventHubObserver(config); //Console.WriteLine("START\n"); //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; var accountKey = ConfigurationManager.AppSettings["accountkey"]; //Configure EventHub (comment this out if using user input code above) var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubObserver = new EventHubObserver(config); //Azure ML Service string ServiceBaseUri = "https://api.datamarket.azure.com/"; var httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(ServiceBaseUri); string creds = "AccountKey:" + accountKey; string authorizationHeader = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(creds)); httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Original Sentiment demo code var datum = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt=Convert.ToDateTime(tweet.CreatedAt),Topic = tweet.Topic, SentimentScore= SentimentValue(tweet.Text,httpClient), Text = tweet.Text}); datum.ToObservable().Subscribe(myEventHubObserver); }