Пример #1
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     if (reader.TokenType == JsonToken.StartArray)
     {
         return(serializer.Deserialize <List <StopLocation> >(reader));
     }
     else
     {
         StopLocation media = serializer.Deserialize <StopLocation>(reader);
         return(new List <StopLocation>(new[] { media }));
     }
 }
Пример #2
0
        private static void GetStops(XmlNode stopsNode, List <RouteStop> stops)
        {
            foreach (XmlElement stop in stopsNode)
            {
                int          stopID       = int.Parse(stop.Attributes["id"].Value);
                int          stopCode     = int.Parse(stop.Attributes["code"].Value);
                string       stopName     = stop.Attributes["publicName"].Value;
                StopLocation stopLocation = new StopLocation(stop.Attributes["lat"].Value, stop.Attributes["lon"].Value);

                RouteStop currentStop = new RouteStop(stopID, stopName);
                currentStop.Code            = stopCode;
                currentStop.DefaultLocation = stopLocation;
                stops.Add(currentStop);
            }
        }
Пример #3
0
        private void ShowNearbyStops(Point position)
        {
            foreach (Feature feature in features)
            {
                StopLocation location = feature["stopObject"] as StopLocation;

                Point point      = new Point(location.Lon, location.Lat);
                Point local      = SphericalMercator.FromLonLat(point.X, point.Y);
                Point difference = position - local;

                if (Math.Abs(difference.X) < STOP_THRESHOLD && Math.Abs(difference.Y) < STOP_THRESHOLD)
                {
                    foreach (Style style in feature.Styles)
                    {
                        style.Enabled = true;
                    }
                }
            }
        }
Пример #4
0
        public void MoveToStop(string code)
        {
            foreach (Feature feature in features)
            {
                StopLocation location = feature["stopObject"] as StopLocation;
                if (location.Code == code)
                {
                    Point point = new Point(location.Lon, location.Lat);
                    Point local = SphericalMercator.FromLonLat(point.X, point.Y);

                    foreach (Style style in feature.Styles)
                    {
                        style.Enabled = true;
                    }

                    MoveTo(local, 16);
                }
            }
        }
Пример #5
0
        private void OnMapInfo(object sender, MapInfoEventArgs e)
        {
            Messenger.Default.Send(new MapClickedMessage());
            mapClickResetEvent.WaitOne();
            mapClickResetEvent.Reset();

            MapClickedResponseMessage message = messages.Dequeue();

            if (message.Handled)
            {
                return;
            }

            if (e.MapInfo.Feature != null && e.MapInfo.Feature.Styles.First().Enabled)
            {
                StopLocation location = e.MapInfo.Feature["stopObject"] as StopLocation;

                Messenger.Default.Send(new StopSelectedMessage(location.Code, false));
                return;
            }
            ShowNearbyStops(e.MapInfo.WorldPosition);
            map.ViewChanged(true);
        }
 public StopViewModel(StopLocation stop)
 {
     this.stop = stop;
 }
