public GraphWindowViewModel(SemanticLink semanticLink, TripDirection direction)
        {
            SemanticLink = semanticLink;
            Direction    = direction;

            Initialize();
        }
Exemplo n.º 2
0
 public static int GetEnergyMinTripID(SemanticLink semanticLink, TripDirection direction)
 {
     return(DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedEnergyMinOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
            .AsEnumerable()
            .Select(x => x.Field <int>("TripID"))
            .ElementAt(0));
 }
Exemplo n.º 3
0
        public DetailComparePageViewModel(SemanticLink link, TripDirection direction)
        {
            this.SelectedSemanticLink = link;
            this.TripDirection        = direction;

            Initialize();
        }
Exemplo n.º 4
0
        public SemanticDetailWindowViewModel(SemanticLink link, TripDirection direction)
        {
            this.SemanticLink  = link;
            this.TripDirection = direction;

            Initialize();
        }
Exemplo n.º 5
0
        public DetailEnergyPageViewModel(SemanticLink link, TripDirection direction)
        {
            this.SemanticLink  = link;
            this.TripDirection = direction;

            Initialize();
        }
        public CompareTimePageViewModel(List <SemanticLink> semanticLinks, TripDirection direction)
        {
            this.SelectedSemanticLinks = semanticLinks;
            this.TripDirection         = direction;

            Initialize();
        }
 public void SetHomewardSemanticLinks()
 {
     _direction = new TripDirection {
         Direction = "homeward"
     };
     SemanticLinks = SemanticLinkDao.HomewardSemanticLinks;
     //InvokeScript("initialize", null);
 }
 public void SetOutwardSemanticLinks()
 {
     _direction = new TripDirection {
         Direction = "outward"
     };
     SemanticLinks = SemanticLinkDao.OutwardSemanticLinks;
     InvokeScript("initialize", null);
 }
        public DetailTripDetailPageViewModel(SemanticLink link, TripDirection direction, InvokeScript script)
        {
            this.SemanticLink  = link;
            this.TripDirection = direction;
            this.invokeScript  = script;

            Initialize();
        }
        public MainMapPageViewModel(List <SemanticLink> extractedSemanticLinks, TripDirection direction, InvokeScript script)
        {
            this.ExtractedSemanticLinks = extractedSemanticLinks;
            this.SelectedSemanticLinks  = new ObservableCollection <SemanticLink>();
            this.TripDirection          = direction;
            this.invokeScript           = script;

            Initialize();
        }
Exemplo n.º 11
0
        public DetailHeatMapPageViewModel(SemanticLink semanticLink, TripDirection direction, List <Driver> drivers, List <Car> cars, List <Sensor> sensors)
        {
            this.semantciLink = semanticLink;
            this.direction    = direction;
            this.drivers      = drivers;
            this.cars         = cars;
            this.sensors      = sensors;

            this.ProgressBarVisibility = System.Windows.Visibility.Visible;

            createPlotModel();
        }
        public void Initialize()
        {
            SemanticLinks = SemanticLinkDao.OutwardSemanticLinks;
            _direction    = new TripDirection {
                Direction = "outward"
            };

            Uri = $"{AppDomain.CurrentDomain.BaseDirectory}Resources\\index.html";

            MapHost = new MapHost()
            {
                MapWindowViewModel = this
            };
        }
        public MainTimePageViewModel(List <SemanticLink> extractedSemanticLinks, TripDirection direction)
        {
            SelectedSemanticLinks = new ObservableCollection <SemanticLink>();
            this.TripDirection    = direction;
            this.SemanticGraphs   = new List <SemanticGraph>();

            foreach (SemanticLink link in extractedSemanticLinks)
            {
                this.SemanticGraphs.Add(new SemanticGraph()
                {
                    SemanticLink = link, SeriesVisibility = true
                });
            }

            this.AreaSeriesList = new List <AreaSeries>();

            CreatePlotModel();
        }
