Exemplo n.º 1
0
        public List <IGeneticTreeNode> GetInheritors(IGeneticTreeNode person)
        {
            List <IGeneticTreeNode> list = new List <IGeneticTreeNode>();

            AddInheritors(list, person);
            return(list);
        }
Exemplo n.º 2
0
 public void GetSomeonesAncestors(List <IGeneticTreeNode> ancestors, IGeneticTreeNode person)
 {
     foreach (var item in GetParents(person))
     {
         ancestors.Add(item);
         GetSomeonesAncestors(ancestors, item);
     }
 }
 public bool CheckFatherRelation(IGeneticTreeNode father, IGeneticTreeNode child)
 {
     return father.Name != child.Name &&
             father.Sex == Sex.Male &&
             father.DateOfBirth.AddYears(12) < child.DateOfBirth &&
             father.DateOfBirth.AddYears(70) > child.DateOfBirth &&
             ((father.DateOfDead == null) || father.DateOfDead.Value.AddDays(270) > child.DateOfBirth);
 }
Exemplo n.º 4
0
 public void GetSomeonesDescendants(List <IGeneticTreeNode> descendants, IGeneticTreeNode person)
 {
     foreach (var item in person.Children)
     {
         descendants.Add(item);
         GetSomeonesDescendants(descendants, item);
     }
 }
Exemplo n.º 5
0
 public bool CheckFatherRelation(IGeneticTreeNode father, IGeneticTreeNode child)
 {
     return(father.Name != child.Name &&
            father.Sex == Sex.Male &&
            father.DateOfBirth.AddYears(12) < child.DateOfBirth &&
            father.DateOfBirth.AddYears(70) > child.DateOfBirth &&
            ((father.DateOfDead == null) || father.DateOfDead.Value.AddDays(270) > child.DateOfBirth));
 }
 public bool CheckMotherRelation(IGeneticTreeNode mother, IGeneticTreeNode child)
 {
     return mother.Name != child.Name &&
             mother.Sex == Sex.Female &&
             !mother.Children.Contains(child) &&
             GetParent(Sex.Female, child) == null &&
             mother.DateOfBirth.AddYears(10) < child.DateOfBirth &&
             mother.DateOfBirth.AddYears(60) > child.DateOfBirth &&
             ((mother.DateOfDead == null) || (mother.DateOfDead.Value > child.DateOfBirth));
 }
Exemplo n.º 7
0
        public List <IGeneticTreeNode> GetCommonAncestors(IGeneticTreeNode person1, IGeneticTreeNode person2)
        {
            var family1 = new List <IGeneticTreeNode>();
            var family2 = new List <IGeneticTreeNode>();

            GetSomeonesAncestors(family1, person1);
            GetSomeonesAncestors(family2, person2);

            return(family1.Intersect <IGeneticTreeNode>(family2).ToList());
        }
Exemplo n.º 8
0
 public bool CheckMotherRelation(IGeneticTreeNode mother, IGeneticTreeNode child)
 {
     return(mother.Name != child.Name &&
            mother.Sex == Sex.Female &&
            !mother.Children.Contains(child) &&
            GetParent(Sex.Female, child) == null &&
            mother.DateOfBirth.AddYears(10) < child.DateOfBirth &&
            mother.DateOfBirth.AddYears(60) > child.DateOfBirth &&
            ((mother.DateOfDead == null) || (mother.DateOfDead.Value > child.DateOfBirth)));
 }
Exemplo n.º 9
0
 private void AddInheritors(List <IGeneticTreeNode> inheritors, IGeneticTreeNode person)
 {
     foreach (var item in person.Children)
     {
         if (item.DateOfDead != null)
         {
             AddInheritors(inheritors, item);
         }
         else
         {
             inheritors.Add(item);
         }
     }
 }
Exemplo n.º 10
0
        public List <IGeneticTreeNode> GetParents(IGeneticTreeNode person)
        {
            var list    = new List <IGeneticTreeNode>();
            var parent1 = GetParent(Sex.Male, person);

            if (parent1 != null)
            {
                list.Add(parent1);
            }
            var parent2 = GetParent(Sex.Female, person);

            if (parent2 != null)
            {
                list.Add(parent2);
            }
            return(list);
        }
Exemplo n.º 11
0
        private void AddToGeneration(int level, IGeneticTreeNode node)
        {
            var generation = GetGeneration(level);

            if (generation == null)
            {
                Generations.Add(new Generation()
                {
                    Level = level, Nodes = new List <IGeneticTreeNode>()
                });
                generation = GetGeneration(level);
            }
            if (!generation.Nodes.Contains(node))
            {
                AddToGeneration(generation, node);
            }
        }
