Пример #1
0
        private static IEnumerable <object> GetNUsersHaveHighestRep(DataSet DataSet, int N)
        {
            HtmlDocGen gen = new HtmlDocGen();

            DataTable usersTable = DataSet.Tables["Users"];

            var users = usersTable.AsEnumerable()
                        .GroupBy(row => row.Field <int>(GlobalDef.AttrToColumnNameDict["Reputation"]))
                        .OrderByDescending(group => group.Key)
                        .Take(N)
                        .SelectMany(group => group.Select(row =>
            {
                short?age = row.Field <short?>(GlobalDef.AttrToColumnNameDict["Age"]);
                return(new
                {
                    Reputation = group.Key,
                    Name = row.Field <string>(GlobalDef.AttrToColumnNameDict["DisplayName"]),
                    Location = row.Field <string>(GlobalDef.AttrToColumnNameDict["Location"]),
                    AboutMe = gen.GetFullHtmlDocAsString(row.Field <string>(GlobalDef.AttrToColumnNameDict["AboutMe"])),
                    Age = age.HasValue ? age.Value.ToString() : "None"
                });
            })
                                    );

            return(users);
        }
Пример #2
0
        private static IEnumerable <object> GetNQuestionsByScore(DataSet DataSet, int N)
        {
            DataTable postsTable = DataSet.Tables["Posts"];

            HtmlDocGen gen = new HtmlDocGen();

            var mostViewsQuestions = from row in postsTable.AsEnumerable()
                                     where row.Field <PostType>(GlobalDef.AttrToColumnNameDict["PostTypeId"]) == PostType.Question
                                     orderby row.Field <int>(GlobalDef.AttrToColumnNameDict["Score"]) descending
                                     select new
            {
                ViewCount = row.Field <uint>(GlobalDef.AttrToColumnNameDict["ViewCount"]),
                Score     = row.Field <int>(GlobalDef.AttrToColumnNameDict["Score"]),
                Title     = row.Field <string>(GlobalDef.AttrToColumnNameDict["Title"]),
                Body      = gen.GetFullHtmlDocAsString(row.Field <string>(GlobalDef.AttrToColumnNameDict["Body"])),
                Tags      = row.Field <string>(GlobalDef.AttrToColumnNameDict["Tags"])
            };

            return(mostViewsQuestions.Take(N));
        }