Пример #7
0
        private static void GetLines(XmlNode linesNode, int currentIDNumeric, List <RouteLine> lines, List <RouteStop> stops)
        {
            foreach (XmlElement line in linesNode)
            {
                int       lineID      = int.Parse(line.Attributes["id"].Value);
                string    lineName    = line.Attributes["publicName"].Value;
                RouteLine currentLine = new RouteLine(lineID, lineName, currentIDNumeric);
                lines.Add(currentLine);

                foreach (XmlElement route in line)
                {
                    int    currentRouteID   = int.Parse(route.Attributes["route_id"].Value);
                    string currentRouteName = route.Attributes["publicName"].Value;

                    Route currentRoute = new Route(currentRouteID, currentRouteName);

                    var currentChildNode = route.ChildNodes[0];
                    int currentChildID   = int.Parse(currentChildNode.Attributes["id"].Value);

                    RouteStop currentStop = null;
                    try
                    {
                        var tempStop = stops.Where(x => x.PublicID == currentChildID).First();
                        currentStop = tempStop.Clone() as RouteStop;
                    }
                    catch (InvalidOperationException)
                    {
                        currentStop = new RouteStop(currentChildID, "MISSING!");
                    }

                    for (int i = 1; i < route.ChildNodes.Count; i++)
                    {
                        if (route.ChildNodes[i].Name == "stopRef")
                        {
                            currentRoute.Stops.Add(currentStop);
                            currentChildNode = route.ChildNodes[i];
                            currentChildID   = int.Parse(currentChildNode.Attributes["id"].Value);
                            try
                            {
                                var tempStop = stops.Where(x => x.PublicID == currentChildID).First();
                                currentStop = tempStop.Clone() as RouteStop;
                            }
                            catch (InvalidOperationException)
                            {
                                currentStop = new RouteStop(currentChildID, "MISSING!");
                            }
                        }
                        else
                        {
                            string lat = route.ChildNodes[i].Attributes["lat"].Value;
                            string lon = route.ChildNodes[i].Attributes["lon"].Value;

                            StopLocation currentStopLocation = new StopLocation(lat, lon);
                            currentStop.StopLocations.Add(currentStopLocation);
                        }
                    }

                    currentRoute.Stops.Add(currentStop);
                    currentLine.LineRoute.Add(currentRoute);
                }
            }
        }
    public static DateTime GetHeadWayEnd(double pTrainId, Segment pSegment, StopLocation pNextSegment, int pLocation, string pStrUD, int pDirection, Int16 pDestTrack, out DateTime pOcupTime)
    {
        DateTime lvRes = DateTime.MinValue;
        DateTime lvOcupTime = DateTime.MinValue;
        Segment lvSegment;
        string lvStrUD = "";
        int lvLocation = Int32.MinValue;
        int lvIndex;

        pOcupTime = DateTime.MinValue;

        DebugLog.Logar(" --------------------------------------------- GetHeadWayEnd(pTrainId = " + pTrainId + ", pLocation = " + pLocation + ", pStrUD = " + pStrUD + ", pDirection = " + pDirection + ", pDestTrack = " + pDestTrack + ") ------------------------------ ");

        if (pDirection > 0)
        {
            lvSegment = Segment.GetCurrentSegment(pNextSegment.Start_coordinate, pDirection, pDestTrack, out lvIndex);
        }
        else if (pDirection < 0)
        {
            lvSegment = Segment.GetCurrentSegment(pNextSegment.End_coordinate, pDirection, pDestTrack, out lvIndex);
        }
        else
        {
            return DateTime.MinValue;
        }

        lvRes = GetHeadWayEndTime(pTrainId, lvSegment.Location, lvSegment.SegmentValue, pDestTrack, out pOcupTime);

        if (!lvSegment.SegmentValue.StartsWith("CV03") && (!lvSegment.SegmentValue.StartsWith("SW")))
        {
            if (pDirection > 0)
            {
                if (lvSegment.SegmentValue.StartsWith("CDV_") || lvSegment.SegmentValue == "WT")
                {
                    lvStrUD = pStrUD;
                    lvLocation = pLocation;
                    lvRes = GetHeadWayEndTime(pTrainId, lvLocation, lvStrUD, 0, out lvOcupTime);
                }
            }
            else if (pDirection < 0)
            {
                if (lvSegment.SegmentValue.StartsWith("CDV_") || lvSegment.SegmentValue == "WT")
                {
                    lvStrUD = pStrUD;
                    lvLocation = pLocation;
                    lvRes = GetHeadWayEndTime(pTrainId, lvLocation, lvStrUD, 0, out lvOcupTime);
                }
            }
            else
            {
                return DateTime.MinValue;
            }
        }

        if (pOcupTime == DateTime.MinValue)
        {
            lvRes = DateTime.MinValue;
        }

        DebugLog.Logar(" ---------------------------------------------------------------------------- Fim de GetHeadWayEnd ---------------------------------------------------------------------------- ");

        return lvRes;
    }
    public static double GetMeanTimeHist(double pTrainId, string pStrTrainType, Segment pSegment, StopLocation pNextSegment, int pDirection, int pLocation, string pStrUD, DateTime pOcupTime, int pTrainAnalysisCount, double pTrainMinSpeed, double pTrainMaxSpeed, Int16 pDestTrack, out double pMeanTime)
    {
        double lvRes;
        int lvCountTimeHeadWay = 0;
        int lvCountTime = 0;
        int lvStartCoordinate = Int32.MinValue;
        int lvEndCoordinate = Int32.MinValue;
        double lvTrainId;
        string lvStrTrainName;
        DateTime lvDepTime;
        DateTime lvStartOcupTime;
        DateTime lvEndDesOcupTime;
        DateTime lvEndOcupTime;
        double lvMeanSpeed;
        double lvMeanSpeedHeadWay;
        double lvTimeHeadWay;
        double lvTime;
        double lvMeanTimeHeadWay = 0.0;
        double lvMeanTime = 0.0;
        HashSet<double> lvTrainList = new HashSet<double>();

        DataSet ds = new DataSet();

        DebugLog.Logar("");
        DebugLog.Logar(" --------------------------------------------- GetMeanTimeHist(pTrainId = " + pTrainId + ", pStrTrainType = " + pStrTrainType + ", pDirection = " + pDirection + ", pLocation = " + pLocation + ", pStrUD = " + pStrUD + ", pOcupTime = " + pOcupTime + ", pTrainAnalysisCount = " + pTrainAnalysisCount + ", pTrainMinSpeed = " + pTrainMinSpeed + ", pTrainMaxSpeed = " + pTrainMaxSpeed + ", pDestTrack = " + pDestTrack + ") ------------------------------ ");

        string lvSql = "select tbtrain.train_id, tbtrain.name, tbtrain.departure_time, tbtrainmovsegment.data_ocup, tbtrainmovsegment.coordinate from tbtrain, tbtrainmovsegment where tbtrain.train_id=tbtrainmovsegment.train_id and tbtrain.train_id<>@trainid and tbtrain.name like '" + pStrTrainType + "%' and tbtrainmovsegment.direction=@direction and tbtrainmovsegment.location=@location and tbtrainmovsegment.ud=@ud and data_ocup<@ocuptime order by data_ocup desc limit " + pTrainAnalysisCount;

        MySqlConnection conn = ConnectionManager.GetObjConnection();
        MySqlCommand cmd = new MySqlCommand(lvSql, conn);

        cmd.Parameters.Add("@trainid", MySqlDbType.Double).Value = pTrainId;
        cmd.Parameters.Add("@direction", MySqlDbType.Int16).Value = pDirection;
        cmd.Parameters.Add("@location", MySqlDbType.Int16).Value = pLocation;
        cmd.Parameters.Add("@ud", MySqlDbType.String).Value = pStrUD;
        cmd.Parameters.Add("@ocuptime", MySqlDbType.DateTime).Value = pOcupTime;

        cmd.CommandType = CommandType.Text;

        conn.Close();

        MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
        adapter.Fill(ds, "tbtraindata");

        ConnectionManager.DebugMySqlQuery(cmd, "GetMeanSpeedHist.lvSql");

        foreach (DataRow row in ds.Tables[0].Rows)
        {
            lvTrainId = ((row["train_id"] == DBNull.Value) ? ConnectionManager.DOUBLE_REF_VALUE : (double)row["train_id"]);

            if (!lvTrainList.Contains(lvTrainId))
            {
                lvStrTrainName = ((row["name"] == DBNull.Value) ? "" : row["name"].ToString());
                lvDepTime = ((row["departure_time"] == DBNull.Value) ? DateTime.MinValue : DateTime.Parse(row["departure_time"].ToString()));
                lvStartOcupTime = ((row["data_ocup"] == DBNull.Value) ? DateTime.MinValue : DateTime.Parse(row["data_ocup"].ToString()));
                lvStartCoordinate = ((row["coordinate"] == DBNull.Value) ? Int32.MinValue : (int)row["coordinate"]);

                DebugLog.Logar(" ");
                DebugLog.Logar("Trem = " + lvTrainId + " : " + lvStrTrainName + " : lvStartOcupTime = " + lvStartOcupTime + " : lvStartCoordinate = " + lvStartCoordinate);

                lvEndDesOcupTime = GetHeadWayEnd(lvTrainId, pSegment, pNextSegment, pLocation, pStrUD, pDirection, pDestTrack, out lvEndOcupTime);
                DebugLog.Logar("lvEndDesOcupTime = " + lvEndDesOcupTime);
                DebugLog.Logar("lvEndOcupTime = " + lvEndOcupTime);
                DebugLog.Logar("lvStartOcupTime = " + lvStartOcupTime);
                DebugLog.Logar("lvStartCoordinate = " + lvStartCoordinate);

                if (pDirection > 0)
                {
                    lvEndCoordinate = pNextSegment.Start_coordinate;
                }
                else if (pDirection < 0)
                {
                    lvEndCoordinate = pNextSegment.End_coordinate;
                }
                DebugLog.Logar("lvEndCoordinate = " + lvEndCoordinate);

                lvMeanSpeed = (Math.Abs(lvEndCoordinate - lvStartCoordinate) / 100000.0) / (lvEndOcupTime - lvStartOcupTime).TotalHours;
                lvMeanSpeedHeadWay = (Math.Abs(lvEndCoordinate - lvStartCoordinate) / 100000.0) / (lvEndDesOcupTime - lvStartOcupTime).TotalHours;

                DebugLog.Logar("lvMeanSpeed = " + lvMeanSpeed);
                DebugLog.Logar("lvMeanSpeedHeadWay = " + lvMeanSpeedHeadWay);

                if (lvEndDesOcupTime > DateTime.MinValue)
                {
                    lvTimeHeadWay = (lvEndDesOcupTime - lvStartOcupTime).TotalMinutes;
                    lvTime = (lvEndOcupTime - lvStartOcupTime).TotalMinutes;

                    if (lvTime < 0)
                    {
                        lvTime = 0;
                    }

                    DebugLog.Logar("lvTimeHeadWay = " + lvTimeHeadWay);
                    DebugLog.Logar("lvTime = " + lvTime);

                    if ((lvMeanSpeedHeadWay > pTrainMinSpeed) && (lvMeanSpeedHeadWay < pTrainMaxSpeed))
                    {
                        lvMeanTimeHeadWay += lvTimeHeadWay;
                        lvCountTimeHeadWay++;
                    }

                    if ((lvMeanSpeed > pTrainMinSpeed) && (lvMeanSpeed < pTrainMaxSpeed))
                    {
                        lvMeanTime += lvTime;
                        lvCountTime++;
                    }
                }
            }
            lvTrainList.Add(lvTrainId);
        }

        if (lvCountTimeHeadWay > 0)
        {
            lvMeanTimeHeadWay /= lvCountTimeHeadWay;
        }

        if (lvCountTime > 0)
        {
            lvMeanTime /= lvCountTime;
        }

        pMeanTime = lvMeanTime;
        lvRes = lvMeanTimeHeadWay;

        DebugLog.Logar(" -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ");

        return lvRes;
    }