Exemplo n.º 12
0
        public bool ChangeDateOfBirth(IGeneticTreeNode person)
        {
            var parent = new Person()
            {
                DateOfBirth = person.DateOfBirth,
                DateOfDead  = person.DateOfDead,
            };

            if (person.Children != null)
            {
                if (person.Children.Any(child => !CheckPartensDateOfBirth(parent, child)))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 13
0
        public bool ChangeDateOfDead(DateTime?newDate, IGeneticTreeNode person)
        {
            var parent = new Person()
            {
                DateOfBirth = person.DateOfBirth,
                DateOfDead  = newDate,
            };

            if (person.Children != null)
            {
                if (person.Children.Any(child => !CheckChildRelation(child, parent)))
                {
                    return(false);
                }
            }

            person.DateOfDead = newDate;
            return(true);
        }
Exemplo n.º 14
0
 public bool CheckMothersDateOfBirth(IGeneticTreeNode parent, IGeneticTreeNode child)
 {
     return(child.DateOfBirth > parent.DateOfBirth.AddYears(10));
 }
Exemplo n.º 15
0
 private void AddToGeneration(Generation generation, IGeneticTreeNode node, IGeneticTreeNode to)
 {
     generation.Nodes.Insert(GetIndexInGeneration(generation, to), node);
 }
Exemplo n.º 16
0
 private int GetIndexInGeneration(Generation generation, IGeneticTreeNode node)
 {
     return(generation.Nodes.IndexOf(node));
 }
Exemplo n.º 17
0
 private bool GotChildrenWithSomeonesChild(IGeneticTreeNode node)
 {
     return(Nodes.Where(n => n != node).Any(n => n.Children.ContainsAny <IGeneticTreeNode>(node.Children)));
 }
Exemplo n.º 18
0
 public Person GetParent(Sex sex, IGeneticTreeNode person)
 {
     var parent = this._db.Query<Person>(n => n.Sex == sex && n.Children.Contains(person)).FirstOrDefault();
     return parent;
 }
Exemplo n.º 19
0
 public IEnumerable <Person> GetAllMothers(IGeneticTreeNode child)
 {
     return(this._db.Query <Person>().Where(n => CheckMotherRelation(n, child)));
 }
Exemplo n.º 20
0
        public List<IGeneticTreeNode> GetCommonAncestors(IGeneticTreeNode person1, IGeneticTreeNode person2)
        {
            var family1 = new List<IGeneticTreeNode>();
            var family2 = new List<IGeneticTreeNode>();

            GetSomeonesAncestors(family1, person1);
            GetSomeonesAncestors(family2, person2);

            return family1.Intersect<IGeneticTreeNode>(family2).ToList();
        }
Exemplo n.º 21
0
 public void GetSomeonesDescendants(List<IGeneticTreeNode> descendants, IGeneticTreeNode person)
 {
     foreach (var item in person.Children)
     {
         descendants.Add(item);
         GetSomeonesDescendants(descendants, item);
     }
 }
Exemplo n.º 22
0
 public void GetSomeonesAncestors(List<IGeneticTreeNode> ancestors, IGeneticTreeNode person)
 {
     foreach (var item in GetParents(person))
     {
         ancestors.Add(item);
         GetSomeonesAncestors(ancestors, item);
     }
 }
Exemplo n.º 23
0
 public List<IGeneticTreeNode> GetInheritors(IGeneticTreeNode person)
 {
     List<IGeneticTreeNode> list = new List<IGeneticTreeNode>();
     AddInheritors(list, person);
     return list;
 }
Exemplo n.º 24
0
        private void AddInheritors(List<IGeneticTreeNode> inheritors, IGeneticTreeNode person)
        {

            foreach (var item in person.Children)
            {
                
                if (item.DateOfDead!=null)
                {
                    AddInheritors(inheritors, item);
                }
                else
                {
                    inheritors.Add(item);
                }
            }
        }
Exemplo n.º 25
0
 public IEnumerable<Person> GetAllChildren(IGeneticTreeNode parent)
 {
     return this._db.Query<Person>().Where(n => CheckChildRelationWithChildEntity(n, parent));
 }
Exemplo n.º 26
0
 public IEnumerable<Person> GetAllMothers(IGeneticTreeNode child)
 {
     return this._db.Query<Person>().Where(n => CheckMotherRelation(n, child));
 }
Exemplo n.º 27
0
        public bool ChangeDateOfDead(DateTime? newDate, IGeneticTreeNode person)
        {
            var parent = new Person()
            {
                DateOfBirth = person.DateOfBirth,
                DateOfDead = newDate,
            };

            if (person.Children != null)
            {
                if (person.Children.Any(child => !CheckChildRelation(child, parent)))
                {
                    return false;
                }
            }

            person.DateOfDead = newDate;
            return true;
        }
Exemplo n.º 28
0
        public Person GetParent(Sex sex, IGeneticTreeNode person)
        {
            var parent = this._db.Query <Person>(n => n.Sex == sex && n.Children.Contains(person)).FirstOrDefault();

            return(parent);
        }
Exemplo n.º 29
0
 public bool CheckChildRelationWithChildEntity(IGeneticTreeNode child, IGeneticTreeNode parent)
 {
     return (parent.Sex == Sex.Male)
         ? CheckFatherRelationWithChildEntity(parent, child)
         : CheckMotherRelationWithChildEntity(parent, child);
 }
Exemplo n.º 30
0
 public bool CheckFatherRelationWithChildEntity(IGeneticTreeNode father, IGeneticTreeNode child)
 {
     return(CheckFatherRelation(father, child) &&
            !father.Children.Contains(child) &&
            GetParent(Sex.Male, child) == null);
 }
Exemplo n.º 31
0
 private bool GotParents(IGeneticTreeNode node)
 {
     return(Nodes.Any(n => n.Children.Contains(node)));
 }
Exemplo n.º 32
0
 public IEnumerable <Person> GetAllChildren(IGeneticTreeNode parent)
 {
     return(this._db.Query <Person>().Where(n => CheckChildRelationWithChildEntity(n, parent)));
 }
Exemplo n.º 33
0
 public bool CheckPartensDateOfBirth(IGeneticTreeNode parent, IGeneticTreeNode child)
 {
     return (parent.Sex == Sex.Male) ? CheckFathersDateOfBirth(parent, child) : CheckMothersDateOfBirth(parent, child);
 }
Exemplo n.º 34
0
 private IGeneticTreeNode GetPartner(IGeneticTreeNode node)
 {
     return(Nodes.SingleOrDefault(n => n != node && n.Children.ContainsAny <IGeneticTreeNode>(node.Children)));
 }
Exemplo n.º 35
0
 private void AddToGeneration(Generation generation, IGeneticTreeNode node)
 {
     generation.Nodes.Add(node);
 }
Exemplo n.º 36
0
 private bool GotChildren(IGeneticTreeNode node)
 {
     return(node.Children.Count > 0);
 }
Exemplo n.º 37
0
 private Generation GetSomeonesGeneration(IGeneticTreeNode node)
 {
     return(Generations.SingleOrDefault(n => n.Nodes.Contains(node)));
 }
Exemplo n.º 38
0
 public bool CheckChildRelationWithChildEntity(IGeneticTreeNode child, IGeneticTreeNode parent)
 {
     return((parent.Sex == Sex.Male)
         ? CheckFatherRelationWithChildEntity(parent, child)
         : CheckMotherRelationWithChildEntity(parent, child));
 }
Exemplo n.º 39
0
 public bool CheckFatherRelationWithChildEntity(IGeneticTreeNode father, IGeneticTreeNode child)
 {
     return CheckFatherRelation(father, child) &&
         !father.Children.Contains(child) &&
         GetParent(Sex.Male, child) == null;
 }
Exemplo n.º 40
0
 public bool CheckPartensDateOfBirth(IGeneticTreeNode parent, IGeneticTreeNode child)
 {
     return((parent.Sex == Sex.Male) ? CheckFathersDateOfBirth(parent, child) : CheckMothersDateOfBirth(parent, child));
 }
Exemplo n.º 41
0
 public List<IGeneticTreeNode> GetParents(IGeneticTreeNode person)
 {
     var list = new List<IGeneticTreeNode>();
     var parent1 = GetParent(Sex.Male, person);
     if (parent1 != null)
     {
         list.Add(parent1);
     }
     var parent2 = GetParent(Sex.Female, person);
     if (parent2 != null)
     {
         list.Add(parent2);
     }
     return list;
 }
Exemplo n.º 42
0
 public bool CheckMothersDateOfBirth(IGeneticTreeNode parent, IGeneticTreeNode child)
 {
     return child.DateOfBirth > parent.DateOfBirth.AddYears(10);
 }
Exemplo n.º 43
0
        public bool ChangeDateOfBirth(IGeneticTreeNode person)
        {
            var parent = new Person()
            {
                DateOfBirth = person.DateOfBirth,
                DateOfDead = person.DateOfDead,
            };

            if (person.Children != null)
            {
                if (person.Children.Any(child => !CheckPartensDateOfBirth(parent, child)))
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 44
0
 public bool CheckMotherRelationWithChildEntity(IGeneticTreeNode mother, IGeneticTreeNode child)
 {
     return CheckMotherRelation(mother, child) &&
         !mother.Children.Contains(child) &&
         GetParent(Sex.Female, child) == null;
 }
Exemplo n.º 45
0
        private void AddPartner(IGeneticTreeNode node, IGeneticTreeNode to)
        {
            var generation = GetSomeonesGeneration(to);

            AddToGeneration(generation, node, to);
        }