예제 #1
0
        private static DataRow GenerateEcologDopplerRow(DataRow newRow, DataRow beforeRow, DataRow tripRow, DataRow correctedGpsRow, InsertDatum datum)
        {
            newRow.SetField(EcologDao.ColumnTripId, tripRow.Field <int>(TripsDao.ColumnTripId));
            newRow.SetField(EcologDao.ColumnDriverId, tripRow.Field <int>(TripsDao.ColumnDriverId));
            newRow.SetField(EcologDao.ColumnCarId, tripRow.Field <int>(TripsDao.ColumnCarId));
            newRow.SetField(EcologDao.ColumnSensorId, tripRow.Field <int>(TripsDao.ColumnSensorId));
            newRow.SetField(EcologDao.ColumnJst, correctedGpsRow.Field <DateTime>(CorrectedGpsDao.ColumnJst));
            newRow.SetField(EcologDao.ColumnLatitude, correctedGpsRow.Field <double>(CorrectedGpsDao.ColumnLatitude));
            newRow.SetField(EcologDao.ColumnLongitude, correctedGpsRow.Field <double>(CorrectedGpsDao.ColumnLongitude));

            double speed            = correctedGpsRow.Field <Single>(CorrectedGpsDao.ColumnSpeed);
            double speedMeterPerSec = speed / 3.6;

            //Console.WriteLine("SPEED: " + speed);

            newRow.SetField(EcologDao.ColumnSpeed, speed);

            newRow.SetField(EcologDao.ColumnHeading,
                            correctedGpsRow.Field <Single>(CorrectedGpsDao.ColumnHeading));

            double distanceDiff = correctedGpsRow.Field <Single>(CorrectedGpsDao.ColumnDistanceDifference);

            //Console.WriteLine("DISTANCE_DIFF: " + distanceDiff);

            newRow.SetField(EcologDao.ColumnDistanceDifference, distanceDiff);

            var meshAndAltitude = AltitudeCalculator.GetInstance().CalcAltitude(
                correctedGpsRow.Field <double>(CorrectedGpsDao.ColumnLatitude),
                correctedGpsRow.Field <double>(CorrectedGpsDao.ColumnLongitude));

            newRow.SetField(EcologDao.ColumnTerraubAltitude, meshAndAltitude.Item2);
            newRow.SetField(EcologDao.ColumnMeshId, meshAndAltitude.Item1);

            double terrainAltitudeDiff = meshAndAltitude.Item2 -
                                         beforeRow.Field <Single>(EcologDao.ColumnTerraubAltitude);

            //Console.WriteLine("ALTITUDE_DIFF: " + terrainAltitudeDiff);

            newRow.SetField(EcologDao.ColumnTerrainAltitudeDiffarencce, terrainAltitudeDiff);

            // TODO 加速度を追加する場合はここへ
            newRow.SetField(EcologDao.ColumnLongitudinalAcc, DBNull.Value);
            newRow.SetField(EcologDao.ColumnLateralAcc, DBNull.Value);
            newRow.SetField(EcologDao.ColumnVerticalAcc, DBNull.Value);

            double airResistancePower = 0;

            if (speed > 1 && distanceDiff > 0)
            {
                airResistancePower = AirResistanceCalculator.CalcPower(
                    Rho, datum.EstimatedCarModel.CdValue, datum.EstimatedCarModel.FrontalProjectedArea, (speed + WindSpeed) / 3.6, speedMeterPerSec);
            }

            //Console.WriteLine("AIR: " + airResistancePower);

            newRow.SetField(
                EcologDao.ColumnEnergyByAirResistance,
                airResistancePower);

            double rollingResistancePower = 0;

            if (speed > 1 && distanceDiff > 0)
            {
                rollingResistancePower = RollingResistanceCalculator.CalcPower(
                    Myu, datum.EstimatedCarModel.Weight, Math.Atan(terrainAltitudeDiff / distanceDiff), speedMeterPerSec);
            }

            //Console.WriteLine("ROLLING: " + rollingResistancePower);

            newRow.SetField(
                EcologDao.ColumnEnergyByRollingResistance,
                rollingResistancePower);

            double climbingResistancePower = 0;

            if (speed > 1 && distanceDiff > 0)
            {
                climbingResistancePower = ClimbingResistanceCalculator.CalcPower(
                    datum.EstimatedCarModel.Weight, Math.Atan(terrainAltitudeDiff / distanceDiff), speedMeterPerSec);
            }

            //Console.WriteLine("CLIMBING: " + climbingResistancePower);

            newRow.SetField(
                EcologDao.ColumnEnergyByClimbingResistance,
                climbingResistancePower);

            double accResistancePower = 0;

            if (speed > 1 && distanceDiff > 0)
            {
                accResistancePower = AccResistanceCalculator.CalcPower(
                    beforeRow.Field <Single>(EcologDao.ColumnSpeed) / 3.6,
                    beforeRow.Field <DateTime>(EcologDao.ColumnJst),
                    speedMeterPerSec, correctedGpsRow.Field <DateTime>(CorrectedGpsDao.ColumnJst),
                    datum.EstimatedCarModel.Weight);
            }

            //Console.WriteLine("ACC: " + accResistancePower);

            newRow.SetField(
                EcologDao.ColumnEnergyByAccResistance,
                accResistancePower);

            double drivingResistancePower =
                airResistancePower + rollingResistancePower + climbingResistancePower + accResistancePower;

            double torque = 0;

            if (drivingResistancePower > 0 && speed > 0)
            {
                torque = drivingResistancePower * 1000 * 3600 / speedMeterPerSec * datum.EstimatedCarModel.TireRadius /
                         datum.EstimatedCarModel.ReductionRatio;
            }

            int efficiency = EfficiencyCalculator.GetInstance().GetEfficiency(datum.EstimatedCarModel, speedMeterPerSec, torque);

            //Console.WriteLine("EFFICIENCY: " + efficiency);

            newRow.SetField(EcologDao.ColumnEfficiency, efficiency);

            double convertLoss = ConvertLossCaluculator.CalcEnergy(
                drivingResistancePower, datum.EstimatedCarModel, speedMeterPerSec, efficiency);

            newRow.SetField(EcologDao.ColumnConvertLoss, convertLoss);

            //Console.WriteLine("CONVERTLOSS: " + convertLoss);

            double regeneEnergy = RegeneEnergyCalculator.CalcEnergy(drivingResistancePower,
                                                                    speedMeterPerSec, datum.EstimatedCarModel, efficiency);

            newRow.SetField(EcologDao.ColumnRegeneEnergy, regeneEnergy);

            double regeneLoss = RegeneLossCalculator.CalcEnergy(drivingResistancePower, regeneEnergy,
                                                                datum.EstimatedCarModel, speedMeterPerSec, efficiency);

            newRow.SetField(EcologDao.ColumnRegeneLoss, regeneLoss);

            double lostEnergy = LostEnergyCalculator.CalcEnergy(convertLoss, regeneLoss, airResistancePower,
                                                                rollingResistancePower);

            newRow.SetField(EcologDao.ColumnLostEnergy, lostEnergy);

            newRow.SetField(EcologDao.ColumnConsumedElectricEnergy, ConsumedEnergyCaluculator.CalcEnergy(drivingResistancePower, datum.EstimatedCarModel, speedMeterPerSec, efficiency));

            newRow.SetField(EcologDao.ColumnLostEnergyByWellToWheel, DBNull.Value);
            newRow.SetField(EcologDao.ColumnConsumedFuel, DBNull.Value);
            newRow.SetField(EcologDao.ColumnConsumedFuelByWellToWheel, DBNull.Value);
            newRow.SetField(EcologDao.ColumnEnergyByEquipment,
                            EquipmentEnergyCalculator.CalcEquipmentEnergy(correctedGpsRow.Field <DateTime>(CorrectedGpsDao.ColumnJst)));
            newRow.SetField(EcologDao.ColumnEnergyByCooling, DBNull.Value);
            newRow.SetField(EcologDao.ColumnEnergyByHeating, DBNull.Value);

            newRow.SetField(EcologDao.ColumnTripDirection, tripRow.Field <string>(TripsDao.ColumnTripDirection));

            newRow.SetField(EcologDao.ColumnLinkId, correctedGpsRow.Field <string>(CorrectedGPSDopplerDao.ColumnLinkId));
            newRow.SetField(EcologDao.ColumnRoadTheta, correctedGpsRow.Field <Single>(CorrectedGPSDopplerDao.ColumnRoadTheta));


            return(newRow);
        }
