Esempio n. 1
0
        public string CreateDiagram(FileInfo fi, string captionDiagram, bool overWrite)
        {
            var year     = TextProcessFunctions.GetYear(fi.Name);
            var location = TextProcessFunctions.GetElectionCommitteeName(fi.FullName, null, TextProcessFunctions.GetMapping());
            var picName  = $@"{fi.DirectoryName}\{TextProcessFunctions.Translit(location)}{year}.jpg";

            if (File.Exists(picName) && !overWrite)
            {
                return(picName);
            }

            return(_barChartDrawer.DrawDiagramForTxtData(DiagramDataCreator.Create(fi.FullName, picName, string.Format(captionDiagram, year, location), PartiesOrder)));
        }
Esempio n. 2
0
 public void TestTrasnlit()
 {
     Assert.AreEqual("PetropavlovskKamchatskaya_gorodskaya_sudovaya_Kamchatskij_kraj_2007",
                     TextProcessFunctions.Translit(
                         "Петропавловск-Камчатская городская (судовая) Камчатский край 2007"));
 }
Esempio n. 3
0
        private void SaveDictionary()
        {
            string[][] translitted;


            ////new FooData() { RussianShort = "АПР", Color = "white", IsMain = false, RussianLong = "АПР" , Result =0},
            ////new FooData() { RussianShort = "РППиПСС", Color = "white", IsMain = false, RussianLong = "РППиПСС" , Result =0},
            ////new FooData() { RussianShort = "Яблоко", Color = "white", IsMain = false, RussianLong = "Яблоко" , Result =0},
            ////new FooData() { RussianShort = "СПС", Color = "white", IsMain = false, RussianLong = "СПС" , Result =0},

            if (_electionYear.ElectionType == ElectionType.Duma)
            {
                translitted = new[]
                {
                    new[] { "Единая Россия", "ER" },
                    new[] { "КПРФ", "KPRF" },
                    new[] { "Яблоко", "YA" },
                    new[] { "Родина", "Rodina" },
                    new[] { "Справедливая Россия", "SR" },
                    new[] { "ЛДПР", "LDPR" },
                    new[] { "АПР", "APR" },
                    new[] { "РППиПСС", "RPPiPSS" },
                    new[] { "СПС", "SPS" },
                };
            }
            else
            {
                var people = _dictionary.Values.First().partiesData.Keys.ToArray();
                translitted = new string[people.Length][];
                for (int i = 0; i < translitted.Length; i++)
                {
                    translitted[i]    = new string[2];
                    translitted[i][0] = people[i];
                    translitted[i][1] = TextProcessFunctions.Translit(people[i]);
                }
            }

            var elections = new List <Election>();

            foreach (var kvp in _dictionary)
            {
                var electionCommitteeResults = kvp.Value;
                int idx = kvp.Key.LastIndexOf('\\');
                var electionCommitteeName = kvp.Key.Substring(0, idx);
                var election = new Election();
                election.ElectionCommittee      = electionCommitteeName;
                election.Number                 = electionCommitteeResults.NumberOfLocalElectionCommitees;
                election.NumberOfElectorsInList = electionCommitteeResults.NumberOfElectorsInList;
                election.NumberOfInvalidBallot  = electionCommitteeResults.NumberOfInvalidBallot;
                election.NumberOfValidBallot    = electionCommitteeResults.NumberOfValidBallot;
                election.Presence               = Math.Round(electionCommitteeResults.Presence, 2);
                election.Href         = electionCommitteeResults.Href;
                election.AllPresences = electionCommitteeResults.AllPresences;
                election.AllNumberOfElectorsInList = electionCommitteeResults.AllNumberOfElectorsInList.ToArray();
                var uiksNumbers = electionCommitteeResults.uiks.Select(TextProcessFunctions.GetUikNumber).ToArray();
                Debug.Assert(uiksNumbers.Length == election.Number, "Wrong numbers");
                election.Uiks = string.Join(",", uiksNumbers);

                var foos = new List <Foo>();
                for (int i = 0; i < translitted.Length; i++)
                {
                    var    shortPartyName = translitted[i][1];
                    string partyName      = translitted[i][0];
                    if (!electionCommitteeResults.partiesData.ContainsKey(partyName))
                    {
                        continue;
                    }
                    var electionCommittee = electionCommitteeResults.partiesData[partyName];
                    var foo = new Foo()
                    {
                        Name      = shortPartyName,
                        Max       = electionCommittee.MaxPercent,
                        Min       = electionCommittee.MinPercent,
                        Value     = electionCommittee.Percent,
                        Number    = electionCommittee.Number,
                        AllValues = electionCommittee.LocalElectionCommittees.Select(l => l.Percent).ToArray()
                    };
                    foos.Add(foo);
                }
                election.Foos = foos.OrderBy(f => f.Name).ToList();
                elections.Add(election);
            }

            var xmlSerializer = new XmlSerializer(typeof(List <Election>));

            using (var sw = new StreamWriter(_fileName))
            {
                xmlSerializer.Serialize(sw, elections);
            }
        }