Exemplo n.º 1
0
        // FIXME: perhaps it is necessary to define the maximum age by statistics
        private bool FilterHandler(GEDCOMRecord record)
        {
            bool result = true;

            try
            {
                GEDCOMIndividualRecord iRec = (GEDCOMIndividualRecord)record;
                int bdy = iRec.GetChronologicalYear("BIRT");
                int ddy = iRec.GetChronologicalYear("DEAT");

                if (bdy != 0 && ddy == 0)
                {
                    ddy = bdy + GKData.PROVED_LIFE_LENGTH;
                }

                if (bdy == 0 && ddy != 0)
                {
                    bdy = ddy - GKData.PROVED_LIFE_LENGTH;
                }

                if (fYearCurrent > 0)
                {
                    result = (fYearCurrent >= bdy && fYearCurrent <= ddy);
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("TimeLineWidget.FilterHandler(): " + ex.Message);
            }

            return(result);
        }
Exemplo n.º 2
0
        public void GetSpecStats(StatsMode mode, List <StatsItem> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            if (mode < StatsMode.smDescGenerations)
            {
                GKUtils.InitExtCounts(fTree, -1);
            }

            // special buffers for difficult calculations with averaged ages
            Dictionary <string, List <int> > xvals = new Dictionary <string, List <int> >();

            int num = fTree.RecordsCount;

            for (int i = 0; i < num; i++)
            {
                GEDCOMRecord rec = fTree[i];

                if (rec.RecordType == GEDCOMRecordType.rtIndividual && mode != StatsMode.smSpousesDiff && fSelectedRecords.Contains(rec))
                {
                    GEDCOMIndividualRecord iRec = rec as GEDCOMIndividualRecord;

                    if (mode != StatsMode.smAAF_1 && mode != StatsMode.smAAF_2)
                    {
                        GetSimplePersonStat(mode, values, iRec);
                    }
                    else
                    {
                        GEDCOMIndividualRecord iChild = GKUtils.GetFirstborn(iRec);
                        int fba = GKUtils.GetFirstbornAge(iRec, iChild);
                        if (fba > 0 && iChild != null)
                        {
                            string     key;
                            List <int> valsList;

                            switch (mode)
                            {
                            case StatsMode.smAAF_1:
                                int dty1 = iRec.GetChronologicalYear("BIRT");
                                if (dty1 != 0)
                                {
                                    key = MathHelper.Trunc(dty1 / 10 * 10).ToString();

                                    if (!xvals.TryGetValue(key, out valsList))
                                    {
                                        valsList = new List <int>();
                                        xvals.Add(key, valsList);
                                    }
                                    valsList.Add(fba);
                                }

                                break;

                            case StatsMode.smAAF_2:
                                int dty2 = iChild.GetChronologicalYear("BIRT");
                                if (dty2 != 0)
                                {
                                    key = MathHelper.Trunc(dty2 / 10 * 10).ToString();

                                    if (!xvals.TryGetValue(key, out valsList))
                                    {
                                        valsList = new List <int>();
                                        xvals.Add(key, valsList);
                                    }
                                    valsList.Add(fba);
                                }

                                break;
                            }
                        }
                    }
                }
                else if (rec.RecordType == GEDCOMRecordType.rtFamily && mode == StatsMode.smSpousesDiff)
                {
                    GEDCOMFamilyRecord fRec = rec as GEDCOMFamilyRecord;

                    int diff = GKUtils.GetSpousesDiff(fRec);
                    if (diff != -1)
                    {
                        values.Add(new StatsItem(GKUtils.GetFamilyString(fRec), diff));
                    }
                }
            }

            if (mode == StatsMode.smAAF_1 || mode == StatsMode.smAAF_2)
            {
                foreach (KeyValuePair <string, List <int> > kvp in xvals)
                {
                    List <int> valsList = kvp.Value;
                    int        count    = valsList.Count;

                    int avg;
                    if (count == 0)
                    {
                        avg = 0;
                    }
                    else
                    {
                        double sum = 0;
                        for (int i = 0; i < count; i++)
                        {
                            sum += valsList[i];
                        }
                        avg = (int)Math.Round(sum / count);
                    }

                    values.Add(new StatsItem(kvp.Key, avg));
                }
            }
        }
Exemplo n.º 3
0
        public void Test_Common()
        {
            Assert.IsNotNull(fContext.Culture);

            Assert.IsNull(fContext.Viewer);

            fContext.SetFileName("testfile.ged");
            Assert.AreEqual("testfile.ged", fContext.FileName);

            //

            fContext.CollectEventValues(null);


            Assert.AreEqual(ShieldState.Maximum, fContext.ShieldState, "BaseContext.ShieldState.1");
            fContext.SwitchShieldState();
            Assert.AreEqual(ShieldState.Middle, fContext.ShieldState, "BaseContext.ShieldState.2");
            fContext.SwitchShieldState();
            Assert.AreEqual(ShieldState.None, fContext.ShieldState, "BaseContext.ShieldState.3");
            fContext.SwitchShieldState();
            Assert.AreEqual(ShieldState.Maximum, fContext.ShieldState, "BaseContext.ShieldState.4");


            GEDCOMSourceRecord srcRec = fContext.FindSource("test source");

            Assert.IsNull(srcRec);

            StringList sources = new StringList();

            fContext.GetSourcesList(sources);
            Assert.AreEqual(1, sources.Count);

            Assert.IsNotNull(fContext.ValuesCollection);

            GEDCOMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GEDCOMIndividualRecord;

            Assert.IsNotNull(iRec);

            fContext.LockRecord(iRec);
            fContext.UnlockRecord(iRec);

            Assert.AreEqual(false, fContext.IsChildless(iRec));

            Assert.IsNotNull(fContext.LangsList);
            Assert.AreEqual(0, fContext.LangsList.Count);
            fContext.CollectNameLangs(null);
            iRec.PersonalNames[0].Language.Value = GEDCOMLanguageID.AncientGreek;
            fContext.CollectNameLangs(iRec.PersonalNames[0]);
            Assert.AreEqual(1, fContext.LangsList.Count);

            // FIXME: move to other tests
            Assert.AreEqual(1990, iRec.GetChronologicalYear("BIRT"));

            Assert.AreEqual(1990, fContext.FindBirthYear(iRec));
            Assert.AreEqual(2010, fContext.FindDeathYear(iRec));

            Assert.IsFalse(fContext.DeleteRecord(null));

            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateIndividual()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateFamily()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateNote()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateMultimedia()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateSource()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateRepository()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateGroup()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateResearch()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateTask()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateCommunication()));
            Assert.IsTrue(fContext.DeleteRecord(fContext.Tree.CreateLocation()));

            Assert.Throws(typeof(ArgumentNullException), () => { fContext.GetStoreType(null); });
            var mediaStore = fContext.GetStoreType(new GEDCOMFileReference(fContext.Tree, null, "", "file.txt"));

            Assert.AreEqual(MediaStoreType.mstReference, mediaStore.StoreType);
            mediaStore = fContext.GetStoreType(new GEDCOMFileReference(fContext.Tree, null, "", "stg:file.txt"));
            Assert.AreEqual(MediaStoreType.mstStorage, mediaStore.StoreType);
            mediaStore = fContext.GetStoreType(new GEDCOMFileReference(fContext.Tree, null, "", "arc:file.txt"));
            Assert.AreEqual(MediaStoreType.mstArchive, mediaStore.StoreType);

            fContext.CollectEventValues(null);

            fContext.BeginUpdate();
            Assert.IsTrue(fContext.IsUpdated());
            fContext.EndUpdate();
            Assert.IsFalse(fContext.IsUpdated());

            fContext.DoUndo();
            fContext.DoRedo();
            fContext.DoCommit();
            fContext.DoRollback();

            // FIXME: error during execution of tests under TravisCI (a problem with UI)
            //var patrGraph = PatriarchsMan.GetPatriarchsGraph(fContext, 1, true, false);
            //Assert.IsNotNull(patrGraph);

            //

            var evt = fContext.CreateEventEx(iRec, "FACT", "17 JAN 2013", "Ivanovo");

            Assert.IsNotNull(evt);

            GEDCOMFamilyRecord fRec = fContext.Tree.CreateFamily();

            Assert.IsNotNull(fRec);

            evt = fContext.CreateEventEx(fRec, "MARR", "28 DEC 2013", "Ivanovo");
            Assert.IsNotNull(evt);
        }