Exemplo n.º 1
0
 private void ValidateDam(RawCalf rawCalf)
 {
     if (rawCalf.DamSN <= 0)
     {
         AddIssue(rawCalf,
                  string.Format("Dam SN is missing or invalid ({0}) and don't know how to add new cows yet",
                                rawCalf.DamSN));
     }
     else
     {
         if (_bbModel.tblDams.Find(rawCalf.DamSN) == null)
         {
             AddIssue(rawCalf, string.Format("Dam SN {0} not found.", rawCalf.DamSN));
         }
     }
 }
Exemplo n.º 2
0
        private void AddToHerd(int sn, RawCalf calf)
        {
            var toHerd = Herds.FirstOrDefault(h => h.HerdSN == sn);

            if (toHerd == null)
            {
                Herds.Add(new Herd
                {
                    Calves = new List <RawCalf>(),
                    HerdSN = sn
                });
                toHerd = Herds.First(h => h.HerdSN == sn);
            }

            toHerd.Calves.Add(calf);
        }
Exemplo n.º 3
0
        private void AddIssue(RawCalf calf, string issueDescription, IssueSeverity issueSeverity = IssueSeverity.Fatal)
        {
            switch (issueSeverity)
            {
            case IssueSeverity.Fatal:
                IssueList.Add(string.Format("FATAL. Id:{0} - {1}", calf.HerdtraxAnimalId, issueDescription));
                break;

            case IssueSeverity.Warn:
                IssueList.Add(string.Format("WARNING. Id:{0} - {1}", calf.HerdtraxAnimalId, issueDescription));
                break;

            case IssueSeverity.Info:
                IssueList.Add(string.Format("Id:{0} - {1}", calf.HerdtraxAnimalId, issueDescription));
                break;
            }
        }