Exemplo n.º 14
0
        public static SemanticHistogramDatum GetEnergyInstance(SemanticLink semanticLink, TripDirection direction, int sensorID)
        {
            SemanticHistogramDatum datum = new SemanticHistogramDatum();

            datum.SemanticLink = semanticLink;
            datum.Direction    = direction;

            string query = "WITH SelectedSemanticLink ";

            query += "AS ( ";
            query += "	SELECT * ";
            query += "	FROM SEMANTIC_LINKS ";
            query += "	WHERE SEMANTIC_LINK_ID = "+ semanticLink.SemanticLinkId;
            query += "	) ";

            query += "	,ExtractedTrips ";
            query += "AS ( ";
            query += "	SELECT Sensor"+ sensorID + ".TRIP_ID ";
            query += "	FROM TRIPS Sensor12 ";
            query += "	INNER JOIN TRIPS Sensor24 ON DATEPART(YEAR, Sensor12.START_TIME) = DATEPART(YEAR, Sensor24.START_TIME) ";
            query += "		AND DATEPART(MONTH, Sensor12.START_TIME) = DATEPART(MONTH, Sensor24.START_TIME) ";
            query += "		AND DATEPART(DAYOFYEAR, Sensor12.START_TIME) = DATEPART(DAYOFYEAR, Sensor24.START_TIME) ";
            query += "		AND DATEPART(HOUR, Sensor12.START_TIME) = DATEPART(HOUR, Sensor24.START_TIME) ";
            query += "		AND DATEPART(MINUTE, Sensor12.START_TIME) = DATEPART(MINUTE, Sensor24.START_TIME) ";
            query += "	WHERE Sensor12.SENSOR_ID = 12 ";
            query += "		AND Sensor24.SENSOR_ID = 24 ";
            query += "	) ";

            query += "	,ExtractedEcolog ";
            query += "AS ( ";
            query += "	SELECT ECOLOG.TRIP_ID ";
            query += "		,SUM(LOST_ENERGY) AS SumLostEnergy ";
            query += "	FROM ECOLOG ";
            query += "	INNER JOIN ExtractedTrips ON ECOLOG.TRIP_ID = ExtractedTrips.TRIP_ID ";
            query += "	INNER JOIN SelectedSemanticLink ON ECOLOG.LINK_ID = SelectedSemanticLink.LINK_ID ";
            query += "	WHERE ECOLOG.DRIVER_ID = 1 ";
            query += "		AND TRIP_DIRECTION = '"+ direction.Direction + "' ";
            query += "		AND (SENSOR_ID = "+ sensorID + ") ";
            query += "	GROUP BY ECOLOG.TRIP_ID ";
            query += "	) ";

            /*
             * query += "	,NormalizedEcolog ";
             * query += "AS ( ";
             * query += "	SELECT SumLostEnergy ";
             * query += "	FROM ExtractedEcolog ";
             * query += "	WHERE SumLostEnergy <= Q3 + 1.5 * (Q3 - Q1) ";
             * query += "		AND SumLostEnergy >= Q1 - 1.5 * (Q3 - Q1) ";
             * query += "	) ";
             * query += "	,NormalizedEcologClassWidth ";
             * query += "AS ( ";
             * query += "	SELECT (MAX(SumLostEnergy) - MIN(SumLostEnergy)) / 10 AS ClassWidth ";
             * query += "	FROM NormalizedEcolog ";
             * query += "	) ";
             */

            query += "SELECT TOP 100 CEILING(SumLostEnergy / 0.003564219668623985) * 0.003564219668623985 AS LEVEL ";
            query += "	,COUNT(*) AS Number ";
            query += "FROM ExtractedEcolog ";
            // query += "	,NormalizedEcologClassWidth ";
            query += "GROUP BY CEILING(SumLostEnergy / 0.003564219668623985) * 0.003564219668623985 ";
            query += "ORDER BY CEILING(SumLostEnergy / 0.003564219668623985) * 0.003564219668623985 ";

            DataTable table = DatabaseAccesserEcolog.GetResult(query);

            datum.HistogramData = new List <LevelAndValue>();
            foreach (DataRow row in table.Rows)
            {
                datum.HistogramData.Add(new LevelAndValue()
                {
                    Level = row.Field <double>("Level"), Value = row.Field <int>("Number")
                });
            }

            /*
             * query = null;
             *
             * query = "WITH SelectedSemanticLink ";
             * query += "AS ( ";
             * query += "	SELECT * ";
             * query += "	FROM SEMANTIC_LINKS ";
             * query += "	WHERE SEMANTIC_LINK_ID = " + semanticLink.SemanticLinkId;
             * query += "	) ";
             * query += "	,ExtractedTrips ";
             * query += "AS ( ";
             * query += "	SELECT Sensor" + sensorID + ".TRIP_ID ";
             * query += "	FROM TRIPS Sensor12 ";
             * query += "	INNER JOIN TRIPS Sensor24 ON DATEPART(YEAR, Sensor12.START_TIME) = DATEPART(YEAR, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(MONTH, Sensor12.START_TIME) = DATEPART(MONTH, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(DAYOFYEAR, Sensor12.START_TIME) = DATEPART(DAYOFYEAR, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(HOUR, Sensor12.START_TIME) = DATEPART(HOUR, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(MINUTE, Sensor12.START_TIME) = DATEPART(MINUTE, Sensor24.START_TIME) ";
             * query += "	WHERE Sensor12.SENSOR_ID = 12 ";
             * query += "		AND Sensor24.SENSOR_ID = 24 ";
             * query += "	) ";
             * query += "	,ExtractedEcolog ";
             * query += "AS ( ";
             * query += "	SELECT ECOLOG.TRIP_ID ";
             * query += "		,SUM(LOST_ENERGY) AS SumLostEnergy ";
             * query += "		,PERCENTILE_DISC(0.25) WITHIN ";
             * query += "	GROUP ( ";
             * query += "			ORDER BY SUM(LOST_ENERGY) ";
             * query += "			) OVER (PARTITION BY NULL) AS Q1 ";
             * query += "		,PERCENTILE_DISC(0.75) WITHIN ";
             * query += "	GROUP ( ";
             * query += "			ORDER BY SUM(LOST_ENERGY) ";
             * query += "			) OVER (PARTITION BY NULL) AS Q3 ";
             * query += "	FROM ECOLOG ";
             * query += "	INNER JOIN ExtractedTrips ON ECOLOG.TRIP_ID = ExtractedTrips.TRIP_ID ";
             * query += "	INNER JOIN SelectedSemanticLink ON ECOLOG.LINK_ID = SelectedSemanticLink.LINK_ID ";
             * query += "	WHERE ECOLOG.DRIVER_ID = 1 ";
             * query += "		AND TRIP_DIRECTION = '" + direction.Direction + "' ";
             * query += "		AND SENSOR_ID = " + sensorID;
             * query += "	GROUP BY ECOLOG.TRIP_ID ";
             * query += "	) ";
             * query += "SELECT TRIP_ID AS TripID ";
             * query += "	,SumLostEnergy AS Min ";
             * query += "FROM ExtractedEcolog ";
             * query += "WHERE SumLostEnergy = ( ";
             * query += "		SELECT MIN(SumLostEnergy) AS Min ";
             * query += "		FROM ExtractedEcolog ";
             * query += "		WHERE SumLostEnergy >= Q1 - 1.5 * (Q3 - Q1) ";
             * query += "		) ";
             *
             * datum.MinLevel = DatabaseAccesserEcolog.GetResult(query)
             *  .AsEnumerable()
             *  .Select(x => x.Field<double>("Min"))
             *  .ElementAt(0);
             *
             * query = null;
             *
             * query = "WITH SelectedSemanticLink ";
             * query += "AS ( ";
             * query += "	SELECT * ";
             * query += "	FROM SEMANTIC_LINKS ";
             * query += "	WHERE SEMANTIC_LINK_ID = " + semanticLink.SemanticLinkId;
             * query += "	) ";
             * query += "	,ExtractedTrips ";
             * query += "AS ( ";
             * query += "	SELECT Sensor" + sensorID + ".TRIP_ID ";
             * query += "	FROM TRIPS Sensor12 ";
             * query += "	INNER JOIN TRIPS Sensor24 ON DATEPART(YEAR, Sensor12.START_TIME) = DATEPART(YEAR, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(MONTH, Sensor12.START_TIME) = DATEPART(MONTH, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(DAYOFYEAR, Sensor12.START_TIME) = DATEPART(DAYOFYEAR, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(HOUR, Sensor12.START_TIME) = DATEPART(HOUR, Sensor24.START_TIME) ";
             * query += "		AND DATEPART(MINUTE, Sensor12.START_TIME) = DATEPART(MINUTE, Sensor24.START_TIME) ";
             * query += "	WHERE Sensor12.SENSOR_ID = 12 ";
             * query += "		AND Sensor24.SENSOR_ID = 24 ";
             * query += "	) ";
             * query += "	,ExtractedEcolog ";
             * query += "AS ( ";
             * query += "	SELECT ECOLOG.TRIP_ID ";
             * query += "		,SUM(LOST_ENERGY) AS SumLostEnergy ";
             * query += "		,PERCENTILE_DISC(0.25) WITHIN ";
             * query += "	GROUP ( ";
             * query += "			ORDER BY SUM(LOST_ENERGY) ";
             * query += "			) OVER (PARTITION BY NULL) AS Q1 ";
             * query += "		,PERCENTILE_DISC(0.75) WITHIN ";
             * query += "	GROUP ( ";
             * query += "			ORDER BY SUM(LOST_ENERGY) ";
             * query += "			) OVER (PARTITION BY NULL) AS Q3 ";
             * query += "	FROM ECOLOG ";
             * query += "	INNER JOIN ExtractedTrips ON ECOLOG.TRIP_ID = ExtractedTrips.TRIP_ID ";
             * query += "	INNER JOIN SelectedSemanticLink ON ECOLOG.LINK_ID = SelectedSemanticLink.LINK_ID ";
             * query += "	WHERE ECOLOG.DRIVER_ID = 1 ";
             * query += "		AND TRIP_DIRECTION = '" + direction.Direction + "' ";
             * query += "		AND SENSOR_ID = " + sensorID;
             * query += "	GROUP BY ECOLOG.TRIP_ID ";
             * query += "	) ";
             * query += "SELECT TRIP_ID AS TripID ";
             * query += "	,SumLostEnergy AS Max ";
             * query += "FROM ExtractedEcolog ";
             * query += "WHERE SumLostEnergy = ( ";
             * query += "		SELECT MAX(SumLostEnergy) AS Max ";
             * query += "		FROM ExtractedEcolog ";
             * query += "		WHERE SumLostEnergy <= Q3 + 1.5 * (Q3 - Q1) ";
             * query += "		) ";
             *
             * datum.MaxLevel = DatabaseAccesserEcolog.GetResult(query)
             *  .AsEnumerable()
             *  .Select(x => x.Field<double>("Max"))
             *  .ElementAt(0);
             */

            /*
             * datum.MedianLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedEnergyMedianOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
             *  .AsEnumerable()
             *  .Select(x => x.Field<double>("Median"))
             *  .ElementAt(0);
             *
             * datum.AvgLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedEnergyAvgOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
             *  .AsEnumerable()
             *  .Select(x => x.Field<double>("Avg"))
             *  .ElementAt(0);
             */

            // datum.ModeLevel = datum.HistogramData.First(v => v.Value.Equals(datum.HistogramData.Select(m => m.Value).Max())).Level;

            // datum.HistogramData.Max(x => x.Level);

            // datum.ClassWidth = (datum.MaxLevel - datum.MinLevel) / 10;
            datum.ClassWidth = 0.003564219668623985;

            /*
             * datum.UnderModeData = datum.HistogramData
             *  .Where(v => v.Value <= datum.HistogramData.Max(x => x.Value) * 0.75)
             *  .Where(v => v.Level < datum.ModeLevel)
             *  .ToList();
             *
             * datum.ModeData = datum.HistogramData
             *  .Where(v => v.Value >= datum.HistogramData.Max(x => x.Value) * 0.75)
             *  .ToList();
             *
             * datum.UpperModeData = datum.HistogramData
             *  .Where(v => v.Value <= datum.HistogramData.Max(x => x.Value) * 0.75)
             *  .Where(v => v.Level > datum.ModeLevel)
             *  .ToList();
             *
             * datum.DistUnderMode = datum.UnderModeData.Sum(x => x.Value) * 100 / datum.HistogramData.Sum(x => x.Value);
             * datum.DistMode = datum.ModeData.Sum(x => x.Value) * 100 / datum.HistogramData.Sum(x => x.Value);
             * datum.DistUpperMode = datum.UpperModeData.Sum(x => x.Value) * 100 / datum.HistogramData.Sum(x => x.Value);
             *
             * datum.CompMinMax = datum.MaxLevel * 100 / datum.MinLevel;
             * datum.CompMinMode = datum.ModeLevel * 100 / datum.MinLevel;
             * datum.CompModeMax = datum.MaxLevel * 100 / datum.ModeLevel;
             */

            return(datum);
        }