Пример #10
0
 /**
  * Sets the stoplocation of the given order for the given train.
  * @param vehicle_id The vehicle to get the value for.
  * @param order_position The order to get the value for.
  * @param stop_location The relative position where a train will stop inside a station.
  * @returns Whether the order has been/can be changed.
  */
 public static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
 {
     throw null;
 }
Пример #11
0
    private void DumpStopLocation(StopLocation pStopLocation)
    {
        if (pStopLocation != null)
        {
            DebugLog.Logar(" ");
            DebugLog.Logar(" -------------------------------------- DumpStopLocations ----------------------------------- ");
            foreach (StopLocation lvStopLocation in mStopLocationOcupation.Keys)
            {
                DebugLog.Logar(" -----------------------");
                DebugLog.Logar("StopLocation = " + lvStopLocation);
                DebugLog.Logar(" ");

                foreach (Gene lvGene in mStopLocationOcupation[lvStopLocation])
                {
                    DebugLog.Logar("lvGene.TrainId = " + lvGene.TrainId);
                    DebugLog.Logar("lvGene.TrainName = " + lvGene.TrainName);
                    if (lvGene.StopLocation != null)
                    {
                        DebugLog.Logar("lvGene.StopLocation.Location = " + lvGene.StopLocation.Location);
                    }
                    DebugLog.Logar("lvGene.Track = " + lvGene.Track);
                    DebugLog.Logar("lvGene.Location = " + lvGene.Location);
                    DebugLog.Logar("lvGene.UD = " + lvGene.UD);
                    DebugLog.Logar("lvGene.Coordinate = " + lvGene.Coordinate);
                    DebugLog.Logar("lvGene.End = " + lvGene.End);
                    DebugLog.Logar("lvGene.Time = " + lvGene.Time);

                    DebugLog.Logar(" ");
                }
                DebugLog.Logar(" -----------------------");
                DebugLog.Logar(" ");
            }
            DebugLog.Logar(" ------------------------------------------------------------------------------------------- ");
            DebugLog.Logar(" ");
        }
    }