public Country GetChartData()
        {
            Country objproduct = new Country();
            /*Get the data from databse and prepare the chart record data in string form.*/
            ChartsViewModel          cVM       = new ChartsViewModel();
            List <RegisterViewModel> users     = cVM.GetAllUsres();  // get the users
            List <CampaignDTO>       campaigns = cVM.GetCampaigns(); // get all the campaigns
            List <VotesDTO>          votes     = cVM.GetAllVotes();  //  get the votes

            objproduct.CountryName = "";
            foreach (var country in users) // get list of countries from registered users, if there are no campaigns still i want to see users region on GEO MAP
            {
                foreach (var item in users)
                {
                    if (country.Country == item.Country)
                    {
                        if (!objproduct.CountryName.Contains(country.Country.ToString()))
                        {
                            objproduct.CountryName += country.Country + ",";
                        }
                    }
                }
            }

            foreach (var country in campaigns) // get list of the countries from the campaigns
            {
                foreach (var item in campaigns)
                {
                    if (country.Country == item.Country)
                    {
                        if (!objproduct.CountryName.Contains(country.Country.ToString()))
                        {
                            objproduct.CountryName += country.Country + ",";
                        }
                    }
                }
            }

            // remove the last comma from the string
            var countries = objproduct.CountryName.TrimEnd(',', ' ');

            ViewBag.Test = countries;



            // get the population of each of the country thats registered in the system.
            // get the total votes are give in the system from that country
            var countryarray = countries.Split(',');

            objproduct.Registerd = "";
            int  countUsers   = 0;
            int  countVote    = 0;
            int  counCampaign = 0;
            bool found        = false;
            bool voteFound    = false;
            bool camFound     = false;

            foreach (var country in countryarray)
            {
                foreach (var user in users)
                {
                    if (country.ToString() == user.Country.ToString()) // match the country related to the users and count the populations
                    {
                        countUsers++;
                        found = true;
                        foreach (var vote in votes)
                        {
                            if (user.UserId == vote.UserId) // get the users vote in each country and county the total of the vote for particular country
                            {
                                countVote++;
                                voteFound = true;
                            }
                        }
                        //foreach(var cam in campaigns)
                        //{
                        //    if(country == cam.Country)
                        //    {
                        //        counCampaign++;
                        //        camFound = true;
                        //    }
                        //}
                    }
                }
                if (found == true && voteFound == true /* & camFound == true*/) // if it's true than add the values to the string
                {
                    objproduct.Registerd += countUsers + ",";
                    objproduct.Vote      += countVote + ",";
                    countUsers            = 0;
                    countVote             = 0;
                }
            }
            //var countries = objproduct.CountryName.TrimEnd(',', ' ');
            var Registerd = objproduct.Registerd.TrimEnd(',', ' '); // remove the comman or space at the end of the line
            var Vote      = objproduct.Vote.TrimEnd(',', ' ');


            //Test them at the View.
            ViewBag.Test1 = Registerd;
            ViewBag.Test2 = Vote;



            //// the following are just the value that will show system features on demo day///////////////////////////////////DEMO/////////////////////////DEMO///////////////////DEMO/////////////DEMO

            objproduct.CountryName = "Ireland,Afghanistan,Australia,USA,United Kingdom,colombia,India,South Africa,Brazil,Russia";
            objproduct.Registerd   = "4500000,10000000,15000000,135000000,46000000,40000000,650000000,26000000,120000000,60000000";
            objproduct.Vote        = "4000000,7000000,12000000,120000000,44000000,35000000,500000000,25000000,100000000,58000000";
            ///////////////////////////////////DEMO/////////////////////////DEMO///////////////////DEMO/////////////DEMO///////////////////////////////////DEMO/////////////////////////DEMO////////////
            return(objproduct);
        }
Beispiel #2
0
        // GET: Charts
        public ActionResult Index()
        {
            // get the data from the DB
            ChartsViewModel          cVM   = new ChartsViewModel();
            List <RegisterViewModel> users = cVM.GetAllUsres();   // get the users
            List <VotesDTO>          vots  = cVM.GetAllVotes();   //  get the votes

            List <CampaignDTO>  campaigns  = cVM.GetCampaigns();  // get all the campaigns
            List <CandidateDTO> candidates = cVM.GetCandidates(); // get all the cadidates data


            int    totalUusers = 0;
            int    totalVots   = 0;
            double totalMale   = 0;
            double totalFemale = 0;
            double totalOthers = 0;



            foreach (var item in users) // count total number of users in the system thats registered
            {
                if (item.Gender == "Male")
                {
                    totalMale++;
                }
                else if (item.Gender == "Female")
                {
                    totalFemale++;
                }
                else
                {
                    totalOthers++;
                }
                totalUusers++;
            }


            // checking the total numbers of votes given by each gender
            double maleVotes   = 0;
            double femaleVotes = 0;
            double othersVotes = 0;

            foreach (var vote in vots) // count total number of votes
            {
                foreach (var user in users)
                {
                    if (vote.UserId == user.UserId && user.Gender == "Male")
                    {
                        maleVotes++;
                    }
                    else if (vote.UserId == user.UserId && user.Gender == "Female")
                    {
                        femaleVotes++;
                    }
                    else if (vote.UserId == user.UserId && user.Gender == "Other")
                    {
                        othersVotes++;
                    }
                }
                totalVots++;
            }



            ////calculate the precentage of each gender out of total
            //double totalGenders = totalMale + totalFemale + totalOthers;
            //if (totalGenders != 0)
            //{

            //    totalMale = (totalMale * 100) / totalGenders;
            //    totalFemale = (totalFemale * 100) / totalGenders;
            //    totalOthers = (totalOthers * 100) / totalGenders;
            //}
            //else
            //{
            //    totalMale = 0;
            //    totalFemale = 0;
            //    totalOthers = 0;
            //}
            //totalMale = Math.Round(totalMale);
            //totalFemale = Math.Round(totalFemale);
            //totalOthers = Math.Round(totalOthers);


            // NEXT BAR CHART
            // you can get the country now and within that you need to get how many campaigns are in the country and how many candidates are in each campaign

            //to following is just for demo day ///////////////////////////////////DEMO/////////////////////////DEMO///////////////////DEMO/////////////DEMO
            totalUusers = 1106500000;
            totalVots   = 905000000;

            totalMale   = 531120000;
            totalFemale = 442600000;
            totalOthers = 132780000;
            ///////////////////////////////////DEMO/////////////////////////DEMO///////////////////DEMO/////////////DEMO
            // the following values just for the demo ///////////////////////////////////DEMO/////////////////////////DEMO///////////////////DEMO/////////////DEMO
            maleVotes   = 470600000;
            femaleVotes = 362000000;
            othersVotes = 72400000;
            ////////////////////////////////////DEMO////////////DEMO/////////////DEMO//////////////DEMO////////////////DEMO//////////////DEMO//////////////


            ViewBag.totalUsers  = totalUusers;
            ViewBag.totalVots   = totalVots;
            ViewBag.totalMale   = totalMale;
            ViewBag.totalFemale = totalFemale;
            ViewBag.totalOters  = totalOthers;

            ViewBag.maleVotes   = maleVotes;
            ViewBag.femaleVotes = femaleVotes;
            ViewBag.othersVotes = othersVotes;


            return(View());
        }