Exemplo n.º 4
0
        public tblCalf BuildFromRawCalf(RawCalf rawCalf, Herd herd)
        {
            var calfBirthYear = (short)(rawCalf.BirthDate.Year);
            var newCalf       = new tblCalf
            {
                Calf_SN          = rawCalf.CalfSN,
                Dam_SN           = rawCalf.DamSN,
                CalfHerd_SN      = herd.HerdSN,
                HerdtraxAnimalId = rawCalf.HerdtraxAnimalId,
                CalfBirthYr_Num  = calfBirthYear,
                CalfTag_Num      = int.Parse(rawCalf.TagNumber),
                CalfYr_Code      = YearLetterCode(calfBirthYear),
                DNA_Tag          = string.IsNullOrEmpty(rawCalf.DNATag) ? (int?)null : int.Parse(rawCalf.DNATag),
                Birth_Date       = rawCalf.BirthDate,
                Birth_Wt         = rawCalf.BirthWt == 0 ? (short?)null : (short)rawCalf.BirthWt,
                Sex_Code         = rawCalf.SexCode,
                Cull_Pull_Flag   = rawCalf.EaseScore > 0,
                Udder_Score      = rawCalf.UdderScore == 0 ? (byte?)null : (byte)rawCalf.UdderScore,
            };

            // Twin stuff
            if (!string.IsNullOrEmpty(rawCalf.TwinType))
            {
                newCalf.Twin_Flag        = true;
                newCalf.HerdtraxTwinType = rawCalf.TwinType;

                if (rawCalf.SiblingCalfAnimalId > 0)
                {
                    RawCalf sib = herd.Calves.First(c => c.HerdtraxAnimalId == rawCalf.SiblingCalfAnimalId);
                    newCalf.CalfTwin_SN = sib.CalfSN;
                }

                if (rawCalf.SurrogateDam_SN > 0)
                {
                    //RawCalf sib = herd.Calves.First(c => c.HerdtraxAnimalId == rawCalf.SiblingCalfAnimalId);
                    //newCalf.CalfTwin_SN = sib.CalfSN;
                    newCalf.GraftedFromDam_SN = rawCalf.SurrogateDam_SN;
                    newCalf.Grafted_Flag      = true;
                }
            }
            return(newCalf);
        }
        public void Process(IEnumerable <Herd> herds)
        {
            foreach (Herd herd in herds)
            {
                List <RawCalf> twinCalfList = herd.Calves.Where(calf => !string.IsNullOrEmpty(calf.TwinType)).ToList();

                // Set sibling
                foreach (RawCalf calf in twinCalfList)
                {
                    RawCalf tc = calf;

                    // Sibling is calf with same mother and different animal id
                    RawCalf sibling =
                        herd.Calves.FirstOrDefault(c => c.HerdtraxAnimalId != tc.HerdtraxAnimalId && c.DamSN == tc.DamSN);
                    if (sibling != null)
                    {
                        calf.SiblingCalfAnimalId = sibling.HerdtraxAnimalId;
                        //sibling.SiblingCalfAnimalId = calf.HerdtraxAnimalId;
                    }
                }


                // Set Surrogate mother
                foreach (RawCalf calf in twinCalfList)
                {
                    int     herdSN = herd.HerdSN;
                    RawCalf gc     = calf;

                    tblDam surrogateDam = _bbModel.tblDams.FirstOrDefault(
                        d =>
                        d.DamHerd_SN == herdSN && d.DamTag_Str == gc.SurrogateTagNumber &&
                        d.DamYr_Code == gc.SurrogateTagLetter);
                    if (surrogateDam != null)
                    {
                        calf.SurrogateDam_SN = surrogateDam.Dam_SN;
                    }
                }
            }
        }
        private RawCalf ExtractValuesUsingColumnDefinitionIndexes(IEnumerable <CalvingDataColumnDefinition> coldefs,
                                                                  IReadOnlyList <string> colvals)
        {
            var calf = new RawCalf();

            foreach (var coldef in coldefs)
            {
                switch (coldef.Column)
                {
                case CalvingColumn.ManagementGroup:
                    calf.Group = colvals[coldef.Index];
                    break;

                case CalvingColumn.HerdLocation:
                    break;

                case CalvingColumn.DamRegId:
                    calf.DamRegistrationNumber = colvals[coldef.Index];
                    calf.DamSN = ConvertInt(colvals[coldef.Index]);
                    break;

                case CalvingColumn.DamHerdtraxId:
                    break;

                case CalvingColumn.DamCCIA:
                    break;

                case CalvingColumn.DamVID:
                    calf.DamVID = colvals[coldef.Index];
                    break;

                case CalvingColumn.DamTagNumber:
                    calf.DamTagNumber = colvals[coldef.Index];
                    break;

                case CalvingColumn.DamTagLetter:
                    calf.DamTagLetter = colvals[coldef.Index];
                    break;

                case CalvingColumn.DamTagColor:
                    calf.DamTagColor = colvals[coldef.Index];
                    break;

                case CalvingColumn.CalfRegId:
                    calf.RegistrationNumber = colvals[coldef.Index];
                    break;

                case CalvingColumn.CalfHerdtraxId:
                    calf.HerdtraxAnimalId = ConvertInt(colvals[coldef.Index]);
                    break;

                case CalvingColumn.CalfVID:
                    calf.VID = colvals[coldef.Index];
                    break;

                case CalvingColumn.CalfCCIA:
                    calf.CCIA = colvals[coldef.Index];
                    break;

                case CalvingColumn.Gender:
                    calf.Gender = colvals[coldef.Index];
                    break;

                case CalvingColumn.Hoof:
                    calf.HoofScore = ConvertInt(colvals[coldef.Index]);
                    break;

                case CalvingColumn.Udder:
                    calf.UdderScore = ConvertInt(colvals[coldef.Index]);
                    break;

                case CalvingColumn.Ease:
                    calf.EaseScore = ConvertInt(colvals[coldef.Index]);
                    break;

                case CalvingColumn.BirthWeight:
                    calf.BirthWt = ConvertInt(colvals[coldef.Index]);
                    break;

                case CalvingColumn.BirthDate:
                    calf.BirthDate = ConvertDate(colvals[coldef.Index]);
                    break;

                case CalvingColumn.TagNumber:
                    calf.TagNumber = colvals[coldef.Index];
                    break;

                case CalvingColumn.TagLetter:
                    calf.TagLetter = colvals[coldef.Index];
                    break;

                case CalvingColumn.TagColor:
                    calf.TagColor = colvals[coldef.Index];
                    break;

                case CalvingColumn.Twins:
                    calf.TwinType = colvals[coldef.Index];
                    break;

                case CalvingColumn.CalfDNA:
                    calf.DNATag = colvals[coldef.Index];
                    break;

                case CalvingColumn.SurrogateTagNumber:
                    calf.SurrogateTagNumber = colvals[coldef.Index];
                    break;

                case CalvingColumn.SurrogateTagLetter:
                    calf.SurrogateTagLetter = colvals[coldef.Index];
                    break;

                case CalvingColumn.SurrogateTagColor:
                    calf.SurrogateTagColor = colvals[coldef.Index];
                    break;
                }
            }
            return(calf);
        }