Exemplo n.º 15
0
        public static SemanticHistogramDatum GetNormalizedStackedTimeInstance(SemanticLink semanticLink, TripDirection direction)
        {
            SemanticHistogramDatum datum = new SemanticHistogramDatum();

            datum.SemanticLink = semanticLink;
            datum.Direction    = direction;

            datum.Sum = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeSumOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                        .AsEnumerable()
                        .Select(x => x.Field <int>("Sum"))
                        .ElementAt(0);

            datum.Number = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeNumberOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                           .AsEnumerable()
                           .Select(x => x.Field <int>("Number"))
                           .ElementAt(0);

            DataTable table = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeStackOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')");

            datum.HistogramData = new List <LevelAndValue>();
            foreach (DataRow row in table.Rows)
            {
                datum.HistogramData.Add(new LevelAndValue()
                {
                    Level = row.Field <int>("Level"), Value = row.Field <int>("Stack") / datum.Number
                });
            }

            datum.MaxLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeMaxOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                             .AsEnumerable()
                             .Select(x => x.Field <int>("Max"))
                             .ElementAt(0);

            datum.MinLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeMinOfSemanticLink(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                             .AsEnumerable()
                             .Select(x => x.Field <int>("Min"))
                             .ElementAt(0);

            datum.ClassWidth = (int)((datum.MaxLevel - datum.MinLevel) / 10);

            return(datum);
        }
Exemplo n.º 16
0
        public static SemanticHistogramDatum GetDistanceNormalizedTimeInstance(SemanticLink semanticLink, TripDirection direction)
        {
            SemanticHistogramDatum datum = new SemanticHistogramDatum();

            datum.SemanticLink = semanticLink;
            datum.Direction    = direction;

            DataTable table = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeHistogramOfSemanticLinkWithDistance(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')");

            datum.HistogramData = new List <LevelAndValue>();
            foreach (DataRow row in table.Rows)
            {
                datum.HistogramData.Add(new LevelAndValue()
                {
                    Level = row.Field <int>("Level"), Value = row.Field <int>("Number")
                });
            }

            datum.MaxLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeMaxOfSemanticLinkWithDistance(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                             .AsEnumerable()
                             .Select(x => x.Field <double>("Max"))
                             .ElementAt(0);

            datum.MinLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeMinOfSemanticLinkWithDistance(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                             .AsEnumerable()
                             .Select(x => x.Field <double>("Min"))
                             .ElementAt(0);

            datum.MedianLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeMedianOfSemanticLinkWithDistance(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                                .AsEnumerable()
                                .Select(x => x.Field <double>("Median"))
                                .ElementAt(0);

            datum.AvgLevel = DatabaseAccesserEcolog.GetResult("SELECT * FROM funcNormalizedTimeAvgOfSemanticLinkWithDistance(" + semanticLink.SemanticLinkId + ", '" + direction.Direction + "')")
                             .AsEnumerable()
                             .Select(x => x.Field <double>("Avg"))
                             .ElementAt(0);

            datum.ModeLevel = datum.HistogramData.First(v => v.Value.Equals(datum.HistogramData.Select(m => m.Value).Max())).Level;

            datum.HistogramData.Max(x => x.Level);

            datum.ClassWidth = (int)((datum.MaxLevel - datum.MinLevel) / 10);

            datum.UnderModeData = datum.HistogramData
                                  .Where(v => v.Value <= datum.HistogramData.Max(x => x.Value) * 0.75)
                                  .Where(v => v.Level < datum.ModeLevel)
                                  .ToList();

            datum.ModeData = datum.HistogramData
                             .Where(v => v.Value >= datum.HistogramData.Max(x => x.Value) * 0.75)
                             .ToList();

            datum.UpperModeData = datum.HistogramData
                                  .Where(v => v.Value <= datum.HistogramData.Max(x => x.Value) * 0.75)
                                  .Where(v => v.Level > datum.ModeLevel)
                                  .ToList();

            datum.DistUnderMode = datum.UnderModeData.Sum(x => x.Value) * 100 / datum.HistogramData.Sum(x => x.Value);
            datum.DistMode      = datum.ModeData.Sum(x => x.Value) * 100 / datum.HistogramData.Sum(x => x.Value);
            datum.DistUpperMode = datum.UpperModeData.Sum(x => x.Value) * 100 / datum.HistogramData.Sum(x => x.Value);

            datum.CompMinMax  = datum.MaxLevel * 100 / datum.MinLevel;
            datum.CompMinMode = datum.ModeLevel * 100 / datum.MinLevel;
            datum.CompModeMax = datum.MaxLevel * 100 / datum.ModeLevel;

            return(datum);
        }
Exemplo n.º 17
0
        public static List <GraphDatum> GetRecentGraphDataOnSemanticLink(SemanticLink semanticLink, TripDirection direction)
        {
            using (var connection = new SqlConnection(DatabaseConnection.ConnectionString))
            {
                connection.Open();

                var query = new StringBuilder();

                query.AppendLine("DECLARE @semantic_link_id INT");
                query.AppendLine("DECLARE @direction VARCHAR(255)");
                query.AppendLine("DECLARE @links_count INT");
                query.AppendLine($"SET @semantic_link_id = {semanticLink.SemanticLinkId}");
                query.AppendLine($"SET @direction = '{direction.Direction}'");
                query.AppendLine("SET @links_count = (");
                query.AppendLine("		SELECT COUNT(*) AS links_count");
                query.AppendLine("		FROM semantic_links");
                query.AppendLine("		WHERE semantic_link_id = @semantic_link_id");
                query.AppendLine("		);");

                query.AppendLine("WITH selected_semantic_link");
                query.AppendLine("AS (");
                query.AppendLine("	SELECT *");
                query.AppendLine("	FROM semantic_links");
                query.AppendLine("	WHERE semantic_link_id = @semantic_link_id");
                query.AppendLine("	)");

                query.AppendLine("	,semantic_link_lat_long");
                query.AppendLine("AS(");
                query.AppendLine("  SELECT MIN(latitude) AS min_lat");
                query.AppendLine("		,MIN(longitude) AS min_long");
                query.AppendLine("		,MAX(latitude) AS max_lat");
                query.AppendLine("		,MAX(longitude) AS max_long");
                query.AppendLine("	FROM links INNER JOIN semantic_links ON links.link_id = semantic_links.link_id");
                query.AppendLine("	WHERE semantic_link_id = @semantic_link_id");
                query.AppendLine("	)");

                query.AppendLine("	,trip_link_count");
                query.AppendLine("AS(");
                query.AppendLine("	SELECT trip_id, COUNT(DISTINCT ecolog.link_id) AS link_count");
                query.AppendLine("	FROM ecolog");
                query.AppendLine("		INNER JOIN selected_semantic_link ON ecolog.link_id = selected_semantic_link.link_id");
                query.AppendLine("	GROUP BY trip_id");
                query.AppendLine("	)");

                query.AppendLine("SELECT ecolog.trip_id AS TripId");
                query.AppendLine("	,MIN(jst) AS Date");
                query.AppendLine("	,COUNT(*) AS TransitTime");
                query.AppendLine("	,SUM(consumed_electric_energy) AS ConsumedElectricEnergy");
                query.AppendLine("	,SUM(lost_energy) AS LostEnergy");
                query.AppendLine("	,SUM(ABS(regene_loss)) AS RegeneLoss");
                query.AppendLine("	,SUM(ABS(convert_loss)) AS ConvertLoss");
                query.AppendLine("	,SUM(energy_by_rolling_resistance) AS RollingResistance");
                query.AppendLine("	,SUM(energy_by_air_resistance) AS AirResistance");
                query.AppendLine("FROM ecolog, semantic_link_lat_long, trip_link_count");

                query.AppendLine("WHERE ecolog.driver_id = 1");
                query.AppendLine("  AND (ecolog.car_id = 1 OR ecolog.car_id = 3)");
                query.AppendLine("  AND ecolog.sensor_id = 16");
                query.AppendLine("	AND trip_direction = @Direction");
                //query.AppendLine("  AND JST < '2014-06-16 00:00:00'");
                query.AppendLine("  AND jst > '2016-12-01 08:00:00'");
                query.AppendLine("  AND latitude <= semantic_link_lat_long.max_lat + 0.0001");
                query.AppendLine("  AND LATITUDE >= semantic_link_lat_long.min_lat - 0.0001");
                query.AppendLine("	AND LONGITUDE <= semantic_link_lat_long.max_long");
                query.AppendLine("	AND LONGITUDE >= semantic_link_lat_long.min_long");
                query.AppendLine("	AND ecolog.trip_id = trip_link_count.trip_id");
                query.AppendLine("	AND trip_link_count.link_count > (@links_count * 0.8)");

                query.AppendLine("GROUP BY ecolog.trip_id");

                var list = connection.Query <GraphDatum>(query.ToString()).ToList();

                Console.WriteLine("List count: " + list.Count);
                Console.WriteLine(query.ToString());

                return(list);
            }
        }
        public SemanticCompareWindowViewModel(List <SemanticLink> selectedSemanticLink, TripDirection direction)
        {
            this.SelectedSemanticLinks = selectedSemanticLink;
            this.TripDirection         = direction;

            Initialize();
        }