예제 #2
0
        private void CalcEcolog(int count)
        {
            if (count == 2)
            {
                _altitudeBefore = AltitudeCalculator.CalcAltitude(PositionCollection[count - 1].Latitude, PositionCollection[count - 1].Longitude);
                //Debug.WriteLine("AltitudeBefore: " + _altitudeBefore.Altitude);
            }
            else if (PositionCollection.Count > 2)
            {
                var positionBefore  = PositionCollection[count - 3];
                var positionCurrent = PositionCollection[count - 2];
                var positionAfter   = PositionCollection[count - 1];

                var distanceDiff = DistanceCalculator.CalcDistance(positionBefore.Latitude,
                                                                   positionBefore.Longitude,
                                                                   positionCurrent.Latitude,
                                                                   positionCurrent.Longitude);
                //Debug.WriteLine("DistanceDiff: " + distanceDiff);

                // meter per sec
                var speed = SpeedCalculator.CalcSpeed(positionBefore.Latitude,
                                                      positionBefore.Longitude,
                                                      positionBefore.Timestamp.DateTime,
                                                      positionAfter.Latitude,
                                                      positionAfter.Longitude,
                                                      positionAfter.Timestamp.DateTime,
                                                      positionCurrent.Latitude,
                                                      positionCurrent.Longitude) / 3.6;
                //Debug.WriteLine("Speed: " + speed * 3.6);

                if (count == 3)
                {
                    _speedBefore = speed;
                }

                var altitude = AltitudeCalculator.CalcAltitude(positionCurrent.Latitude, positionCurrent.Longitude);
                //var altitude = new AltitudeDatum { Altitude = 40 };
                double altitudeDiff = 0;
                if (altitude != null && _altitudeBefore != null)
                {
                    altitudeDiff = altitude.Altitude - _altitudeBefore.Altitude;
                }
                _altitudeBefore = altitude;
                //Debug.WriteLine("AltitudeDiff: " + altitudeDiff);

                double airResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    airResistancePower = AirResistanceCalculator.CalcPower(
                        Constants.Rho, Car.GetLeaf().CdValue, Car.GetLeaf().FrontalProjectedArea, speed, speed);
                }
                //Debug.WriteLine("AirResistace: " + airResistancePower);

                double rollingResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    rollingResistancePower = RollingResistanceCalculator.CalcPower(
                        Constants.Myu, Car.GetLeaf().Weight, Math.Atan(altitudeDiff / distanceDiff), speed);
                }
                //Debug.WriteLine("rollingResistancePower: " + rollingResistancePower);

                double climbingResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    climbingResistancePower = ClimbingResistanceCalculator.CalcPowerPreVer(
                        Car.GetLeaf().Weight, altitudeDiff);
                }
                //Debug.WriteLine("climbingResistancePower: " + climbingResistancePower);

                double accResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    accResistancePower = AccResistanceCalculator.CalcPower(
                        _speedBefore,
                        positionBefore.Timestamp.DateTime,
                        speed,
                        positionCurrent.Timestamp.DateTime,
                        Car.GetLeaf().Weight);
                }
                //Debug.WriteLine("accResistancePower: " + accResistancePower);

                double drivingResistancePower =
                    airResistancePower + rollingResistancePower + climbingResistancePower + accResistancePower;

                double torque = 0;
                if (drivingResistancePower > 0 && speed > 0)
                {
                    torque = drivingResistancePower * 1000 * 3600 / speed * Car.GetLeaf().TireRadius /
                             Car.GetLeaf().ReductionRatio;
                }
                //Debug.WriteLine("torque: " + torque);

                var efficiency = EfficiencyCalculator.CalcEfficiency(Car.GetLeaf(), speed, torque).Efficiency;
                //var efficiency = 90;
                //Debug.WriteLine("efficiency: " + efficiency);

                double convertLoss = ConvertLossCalculator.CalcEnergyPreVer(
                    drivingResistancePower, speed, efficiency);
                //Debug.WriteLine("convertLoss: " + convertLoss);

                double regeneEnergy = RegeneEnergyCalculator.CalcEnergy(drivingResistancePower,
                                                                        speed, Car.GetLeaf(), efficiency);
                //Debug.WriteLine("regeneEnergy: " + regeneEnergy);

                double regeneLoss = RegeneLossCalculator.CalcEnergyPreVer(drivingResistancePower, speed, efficiency);
                //Debug.WriteLine($"{positionCurrent.Timestamp.DateTime}: {regeneLoss}, {efficiency}");

                double lostEnergy = LostEnergyCalculator.CalcEnergy(convertLoss, regeneLoss, airResistancePower,
                                                                    rollingResistancePower);
                //Debug.WriteLine("LostEnergy: " + lostEnergy);

                _speedBefore = speed;

                //var consumedEnergy = ConsumedEnergyCaluculator.CalcEnergy(drivingResistancePower, Car.GetLeaf(), speed, efficiency);

                //Debug.WriteLine($"Efficiency: {efficiency}, CalcEfficiency: {(consumedEnergy / convertLoss) * 100}");

                LostEnergyList.Add(lostEnergy);
                AirResistanceList.Add(airResistancePower);
                RollingResistanceList.Add(rollingResistancePower);
                ConvertLossList.Add(Math.Abs(convertLoss));
                RegeneLossList.Add(Math.Abs(regeneLoss));
            }
        }
