Esempio n. 1
0
        public MostMentionedModule(
            IRepository<string, IEnumerable<Mention>> mentions, IIgnoredUserNamesService ignoredUserNamesService)
        {
            this.Get["/most-mentioned/{track}", true] = async (parameters, __) =>
            {
                // see https://github.com/NancyFx/Nancy/issues/1154
                var track = ((string)parameters.track).Replace("해시", "#");
                var trackMentions = (await mentions.GetAsync(track)).ToList();
                var entries = trackMentions
                    .Where(item => !ignoredUserNamesService.Get().Contains(item.UserMentionScreenName))
                    .GroupBy(mention => mention.UserMentionId)
                    .Select(g => new UserEntry
                    {
                        Id = g.Key,
                        IdStr = g.First().UserMentionIdStr,
                        Name = g.First().UserMentionName,
                        ScreenName = g.First().UserMentionScreenName,
                        Count = g.Count(),
                    })
                    .OrderByDescending(entry => entry.Count)
                    .Select((entry, index) =>
                    {
                        entry.Position = index + 1;
                        return entry;
                    })
                    .Take(10)
                    .ToList();

                return new Leaderboard<UserEntry>
                {
                    Entries = entries,
                    Count = trackMentions.Count,
                    Since = trackMentions.Any() ? trackMentions.Min(mention => mention.MentionedAt) : (DateTime?) null,
                    LastActivityDateTime = trackMentions.Any()? trackMentions.Max(mention => mention.MentionedAt): (DateTime?) null,
                };
            };
        }
Esempio n. 2
0
        public TopTweetersModule(
            IRepository <string, IEnumerable <Tweet> > tweets, IIgnoredUserNamesService ignoredUserNamesService)
        {
            this.Get["/top-tweeters/{track}", true] = async(parameters, __) =>
            {
                // see https://github.com/NancyFx/Nancy/issues/1154
                var track       = ((string)parameters.track).Replace("해시", "#");
                var trackTweets = (await tweets.GetAsync(track)).ToList();
                var entries     = trackTweets
                                  .Where(item => !ignoredUserNamesService.Get().Contains(item.UserScreenName))
                                  .GroupBy(tweet => tweet.UserId)
                                  .Select(g => new UserEntry
                {
                    Id         = g.Key,
                    Name       = g.First().UserName,
                    ScreenName = g.First().UserScreenName,
                    Count      = g.Count(),
                })
                                  .OrderByDescending(entry => entry.Count)
                                  .Select((entry, index) =>
                {
                    entry.Position = index + 1;
                    return(entry);
                })
                                  .Take(10)
                                  .ToList();

                return(new Leaderboard <UserEntry>
                {
                    Entries = entries,
                    Count = trackTweets.Count,
                    Since = trackTweets.Any() ? trackTweets.Min(tweet => tweet.TweetedAt) : (DateTime?)null,
                    LastActivityDateTime = trackTweets.Any() ? trackTweets.Max(tweet => tweet.TweetedAt) : (DateTime?)null,
                });
            };
        }
Esempio n. 3
0
 public Bootstrapper(IMongoDatabase mongoDatabase, IIgnoredUserNamesService ignoredUserNamesService, IIgnoredHashtagsService ignoredHashtagsService)
 {
     this.mongoDatabase           = mongoDatabase;
     this.ignoredUserNamesService = ignoredUserNamesService;
     this.ignoredHashtagsService  = ignoredHashtagsService;
 }
Esempio n. 4
0
 public Bootstrapper(IMongoDatabase mongoDatabase, IIgnoredUserNamesService ignoredUserNamesService)
 {
     this.mongoDatabase = mongoDatabase;
     this.ignoredUserNamesService = ignoredUserNamesService;
 }