public void AddUniversity(AmericanUniversity univ, DateTime?gradDt) { _universities.Add(new AmericanCollegeStudent(univ) { Graduation = gradDt }); }
internal static bool TryParseXml(XmlElement node, out AmericanUniversity univ) { try { univ = null; if (node == null) { return(false); } if (node.LocalName != "college-univ") { return(false); } univ = new AmericanUniversity(); var attr = node.Attributes["name"]; univ.Name = attr == null ? string.Empty : attr.Value; attr = node.Attributes["campus"]; univ.CampusName = attr == null ? string.Empty : attr.Value; attr = node.Attributes["percent-of-state-students"]; if (attr != null) { if (float.TryParse(attr.Value, out var percentStudents)) { univ.PercentOfStateStudents = percentStudents; } } attr = node.Attributes["crime-rate"]; if (attr != null) { if (float.TryParse(attr.Value, out var crimeRate)) { univ.CrimeRate = crimeRate; } } if (!(node.ParentNode is XmlElement stateNode) || stateNode.LocalName != "state") { return(true); } attr = stateNode.Attributes["name"]; univ.StateName = attr == null ? string.Empty : attr.Value; attr = stateNode.Attributes["abbreviation"]; univ.StateAbbrev = attr == null ? string.Empty : attr.Value; return(true); } catch { univ = null; return(false); } }
/// <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)); }
/// <summary> /// Factory method to get an instance of <see cref="AmericanUniversity"/> at random. /// </summary> /// <param name="homeState"> /// There is a 73 percent chance this will be used, otherwise the result is anywhere /// in the nation /// src [https://www.washingtonpost.com/blogs/govbeat/wp/2014/06/05/map-the-states-college-kids-cant-wait-to-leave] /// </param> /// <returns></returns> internal static AmericanUniversity GetAmericanUniversity(string homeState) { homeState = Etx.RandomRollBelowOrAt(73, Etx.Dice.OneHundred) ? homeState : null; return(AmericanUniversity.RandomUniversity(homeState)); }