Party from Parties.txt 1;“Партия 1“ 2;“Коалиция 1“ 1000;“Инициативен комитет в МИР 1“ 1001;“Инициативен комитет в МИР 2“
コード例 #1
0
ファイル: Party.cs プロジェクト: elections-contest/pe2013
 public bool Equals(Party otherObj)
 {
     return otherObj.Id == this.Id
             && otherObj.Name == this.Name
             && otherObj.MandatesCount == this.MandatesCount
             && otherObj.Type == this.Type;
 }
コード例 #2
0
        /// <summary>
        /// Parse Parties from Parties.txt
        /// ex:
        /// 1;“Партия 1“
        /// 2;“Коалиция 1“
        /// 1000;“Инициативен комитет в МИР 1“
        /// 1001;“Инициативен комитет в МИР 2“
        /// </summary>
        /// <param name="recordLine"></param>
        /// <returns></returns>
        public static Party ParsePartyFromString(string recordLine)
        {
            if (string.IsNullOrEmpty(recordLine))
            {
                throw new ArgumentNullException();
            }

            var propValues = recordLine.Split(SEPARATOR);

            var item = new Party(
                                id: int.Parse(propValues[0]),
                                name: propValues[1]
                           );

            return item;
        }
コード例 #3
0
        private void GiveInitialMandatesOnNationalLevel(int mirsCount, int partiesCountTable1, int[,] votesTable2, Party[] partiesTable2, int partiesCountInTable2, int partiesCountTable2, int allMandatesAfterStep0, int allVotesTable2, out List<PartyCalcInfo> partiesWithCalcInfo, out List<MirCalcInfo> mirsWithCalcInfo, out int mandatesLeft)
        {
            Logger.Info("\r\n==Разпределяне на мандатите на национално ниво==");
            decimal globalHareQuote = (decimal)allVotesTable2 / allMandatesAfterStep0;
            Logger.logger.InfoFormat("Квота на Хеър = {0} = {1}/{2}", globalHareQuote, allVotesTable2, allMandatesAfterStep0);

            //parties with calc info
            partiesWithCalcInfo = new List<PartyCalcInfo>();
            for (int i = 0; i < partiesCountInTable2; i++)
            {
                var partyWithCalcInfo = new PartyCalcInfo()
                {
                    Index = i,
                    PartyId = partiesTable2[i].Id,
                };
                partiesWithCalcInfo.Add(partyWithCalcInfo);

            }

            //calculate party mir mandates
            mirsWithCalcInfo = new List<MirCalcInfo>();
            for (int i = 0; i < mirsCount; i++)
            {
                var mirCalcInfo = new MirCalcInfo()
                {
                    MirId = _mirsAll[i].Id,
                    MirIndex = i,
                };
                mirsWithCalcInfo.Add(mirCalcInfo);
            }

            //calculate mir and partyVotes votes
            int[] mirVotesCountTable2 = new int[mirsCount];
            int[] partyVotesCountTable2 = new int[partiesCountTable1];
            for (int i = 0; i < mirsCount; i++)
            {
                for (int j = 0; j < partiesCountTable2; j++)
                {
                    //mir votes
                    mirVotesCountTable2[i] += votesTable2[i, j];
                    mirsWithCalcInfo[i].Votes = mirVotesCountTable2[i];
                    mirsWithCalcInfo[i].MandatesLimit = _mirMandatesAvailable[i];
                    mirsWithCalcInfo[i].MandateHareQuote = _mirMandatesAvailable[i] != 0 ? decimal.Divide(mirVotesCountTable2[i], _mirMandatesAvailable[i]) : 0;
                    //party votes
                    partyVotesCountTable2[j] += votesTable2[i, j];
                    partiesWithCalcInfo[j].Votes = partyVotesCountTable2[j];
                }
            }

            //mandates that every party should have
            for (int i = 0; i < partiesCountTable2; i++)
            {
                decimal mandateCoefHare = decimal.Divide(partyVotesCountTable2[i], globalHareQuote);
                int mandatesInit = (int)mandateCoefHare;
                partiesWithCalcInfo[i].MandatesGivenInit = mandatesInit;
                decimal mandateCoefHareR = mandateCoefHare - mandatesInit;
                partiesWithCalcInfo[i].MandateCoefHareR = mandateCoefHareR;
            }

            //summary init mandates given
            int mandatesInitGiven = partiesWithCalcInfo.Sum(p => p.MandatesGivenInit);
            mandatesLeft = allMandatesAfterStep0 - mandatesInitGiven;

            Logger.logger.Info("Начални мандати по партии:");
            LogNationalMandatesByParties(partiesWithCalcInfo);
        }
コード例 #4
0
        private void PrepareWorkingDataForNationalMandateGiving(int mirsCount, int partiesCountTable1, bool[] workingPartyFlagsTable1, int[,] votesTable1, out int partiesCountInTable2, out int[,] votesTable2, out Party[] partiesTable2, out int partiesCountTable2, out int allMandatesAfterStep0, out int allVotesTable2)
        {
            //GENERATE TABLE2
            partiesCountInTable2 = workingPartyFlagsTable1.Count(f => f);

            //Votes table
            votesTable2 = new int[mirsCount, partiesCountInTable2];
            int[,] givenMandatesTable2 = new int[mirsCount, partiesCountInTable2];
            List<Party> partiesListTable2 = new List<Party>();
            int partyIndexTable2 = 0;
            for (int j = 0; j < partiesCountTable1; j++)//TO DO - optimize by j
            {
                if (workingPartyFlagsTable1[j])
                {
                    for (int i = 0; i < mirsCount; i++)
                    {
                        votesTable2[i, partyIndexTable2] = votesTable1[i, j];
                        givenMandatesTable2[i, partyIndexTable2] = 0;//_givenMandatesTable1[i, j];
                    }

                    partiesListTable2.Add(_partiesAll[j]);
                    partyIndexTable2++;
                }
            }

            partiesTable2 = partiesListTable2.ToArray();//indexed array with parties in Table2
            partiesCountTable2 = partiesListTable2.Count;
            //calculatae new quote - Hare
            allMandatesAfterStep0 = _mirMandatesAvailable.Sum();
            allVotesTable2 = 0;//chl.14-chl16
            for (int i = 0; i < mirsCount; i++)
            {
                for (int j = 0; j < partiesCountTable2; j++)
                {
                    allVotesTable2 += votesTable2[i, j];
                }
            }
        }
コード例 #5
0
 public void Parse_Party_From_StringTest_For_Type_Party()
 {
     string recordLine = @"1;“Партия 1“"; // TODO: Initialize to an appropriate value
     /// 1;“Партия 1“
     /// 2;“Коалиция 1“
     /// 1000;“Инициативен комитет в МИР 1“
     /// 1001;“Инициативен комитет в МИР 2“
     Party expected = new Party(1, "“Партия 1“"); // TODO: Initialize to an appropriate value
     Party actual;
     actual = InputParsers.ParsePartyFromString(recordLine);
     Assert.AreEqual(expected, actual);
 }