예제 #1
0
 /// <summary>
 /// Count the sessions in current segment
 /// </summary>
 /// <param name="segment"></param>
 /// <returns></returns>
 public int countSegmentUsers(SearchParkingSegment segment)
 {
     if (segmentToSessionMap.ContainsKey(segment.SegmentUnique))
     {
         return(segmentToSessionMap[segment.SegmentUnique].sessionList.Count);
     }
     return(0);
 }
예제 #2
0
 /// <summary>
 /// Count the sessions in current segment
 /// </summary>
 /// <param name="segment"></param>
 /// <returns></returns>
 public int countSegmentUsers(SearchParkingSegment segment)
 {
     if(segmentToSessionMap.ContainsKey(segment.SegmentUnique))
     {
         return segmentToSessionMap[segment.SegmentUnique].sessionList.Count;
     }
     return 0;
 }
예제 #3
0
        /// <summary>
        /// Get the search parking segment is exists and if not create it
        /// </summary>
        /// <param name="sps">SearchParkingSegment</param>
        /// <returns>SearchParkingSegment</returns>
        public SearchParkingSegment getSearchParkingSegment(SearchParkingSegment sps)
        {
            if (segmentToSessionMap.ContainsKey(sps.SegmentUnique))
            {
                return(segmentToSessionMap[sps.SegmentUnique].sps);
            }

            segmentToSessionMap.Add(sps.SegmentUnique, new SearchParkingSegmentDetails(sps, new List <String>()));
            return(sps);
        }
예제 #4
0
 /// <summary>
 /// Add the session to segment
 /// </summary>
 /// <param name="sessionData"></param>
 /// <param name="segment"></param>
 public void addSessionDataToSegment(String sessionData,SearchParkingSegment segment)
 {
     try
     {
         if (segmentToSessionMap.ContainsKey(segment.SegmentUnique))
         {
             SearchParkingSegmentDetails spsd = segmentToSessionMap[segment.SegmentUnique];
             if (!spsd.sessionList.Contains(sessionData))
             {
                 spsd.sessionList.Add(sessionData);
             }
         }
         else
         {
             segment = getSearchParkingSegment(segment);
             segmentToSessionMap[segment.SegmentUnique].sessionList.Add(sessionData);
         }
     }
     catch (Exception ex) { }
 }
예제 #5
0
 /// <summary>
 /// Add the session to segment
 /// </summary>
 /// <param name="sessionData"></param>
 /// <param name="segment"></param>
 public void addSessionDataToSegment(String sessionData, SearchParkingSegment segment)
 {
     try
     {
         if (segmentToSessionMap.ContainsKey(segment.SegmentUnique))
         {
             SearchParkingSegmentDetails spsd = segmentToSessionMap[segment.SegmentUnique];
             if (!spsd.sessionList.Contains(sessionData))
             {
                 spsd.sessionList.Add(sessionData);
             }
         }
         else
         {
             segment = getSearchParkingSegment(segment);
             segmentToSessionMap[segment.SegmentUnique].sessionList.Add(sessionData);
         }
     }
     catch (Exception ex) { }
 }
예제 #6
0
        /// <summary>
        /// Get the search parking segment is exists and if not create it
        /// </summary>
        /// <param name="sps">SearchParkingSegment</param>
        /// <returns>SearchParkingSegment</returns>
        public SearchParkingSegment getSearchParkingSegment(SearchParkingSegment sps)
        {
            if (segmentToSessionMap.ContainsKey(sps.SegmentUnique))
            {
                return segmentToSessionMap[sps.SegmentUnique].sps;
            }

            segmentToSessionMap.Add(sps.SegmentUnique, new SearchParkingSegmentDetails(sps,new List<String>()));
            return sps;
        }
