Пример #1
0
    // 투표 내용을 띄워줌
    public void ShowVote()
    {
        VoteData data = VoteManager.currentVote;

        _day.text   = data.day.ToString();
        _topic.text = data.voteTopic;
    }
Пример #2
0
    public static void Vote(int agree)
    {
        VoteData temp = _voteDatas[_currentIndex];

        temp.isAgree = agree;
        _voteDatas[_currentIndex] = temp;
    }
Пример #3
0
        public void UpdateBillData(HttpContext context)
        {
            _context = context;
            PopulateConstituencies();
            PopulateMPs();

            var newBillList = _rssClient.GetBills("http://services.parliament.uk/bills/AllBills.rss");

            foreach (var newBillData in newBillList)
            {
                var bill = _db.Single <BillDataModel>(b => b.Url == newBillData.Url);
                if (bill != null)
                {
                    if (bill.UpdatedDate < newBillData.UpdatedDate)
                    {
                        bill.UpdatedDate = newBillData.UpdatedDate;
                        bill.BillType    = newBillData.BillType;
                        bill.Description = newBillData.Description;
                        bill.House       = newBillData.House;
                        bill.Stage       = newBillData.Stage;
                        bill.Title       = newBillData.Title;
                        bill.IsUpdated   = true;
                    }
                    _db.Update <BillDataModel>(bill);
                    _db.CommitChanges();
                }
                else
                {
                    newBillData.IsNew = true;
                    _db.Add <BillDataModel>(newBillData);
                    _db.CommitChanges();
                    bill = _db.Single <BillDataModel>(b => b.Url == newBillData.Url);
                }

                var parliamentaryDebates = PopulateParliamentaryDebatesForBill(bill.Id);
                if (parliamentaryDebates.Count > 0)
                {
                    var debates = new List <DebateDataModel>();
                    foreach (var debateResult in parliamentaryDebates)
                    {
                        if (debateResult.speaker != null)
                        {
                            var mpId       = Convert.ToInt32(debateResult.speaker.person_id);
                            var speakingMP = _db.Single <MPDataModel>(m => m.TWFYPersonId == mpId);
                            debates.Add(new DebateDataModel
                            {
                                Body    = debateResult.body,
                                Date    = DateTime.Parse(debateResult.hdate),
                                Speaker = speakingMP,
                                BillId  = bill.Id
                            });
                        }
                    }
                    _db.Add <DebateDataModel>(debates);
                }
            }
            var voteDataProvider = new VoteData(_db);

            voteDataProvider.PopulateVoteData();
        }
Пример #4
0
        // public void DoneWithVote(T candidate)
        // {
        //     try {
        //         voteDict.Remove(candidate);
        //     } catch (KeyNotFoundException) {}
        // }

        public VoteResult GetResult(T candidate, bool justPeeking = false)
        {
            // Have to get to it before it expires
            // If the vote is finished (timed out or won)
            // this will set the status to Done - which means it has been
            // read
            UpdateAllStatus();
            VoteResult result = new VoteResult(false, VoteStatus.NotFound, 0, 0);

            try {
                VoteData vd = _voteDict[candidate];
                result = new VoteResult(vd.IsComplete, vd.Status, vd.PeerIds.Count, vd.InitialMsgTime);
                if (!justPeeking)
                {
                    if (vd.Status == VoteStatus.Lost || vd.Status == VoteStatus.Won)
                    {
                        vd.SetComplete();
                        _voteDict[candidate] = vd;
                    }
                }
            } catch (KeyNotFoundException)
            {
                //logger.Warn($"GetStatus: Vote not found");
            }
            return(result);
        }
