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

            try
            {
                GDMIndividualRecord iRec = (GDMIndividualRecord)record;
                int bdy = iRec.GetChronologicalYear(GEDCOMTagName.BIRT);
                int ddy = iRec.GetChronologicalYear(GEDCOMTagName.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 Test_Common()
        {
            Assert.IsNull(fContext.Viewer);

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

            Assert.IsNotNull(iRec);

            Assert.AreEqual(1990, iRec.GetChronologicalYear(GEDCOMTagName.BIRT));

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

            // FIXME: error during execution of tests under TravisCI (a problem with UI)
            //var patrGraph = PatriarchsMan.GetPatriarchsGraph(fContext, 1, true, false);
            //Assert.IsNotNull(patrGraph);
        }
Exemplo n.º 3
0
        public void GetSpecStats(StatsMode mode, List <StatsItem> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

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

            int num = fTree.RecordsCount;

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

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

                    if (mode != StatsMode.smAAF_1 && mode != StatsMode.smAAF_2)
                    {
                        GetSimplePersonStat(mode, values, iRec);
                    }
                    else
                    {
                        GDMIndividualRecord iChild = GKUtils.GetFirstborn(fTree, 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(GEDCOMTagName.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(GEDCOMTagName.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 == GDMRecordType.rtFamily && mode == StatsMode.smSpousesDiff)
                {
                    GDMFamilyRecord fRec = rec as GDMFamilyRecord;

                    int diff = GKUtils.GetSpousesDiff(fTree, fRec);
                    if (diff != -1)
                    {
                        values.Add(new StatsItem(GKUtils.GetFamilyString(fTree, 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));
                }
            }
        }