Esempio n. 1
0
        /// <summary>
        /// Assigns a value to <see cref="HighSchool"/> at random based on the given inputs
        /// </summary>
        /// <param name="homeState"></param>
        /// <param name="zipCode"></param>
        /// <param name="isLegalAdult"></param>
        /// <param name="dtAtAge18"></param>
        /// <param name="hsGradDt"></param>
        /// <returns></returns>
        protected internal bool AssignRandomHighSchool(string homeState, string zipCode, bool isLegalAdult, DateTime dtAtAge18,
                                                       out DateTime?hsGradDt)
        {
            hsGradDt = null;

            //get hs grad data for state amer lived in when 18
            var hsGradData =
                UsStateData.GetStateData(homeState)?.PercentOfGrads
                .FirstOrDefault(x => x.Item1 == (OccidentalEdu.HighSchool | OccidentalEdu.Grad));

            //determine prob. of having hs grad
            var hsGradRate = hsGradData?.Item2 ?? AmericanHighSchool.DF_NATL_AVG;

            //first try city, then state, last natl
            var hss = AmericanHighSchool.GetHighSchoolsByZipCode(zipCode)
                      ?? AmericanHighSchool.GetHighSchoolsByState(homeState);

            var hs = hss.Length > 1 ? hss[Etx.RandomInteger(0, hss.Length - 1)] : hss.First();

            //still in hs or dropped out
            if (!isLegalAdult || Etx.RandomRollAboveOrAt((int)Math.Round(hsGradRate) + 1, Etx.Dice.OneHundred))
            {
                //assign grad hs but no date
                _highSchools.Add(new AmericanHighSchoolStudent(hs));
                AssignEduFlagAndLevel();
                return(false);
            }

            //get a date of when amer would be grad'ing from hs
            hsGradDt = GetRandomGraduationDate(dtAtAge18.AddYears(-4), AmericanHighSchool.YearsInHighSchool, true);

            //assign grad hs with grad date
            _highSchools.Add(new AmericanHighSchoolStudent(hs)
            {
                Graduation = hsGradDt
            });
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Difference of national avg to race average added to state average.
        /// </summary>
        /// <param name="state"></param>
        /// <param name="race"></param>
        /// <param name="edu"></param>
        /// <returns></returns>
        public static double SolvePercentGradByStateAndRace(string state, NorthAmericanRace?race,
                                                            OccidentalEdu edu = OccidentalEdu.HighSchool | OccidentalEdu.Grad)
        {
            AmericanRacePercents p;

            p = edu >= OccidentalEdu.Bachelor ? AmericanUniversity.NatlGradRate() : AmericanHighSchool.NatlGradRate();
            var stateAvg  = p.National;
            var natlAvg   = p.National;
            var stateData = UsStateData.GetStateData(state);

            if (stateData?.PercentOfGrads != null && stateData.PercentOfGrads.Count > 0)
            {
                var f = stateData.PercentOfGrads.FirstOrDefault(x => x.Item1 == edu);
                if (f != null)
                {
                    stateAvg = Math.Round(f.Item2, 1);
                }
            }

            var raceNatlAvg = new Dictionary <NorthAmericanRace, double>
            {
                { NorthAmericanRace.AmericanIndian, p.AmericanIndian - natlAvg },
                { NorthAmericanRace.Asian, p.Asian - natlAvg },
                { NorthAmericanRace.Hispanic, p.Hispanic - natlAvg },
                { NorthAmericanRace.Black, p.Black - natlAvg },
                { NorthAmericanRace.White, p.White - natlAvg },
                { NorthAmericanRace.Pacific, p.Pacific - natlAvg },
                { NorthAmericanRace.Mixed, p.Mixed - natlAvg }
            };

            if (race == null || !raceNatlAvg.ContainsKey(race.Value))
            {
                return(Math.Round(stateAvg, 1));
            }

            return(Math.Round(stateAvg + raceNatlAvg[race.Value], 1));
        }
Esempio n. 3
0
        internal static bool TryParseXml(XmlElement node, out AmericanHighSchool hs)
        {
            try
            {
                hs = new AmericanHighSchool();
                if (node == null)
                {
                    return(false);
                }

                if (node.LocalName != "high-school")
                {
                    return(false);
                }
                var attr = node.Attributes["name"];
                hs.Name = attr == null ? String.Empty : attr.Value;

                attr = node.Attributes["urban-centric"];
                if (attr != null)
                {
                    switch (attr.Value)
                    {
                    case "City-Large":
                        hs.UrbanCentric = UrbanCentric.City | UrbanCentric.Large;
                        break;

                    case "City-Midsize":
                        hs.UrbanCentric = UrbanCentric.City | UrbanCentric.Large;
                        break;

                    case "City-Small":
                        hs.UrbanCentric = UrbanCentric.City | UrbanCentric.Small;
                        break;

                    case "Rural-Distant":
                        hs.UrbanCentric = UrbanCentric.Rural | UrbanCentric.Distant;
                        break;

                    case "Rural-Fringe":
                        hs.UrbanCentric = UrbanCentric.Rural | UrbanCentric.Fringe;
                        break;

                    case "Rural-Remote":
                        hs.UrbanCentric = UrbanCentric.Rural | UrbanCentric.Remote;
                        break;

                    case "Suburb-Large":
                        hs.UrbanCentric = UrbanCentric.Suburb | UrbanCentric.Large;
                        break;

                    case "Suburb-Midsize":
                        hs.UrbanCentric = UrbanCentric.Suburb | UrbanCentric.Midsize;
                        break;

                    case "Suburb-Small":
                        hs.UrbanCentric = UrbanCentric.Suburb | UrbanCentric.Small;
                        break;

                    case "Town-Distant":
                        hs.UrbanCentric = UrbanCentric.Town | UrbanCentric.Distant;
                        break;

                    case "Town-Fringe":
                        hs.UrbanCentric = UrbanCentric.Town | UrbanCentric.Fringe;
                        break;

                    case "Town-Remote":
                        hs.UrbanCentric = UrbanCentric.Town | UrbanCentric.Remote;
                        break;
                    }
                }

                attr = node.Attributes["teachers"];
                if (attr != null)
                {
                    if (Double.TryParse(attr.Value, out var dblOut))
                    {
                        hs.TotalTeachers = dblOut;
                    }
                }
                attr = node.Attributes["total-students"];
                if (attr != null)
                {
                    if (Int32.TryParse(attr.Value, out var intOut))
                    {
                        hs.TotalStudents = intOut;
                    }
                }

                if (node.ParentNode == null || node.ParentNode.LocalName != "zip-stat" ||
                    node.ParentNode.Attributes?["value"] == null)
                {
                    return(true);
                }
                var zipStatNode = node.ParentNode;
                if (zipStatNode.Attributes != null)
                {
                    attr = zipStatNode.Attributes["value"];
                }
                hs.PostalCode = attr?.Value;

                hs.Name = NfString.CapWords(hs.Name.Replace("JR\\SR", "Jr\\Sr"), ' ');
                return(true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"{ex.Message}\n{ex.StackTrace}");
                hs = null;
                return(false);
            }
        }