示例#1
0
        private void DisplayArticles()
        {
            Guid session = new Guid();

            //we've never seen this user before or they've cleared their cookies
            if (Request.Cookies["session"] != null && Guid.TryParse(Request.Cookies["session"].Value, out session))
            {
                int userID = Auth.checkSession(session);
                if (userID != 0)
                {
                    List <string> IPList = RatingHelper.GetImprovementProgramList();

                    List <Tuple <string, double> > RatedArticles = RatingHelper.GetAllRatedArticles(userID, "rated", 0, 10);


                    DataTable dt = new DataTable();
                    dt.Columns.Add("Article");
                    dt.Columns.Add("Rated", System.Type.GetType("System.String"));
                    dt.Columns.Add("RatedStyle", System.Type.GetType("System.String"));

                    foreach (string article in IPList)
                    {
                        bool found = false;
                        foreach (Tuple <string, double> ratedArt in RatedArticles)
                        {
                            if (article == ratedArt.Item1)
                            {
                                DataRow dr = dt.NewRow();
                                //encode
                                dr["Article"]    = Server.HtmlEncode(article);
                                dr["Rated"]      = "Rated";
                                dr["RatedStyle"] = "Rated";

                                dt.Rows.Add(dr);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            DataRow dr = dt.NewRow();
                            //encode
                            dr["Article"]    = Server.HtmlEncode(article);
                            dr["Rated"]      = "Not Yet";
                            dr["RatedStyle"] = "NotRated";

                            dt.Rows.Add(dr);
                        }
                    }
                    dt.DefaultView.Sort   = "Article";
                    IPListView.DataSource = dt.DefaultView;
                    IPListView.DataBind();
                }
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            double lowerBound = Settings.Default.defaultLowerBound;
            double upperBound = Settings.Default.defaultUpperBound;
            bool   hasLower   = false;
            bool   hasUpper   = false;

            if (Request["lowerBound"] != null &&
                !string.IsNullOrEmpty(Request["lowerBound"]))
            {
                hasLower = double.TryParse(Request["lowerBound"], out lowerBound);
            }

            if (Request["upperBound"] != null &&
                !string.IsNullOrEmpty(Request["upperBound"]))
            {
                hasUpper = double.TryParse(Request["upperBound"], out upperBound);
            }

            //if (hasLower || hasUpper)
            //{
            int  userID  = 0;
            Guid session = new Guid();

            //we've never seen this user before or they've cleared their cookies
            if (Request.Cookies["session"] != null && Guid.TryParse(Request.Cookies["session"].Value, out session))
            {
                userID = Auth.checkSession(session);
            }

            //DataClassesDataContext dc = new DataClassesDataContext();
            //Random rand = new Random();
            //int ratingCount = dc.Ratings.Count();
            //List<Rating> allRatings = (from r in dc.Ratings
            //                          select r).ToList();
            //string title = "";
            //Rating searchRating = null;
            //while (searchRating == null)
            //{
            //    searchRating = dc.Ratings.FirstOrDefault(r1 => r1.RatingID == rand.Next(ratingCount) && r1.UserID != userID);
            //}
            //double value = RatingHelper.GetWeightedAverage(searchRating.Article, allRatings);
            //if (value > lowerBound && value < upperBound)
            //{
            //    title = searchRating.Article;
            //}
            //Response.Redirect(Settings.Default.WikipediaBaseURL + title);


            List <Tuple <string, double, bool> > unratedArticles = RatingHelper.GetAllRatedArticles(userID, lowerBound, upperBound);

            Response.Redirect(Settings.Default.WikipediaBaseURL + unratedArticles[new Random().Next(unratedArticles.Count)].Item1);
            //}
        }
示例#3
0
        private DataTable GenerateTable(bool isLoggedIn, int userID, double lowerBound, double upperBound)
        {
            //A list of all articles and their average rating if their average rating is between the lower and upper bound
            List <Tuple <string, double, bool> > articles = RatingHelper.GetAllRatedArticles(userID, lowerBound, upperBound);

            DataTable dt = new DataTable();

            dt.Columns.Add("Article");
            dt.Columns.Add("Rating", System.Type.GetType("System.Double"));
            dt.Columns.Add("RatedStyle", System.Type.GetType("System.String"));

            foreach (Tuple <string, double, bool> a in articles)
            {
                DataRow dr = dt.NewRow();
                //encode
                if (a.Item1.Length > Settings.Default.TruncateArticleLength)
                {
                    dr["Article"] = Server.HtmlEncode(a.Item1.Substring(0, Settings.Default.TruncateArticleLength - 3)) + "...";
                }
                else
                {
                    dr["Article"] = Server.HtmlEncode(a.Item1);
                }
                dr["Rating"] = a.Item2;
                if (userID == 0)
                {
                    dr["RatedStyle"] = "none";
                }
                else
                if (a.Item3)
                {
                    dr["RatedStyle"] = "Rated";
                }
                else
                {
                    dr["RatedStyle"] = "NotRated";
                }

                dt.Rows.Add(dr);
            }

            return(dt);
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int  currentUserID = 0;
            bool isLoggedIn    = false;
            Guid session       = new Guid();

            if (Request.Cookies["session"] != null && Guid.TryParse(Request.Cookies["session"].Value, out session))
            {
                currentUserID = Auth.checkSession(session);
                if (currentUserID > 0)
                {
                    isLoggedIn = true;
                }
            }

            //Hacker News Formula:
            //(p - 1) / (t + 2)^1.5
            //Description:
            //Votes divided by age factor
            //p = votes (points) from users.
            //t = time since submission in hours.
            //p is subtracted by 1 to negate submitters vote.
            //age factor is (time since submission in hours plus two) to the power of 1.5.

            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("Article"));
            dt.Columns.Add(new DataColumn("Points", System.Type.GetType("System.Double")));
            dt.Columns.Add(new DataColumn("Description"));
            dt.Columns.Add(new DataColumn("RatedStyle"));

            List <Tuple <string, double> > userRatings = RatingHelper.GetAllRatedArticles(currentUserID, "rated", 0, 10);

            foreach (Tuple <string, int, DateTime, double> article in RatingHelper.GetTrendingValues())
            {
                int hours = (int)DateTime.Now.Subtract(article.Item3).TotalHours;

                DataRow dr = dt.NewRow();
                if (article.Item1.Length > Settings.Default.TruncateArticleLength)
                {
                    dr["Article"] = Server.HtmlEncode(article.Item1.Substring(0, Settings.Default.TruncateArticleLength - 3)) + "...";
                }
                else
                {
                    dr["Article"] = Server.HtmlEncode(article.Item1);
                }
                //subtract one for the initial vote
                int    votes        = article.Item2 - 1;
                double averageValue = article.Item4;
                int    points       = (int)Math.Round(((double)votes) / System.Math.Pow(((double)hours + 2), 1.5) * 100 * averageValue);
                if (points == 0)
                {
                    continue;
                }

                dr["Points"] = points;
                string description = "";
                if (votes < 2)
                {
                    description += votes + " vote";
                }
                else
                {
                    description += votes + " votes";
                }

                description += GetSaneTime(hours);

                description += "<br/>Average: " + Math.Round(averageValue, 2);

                dr["Description"] = description;

                if (!isLoggedIn)
                {
                    dr["RatedStyle"] = "none";
                }
                else if (RatingHelper.Contains(userRatings, article.Item1))
                {
                    dr["RatedStyle"] = "Rated";
                }
                else
                {
                    dr["RatedStyle"] = "NotRated";
                }

                dt.Rows.Add(dr);
            }
            dt.DefaultView.Sort         = "Points DESC";
            TrendingListView.DataSource = dt.DefaultView;
            TrendingListView.DataBind();
        }