Ejemplo n.º 1
0
        public Tik Create(string fileName)
        {
            var electionFoo = ElectionFoo.GetFoo(fileName);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var lineCounter = 0;

            //var firstTime = true;

            var tik = new Tik()
            {
                Name = StringUtils.GetTikName(fileName)
            };

            using (var sr = new StreamReader(fileName, Encoding.GetEncoding(1251)))
            {
                while (!sr.EndOfStream)
                {
                    lineCounter++;
                    var line = sr.ReadLine();

                    if (lineCounter == electionFoo.NumberOfElectorsInList.LineNumber)
                    {
                        Set(tik, line, electionFoo.NumberOfElectorsInList, (x, v) => x.NumberOfVoters = v);
                    }
                    if (lineCounter == electionFoo.NumberOfEarlier.LineNumber)
                    {
                        Set(tik, line, electionFoo.NumberOfEarlier, (x, v) => x.NumberOfEarlier = v);
                    }
                    if (lineCounter == electionFoo.NumberOfIn.LineNumber)
                    {
                        Set(tik, line, electionFoo.NumberOfIn, (x, v) => x.NumberOfInside = v);
                    }
                    if (lineCounter == electionFoo.NumberOfOut.LineNumber)
                    {
                        Set(tik, line, electionFoo.NumberOfOut, (x, v) => x.NumberOfOutside = v);
                    }
                    if (lineCounter == electionFoo.NumberOfValidBallot.LineNumber)
                    {
                        Set(tik, line, electionFoo.NumberOfValidBallot, (x, v) => x.Valid = v);
                    }
                    if (lineCounter == electionFoo.NumberOfInvalidBallot.LineNumber)
                    {
                        Set(tik, line, electionFoo.NumberOfInvalidBallot, (x, v) => x.InValid = v);
                    }
                    if (lineCounter == electionFoo.Stationary.LineNumber)
                    {
                        Set(tik, line, electionFoo.Stationary, (x, v) => x.Stationary = v);
                    }
                    if (lineCounter == electionFoo.Portable.LineNumber)
                    {
                        Set(tik, line, electionFoo.Portable, (x, v) => x.Portable = v);
                    }

                    if (lineCounter == electionFoo.RowLocalElectionCommittee)
                    {
                        tik.Uiks = GetUiks(line);
                    }
                    if (lineCounter >= electionFoo.MinRowNumberForFactions)
                    {
                        //if (firstTime)
                        //{
                        //    CheckZero();
                        //    firstTime = false;
                        //}
                        //if (!GetNewPartyData(line, sr, fileName)) break;
                    }
                }
            }

            //Presence = 100 * ((double)(NumberOfEarlier + NumberOfIn + NumberOfOut)) / NumberOfElectorsInList;
            //AllPresences = Enumerable
            //   .Range(0, allNumberOfEarlier.Count)
            //   .Select(
            //      i =>
            //      Math.Round(
            //         100.0 * (allNumberOfEarlier[i] + allNumberOfIn[i] + allNumberOfOut[i]) /
            //         AllNumberOfElectorsInList[i], 2))
            //   .ToArray();

            //for (int i = 0; i < AllPresences.Length; i++)
            //{
            //    if (double.IsNaN(AllPresences[i]))
            //    {
            //        foreach (var electionCommittee in partiesData)
            //        {
            //            electionCommittee.Value.LocalElectionCommittees[i].Percent = double.NaN;
            //        }
            //        //Trace.WriteLine(uiks[i]);
            //    }
            //}

            stopWatch.Stop();
            //Trace.WriteLine(stopWatch.Elapsed);

            return(tik);
        }
Ejemplo n.º 2
0
        public ElectionCommitteeResults(string fileName)
        {
            ElectionFoo electionFoo = ElectionFoo.GetFoo(fileName);

            const int captionIndex = 1;
            var       stopWatch    = new Stopwatch();

            stopWatch.Start();

            var lineCouner = 0;

            var firstTime = true;

            using (var sr = new StreamReader(fileName, Encoding.GetEncoding(1251)))
            {
                while (!sr.EndOfStream)
                {
                    lineCouner++;
                    var line  = sr.ReadLine();
                    var parts = line.Split(new[] { Data.Core.Consts.Tab }, StringSplitOptions.RemoveEmptyEntries);

                    Func <int>         getTotal = () => Convert.ToInt32(parts[captionIndex + 1].Trim());
                    Func <List <int> > getAll   = () =>
                                                  Enumerable.Range(captionIndex + 2, parts.Length - captionIndex - 2)
                                                  .Select(i => Convert.ToInt32(parts[i].Trim()))
                                                  .ToList();

                    if (lineCouner == electionFoo.NumberOfElectorsInList.LineNumber)
                    {
                        AssertCaption(parts[captionIndex], electionFoo.NumberOfElectorsInList.Caption);
                        NumberOfElectorsInList = getTotal();

                        AllNumberOfElectorsInList = getAll();
                    }
                    if (lineCouner == electionFoo.NumberOfEarlier.LineNumber)
                    {
                        AssertCaption(parts[captionIndex], electionFoo.NumberOfEarlier.Caption);
                        NumberOfEarlier = getTotal();

                        allNumberOfEarlier = getAll();
                    }
                    if (lineCouner == electionFoo.NumberOfIn.LineNumber)
                    {
                        AssertCaption(parts[captionIndex], electionFoo.NumberOfIn.Caption);
                        NumberOfIn = getTotal();

                        allNumberOfIn = getAll();
                    }
                    if (lineCouner == electionFoo.NumberOfOut.LineNumber)
                    {
                        AssertCaption(parts[captionIndex], electionFoo.NumberOfOut.Caption);
                        NumberOfOut = getTotal();

                        allNumberOfOut = getAll();
                    }
                    if (lineCouner == electionFoo.NumberOfValidBallot.LineNumber)
                    {
                        AssertCaption(parts[captionIndex], electionFoo.NumberOfValidBallot.Caption);
                        NumberOfValidBallot = getTotal();
                    }
                    if (lineCouner == electionFoo.NumberOfInvalidBallot.LineNumber)
                    {
                        AssertCaption(parts[captionIndex], electionFoo.NumberOfInvalidBallot.Caption);
                        NumberOfInvalidBallot = getTotal();
                    }

                    if (lineCouner == electionFoo.RowLocalElectionCommittee)
                    {
                        GetUiks(line);
                    }
                    if (lineCouner >= electionFoo.MinRowNumberForFactions)
                    {
                        if (firstTime)
                        {
                            CheckZero();
                            firstTime = false;
                        }
                        if (!GetNewPartyData(line, sr, fileName))
                        {
                            break;
                        }
                    }
                }
            }

            Presence     = 100 * ((double)(NumberOfEarlier + NumberOfIn + NumberOfOut)) / NumberOfElectorsInList;
            AllPresences = Enumerable
                           .Range(0, allNumberOfEarlier.Count)
                           .Select(
                i =>
                Math.Round(
                    100.0 * (allNumberOfEarlier[i] + allNumberOfIn[i] + allNumberOfOut[i]) /
                    AllNumberOfElectorsInList[i], 2))
                           .ToArray();

            for (int i = 0; i < AllPresences.Length; i++)
            {
                if (double.IsNaN(AllPresences[i]))
                {
                    foreach (var electionCommittee in partiesData)
                    {
                        electionCommittee.Value.LocalElectionCommittees[i].Percent = double.NaN;
                    }
                    //Trace.WriteLine(uiks[i]);
                }
            }

            stopWatch.Stop();
            //Trace.WriteLine(stopWatch.Elapsed);
        }