public void GetHashTags(ref TwitterStatistics stats) { var hashtags = this.SnapshotTweetList.Where(p => p.Entities != null && p.Entities.Hashtags != null).Select(p => p.Entities.Hashtags); stats.HashTags = hashtags.Take(10); return; }
public void GetUrlCount(ref TwitterStatistics stats) { var entities = this.SnapshotTweetList.Where(p => p.Entities != null).Select(p => p.Entities); var urls = entities.Where(p => p.Urls != null).Select(p => p.Urls); stats.TweetsWithUrlCount = urls.Count(); }
public void GetUrlInfo(ref TwitterStatistics stats) { int picUrlCount = 0; int tweetCount = stats.TweetCount; float percentUrlsWithPic; float percentTweetsWithUrl; int urlCount = 0; var urls = this.TweetList.Where(p => p.Entities != null && p.Entities.Urls != null).Select(p => p.Entities.Urls).ToList(); urlCount = urls.Count; foreach (var url in urls) { foreach (var u in url) { if (u.DisplayUrl.ToLower().Contains("pic.twitter") || u.DisplayUrl.ToLower().Contains("instagram")) { ++picUrlCount; } Console.WriteLine($"Display: {u.DisplayUrl}, Expanded: {u.ExpandedUrl}, Unwound: {u.UnwoundUrl}, Url: {u.Url}"); } } percentUrlsWithPic = (float)picUrlCount / tweetCount; percentTweetsWithUrl = (float)urlCount / tweetCount; // Add url info to stats ... stats.TweetsWithPhotoUrlCount = picUrlCount; stats.PercentTweetsWithPhotoUrl = percentUrlsWithPic; stats.PercentTweetsWithUrl = percentTweetsWithUrl; }
public void GetTweetRates(ref TwitterStatistics stats) { float perSecond; float perMinute; float perHour; // Normalize the run time into seconds. stats.FromDateTime = this.StreamStartTime; stats.ToDateTime = DateTime.UtcNow; var runTime = stats.ToDateTime - stats.FromDateTime; stats.SampleTimeInSeconds = runTime.Seconds + (runTime.Minutes * MinutesAsSeconds) + (runTime.Hours * HoursAsSeconds); int sampleTimeInSeconds = stats.SampleTimeInSeconds; float minuteDenominator = (float)(sampleTimeInSeconds / (float)MinutesAsSeconds); float hourDenominator = (float)(sampleTimeInSeconds / (float)HoursAsSeconds); perSecond = sampleTimeInSeconds > 0 ? (float)stats.TweetCount / sampleTimeInSeconds : 0; perMinute = (float)(stats.TweetCount / (float)minuteDenominator); perHour = (float)(stats.TweetCount / (float)hourDenominator); stats.TweetsPerSecond = perSecond; stats.TweetsPerMinute = perMinute; stats.TweetsPerHour = perHour; }
/// <summary> /// Gets the twitter statistics. /// </summary> /// <returns></returns> public TwitterStatistics GetTwitterStatistics() { var stats = new TwitterStatistics(); if (this.TweetList == null) { return(stats); } // Take a snapshot of the current TweetList and report against those. this.SnapshotTweetList = this.TweetList.Take(this.TweetList.Count).ToList(); // Tweets - total and rates ... this.GetTweetCount(ref stats, Contract.Enums.TwitterCountType.PreReportingCount); this.GetTweetRates(ref stats); // URL info ... this.GetUrlCount(ref stats); // HashTag info ... this.GetHashTags(ref stats); //var entities = this.TweetList.Where(p => p.Entities != null).Select(p => p.Entities); //var urls = entities.Where(p => p.Urls != null).Select(p => p.Urls); //var hashTags = entities.Where(p => p.Hashtags != null).Select(p => p.Hashtags); // moved // Get the number of tweets that have arrived since we took our snapshot ... this.GetTweetCount(ref stats, Contract.Enums.TwitterCountType.PostReportingCount); this.SnapshotTweetList.Clear(); return(stats); }
/// <summary> /// Public constructor /// </summary> /// <param name="logger">DI logger</param> /// <param name="twitterStatistics">DI statistics class</param> public TwitterStreamService(IConfiguration configuration, ILogger <TwitterStreamService> logger, TwitterStatistics twitterStatistics) { _logger = logger; _twitterStatistics = twitterStatistics; _bearerToken = configuration["TwitterApi:BearerToken"]; }
public void GetTweetCount(ref TwitterStatistics stats, JHA.WebServices.Contract.Enums.TwitterCountType countType) { switch (countType) { case JHA.WebServices.Contract.Enums.TwitterCountType.PreReportingCount: stats.TweetCount = this.SnapshotTweetList.Count; break; case JHA.WebServices.Contract.Enums.TwitterCountType.PostReportingCount: var tweets = this.TweetList.Count; stats.TweetsSinceReporting = tweets - stats.TweetCount; break; default: break; } }
public void GetTwitterStatistics_Test() { // Arrange TwitterStatistics stats; // Act stats = new TwitterStatistics(); // Assert Assert.IsNotNull(stats.EmojiList); Assert.IsEmpty(stats.EmojiList); Assert.IsNotNull(stats.HashTags); Assert.IsEmpty(stats.HashTags); Assert.IsNotNull(stats.UrlList); Assert.IsEmpty(stats.UrlList); Assert.AreEqual(0, stats.TweetCount); Console.WriteLine($"Twitter statistics: {stats.ToString()}"); }
public void GetEmojiInfo(ref TwitterStatistics stats) { throw new NotImplementedException(); }
public void GetEmojiInfo(ref TwitterStatistics stats) { // TODO: get emoji info (top emojis) // Need to determine where emoji are located in the Twitter Feed. return; }
public void GetEmojiCount(ref TwitterStatistics stats) { // TODO: get emoji count // Need to determine where emoji are located in the Twitter Feed. return; }
/// <summary> /// Public constructor /// </summary> /// <param name="twitterStatistics">DI TwitterStatistics Singleton</param> public TwitterStatisticsController(TwitterStatistics twitterStatistics) { _twitterStatistics = twitterStatistics; }