Пример #5
0
        public JsonResult GetRate(int?id, bool isGrouping)
        {
            VoteData newVote = null;

            try
            {
                if (id != null)
                {
                    using (new SystemAccount())
                    {
                        var content = ContentRepository.Content.Load(id.Value);
                        if (content != null)
                        {
                            newVote = content.Fields["Rate"].OriginalValue as VoteData;
                            newVote.EnableGrouping = isGrouping;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                newVote.Success = false;
            }
            return(Json(newVote, JsonRequestBehavior.AllowGet));
        }
Пример #6
0
        private void sumbitVote_Click()
        {
            if (buttonClickCount == 0)
            {
                return;
            }
            buttonClickCount = 0;
            Slide activeSlide = Globals.ThisAddIn.Application.ActivePresentation.SlideShowWindow.View.Slide;

            MF.CommandButton button = (MF.CommandButton)activeSlide.Shapes["sumbitButton"].OLEFormat.Object;
            button.Enabled = false;

            //Question question = new Question();
            //question.questionType = int.Parse(activeSlide.Shapes["questionType"].TextFrame.TextRange.Text);
            //question.questionScore = int.Parse(activeSlide.Shapes["questionScore"].TextFrame.TextRange.Text);
            //question.questionLimitTime = int.Parse(activeSlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text);
            //question.questionDescribe = activeSlide.Shapes["questionDescribe"].TextFrame.TextRange.Text;
            //question.questionAnswer = activeSlide.Shapes["questionAnswer"].TextFrame.TextRange.Text;
            Vote vote = new Vote();

            //vote.voteType = int.Parse(activeSlide.Shapes["questionType"].TextFrame.TextRange.Text);
            vote.voteLimitTime = int.Parse(activeSlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text);
            vote.voteDescribe  = activeSlide.Shapes["questionDescribe"].TextFrame.TextRange.Text;

            List <VoteChoice> voteList = new List <VoteChoice>();

            string chars = "ABCDEFG";

            for (int i = 0; i < 7; i++)
            {
                if (ShapesUitls.IsExistedOfShape(activeSlide, "option" + chars[i] + "Type"))
                {
                    // Option option = new Option();
                    VoteChoice voteChoice = new VoteChoice();
                    voteChoice.voteChoiceType     = activeSlide.Shapes["option" + chars[i] + "Type"].TextFrame.TextRange.Text;
                    voteChoice.voteChoiceDescribe = activeSlide.Shapes["option" + chars[i] + "Text"].TextFrame.TextRange.Text;
                    voteList.Add(voteChoice);
                }
                else
                {
                    break;
                }
            }

            //QuestionData questionData = new QuestionData();
            //questionData.question = question;
            //questionData.optionList = optionList;
            VoteData voteData = new VoteData();

            voteData.vote           = vote;
            voteData.voteChoiceList = voteList;

            SubmitVoteForm submitVoteForm = new SubmitVoteForm();

            submitVoteForm.voteData = voteData;
            submitVoteForm.LoadText();
            submitVoteForm.ShowDialog();
        }
Пример #7
0
            public void CastClientVote(string guid, Map map)
            {
                var vote = new VoteData()
                {
                    guid = guid,
                    map  = map
                };

                VoteList.Add(vote);
            }
Пример #8
0
        private void SaveVotes(List <VoteEntrieData> entries)
        {
            VoteData        thePlaylistData = new VoteData(entries.ToArray());
            BinaryFormatter saveFormater    = new BinaryFormatter();
            //Create file
            FileStream saveStream = new FileStream(Application.StartupPath + "/Vote/Vote", FileMode.Create);

            //Write to file
            saveFormater.Serialize(saveStream, thePlaylistData);
            saveStream.Close();
        }
Пример #9
0
        public async Task <ActionResult> PostVote([FromBody] VoteData data)
        {
            var user = await _userManager.GetUserAsync(User);

            var story = await _context.Stories
                        .Where(s => s.Id == data.StoryId)
                        .Include(s => s.Votes)
                        .FirstOrDefaultAsync();

            var vote = await _context.Votes
                       .FirstOrDefaultAsync(v => v.User == user && v.StoryId == data.StoryId);

            var didVote = false;

            if (story is null)
            {
                return(NotFound());
            }

            // Check if the vote already exists
            if (vote is null)
            {
                story.Votes.Add(new Vote
                {
                    User = user
                });
                didVote = true;
            }
            else
            {
                story.Votes.Remove(vote);
            }

            // Save
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(500));
            }

            var res = new CountReturn
            {
                Count   = story.Votes.Count,
                DidVote = didVote
            };

            return(new OkObjectResult(res));
        }
Пример #10
0
        private static List <Candidate> CreateCandidates(VoteData vd)
        {
            List <Candidate> candidates = new();

            Parallel.For(0, vd.canCount, (i) =>
            {
                int[] votes = new int[vd.canCount];
                for (int j = 0; j < vd.BullCount; j++)
                {
                    votes[vd.Bulletins[j, i] - 1] += 1;
                }
                candidates.Add(new Candidate(votes, i, vd.Names[i]));
            });
            candidates.Sort();
            return(candidates);
        }
Пример #11
0
        public JsonResult Rate(int?id, int?vote, bool isGrouping, int?oldVote = null)
        {
            VoteData newVote = VoteData.CreateVoteData(5, 1);

            try
            {
                bool isOK = false;

                if (id != null && vote != null)
                {
                    using (new SystemAccount())
                    {
                        var content = ContentRepository.Content.Load(id.Value);
                        if (content != null)
                        {
                            newVote.SelectedValue = vote.Value;
                            newVote.OldValue      = oldVote;
                            content.Fields["Rate"].SetData(newVote);
                            if (content.IsValid)
                            {
                                try
                                {
                                    content.Save();
                                    isOK = true;
                                }
                                catch (Exception ex) //logged
                                {
                                    Logger.WriteException(ex);
                                    newVote.ErrorMessage = "You can not vote right now!";
                                }
                            }
                            newVote = content.Fields["Rate"].OriginalValue as VoteData;
                            newVote.EnableGrouping = isGrouping;
                        }
                    }
                }
                newVote.Success = isOK;
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                newVote.Success = false;
            }
            return(Json(newVote, JsonRequestBehavior.AllowGet));
        }
Пример #12
0
        private void submitButton1_Click(object sender, EventArgs e)
        {
            Slide activeSlide = (Slide)Globals.ThisAddIn.Application.ActiveWindow.View.Slide;
            Vote  vote        = new Vote();

            //vote.voteType = int.Parse(activeSlide.Shapes["questionType"].TextFrame.TextRange.Text);
            vote.voteLimitTime = int.Parse(activeSlide.Shapes["questionLimitTime"].TextFrame.TextRange.Text);
            vote.voteDescribe  = activeSlide.Shapes["questionDescribe"].TextFrame.TextRange.Text;

            List <VoteChoice> voteList = new List <VoteChoice>();

            string chars = "ABCDEFG";

            for (int i = 0; i < 7; i++)
            {
                if (ShapesUitls.IsExistedOfShape(activeSlide, "option" + chars[i] + "Type"))
                {
                    // Option option = new Option();
                    VoteChoice voteChoice = new VoteChoice();
                    voteChoice.voteChoiceType     = activeSlide.Shapes["option" + chars[i] + "Type"].TextFrame.TextRange.Text;
                    voteChoice.voteChoiceDescribe = activeSlide.Shapes["option" + chars[i] + "Text"].TextFrame.TextRange.Text;
                    voteList.Add(voteChoice);
                }
                else
                {
                    break;
                }
            }

            //QuestionData questionData = new QuestionData();
            //questionData.question = question;
            //questionData.optionList = optionList;
            VoteData voteData = new VoteData();

            voteData.vote           = vote;
            voteData.voteChoiceList = voteList;

            SubmitVoteForm submitVoteForm = new SubmitVoteForm();

            submitVoteForm.voteData = voteData;
            submitVoteForm.LoadText1();
            submitVoteForm.ShowDialog();
        }
Пример #13
0
 protected void voteButton_Click(object sender, EventArgs e)
 {
     if (CandidateList.SelectedItem != null)
     {
         try
         {
             errorComment.Text = "";
             VoteData.Update();
             Response.Redirect("current.aspx");
         }
         catch (Exception ee)
         {
             errorComment.Text = ee.ToString();
         }
     }
     else
     {
         errorComment.Text = "Please select a candidate";
     }
 }
Пример #14
0
        public List <BillViewModel> GetAllBills()
        {
            var bills     = new List <BillViewModel>();
            var billsData = _db.All <BillDataModel>().ToList();

            if (!billsData.Any())
            {
                //UpdateBillData();
                var voteDataProvider = new VoteData(_db);
                voteDataProvider.PopulateVoteData();
                billsData = _db.All <BillDataModel>().ToList();
            }
            foreach (var billDataModel in billsData)
            {
                var bill = new BillViewModel();
                bill.MapBillDataModel(billDataModel);
                bills.Add(bill);
            }
            return(bills);
        }
Пример #15
0
    private static VoteData GenerateVoteData(List <string> column)
    {
        VoteData data = new VoteData();

        data.id        = Int32.Parse(column[0].Substring(1));
        data.day       = Int32.Parse(column[1]);
        data.voteTopic = column[2];
        data.isAgree   = -1;

        VoteDetailData agree = new VoteDetailData();

        SetNextVoteIndex(column[7], ref agree);
        agree.economy   = column[10].Equals("") ? 0 : Int32.Parse(column[10]);
        agree.political = column[11].Equals("") ? 0 : Int32.Parse(column[11]);
        agree.mechanic  = column[12].Equals("") ? 0 : Int32.Parse(column[12]);
        agree.action    = column[16].StartsWith("E") ? Int32.Parse(column[16].Substring(1, column[16].IndexOf(":") - 1)) : 0;

        VoteDetailData disagree = new VoteDetailData();

        SetNextVoteIndex(column[8], ref disagree);
        disagree.economy   = column[13].Equals("") ? 0 : Int32.Parse(column[13]);
        disagree.political = column[14].Equals("") ? 0 : Int32.Parse(column[14]);
        disagree.mechanic  = column[15].Equals("") ? 0 : Int32.Parse(column[15]);
        disagree.action    = column[17].StartsWith("E") ? Int32.Parse(column[17].Substring(1, column[17].IndexOf(":") - 1)) : 0;

        VoteDetailData abstention    = disagree;
        bool           peoplesChoice = column[9].CompareTo("예").Equals(0) ? true : false;

        if (peoplesChoice)
        {
            abstention = agree;
        }

        data.agree      = agree;
        data.disagree   = disagree;
        data.abstention = abstention;

        return(data);
    }
Пример #16
0
        public XPathNodeIterator SplitRate(string value, bool enableGrouping, int contentid, string propertyname)
        {
            if (String.IsNullOrEmpty(value))
            {
                if (contentid < 1 || string.IsNullOrEmpty(propertyname))
                {
                    throw new NotSupportedException("You must set content id and rating property name");
                }
                var c    = Content.Load(contentid);
                var data = c.Fields[propertyname].GetData() as VoteData;
                value = data == null ? string.Empty : data.Serialize();
                if (string.IsNullOrEmpty(value))
                {
                    value = c.Fields[propertyname].FieldSetting.DefaultValue;
                }
                if (string.IsNullOrEmpty(value))
                {
                    value = "0.0|1|0|0|0|0|0";
                }
            }

            var stream    = new MemoryStream();
            var xmlWriter = XmlWriter.Create(stream);

            var vd = VoteData.CreateVoteData(value);

            vd.EnableGrouping = enableGrouping;
            var x = new System.Xml.Serialization.XmlSerializer(vd.GetType());

            x.Serialize(xmlWriter, vd);
            xmlWriter.Flush();
            stream.Seek(0, 0);
            var doc  = new XPathDocument(stream);
            var nav  = doc.CreateNavigator();
            var iter = nav.Select(".");

            return(iter);
        }
Пример #17
0
        public void AddVote(T candidate, string votingPeer, long msgTime, int totalPeers)
        {
            UpdateAllStatus();
            VoteData vd;

            try {
                vd = _voteDict[candidate];
                if (vd.Status == VoteStatus.Voting)
                {
                    vd.AddVote(votingPeer, msgTime);
                    vd.UpdateStatus(SysMs);
                    _voteDict[candidate] = vd; // VoteData is a struct (value) so must be re-added
                    Logger.Debug($"Vote.Add: +1 for: {candidate.ToString()}, Votes: {vd.PeerIds.Count}");
                }
            } catch (KeyNotFoundException) {
                int majorityCnt = MajorityVotes(totalPeers);
                vd = new VoteData(majorityCnt, msgTime, SysMs + TimeoutMs, SysMs + CleanupMs);
                vd.PeerIds.Add(votingPeer);
                vd.UpdateStatus(SysMs);
                _voteDict[candidate] = vd;
                Logger.Debug($"Vote.Add: New: {candidate.ToString()}, Majority: {majorityCnt}");
            }
        }
Пример #18
0
        public DiscoveredType <VoteAttribute> FindByType(Type type)
        {
            var result = VoteData.FirstOrDefault(x => x.Type == type);

            return(result);
        }
Пример #19
0
 public IActionResult Vote([FromBody] VoteData data)
 {
     _affairService.Vote(User, data.VorfallId, _mapper.Map <bo.VoteType?>(data.VoteType));
     return(Ok());
 }
Пример #20
0
 public override object GetData()
 {
     return(Convert.ToBoolean(Content.Fields["IsRateable"].OriginalValue) ? _rateControl.VotesArray : VoteData.CreateVoteData(5, 1));
 }
Пример #21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        errorComment.Text = "";
        int totalvotes = 0;

        DataView  dv = (DataView)VoteData.Select(DataSourceSelectArguments.Empty);
        TableRow  r  = new TableRow();
        TableCell c1 = new TableCell();
        TableCell c2 = new TableCell();
        TableCell c3 = new TableCell();

        r.Cells.Add(c1);
        r.Cells.Add(c2);
        r.Cells.Add(c3);
        c1.BorderWidth = 1;
        c1.BorderColor = Color.Black;
        c1.BackColor   = Color.LightGray;
        c1.Width       = 180;
        c2.BorderWidth = 1;
        c2.BorderColor = Color.Black;
        c2.BackColor   = Color.LightGray;
        c2.Width       = 180;
        c3.BorderWidth = 1;
        c3.BorderColor = Color.Black;
        c3.BackColor   = Color.LightGray;
        c3.Width       = 180;
        c1.Text        = "Candidate";
        c2.Text        = "Votes";
        c3.Text        = "Vote Percentage";
        VoteTable.Rows.Add(r);
        foreach (DataRow dr in dv.Table.Rows)
        {
            totalvotes = totalvotes + Convert.ToInt32(dr["Count"]);
        }
        if (totalvotes != 0)
        {
            foreach (DataRow dr in dv.Table.Rows)
            {
                r  = new TableRow();
                c1 = new TableCell();
                c2 = new TableCell();
                c3 = new TableCell();
                r.Cells.Add(c1);
                r.Cells.Add(c2);
                r.Cells.Add(c3);
                c1.BorderWidth = 1;
                c1.BorderColor = Color.Black;
                c1.BackColor   = Color.White;
                c1.Width       = 180;
                c2.BorderWidth = 1;
                c2.BorderColor = Color.Black;
                c2.BackColor   = Color.White;
                c2.Width       = 180;
                c3.BorderWidth = 1;
                c3.BorderColor = Color.Black;
                c3.BackColor   = Color.White;
                c3.Width       = 180;
                c1.Text        = dr["Candidate"].ToString();
                c2.Text        = dr["Count"].ToString();
                double percent = Math.Round(100 * (Convert.ToDouble(Convert.ToDouble(dr["Count"]) / totalvotes)), 2);
                c3.Text = percent.ToString() + "%";
                VoteTable.Rows.Add(r);
            }
        }
        else
        {
            errorComment.Text = "No votes recorded yet";
        }
    }
Пример #22
0
        public DiscoveredType <VoteAttribute> FindByName(string name)
        {
            var result = VoteData.FirstOrDefault(x => x.Type.Name.IsEqual(name));

            return(result);
        }