109 lines
2.1 KiB
C#
109 lines
2.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using TrainInfomationProviderService.StationInfo;
|
|||
|
using TrainInfomationProviderService.StationInfo.Entities;
|
|||
|
|
|||
|
namespace TrainInfomationProviderService.TrainInfo.Entities
|
|||
|
{
|
|||
|
public class TrainLineSegment
|
|||
|
{
|
|||
|
StationDetailInfo _toStation;
|
|||
|
StationDetailInfo _fromStation;
|
|||
|
TimeSpan? _elapsedTime;
|
|||
|
|
|||
|
public Train Train { get; private set; }
|
|||
|
|
|||
|
public TrainStop From { get; private set; }
|
|||
|
|
|||
|
public TrainStop To { get; private set; }
|
|||
|
|
|||
|
public StationDetailInfo FromStation
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_fromStation == null)
|
|||
|
_fromStation = StationManager.Instance.Storage.Stations.GetValue(From.Code);
|
|||
|
return _fromStation;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public StationDetailInfo ToStation
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_toStation == null)
|
|||
|
_toStation = StationManager.Instance.Storage.Stations.GetValue(To.Code);
|
|||
|
return _toStation;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 历时
|
|||
|
/// </summary>
|
|||
|
public TimeSpan ElapsedTime
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_elapsedTime == null)
|
|||
|
_elapsedTime = To.Arrive - From.Left;
|
|||
|
return _elapsedTime ?? TimeSpan.Zero;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
int? _calculatedMinutesBase;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 进行时间对比的基础分钟数
|
|||
|
/// </summary>
|
|||
|
public int CalculatedMinutesBase
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_calculatedMinutesBase == null)
|
|||
|
{
|
|||
|
var minutes = ElapsedTime.TotalMinutes;
|
|||
|
var rate = 1.0;
|
|||
|
switch (Train.TrainClass)
|
|||
|
{
|
|||
|
case 'G':
|
|||
|
rate = 1.0;
|
|||
|
break;
|
|||
|
case 'D':
|
|||
|
rate = 0.71428;
|
|||
|
break;
|
|||
|
case 'Z':
|
|||
|
rate = 0.45714;
|
|||
|
break;
|
|||
|
case 'T':
|
|||
|
rate = 0.4;
|
|||
|
break;
|
|||
|
default:
|
|||
|
rate = 0.28571;
|
|||
|
break;
|
|||
|
}
|
|||
|
_calculatedMinutesBase = (int)(rate*minutes);
|
|||
|
}
|
|||
|
return _calculatedMinutesBase ?? 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 创建 <see cref="TrainLineSegment" /> 的新实例(TrainLineSegment)
|
|||
|
/// </summary>
|
|||
|
/// <param name="train"></param>
|
|||
|
/// <param name="from"></param>
|
|||
|
/// <param name="to"></param>
|
|||
|
public TrainLineSegment(Train train, TrainStop from, TrainStop to)
|
|||
|
{
|
|||
|
Train = train;
|
|||
|
From = from;
|
|||
|
To = to;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|