예제 #3
0
        public static double CalcLostEnergy(IList <Position> positions)
        {
            Debug.WriteLine("List Count: " + positions.Count);

            AltitudeDatum altitudeBefore;
            double        speedBefore = 0;

            double airSum         = 0;
            double rollingSum     = 0;
            double convertLossSum = 0;
            double regeneLossSum  = 0;
            double lostEnergy     = 0;

            altitudeBefore = AltitudeCalculator.CalcAltitude(positions[1].Latitude, positions[1].Longitude);

            for (int i = 3; i < positions.Count; i++)
            {
                var positionBefore  = positions[i - 3];
                var positionCurrent = positions[i - 2];
                var positionAfter   = positions[i - 1];

                var distanceDiff = DistanceCalculator.CalcDistance(positionBefore.Latitude,
                                                                   positionBefore.Longitude,
                                                                   positionCurrent.Latitude,
                                                                   positionCurrent.Longitude);
                //Debug.WriteLine("DistanceDiff: " + distanceDiff);

                // meter per sec
                var speed = SpeedCalculator.CalcSpeed(positionBefore.Latitude,
                                                      positionBefore.Longitude,
                                                      positionBefore.Timestamp.DateTime,
                                                      positionAfter.Latitude,
                                                      positionAfter.Longitude,
                                                      positionAfter.Timestamp.DateTime,
                                                      positionCurrent.Latitude,
                                                      positionCurrent.Longitude) / 3.6;
                //Debug.WriteLine("Speed: " + speed * 3.6);

                if (i == 3)
                {
                    speedBefore = speed;
                }

                var    altitude     = AltitudeCalculator.CalcAltitude(positionCurrent.Latitude, positionCurrent.Longitude);
                double altitudeDiff = 0;
                if (altitude != null && altitudeBefore != null)
                {
                    altitudeDiff = altitude.Altitude - altitudeBefore.Altitude;
                }
                altitudeBefore = altitude;
                //Debug.WriteLine("AltitudeDiff: " + altitudeDiff);

                double airResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    airResistancePower = AirResistanceCalculator.CalcPower(
                        Constants.Rho, Car.GetLeaf().CdValue, Car.GetLeaf().FrontalProjectedArea, speed, speed);
                }
                //Debug.WriteLine("AirResistace: " + airResistancePower);
                airSum += airResistancePower;

                double rollingResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    rollingResistancePower = RollingResistanceCalculator.CalcPower(
                        Constants.Myu, Car.GetLeaf().Weight, Math.Atan(altitudeDiff / distanceDiff), speed);
                }
                //Debug.WriteLine("rollingResistancePower: " + rollingResistancePower);
                rollingSum += rollingResistancePower;

                double climbingResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    climbingResistancePower = ClimbingResistanceCalculator.CalcPowerPreVer(
                        Car.GetLeaf().Weight, altitudeDiff);
                }
                //Debug.WriteLine("climbingResistancePower: " + climbingResistancePower);

                double accResistancePower = 0;
                if (speed > 1.0 / 3.6 && distanceDiff > 0)
                {
                    accResistancePower = AccResistanceCalculator.CalcPower(
                        speedBefore,
                        positionBefore.Timestamp.DateTime,
                        speed,
                        positionCurrent.Timestamp.DateTime,
                        Car.GetLeaf().Weight);
                }
                //Debug.WriteLine("accResistancePower: " + accResistancePower);

                double drivingResistancePower =
                    airResistancePower + rollingResistancePower + climbingResistancePower + accResistancePower;

                double torque = 0;
                if (drivingResistancePower > 0 && speed > 0)
                {
                    torque = drivingResistancePower * 1000 * 3600 / speed * Car.GetLeaf().TireRadius /
                             Car.GetLeaf().ReductionRatio;
                }
                //Debug.WriteLine("torque: " + torque);

                var efficiency = EfficiencyCalculator.CalcEfficiency(Car.GetLeaf(), speed, torque).Efficiency;
                //Debug.WriteLine("efficiency: " + efficiency);

                double convertLoss = ConvertLossCalculator.CalcEnergyPreVer(
                    drivingResistancePower, speed, efficiency);
                //Debug.WriteLine("convertLoss: " + convertLoss);
                convertLossSum += Math.Abs(convertLoss);

                double regeneEnergy = RegeneEnergyCalculator.CalcEnergy(drivingResistancePower,
                                                                        speed, Car.GetLeaf(), efficiency);
                //Debug.WriteLine("regeneEnergy: " + regeneEnergy);

                double regeneLoss = RegeneLossCalculator.CalcEnergyPreVer(drivingResistancePower, speed, efficiency);
                //Debug.WriteLine($"{positionCurrent.Timestamp.DateTime}: {regeneLoss}, {efficiency}");
                regeneLossSum += Math.Abs(regeneLoss);

                lostEnergy += LostEnergyCalculator.CalcEnergy(convertLoss, regeneLoss, airResistancePower,
                                                              rollingResistancePower);
                //Debug.WriteLine("LostEnergy: " + lostEnergy);

                speedBefore = speed;

                //var consumedEnergy = ConsumedEnergyCaluculator.CalcEnergy(drivingResistancePower, Car.GetLeaf(), speed, efficiency);
                //Debug.WriteLine($"Efficiency: {efficiency}, CalcEfficiency: {(consumedEnergy / convertLoss) * 100}");
                //LostEnergyList.Add(lostEnergy);
            }

            Debug.WriteLine("LostEnergy: " + lostEnergy);
            Debug.WriteLine("Air: " + airSum);
            Debug.WriteLine("Rolling: " + rollingSum);
            Debug.WriteLine("Convert: " + convertLossSum);
            Debug.WriteLine("Regene: " + regeneLossSum);

            return(lostEnergy);
        }
예제 #4
0
        public static ECOLOGTuple calculateEcologTuple(GPSTuple previusGPS, GPSTuple currentGPSTuple, DataTable roadLinks, Car car)
        {
            // ECOLOGTupleの空のインスタンスを作成
            ECOLOGTuple retTuple = new ECOLOGTuple();

            // GPSTupleから現在地、GPS時刻、速度を取得。
            // 端末時刻は時刻同期がちゃんと取れてる必要があるので、GPS時刻を使うのが無難な気がする。
            retTuple.Jst       = currentGPSTuple.GpsTime;
            retTuple.Latitude  = currentGPSTuple.Latitude;
            retTuple.Longitude = currentGPSTuple.Longitude;
            retTuple.Speed     = currentGPSTuple.Speed;

            // 10mメッシュ標高データから取得する。
            // シングルトンクラスのGetInstance()はインスタンスそのものを返すのでnewいらない。
            AltitudeCalculator  altitudeCalculator  = AltitudeCalculator.GetInstance();
            Tuple <int, double> meshIdAltitudeTuple = altitudeCalculator.CalcAltitude(currentGPSTuple.Latitude, currentGPSTuple.Longitude);

            retTuple.TerrainAltitude = meshIdAltitudeTuple.Item2;

            double previusAltitude = altitudeCalculator.CalcAltitude(previusGPS.Latitude, previusGPS.Longitude).Item2;
            double altitudeDiff    = retTuple.TerrainAltitude - previusAltitude;

            // distance
            double distanceDiff = DistanceCalculator.CalcDistance(previusGPS.Latitude,
                                                                  previusGPS.Longitude,
                                                                  currentGPSTuple.Latitude,
                                                                  currentGPSTuple.Longitude);



            // calculate resistancePower
            double airResistancePower      = 0;
            double rollingResistancePower  = 0;
            double climbingResistancePower = 0;
            double accResitancePower       = 0;

            if (currentGPSTuple.Speed > 1 && distanceDiff > 0)
            {
                airResistancePower = AirResistanceCalculator.CalcPower(Rho,
                                                                       car.CdValue,
                                                                       car.FrontalProjectedArea,
                                                                       (currentGPSTuple.Speed + WindSpeed) / 3.6,
                                                                       currentGPSTuple.Speed / 3.6);

                rollingResistancePower = RollingResistanceCalculator.CalcPower(Myu,
                                                                               car.Weight,
                                                                               Math.Atan(altitudeDiff / distanceDiff),                           // TODO: 前のタプルとの標高差と距離が角度求めるには必要。
                                                                               currentGPSTuple.Speed / 3.6);

                climbingResistancePower = ClimbingResistanceCalculator.CalcPower(car.Weight,
                                                                                 Math.Atan(altitudeDiff / distanceDiff),                              // TODO: rollingResistancePowerと同様
                                                                                 currentGPSTuple.Speed / 3.6);

                accResitancePower = AccResistanceCalculator.CalcPower(previusGPS.Speed / 3.6,
                                                                      previusGPS.GpsTime,
                                                                      currentGPSTuple.Speed / 3.6,
                                                                      currentGPSTuple.GpsTime,
                                                                      car.Weight);
            }

            double drivingResistancePower = airResistancePower
                                            + rollingResistancePower
                                            + climbingResistancePower
                                            + accResitancePower;


            // torque
            double torque = 0;

            if (drivingResistancePower > 0 && currentGPSTuple.Speed > 0)
            {
                torque = drivingResistancePower * 1000 * 3600 / (currentGPSTuple.Speed / 3.6) * car.TireRadius / car.ReductionRatio;
            }

            // Efficiency
            int efficiency = EfficiencyCalculator.GetInstance().GetEfficiency(car, currentGPSTuple.Speed / 3.6, torque);

            // 各種損失はSensorLogInserterReの計算メソッドを用いて算出する
            double convertLoss = ConvertLossCaluculator.CalcEnergy(drivingResistancePower,
                                                                   car,
                                                                   currentGPSTuple.Speed / 3.6,
                                                                   efficiency);

            double regeneEnergy = RegeneEnergyCalculator.CalcEnergy(drivingResistancePower,
                                                                    currentGPSTuple.Speed / 3.6,
                                                                    car,
                                                                    efficiency);

            double regeneLoss = RegeneLossCalculator.CalcEnergy(drivingResistancePower,
                                                                regeneEnergy,
                                                                car,
                                                                currentGPSTuple.Speed / 3.6,
                                                                efficiency);

            double lostEnergy = LostEnergyCalculator.CalcEnergy(convertLoss,
                                                                regeneLoss,
                                                                airResistancePower,
                                                                rollingResistancePower);



            // link and semantic_link
            // 近傍リンクをSQLで指定、すべてのリンクに対して、GPS点とリンクの距離を求める
            // 最近傍リンクまでの距離が閾値を超えない場合には、それをGPS点が通過するリンクとする


            return(retTuple);
        }