Exemple #1
0
        public JsonResult getQuestions()
        {
            var userVote = (TB_UserVote)Session["UserVote"];

            ListVote      lv       = new ListVote();
            List <string> lsresult = new List <string>();

            int order = lv.getOrderQuestion(DBConnect.open(), userVote.votationid);

            TB_Votation_Questions _Questions = new TB_Votation_Questions();

            _Questions.votationId = userVote.votationid;
            _Questions.order      = order;


            TB_Votation_Questions qRequest = lv.getquestions(DBConnect.open(), _Questions);
            List <TB_Votation_Questions_Answer> lstanswer = lv.getAnswer(DBConnect.opentwo(), qRequest.id);

            lsresult.Add(qRequest.question);

            for (int e = 0; e < lstanswer.Count; e++)
            {
                lsresult.Add(lstanswer[e].answer.ToString());
            }

            return(Json(lsresult, JsonRequestBehavior.AllowGet));
        }
        public JsonResult Report(string key)
        {
            string[] colors  = new string[9];
            string[] graphic = new string[] { };
            string[] options = new string[9];

            int      idf = int.Parse(key);
            ListVote lv  = new ListVote();

            List <ResultOptions> lstro = lv.getOptions(DBConnect.open(), idf);


            int order = lv.getOrderQuestion(DBConnect.open(), idf);

            TB_Votation_Questions _Questions = new TB_Votation_Questions();

            _Questions.votationId = idf;
            _Questions.order      = order;


            TB_Votation_Questions qRequest = lv.getquestions(DBConnect.open(), _Questions);
            List <TB_Vote>        votes    = lv.getListVote("max", idf, qRequest.id, DBConnect.open());

            List <TB_Votation_Questions_Answer> lstanswer = lv.getAnswer(DBConnect.open(), qRequest.id);

            graphic = new string[] { qRequest.question, lstro[0].graphic, lstro[0].height.ToString(), lstro[0].width.ToString(), lstro[0].imagefondo, lstro[0].visible };

            /*
             *          for (int i = 0; i < lstro.Count; i++)
             *          {
             *              colors[i] = lstro[i].color;
             *              options[i] = lstro[i].option;
             *          }
             */
            for (int i = 0; i < lstanswer.Count; i++)
            {
                colors[i]  = lstro[i].color;
                options[i] = lstanswer[i].answer;
            }
            ResultVote rv  = lv.getVote(votes);
            ResultVote rv2 = new ResultVote();

            string[] value   = GetCountOptions(rv, rv2);
            var      Tablero = new[] { graphic, colors, options, value };

            return(Json(Tablero, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        public override string GetAnswer()
        {
            try
            {
                string ans = "[Метод Кондорсе]\r\n";
                for (int i = 0; i < CandidateCount; i++)
                {
                    for (int j = i + 1; j < CandidateCount; j++)
                    {
                        ans += CompareAlter(i, j);
                    }
                }

                ans += "Ответ: " + Result() + "\r\n\r\n";
                return(ans);

                string CompareAlter(int X, int Y)
                {
                    int CountVotes = ListVote.Sum();

                    int X_Votes = 0;

                    for (int i = 0; i < ListAlt.Count; i++)
                    {
                        if (ListAlt[i].IndexOf(ALPHABET[X].ToString()) < ListAlt[i].IndexOf(ALPHABET[Y].ToString()))
                        {
                            X_Votes += ListVote[i];
                        }
                    }

                    char symbol;

                    if (X_Votes > (CountVotes - X_Votes))
                    {
                        symbol = '>';
                        ListScore[X]++;
                    }
                    else if (X_Votes < (CountVotes - X_Votes))
                    {
                        symbol = '<';
                        ListScore[Y]++;
                    }
                    else
                    {
                        symbol = '=';
                    }

                    string s = ALPHABET[X] + " " + symbol + " " + ALPHABET[Y] + " : " + X_Votes + " " + symbol + " " + (CountVotes - X_Votes) + "\r\n";

                    return(s);
                }

                string Result()
                {
                    List <int> list_temp = new List <int>();

                    for (int i = 0; i < ListScore.Count; i++)
                    {
                        list_temp.Add(ListScore[i]);
                    }
                    list_temp.Sort();

                    for (int i = 0; i < list_temp.Count; i++)
                    {
                        if (list_temp[i] > i)
                        {
                            return("Парадокс Кондорсе!");
                        }
                        else if (i != 0)
                        {
                            if (list_temp[i] != list_temp[i - 1] && list_temp[i] != i)
                            {
                                return("Парадокс Кондорсе!");
                            }
                        }
                    }

                    string s   = null;
                    int    cnt = ListScore.Count;
                    int    max = ListScore.Max();

                    for (int i = 0; i < cnt; i++)
                    {
                        if (i != 0)
                        {
                            if (max == ListScore.Max())
                            {
                                s += " = ";
                            }
                            else
                            {
                                s += " > ";
                            }
                        }
                        s  += ALPHABET[ListScore.IndexOf(ListScore.Max())];
                        max = ListScore.Max();
                        ListScore[ListScore.IndexOf(max)] = -1;
                    }

                    return(s);
                }
            }
            catch { return(null); }
        }
        public override string GetAnswer()
        {
            try
            {
                string ans = "[Метод Копленда]\r\n";
                for (int i = 0; i < CandidateCount; i++)
                {
                    for (int j = 0; j < CandidateCount; j++)
                    {
                        if (i != j)
                        {
                            CompareAlter(i, j);
                        }
                    }
                    ans += ALPHABET[i] + " = " + ListScore[i] + "\r\n";
                }
                ans += "Ответ: " + Answer() + "\r\n\r\n";
                return(ans);

                bool CompareAlter(int X, int Y)
                {
                    int sum        = 0;
                    int CountVotes = ListVote.Sum();

                    for (int i = 0; i < ListAlt.Count; i++)
                    {
                        if (ListAlt[i].IndexOf(ALPHABET[X].ToString()) < ListAlt[i].IndexOf(ALPHABET[Y].ToString()))
                        {
                            sum += ListVote[i];
                        }
                    }
                    if (sum > (CountVotes - sum))
                    {
                        ListScore[X]++;
                    }
                    else if (sum < (CountVotes - sum))
                    {
                        ListScore[X]--;
                    }
                    return(true);
                }

                string Answer()
                {
                    string s   = null;
                    int    cnt = ListScore.Count;
                    int    max = ListScore.Max();
                    int    min = ListScore.Min();

                    for (int i = 0; i < cnt; i++)
                    {
                        if (i != 0)
                        {
                            if (max == ListScore.Max())
                            {
                                s += " = ";
                            }
                            else
                            {
                                s += " > ";
                            }
                        }
                        s  += ALPHABET[ListScore.IndexOf(ListScore.Max())];
                        max = ListScore.Max();
                        ListScore[ListScore.IndexOf(max)] = min - 1;
                    }
                    return(s);
                }
            }
            catch { return(null); }
        }