예제 #7
0
 public SearchParkingSegmentDetails(SearchParkingSegment pSps, List<String> pSessionList)
 {
     sps = pSps;
     sessionList = pSessionList;
 }
 private int getSegmentUsersCount(SearchParkingSegment searchParkingSegment)
 {
     return segmentSessionMap.countSegmentUsers(searchParkingSegment);
 }
 private SearchParkingSegment getParkingSegment(float lat, float lon)
 {
     //Algo:
     //Select from segment
     //todo:fix the SQL logic
     SearchParkingSegment sps = null;
     String conStr = ConfigurationManager.ConnectionStrings["CityParkCS"].ConnectionString;
     using (SqlConnection con = new SqlConnection(conStr))
     {
         using (SqlCommand cmd = new SqlCommand())
         {
             String sql = String.Format(@"DECLARE @UserLat float = {0}
                     DECLARE @UserLong float = {1}
                     SELECT TOP 1 SQRT  ( POWER((a.StartLatitude - @UserLat) * COS(@UserLat/180) * 40000 / 360, 2)
                         + POWER((a.StartLongitude -@UserLong) * 40000 / 360, 2)) as distance,*
                     FROM [CITYPARK].[dbo].[StreetSegmentLine] a
                         order by distance", lat, lon);
             cmd.Connection = con;
             cmd.CommandText = sql;
             con.Open();
             using (SqlDataReader sqlDataReader = cmd.ExecuteReader())
             {
                 if (sqlDataReader.HasRows)
                 {
                     while (sqlDataReader.Read())
                     {
                         StreetSegmentLine ssl = new StreetSegmentLine();
                         ssl.StartLatitude = sqlDataReader["StartLatitude"].ToString();
                         ssl.StartLongitude = sqlDataReader["StartLongitude"].ToString();
                         ssl.EndLatitude = sqlDataReader["EndLatitude"].ToString();
                         ssl.EndLongitude = sqlDataReader["EndLongitude"].ToString();
                         ssl.SegmentUnique = sqlDataReader["SegmentUnique"].ToString();
                         sps = new SearchParkingSegment(-1, ssl.SegmentUnique);
                         break;
                     }
                 }
             }
         }
     }
     return segmentSessionMap.getSearchParkingSegment(sps);
 }
 private float calcSWT(SearchParkingSegment segment, int rate, int radius)
 {
     float SWT = 0;
     if (rate > 0 && segmentSessionMap.countSegmentUsers(segment) > 0)
     {
         //Algo:
         //calulate SWT
         //for each user in the segment waiting list [[1/(sum[user distance from segment/searchRadiusConstant ])]/waitingList[segment].count]/rate
         int waitingListCount = segmentSessionMap.countSegmentUsers(segment);
         List<String> sdList = segmentSessionMap.getSegmetsSessionDataList(segment.SegmentUnique);
         float tmpDistanceDivRadius = 0;
         foreach (String sd in sdList)
         {
             if (sessionMap.ContainsKey(sd))
             {
                 Dictionary<String, DistancePredictionWrapper> sdMap = sessionMap[sd].SegmentDistanceAndPredictionMap;
                 if (sdMap != null && sdMap.ContainsKey(segment.SegmentUnique))
                 {
                     float distance = sdMap[segment.SegmentUnique].distance;
                     tmpDistanceDivRadius += distance / radius;
                 }
             }
         }
         SWT = (1 / tmpDistanceDivRadius) * waitingListCount / rate;
         //store the data SWT in the segment map
         segment.SWT = SWT;
         return SWT;
     }
     else
     {
         return TPhigh;//30 minutes
     }
 }
        /**
         *Recalculate SegmentParkingRate (++)
         * */
        private int calcSegmentParkingRate(SearchParkingSegment sps)
        {
            //Algo:
            //count and return how many start parking in last DELTA T
            int previousSegmentRate = 0;
            int delta = -1;//last houre
            String conStr = ConfigurationManager.ConnectionStrings["CityParkCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(conStr))
            {
                using (SqlCommand cmd = new SqlCommand())
                {

                    String sql = String.Format(
                        @"SELECT COUNT(*)
                            FROM CITYPARK.[dbo].[StreetParking] where Date > dateadd(hh, {0}, getdate()) and SegementUniqueId='{1}'", delta, sps.SegmentUnique);
                    cmd.Connection = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = sql;
                    con.Open();
                    previousSegmentRate = (Int32)cmd.ExecuteScalar();
                }
            }
            return previousSegmentRate;
        }
예제 #12
0
 public SearchParkingSegmentDetails(SearchParkingSegment pSps, List <String> pSessionList)
 {
     sps         = pSps;
     sessionList = pSessionList;
 }