Example #1
0
        public PositionResult GetBillPublicPosition(string house = "", string senate = "", string dis = "")
        {
            PositionResult result = new PositionResult();
            Random r = new Random();
            IQueryable<Vote> q = context.Votes.AsQueryable<Vote>();
            if (house != "")
            {
                house = san(house);
                q = q.Where(v => v.house_id == house);
            }
            else if (senate != "")
            {
                senate = san(senate);
                q = q.Where(v => v.senate_id == senate);
            }
            else
            {
                throw new ArgumentException("Resolution not found. Please enter a valid House or Senate Resolution number. Ex: hr1420");
            }
            if (dis != "")
            {
                dis = san(dis);
                q = q.Where(v => v.District == dis);
                result.District = dis;
            }
            List<Vote> votes = q.ToList();
            double AvgImport = votes.Average(v => v.importance);
            int For = votes.FindAll(v => (v.support == "For")).Count();
            int Against = votes.FindAll(v => (v.support == "Against")).Count();
            int j = Convert.ToInt32(r.Next(0, votes.Count));

            result.For = For;
            result.Against = Against;
            result.AvgImportance = Math.Round(AvgImport, 2);
            result.VideoId = votes[j].video_id;

            return result;
        }
Example #2
0
        public PositionResult GetIssuePublicPosition(string iss_name, string dis = "")
        {
            iss_name = san(iss_name);
            Issue iss = GetIssueByName(iss_name);
            Random r = new Random();
            PositionResult result = new PositionResult();

            IQueryable<Vote> q = context.Votes.AsQueryable();
            q = q.Where(v => v.issue_name == iss_name);
            if (dis != "")
            {
                dis = san(dis);
                q = q.Where(v => v.District == dis);
                result.District = dis;
            }

            List<Vote> votes = q.ToList();
            double AvgImport = votes.Average(v => v.importance);
            int For = votes.FindAll(v => (v.support == "For")).Count();
            int Against = votes.FindAll(v => (v.support == "Against")).Count();

            result.Issue_Name = iss.Name;
            result.For = For;
            result.Against = Against;
            result.AvgImportance = Math.Round(AvgImport, 2);
            int j = Convert.ToInt32(r.Next(0, votes.Count));
            result.VideoId = votes[j].video_id;
            return result;
        }