Exemplo n.º 7
0
        private void ValidateCalf(RawCalf rawCalf, Herd herd)
        {
            // Calf Registration # should be null
            if (!string.IsNullOrWhiteSpace(rawCalf.RegistrationNumber))
            {
                AddIssue(rawCalf,
                         string.Format("Calf registration number ({0}) should not exist for new calves.",
                                       rawCalf.RegistrationNumber));
            }

            // Herdtrax Animal Id
            if (rawCalf.HerdtraxAnimalId == 0)
            {
                AddIssue(rawCalf,
                         string.Format("Herdtrax Animal Id is required for every calf. Its missing for calf with VID {0}",
                                       rawCalf.VID));
            }
            else
            {
                tblCalf dbCalf = _bbModel.tblCalves.FirstOrDefault(c => c.HerdtraxAnimalId == rawCalf.HerdtraxAnimalId);
                if (dbCalf != null)
                {
                    AddIssue(rawCalf,
                             string.Format(
                                 "Animal Id already exists. This import progam is not prepared to UPDATE... only INSERTS.  Calf_SN:{0}",
                                 dbCalf.Calf_SN));
                }
            }

            // Sex
            if (string.IsNullOrWhiteSpace(rawCalf.Gender))
            {
                AddIssue(rawCalf, string.Format("No gender (Calf-M/Calf-F)."));
            }

            if ((rawCalf.SexCode != "F") && (rawCalf.SexCode != "M"))
            {
                AddIssue(rawCalf,
                         string.Format("Missing or invalid sex code - {0},  Herdtrax Gender:{1}", rawCalf.SexCode,
                                       rawCalf.Gender));
            }

            // Date
            if (rawCalf.BirthDate == DateTime.MinValue)
            {
                AddIssue(rawCalf, string.Format("Birth date is missing."));
            }

            // Weight
            if ((rawCalf.BirthWt > 0) && ((rawCalf.BirthWt < 20) || (rawCalf.BirthWt > 150)))
            {
                AddIssue(rawCalf, string.Format("Birth weight is out of range ({0})", rawCalf.BirthWt));
            }

            // Ease (we have true/false for assisted birth flag)
            if ((rawCalf.EaseScore < 0) || (rawCalf.EaseScore > 1))
            {
                AddIssue(rawCalf, string.Format("Calving ease is out of range ({0})", rawCalf.EaseScore));
            }

            // Udder
            if ((rawCalf.UdderScore < 0) || (rawCalf.UdderScore > 4))
            {
                AddIssue(rawCalf, string.Format("Udder score is out of range ({0})", rawCalf.UdderScore));
            }

            // Tag
            if (string.IsNullOrWhiteSpace(rawCalf.TagNumber))
            {
                AddIssue(rawCalf, string.Format("Calf tag number is null or missing"));
            }
            else
            {
                int tagnum;
                if (!int.TryParse(rawCalf.TagNumber, out tagnum))
                {
                    AddIssue(rawCalf, string.Format("Calf tag number is not a real number {0}.", rawCalf.TagNumber));
                }
                else
                {
                    tblCalf dbCalf = _bbModel.tblCalves.FirstOrDefault(
                        c =>
                        c.CalfHerd_SN == herd.HerdSN && c.CalfBirthYr_Num == rawCalf.BirthDate.Year &&
                        c.CalfTag_Num == tagnum);
                    if (dbCalf != null)
                    {
                        AddIssue(rawCalf,
                                 string.Format("Calf exists: HerdSN:{0}  BirthYrNum:{1}  TagNumber{2}.  Calf_SN={3}",
                                               herd.HerdSN, rawCalf.BirthDate.Year, rawCalf.TagNumber, dbCalf.Calf_SN));
                    }
                }
            }

            // DNA tag
            if (!string.IsNullOrEmpty(rawCalf.DNATag))
            {
                int dnatag;
                if (!int.TryParse(rawCalf.DNATag, out dnatag))
                {
                    AddIssue(rawCalf, string.Format("Calf DNA tag is not numeric {0}.", rawCalf.DNATag));
                }
                else
                {
                    tblCalf dbCalf = _bbModel.tblCalves.FirstOrDefault(
                        c => c.DNA_Tag == dnatag);
                    if (dbCalf != null)
                    {
                        AddIssue(rawCalf,
                                 string.Format(
                                     "DNA tag {0} already exists: HerdSN:{1}  BirthYrNum:{2}  TagNumber{3}.  Calf_SN={4}",
                                     dnatag,
                                     herd.HerdSN, rawCalf.BirthDate.Year, rawCalf.TagNumber, dbCalf.Calf_SN));
                    }
                }
            }
        }