示例#1
0
        /// <summary>Gets the car statistics group by category.</summary>
        /// <returns>The list of car statistics.</returns>
        public List <CarStatistic> GetCarStatistics()
        {
            List <CarStatistic> carStatistics = new List <CarStatistic>();

            var cmd = new NpgsqlCommand();

            cmd.Connection  = npgsqlConnection;
            cmd.CommandText = "SELECT carcategory, count(*), avg(carmaxpower), "
                              + "avg(carmaxspeed), avg(caracceleration), avg(carbraking), avg(carcornering), avg(carstability), avg(carprice) FROM cars "
                              + "GROUP BY carcategory ORDER BY carcategory";

            cmd.Prepare();

            NpgsqlDataReader dataReader = cmd.ExecuteReader();

            while (dataReader.Read())
            {
                CarStatistic carStatistic = RecordToStatistic(dataReader);

                carStatistics.Add(carStatistic);
            }

            dataReader.Close();

            cmd.Dispose();

            return(carStatistics);
        }
示例#2
0
        private CarStatistic RecordToStatistic(NpgsqlDataReader dataReader)
        {
            CarStatistic carStatistic = new CarStatistic();

            carStatistic.Category        = CarCategory.GetCategoryByDBValue(dataReader.GetString(0));
            carStatistic.NumberOfCars    = dataReader.GetInt32(1);
            carStatistic.AvgMaxPower     = dataReader.GetDouble(2);
            carStatistic.AvgMaxSpeed     = dataReader.GetDouble(3);
            carStatistic.AvgAcceleration = dataReader.GetDouble(4);
            carStatistic.AvgBraking      = dataReader.GetDouble(5);
            carStatistic.AvgCornering    = dataReader.GetDouble(6);
            carStatistic.AvgStability    = dataReader.GetDouble(7);
            carStatistic.AvgPrice        = dataReader.GetDouble(8);

            return(carStatistic);
        }