public static void Add(NpgsqlConnection conn, string tail_no, ConcurrentDictionary <string, Models.Dim_Tail> dictTail)
        {
            if (TailRepository.Find(conn, tail_no, dictTail) == null)
            {
                // clean the tail
                var cleanTailNo = CleanTail(tail_no);

                // Write the airline to the database.
                conn.Execute(tail_insert, new
                {
                    tail_no = cleanTailNo
                });

                // find to Add to hash table.
                Find(conn, cleanTailNo, dictTail);
            }
        }
Beispiel #2
0
        public static void Add(NpgsqlConnection conn, Row row,
                               ConcurrentDictionary <string, Models.Dim_Airline> dictAirline,
                               ConcurrentDictionary <string, Models.Dim_Airport> dictAirport,
                               ConcurrentDictionary <string, Models.Dim_City> dictCity,
                               ConcurrentDictionary <string, Models.Dim_State> dictState,
                               ConcurrentDictionary <string, Models.Dim_Tail> dictTail)
        {
            // Convert Distance.
            string tempDistance      = (string)row["Distance"];
            int    tempDistanceInt   = 0;
            string tempDistanceUnits = string.Empty;
            string tempDistanceGroup = string.Empty;
            var    tempDistArray     = tempDistance.Split(' ');
            string unit = string.Empty;

            if (tempDistArray.Length == 2)
            {
                tempDistanceInt   = Convert.ToInt32(tempDistArray[0]);
                tempDistanceUnits = tempDistArray[1].ToString().Trim();
                tempDistanceGroup = GetDistanceGroup(tempDistanceInt);
            }
            else
            {
                throw new Exception("Invalid disance");
            }

            // Find codes
            var airline        = dictAirline.Where(w => w.Key == (string)row["AirlineCode"]).FirstOrDefault().Value;;
            var tail           = dictTail.Where(w => w.Key == TailRepository.CleanTail((string)row["TailNum"])).FirstOrDefault().Value;
            var origin_airport = dictAirport.Where(w => w.Key == AirportRepository.Clean((string)row["OriginAirportName"])).FirstOrDefault().Value;
            var dest_airport   = dictAirport.Where(w => w.Key == AirportRepository.Clean((string)row["DestAirportName"])).FirstOrDefault().Value;

            // Write the airline to the database.
            conn.Execute(fact_insert, new
            {
                transaction_id         = row["TransactionId"],
                flight_date            = row["FlightDate"],
                airline_id             = airline.airline_id,
                tail_id                = tail.tail_id,
                flight_num             = row["FlightNum"],
                origin_airport_id      = origin_airport.airport_id,
                destination_airport_id = dest_airport.airport_id,
                crs_dep_time           = row["CrsDepTime"],
                dep_time               = row["DepTime"],
                dep_delay              = row["DepDelay"],
                taxi_out               = row["TaxiOut"],
                wheels_off             = row["WheelsOff"],
                wheels_on              = row["WheelsOn"],
                taxi_in                = row["TaxiIn"],
                crs_arr_time           = row["CrsArrTime"],
                arr_time               = row["ArrTime"],
                arr_delay              = row["ArrDelay"],
                crs_elapsed_time       = row["CrsElapsedTime"],
                actual_elapsed_time    = row["ActualElapsedTime"],
                cancelled              = row["Cancelled"],
                diverted               = row["Diverted"],
                distance               = tempDistanceInt,
                distance_unit          = tempDistanceUnits,
                distance_group         = GetDistanceGroup(tempDistanceInt),
                long_dep_delay         = ((int)row["DepDelay"] > 15),
                arr_next_day           = (DateTime.Compare((DateTime)row["ArrTime"], (DateTime)row["DepTime"]) < 0)
            });
        }