Пример #1
0
 /// <summary>
 /// Statistics Constructor
 /// </summary>
 /// <param name="data">The table of data to construct this statistics set for.</param>
 public Statistics(System.Data.DataTable data)
 {
     results             = data;
     sumOfEventsPerState = new EventsPerState();
 }
Пример #2
0
        /// <summary>
        /// Get the state with the most events
        /// </summary>

        /*public void GetStateWithMostEvents()
         * {
         *  if (results != null)
         *  {
         *      List<string> states = new List<string>();
         *
         *      foreach (DataRow row in results.Rows)
         *      {
         *          states.Add(row[3].ToString());
         *      }
         *
         *      if (states.Count != 0)
         *      {
         *          this.StateWithMostEvents = states.GroupBy(x => x).OrderByDescending(g => g.Count()).Select(g => g.Key).First();
         *      }
         *      else
         *      {
         *          this.StateWithMostEvents = "N/A";
         *      }
         *  }
         *  else
         *  {
         *      throw new Exception("Error 8017: Data table is null.");
         *  }
         * }*/

        /// <summary>
        /// Get the sum of events for each state.
        /// </summary>
        public void GetCountOfEventsPerState()
        {
            if (results != null)
            {
                List <string> states = new List <string>();

                foreach (DataRow row in results.Rows)
                {
                    states.Add(row[3].ToString());
                }

                EventsPerState eventsPerState = new EventsPerState();

                if (states.Count != 0)
                {
                    eventsPerState.Alabama            = states.Where(x => x.ToString().ToLower().Equals("alabama")).Select(x => x).Count();
                    eventsPerState.Alaska             = states.Where(x => x.ToString().ToLower().Equals("alaska")).Select(x => x).Count();
                    eventsPerState.Arizona            = states.Where(x => x.ToString().ToLower().Equals("arizona")).Select(x => x).Count();
                    eventsPerState.Arkansas           = states.Where(x => x.ToString().ToLower().Equals("arkansas")).Select(x => x).Count();
                    eventsPerState.California         = states.Where(x => x.ToString().ToLower().Equals("california")).Select(x => x).Count();
                    eventsPerState.Colorado           = states.Where(x => x.ToString().ToLower().Equals("colorado")).Select(x => x).Count();
                    eventsPerState.Connecticut        = states.Where(x => x.ToString().ToLower().Equals("connecticut")).Select(x => x).Count();
                    eventsPerState.Delaware           = states.Where(x => x.ToString().ToLower().Equals("delaware")).Select(x => x).Count();
                    eventsPerState.DistrictOfColumbia = states.Where(x => x.ToString().ToLower().Equals("district of columbia")).Select(x => x).Count();
                    eventsPerState.Florida            = states.Where(x => x.ToString().ToLower().Equals("florida")).Select(x => x).Count();
                    eventsPerState.Georgia            = states.Where(x => x.ToString().ToLower().Equals("georgia")).Select(x => x).Count();
                    eventsPerState.Hawaii             = states.Where(x => x.ToString().ToLower().Equals("hawaii")).Select(x => x).Count();
                    eventsPerState.Idaho         = states.Where(x => x.ToString().ToLower().Equals("idaho")).Select(x => x).Count();
                    eventsPerState.Illinois      = states.Where(x => x.ToString().ToLower().Equals("illinois")).Select(x => x).Count();
                    eventsPerState.Indiana       = states.Where(x => x.ToString().ToLower().Equals("indiana")).Select(x => x).Count();
                    eventsPerState.Iowa          = states.Where(x => x.ToString().ToLower().Equals("iowa")).Select(x => x).Count();
                    eventsPerState.Kansas        = states.Where(x => x.ToString().ToLower().Equals("kansas")).Select(x => x).Count();
                    eventsPerState.Kentucky      = states.Where(x => x.ToString().ToLower().Equals("kentucky")).Select(x => x).Count();
                    eventsPerState.Louisiana     = states.Where(x => x.ToString().ToLower().Equals("louisiana")).Select(x => x).Count();
                    eventsPerState.Maine         = states.Where(x => x.ToString().ToLower().Equals("maine")).Select(x => x).Count();
                    eventsPerState.Maryland      = states.Where(x => x.ToString().ToLower().Equals("maryland")).Select(x => x).Count();
                    eventsPerState.Massachusetts = states.Where(x => x.ToString().ToLower().Equals("massachusetts")).Select(x => x).Count();
                    eventsPerState.Michigan      = states.Where(x => x.ToString().ToLower().Equals("michigan")).Select(x => x).Count();
                    eventsPerState.Minnesota     = states.Where(x => x.ToString().ToLower().Equals("minnesota")).Select(x => x).Count();
                    eventsPerState.Mississippi   = states.Where(x => x.ToString().ToLower().Equals("mississippi")).Select(x => x).Count();
                    eventsPerState.Missouri      = states.Where(x => x.ToString().ToLower().Equals("missouri")).Select(x => x).Count();
                    eventsPerState.Montana       = states.Where(x => x.ToString().ToLower().Equals("montana")).Select(x => x).Count();
                    eventsPerState.Nebraska      = states.Where(x => x.ToString().ToLower().Equals("nebraska")).Select(x => x).Count();
                    eventsPerState.Nevada        = states.Where(x => x.ToString().ToLower().Equals("nevada")).Select(x => x).Count();
                    eventsPerState.NewHampshire  = states.Where(x => x.ToString().ToLower().Equals("new hampshire")).Select(x => x).Count();
                    eventsPerState.NewJersey     = states.Where(x => x.ToString().ToLower().Equals("new jersey")).Select(x => x).Count();
                    eventsPerState.NewMexico     = states.Where(x => x.ToString().ToLower().Equals("new mexico")).Select(x => x).Count();
                    eventsPerState.NewYork       = states.Where(x => x.ToString().ToLower().Equals("new york")).Select(x => x).Count();
                    eventsPerState.NorthCarolina = states.Where(x => x.ToString().ToLower().Equals("north carolina")).Select(x => x).Count();
                    eventsPerState.NorthDakota   = states.Where(x => x.ToString().ToLower().Equals("north dakota")).Select(x => x).Count();
                    eventsPerState.Ohio          = states.Where(x => x.ToString().ToLower().Equals("ohio")).Select(x => x).Count();
                    eventsPerState.Oklahoma      = states.Where(x => x.ToString().ToLower().Equals("oklahoma")).Select(x => x).Count();
                    eventsPerState.Oregon        = states.Where(x => x.ToString().ToLower().Equals("oregon")).Select(x => x).Count();
                    eventsPerState.Pennsylvania  = states.Where(x => x.ToString().ToLower().Equals("pennsylvania")).Select(x => x).Count();
                    eventsPerState.RhodeIsland   = states.Where(x => x.ToString().ToLower().Equals("rhode island")).Select(x => x).Count();
                    eventsPerState.SouthCarolina = states.Where(x => x.ToString().ToLower().Equals("south carolina")).Select(x => x).Count();
                    eventsPerState.SouthDakota   = states.Where(x => x.ToString().ToLower().Equals("south dakota")).Select(x => x).Count();
                    eventsPerState.Tennessee     = states.Where(x => x.ToString().ToLower().Equals("tennessee")).Select(x => x).Count();
                    eventsPerState.Texas         = states.Where(x => x.ToString().ToLower().Equals("texas")).Select(x => x).Count();
                    eventsPerState.Utah          = states.Where(x => x.ToString().ToLower().Equals("utah")).Select(x => x).Count();
                    eventsPerState.Vermont       = states.Where(x => x.ToString().ToLower().Equals("vermont")).Select(x => x).Count();
                    eventsPerState.Virginia      = states.Where(x => x.ToString().ToLower().Equals("virginia")).Select(x => x).Count();
                    eventsPerState.Washington    = states.Where(x => x.ToString().ToLower().Equals("washington")).Select(x => x).Count();
                    eventsPerState.WestVirginia  = states.Where(x => x.ToString().ToLower().Equals("west virginia")).Select(x => x).Count();
                    eventsPerState.Wisconsin     = states.Where(x => x.ToString().ToLower().Equals("wisconsin")).Select(x => x).Count();
                    eventsPerState.Wyoming       = states.Where(x => x.ToString().ToLower().Equals("wyoming")).Select(x => x).Count();
                    eventsPerState.PuertoRico    = states.Where(x => x.ToString().ToLower().Equals("puerto rico")).Select(x => x).Count();

                    this.SumOfEventsPerState = eventsPerState;
                }
                else
                {
                    eventsPerState.Alabama            = 0;
                    eventsPerState.Alaska             = 0;
                    eventsPerState.Arizona            = 0;
                    eventsPerState.Arkansas           = 0;
                    eventsPerState.California         = 0;
                    eventsPerState.Colorado           = 0;
                    eventsPerState.Connecticut        = 0;
                    eventsPerState.Delaware           = 0;
                    eventsPerState.DistrictOfColumbia = 0;
                    eventsPerState.Florida            = 0;
                    eventsPerState.Georgia            = 0;
                    eventsPerState.Hawaii             = 0;
                    eventsPerState.Idaho         = 0;
                    eventsPerState.Illinois      = 0;
                    eventsPerState.Indiana       = 0;
                    eventsPerState.Iowa          = 0;
                    eventsPerState.Kansas        = 0;
                    eventsPerState.Kentucky      = 0;
                    eventsPerState.Louisiana     = 0;
                    eventsPerState.Maine         = 0;
                    eventsPerState.Maryland      = 0;
                    eventsPerState.Massachusetts = 0;
                    eventsPerState.Michigan      = 0;
                    eventsPerState.Minnesota     = 0;
                    eventsPerState.Mississippi   = 0;
                    eventsPerState.Missouri      = 0;
                    eventsPerState.Montana       = 0;
                    eventsPerState.Nebraska      = 0;
                    eventsPerState.Nevada        = 0;
                    eventsPerState.NewHampshire  = 0;
                    eventsPerState.NewJersey     = 0;
                    eventsPerState.NewMexico     = 0;
                    eventsPerState.NewYork       = 0;
                    eventsPerState.NorthCarolina = 0;
                    eventsPerState.NorthDakota   = 0;
                    eventsPerState.Ohio          = 0;
                    eventsPerState.Oklahoma      = 0;
                    eventsPerState.Oregon        = 0;
                    eventsPerState.Pennsylvania  = 0;
                    eventsPerState.RhodeIsland   = 0;
                    eventsPerState.SouthCarolina = 0;
                    eventsPerState.SouthDakota   = 0;
                    eventsPerState.Tennessee     = 0;
                    eventsPerState.Texas         = 0;
                    eventsPerState.Utah          = 0;
                    eventsPerState.Vermont       = 0;
                    eventsPerState.Virginia      = 0;
                    eventsPerState.Washington    = 0;
                    eventsPerState.WestVirginia  = 0;
                    eventsPerState.Wisconsin     = 0;
                    eventsPerState.Wyoming       = 0;
                    eventsPerState.PuertoRico    = 0;
                }
            }
            else
            {
                throw new Exception("Error 8018: Data table is null.");
            }
        }