Ejemplo n.º 1
0
        public void DictionaryCounterInt32_Augment_2()
        {
            DictionaryCounterInt32 <string> dictionary
                = new DictionaryCounterInt32 <string>(_GetComparer());

            dictionary.Augment("first", 2);
            Assert.AreEqual(2, dictionary.GetValue("first"));

            dictionary.Augment("FIRST", 2);
            Assert.AreEqual(4, dictionary.GetValue("first"));
        }
Ejemplo n.º 2
0
        public void DictionaryCounterInt32_Augment_1()
        {
            DictionaryCounterInt32 <string> dictionary
                = new DictionaryCounterInt32 <string>();

            dictionary.Augment("first", 2);
            Assert.AreEqual(2, dictionary.GetValue("first"));

            dictionary.Augment("first", 2);
            Assert.AreEqual(4, dictionary.GetValue("first"));
        }
Ejemplo n.º 3
0
        public void DictionaryCounterInt32_Clear_2()
        {
            DictionaryCounterInt32 <string> dictionary = _GetDictionary2();

            dictionary.Clear();

            Assert.AreEqual(0, dictionary.GetValue("first"));
            Assert.AreEqual(0, dictionary.GetValue("second"));
            Assert.AreEqual(0, dictionary.GetValue("third"));
            Assert.AreEqual(0, dictionary.GetValue("fourth"));
        }
Ejemplo n.º 4
0
        static void AnalyzeCategories
        (
            int year,
            int month
        )
        {
            string expression = string.Format
                                (
                CultureInfo.InvariantCulture,
                "RD={0:0000}{1:00}$",
                year,
                month
                                );

            int[]             found   = connection.Search(expression);
            List <MarcRecord> records = new BatchRecordReader
                                        (
                connection,
                connection.Database,
                500,
                true,
                found
                                        )
                                        .ReadAll(true);

            ReaderInfo[] readers = records.Select(ReaderInfo.Parse).ToArray();
            DictionaryCounterInt32 <string> counter = new DictionaryCounterInt32 <string>();

            foreach (ReaderInfo reader in readers)
            {
                string category = reader.Category;
                if (!string.IsNullOrEmpty(category))
                {
                    counter.Increment(category);
                }
            }

            CultureInfo        culture = CultureInfo.CurrentCulture;
            DateTimeFormatInfo format  = culture.DateTimeFormat;

            Console.Write("{0} {1}", format.GetAbbreviatedMonthName(month), year);
            foreach (string category in knownCategories)
            {
                Console.Write("\t{0}", counter.GetValue(category));
            }
            int others = 0;

            foreach (string key in counter.Keys)
            {
                if (!knownCategories.Contains(key))
                {
                    int value = counter[key];
                    others += value;
                }
            }

            Console.WriteLine("\t{0}", others);
        }
Ejemplo n.º 5
0
        public void DictionaryCounterInt32_GetValue_2()
        {
            DictionaryCounterInt32 <string> dictionary = _GetDictionary2();

            Assert.AreEqual(10, dictionary.GetValue("first"));
            Assert.AreEqual(10, dictionary.GetValue("FIRST"));
            Assert.AreEqual(20, dictionary.GetValue("second"));
            Assert.AreEqual(20, dictionary.GetValue("SECOND"));
            Assert.AreEqual(30, dictionary.GetValue("third"));
            Assert.AreEqual(30, dictionary.GetValue("THIRD"));
            Assert.AreEqual(0, dictionary.GetValue("fourth"));
            Assert.AreEqual(0, dictionary.GetValue("FOURTH"));
        }
Ejemplo n.º 6
0
        public void DictionaryCounterInt32_Increment_1()
        {
            DictionaryCounterInt32 <string> dictionary = _GetDictionary1();

            dictionary.Increment("second");
            dictionary.Increment("third");
            dictionary.Increment("first");

            Assert.AreEqual(11, dictionary.GetValue("first"));
            Assert.AreEqual(0, dictionary.GetValue("FIRST"));
            Assert.AreEqual(21, dictionary.GetValue("second"));
            Assert.AreEqual(0, dictionary.GetValue("SECOND"));
            Assert.AreEqual(31, dictionary.GetValue("third"));
            Assert.AreEqual(0, dictionary.GetValue("THIRD"));
            Assert.AreEqual(0, dictionary.GetValue("fourth"));
            Assert.AreEqual(0, dictionary.GetValue("FOURTH"));
        }
Ejemplo n.º 7
0
        static void Main()
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            try
            {
                using (connection = new IrbisConnection())
                {
                    connection.ParseConnectionString(ConnectionString);
                    connection.Connect();
                    connection.Database = DatabaseName;
                    Console.WriteLine("Подключились");

                    IEnumerable <MarcRecord> records
                        = BatchRecordReader.WholeDatabase
                          (
                              connection,
                              DatabaseName,
                              500
                              //, rdr =>
                              //{
                              //    Console.WriteLine
                              //        (
                              //            "{0} из {1}",
                              //            rdr.RecordsRead,
                              //            rdr.TotalRecords
                              //        );
                              //}
                          );

                    foreach (MarcRecord record in records)
                    {
                        if (Cancel)
                        {
                            break;
                        }

                        if (record.Deleted)
                        {
                            continue;
                        }

                        ReaderInfo reader = ReaderInfo.Parse(record);
                        if (reader.WorkPlace.SafeContains("ИОГУНБ"))
                        {
                            continue;
                        }

                        int age    = reader.Age;
                        int visits = reader.Visits.Count(v => v.IsVisit);

                        if (reader.Gender.SameString("ж"))
                        {
                            FemaleCount++;
                            FemaleAge.Increment(age);
                            FemaleVisits.Augment(age, visits);
                        }
                        else
                        {
                            MaleCount++;
                            MaleAge.Increment(age);
                            MaleVisits.Augment(age, visits);
                        }
                    }
                }
                Console.WriteLine("Отключились");

                Console.WriteLine(";Муж;Жен;М пос;Ж пос");
                Console.WriteLine
                (
                    "Всего;{0};{1};{2};{3}",
                    MaleCount,
                    FemaleCount,
                    MaleVisits.Total,
                    FemaleVisits.Total
                );
                for (int age = 12; age < 100; age++)
                {
                    Console.WriteLine
                    (
                        "{0};{1};{2};{3};{4}",
                        age,
                        MaleAge.GetValue(age),
                        FemaleAge.GetValue(age),
                        MaleVisits.GetValue(age),
                        FemaleVisits.GetValue(age)
                    );
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }