//Check the percentage of the distances per interval compared to complete trip
        //Input only complete dataset
        //********************************************************************************************

        /*Parameters:
         *      - dt:               DataTable with the complete dataset
         *      - column_speed:     string with the name of the speed column
         *      - column_distance:  string with the name of the distance column
         */
        //********************************************************************************************
        public bool CheckDistributionComplete(DataTable dt, string column_speed, string column_distance)
        {
            DataTable urban    = new DataTable();
            DataTable rural    = new DataTable();
            DataTable motorway = new DataTable();
            double    trip     = 0;

            double[] distances = new double[3];

            //Seperate DataTable into intervals, using the methods of the Calculations class's object
            //Get the now seperated intervals
            Berechnungen.SepIntervals(dt, column_speed);
            Berechnungen.GetIntervals(ref urban, ref rural, ref motorway);

            //Calculate and get the distances driven per interval
            CalcDistances(urban, rural, motorway, column_distance, ref distances);

            //Calculate distance of complete trip
            trip = (double)dt.Compute("SUM([" + column_distance + "])", "") / 1000;

            //Calculate percentage per interval compared to complete trip
            distrUrban    = distances[0] * 100 / trip;
            distrRural    = distances[1] * 100 / trip;
            distrMotorway = distances[2] * 100 / trip;

            //if criteria are matched, return true
            if (distrUrban >= 29 && distrUrban <= 44 && distrRural >= 23 && distrRural <= 43 && distrMotorway >= 23 && distrMotorway <= 43)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        private void AddRoute(string column_latitude, string column_longitude, string column_speed, string column_time)
        {
            GMapOverlay        routes         = new GMapOverlay("routes");
            List <PointLatLng> points         = new List <PointLatLng>();
            List <PointLatLng> pointsUrban    = new List <PointLatLng>();
            List <PointLatLng> pointsRural    = new List <PointLatLng>();
            List <PointLatLng> pointsMotorway = new List <PointLatLng>();

            DataTable urban    = new DataTable();
            DataTable rural    = new DataTable();
            DataTable motorway = new DataTable();
            DataTable dt       = new DataTable();

            Berechnungen.SepIntervals(dataset, column_speed);
            Berechnungen.GetIntervals(ref urban, ref rural, ref motorway);

            Berechnungen.SortData(ref urban, column_time);
            Berechnungen.SortData(ref rural, column_time);
            Berechnungen.SortData(ref motorway, column_time);

            for (int i = 0; i < urban.Rows.Count; i++)
            {
                points.Add(new PointLatLng(Convert.ToDouble(urban.Rows[i][column_latitude]), Convert.ToDouble(urban.Rows[i][column_longitude])));

                if (i >= 1 && (Convert.ToDouble(urban.Rows[i][column_time]) - (Convert.ToDouble(urban.Rows[(i - 1)][column_time])) > 1000))
                {
                    dt = rural.Select("[" + column_time + "] = " + (Convert.ToInt32(urban.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();

                    points.RemoveAt(points.Count - 1);
                    points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

                    GMapRoute route = new GMapRoute(points, "Urban");
                    route.Stroke = new Pen(Color.IndianRed, 4);
                    routes.Routes.Add(route);

                    points.Clear();
                    points.Add(new PointLatLng(Convert.ToDouble(urban.Rows[i][column_latitude]), Convert.ToDouble(urban.Rows[i][column_longitude])));
                }
            }

            GMapRoute routeA = new GMapRoute(points, "Urban");

            routeA.Stroke = new Pen(Color.IndianRed, 4);
            routes.Routes.Add(routeA);

            points.Clear();

            for (int i = 0; i < rural.Rows.Count; i++)
            {
                points.Add(new PointLatLng(Convert.ToDouble(rural.Rows[i][column_latitude]), Convert.ToDouble(rural.Rows[i][column_longitude])));

                if (i >= 1 && (Convert.ToDouble(rural.Rows[i][column_time]) - (Convert.ToDouble(rural.Rows[(i - 1)][column_time])) > 1000))
                {
                    if (Convert.ToDouble(rural.Rows[i - 1]["ai"]) < 0)
                    {
                        dt = urban.Select("[" + column_time + "] = " + (Convert.ToInt32(rural.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();
                    }
                    else
                    {
                        dt = motorway.Select("[" + column_time + "] = " + (Convert.ToInt32(rural.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();
                    }

                    points.RemoveAt(points.Count - 1);
                    points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

                    GMapRoute route = new GMapRoute(points, "Rural");
                    route.Stroke = new Pen(Color.MediumSeaGreen, 4);
                    routes.Routes.Add(route);

                    points.Clear();
                    points.Add(new PointLatLng(Convert.ToDouble(rural.Rows[i][column_latitude]), Convert.ToDouble(rural.Rows[i][column_longitude])));
                }
            }
            dt = urban.Select("[" + column_time + "] = " + (Convert.ToInt32(rural.Rows[rural.Rows.Count - 1][column_time]) + 1000)).CopyToDataTable();
            points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

            GMapRoute routeB = new GMapRoute(points, "Rural");

            routeB.Stroke = new Pen(Color.MediumSeaGreen, 4);
            routes.Routes.Add(routeB);

            points.Clear();

            for (int i = 0; i < motorway.Rows.Count; i++)
            {
                points.Add(new PointLatLng(Convert.ToDouble(motorway.Rows[i][column_latitude]), Convert.ToDouble(motorway.Rows[i][column_longitude])));

                if (i >= 1 && (Convert.ToDouble(motorway.Rows[i][column_time]) - (Convert.ToDouble(motorway.Rows[(i - 1)][column_time])) > 1000))
                {
                    dt = rural.Select("[" + column_time + "] = " + (Convert.ToInt32(motorway.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();

                    points.RemoveAt(points.Count - 1);
                    points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

                    GMapRoute route = new GMapRoute(points, "motorway");
                    route.Stroke = new Pen(Color.LightSkyBlue, 4);
                    routes.Routes.Add(route);

                    points.Clear();
                    points.Add(new PointLatLng(Convert.ToDouble(motorway.Rows[i][column_latitude]), Convert.ToDouble(motorway.Rows[i][column_longitude])));
                }
            }
            dt = rural.Select("[" + column_time + "] = " + (Convert.ToInt32(motorway.Rows[motorway.Rows.Count - 1][column_time]) + 1000)).CopyToDataTable();
            points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

            GMapRoute routeC = new GMapRoute(points, "Motorway");

            routeC.Stroke = new Pen(Color.LightSkyBlue, 4);
            routes.Routes.Add(routeC);
            gMap.Overlays.Add(routes);

            //GMapOverlay markers = new GMapOverlay("markers");
            //GMapMarker marker = new GMarkerGoogle(
            //    new PointLatLng(Convert.ToDouble(motorway.Rows[motorway.Rows.Count - 1][column_latitude]), Convert.ToDouble(motorway.Rows[motorway.Rows.Count - 1][column_longitude])),
            //    GMarkerGoogleType.blue_pushpin);
            //markers.Markers.Add(marker);
            //gMap.Overlays.Add(markers);

            //points.Clear();
            //for (int i = 0; i < dataset.Rows.Count; i++)
            //{
            //    points.Add(new PointLatLng(Convert.ToDouble(dataset.Rows[i][column_latitude]), Convert.ToDouble(dataset.Rows[i][column_longitude])));
            //}

            //GMapRoute routee = new GMapRoute(points, "Color Coded Trip");
            //routee.Stroke = new Pen(Color.Blue, 1);
            //routes.Routes.Add(routee);
            //gMap.Overlays.Add(routes);

            //MainForm.Controls["txtMeasurement"].Text = "//Gemessene Distanz anhand GPS Datenauswertung:\n" + routee.Distance.ToString();
        }
        private void btnReadMeasuremntfile_Click(object sender, EventArgs e)
        {
            ofd.Filter           = "Textdateien |*.txt| Alle Dateien|*.*";
            ofd.InitialDirectory = "C:\\Repositories\01_Doku\\Vorgabe\\";
            //ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            ofd.Title    = "Textdatei öffnen";
            ofd.FileName = "";

            DialogResult dr = ofd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                Datei = new MeasurementFile(ofd.FileName);
                //DataTable test = new DataTable();
                test          = Datei.ConvertCSVtoDataTable();
                ColumnHeaders = Datei.Titles();              //Ausgabe der Spaltenüberschriften
                units         = Datei.GetMeasurementUnits(); //Ausgabe der Einheiten
                // var listofData = Datei.ReadMeasurementFile();

                //txtMeasurement.Text = listofData[1][1].ToString();
                berechnungDurchführenToolStripMenuItem.Enabled = true;
                //txtMeasurement.Text = "Berechnung durchführen bevor Grafik - Zeichnen möglich ist!";
            }
            else
            {
                txtMeasurement.Text = "Fail";
            }

            /*--------------------------------------------------------------------------------------------
             * Code für Testzwecke! Zur Ferstigstellung zu entfernen!!*/

            //Init the value DataTable
            InitValueData();
            Berechnung  = new Calculations();
            Gueltigkeit = new Validation();
            bool   test1, testdur;
            string column_speed = "OBD_Vehicle_Speed_(PID_13)";
            string column_acc = "ai";
            string column_dynamic = "a*v";
            string column_distance = "di";
            string column_time = "Time";
            string column_coolant = "OBD_Engine_Coolant_Temperature_(PID_5)";
            double avgUrban = 0, avgRural = 0, avgMotorway = 0;
            double distrUrban = 0, distrRural = 0, distrMotorway = 0;
            double tripUrban = 0, tripRural = 0, tripMotorway = 0;

            test1   = Berechnung.CalcAll(test, column_speed, column_acc, column_dynamic, column_distance);
            testdur = Gueltigkeit.CheckValidity(test, column_speed, column_time, column_coolant, column_distance);

            Berechnung.SepIntervals(test, column_speed);
            Berechnung.GetIntervals(ref urban, ref rural, ref motorway);
            Berechnung.AddUnits(units);

            Berechnung.GetAvgSpeed(ref avgUrban, ref avgRural, ref avgMotorway);
            Berechnung.GetTripInt(ref tripUrban, ref tripRural, ref tripMotorway);
            Gueltigkeit.GetDistribution(ref distrUrban, ref distrRural, ref distrMotorway);

            values.Rows[1]["Geschwindigkeit"] = avgUrban;
            values.Rows[2]["Geschwindigkeit"] = avgRural;
            values.Rows[3]["Geschwindigkeit"] = avgMotorway;

            values.Rows[1]["Verteilung"] = distrUrban;
            values.Rows[2]["Verteilung"] = distrRural;
            values.Rows[3]["Verteilung"] = distrMotorway;

            values.Rows[0]["Strecke"] = (double)test.Compute("SUM([" + column_distance + "])", "") / 1000;
            values.Rows[1]["Strecke"] = tripUrban;
            values.Rows[2]["Strecke"] = tripRural;
            values.Rows[3]["Strecke"] = tripMotorway;

            values.Rows[0]["Dauer"]     = Convert.ToDouble(test.Rows[test.Rows.Count - 1][column_time]) / 60000d;
            values.Rows[0]["Haltezeit"] = Gueltigkeit.GetHoldDurtation();
            values.Rows[0]["Hoechstgeschwindigkeit"]                 = Gueltigkeit.GetMaxSpeed();
            values.Rows[0]["Kaltstart Hoechstgeschwindigkeit"]       = Gueltigkeit.GetMaxSpeedCold();
            values.Rows[0]["Kaltstart Durchschnittsgeschwindigkeit"] = Gueltigkeit.GetAvgSpeedCold();
            values.Rows[0]["Kaltstart Haltezeit"] = Gueltigkeit.GetTimeHoldCold();

            grafikToolStripMenuItem.Enabled = true;
            txtMeasurement.Text             = "Berechnung durchgeführt!";
            /*--------------------------------------------------------------------------------------------*/
        }
        private void btnBerechnen_Click(object sender, EventArgs e)
        {
            Berechnung  = new Calculations();
            Gueltigkeit = new Validation();
            bool   test1, testdur;
            string column_speed    = "OBD_Vehicle_Speed_(PID_13)";
            string column_acc      = "ai";
            string column_dynamic  = "a*v";
            string column_distance = "di";
            string column_time     = "Time";
            string column_coolant  = "OBD_Engine_Coolant_Temperature_(PID_5)";
            string erg;
            double avgUrban = 0, avgRural = 0, avgMotorway = 0;

            //Init the value DataTable
            InitValueData();

            //DataTable city = new DataTable();
            //DataTable land = new DataTable();
            //DataTable autobahn = new DataTable();

            //Stopwatch watch = new Stopwatch();
            //watch.Start();

            test1   = Berechnung.CalcAll(test, column_speed, column_acc, column_dynamic, column_distance);
            testdur = Gueltigkeit.CheckValidity(test, column_speed, column_time, column_coolant, column_distance);

            Berechnung.SepIntervals(test, column_speed);
            Berechnung.GetIntervals(ref urban, ref rural, ref motorway);
            Berechnung.AddUnits(units);
            Berechnung.GetAvgSpeed(ref avgUrban, ref avgRural, ref avgMotorway);

            values.Rows[1]["Geschwindigket"] = avgUrban;
            values.Rows[2]["Geschwindigket"] = avgRural;
            values.Rows[3]["Geschwindigket"] = avgMotorway;


            if (test1 && testdur)
            {
                erg = "gültig";
            }
            else
            {
                erg = "ungültig";
            }

            //Berechnung.CalcReq(ref test, column_speed);
            //testdur = Gueltigkeit.CheckValidity(test, column_speed, column_time, column_coolant, column_distance);

            //Berechnung.SortData(ref test, column_speed);
            //Berechnung.SepIntervals(test, column_speed);
            //Berechnung.GetIntervals(ref city, ref land, ref autobahn);
            //testdur = Gueltigkeit.CheckDistanceIntervals(city, land, autobahn, column_distance);
            //testdur = Gueltigkeit.CheckDistributionIntervals(city, land, autobahn, column_distance);
            //testdur = Gueltigkeit.CheckDistributionComplete(test, column_speed, column_distance);

            //test1 = Berechnung.PosCheck(column_acc);
            //Berechnung.CalcAvgSpeedInt(column_speed);
            //Berechnung.GetIntervals(ref city, ref land, ref autobahn);
            //nfPerc = Berechnung.CalcPercentile_Interval(ref city, column_dynamic);
            //RPA_city = Berechnung.CalcRPA(test, city, column_speed, column_acc, column_distance);

            //testdur = Gueltigkeit.CheckDuration(test, column_time);
            //testdur = Gueltigkeit.CheckDistanceComplete(test, column_speed, column_distance);
            //testdur = Gueltigkeit.CheckDistributionComplete(test, column_speed, column_distance);

            //testdur = Gueltigkeit.CheckSpeeds(city, autobahn, column_speed, column_time);
            //testdur = Gueltigkeit.CheckColdStart(test, column_speed, column_time, column_coolant);
            //watch.Stop();
            MessageBox.Show("Berechnung durchgeführt!\nFahrt ist " + erg, "Berechnungsergebnis");
            grafikToolStripMenuItem.Enabled = true;
        }