private static (decimal Swing, string Party) GenerateSwing(DateTime forecastDate, DateTime electionDay) { string party = new Random().Next() % 2 == 0 ? "Republican" : "Democratic"; decimal swing = Guassian.Next(0, ((decimal)(electionDay - forecastDate).Days / 90) + 1); return(swing, party); }
private static (decimal Result, decimal Weight) GetGuassian(Poll poll, string candidateName, DateTime date) { PollResult result = poll.Results.FirstOrDefault(c => c.Candidate == candidateName); if (result != null) { decimal mean = result.Percent; decimal stdDev = ((decimal)(date - poll.Date).Days / 60) + 1; decimal pct = Guassian.Next(mean, stdDev); int denominator = (date - poll.Date).Days; if (denominator == 0) { denominator = 1; } var weight = (decimal)System.Math.Sqrt(1.0 / denominator); return(pct * weight, weight); } return(0.0M, 0.0M); }