Example #1
0
        public static ChoraleModel CreateChoraleModel(SemanticLink semanticLink)
        {
            var data = Realm.GetInstance()
                       .All <GraphDatum>()
                       .Where(v => v.SemanticLinkId == semanticLink.SemanticLinkId)
                       .ToList();

            var quartilesEnergy     = MathUtil.Quartiles(data.OrderBy(d => d.LostEnergy).Select(d => (double)d.LostEnergy).ToArray());
            var firstQuartileEnergy = quartilesEnergy.Item1;
            var thirdQuartileEnergy = quartilesEnergy.Item3;
            var iqrEnergy           = thirdQuartileEnergy - firstQuartileEnergy;

            var quartilesTransitTime     = MathUtil.Quartiles(data.OrderBy(d => d.TransitTime).Select(d => (double)d.TransitTime).ToArray());
            var firstQuartileTransitTime = quartilesTransitTime.Item1;
            var thirdQuartileTransitTime = quartilesTransitTime.Item3;
            var iqrTransitTime           = thirdQuartileTransitTime - firstQuartileTransitTime;

            data = data.Where(d => d.LostEnergy > firstQuartileEnergy - 1.5 * iqrEnergy)
                   .Where(d => d.LostEnergy < thirdQuartileEnergy + 1.5 * iqrEnergy)
                   .ToList();

            data = data.Where(d => d.TransitTime > firstQuartileTransitTime - 1.5 * iqrTransitTime)
                   .Where(d => d.TransitTime < thirdQuartileTransitTime + 1.5 * iqrTransitTime)
                   .ToList();

            var model = new ChoraleModel
            {
                ClassNumber           = MathUtil.CalculateClassNumber(data),
                MinLostEnegry         = data.Min(d => d.LostEnergy),
                MaxLostEnergy         = data.Max(d => d.LostEnergy),
                ClassWidthEnergy      = (data.Max(d => d.LostEnergy) - data.Min(d => d.LostEnergy)) / MathUtil.CalculateClassNumber(data),
                MinTransitTime        = data.Min(d => d.TransitTime),
                MaxTransitTime        = data.Max(d => d.TransitTime),
                ClassWidthTransitTime = (float)(data.Max(d => d.TransitTime) - data.Min(d => d.TransitTime)) / MathUtil.CalculateClassNumber(data)
            };

            model.SetData(data);

            return(model);
        }
Example #2
0
        public static ECGModel GetECGModel(SemanticLink semanticLink)
        {
            var data = Realm.GetInstance()
                       .All <GraphDatum>()
                       .Where(v => v.SemanticLinkId == semanticLink.SemanticLinkId)
                       .ToList();

            var quartilesEnergy     = MathUtil.Quartiles(data.OrderBy(d => d.LostEnergy).Select(d => (double)d.LostEnergy).ToArray());
            var firstQuartileEnergy = quartilesEnergy.Item1;
            var thirdQuartileEnergy = quartilesEnergy.Item3;
            var iqrEnergy           = thirdQuartileEnergy - firstQuartileEnergy;

            var quartilesTransitTime     = MathUtil.Quartiles(data.OrderBy(d => d.TransitTime).Select(d => (double)d.TransitTime).ToArray());
            var firstQuartileTransitTime = quartilesTransitTime.Item1;
            var thirdQuartileTransitTime = quartilesTransitTime.Item3;
            var iqrTransitTime           = thirdQuartileTransitTime - firstQuartileTransitTime;

            data = data.Where(d => d.LostEnergy > firstQuartileEnergy - 1.5 * iqrEnergy)
                   .Where(d => d.LostEnergy < thirdQuartileEnergy + 1.5 * iqrEnergy)
                   .ToList();

            data = data.Where(d => d.TransitTime > firstQuartileTransitTime - 1.5 * iqrTransitTime)
                   .Where(d => d.TransitTime < thirdQuartileTransitTime + 1.5 * iqrTransitTime)
                   .ToList();

            string atentionText = null;

            switch (semanticLink.SemanticLinkId)
            {
            case 188:
                atentionText = "回生ブレーキに注意!";
                break;

            case 189:
                atentionText = "加減速を減らして!";
                break;

            case 190:
                atentionText = "いつも通り運転してください";
                break;

            case 191:
                atentionText = "加減速を減らして!";
                break;

            case 192:
                atentionText = "いつも通り運転してください";
                break;

            case 193:
                atentionText = "回生ブレーキに注意!";
                break;

            case 194:
                atentionText = "いつも通り運転してください";
                break;

            case 195:
                atentionText = "いつも通り運転してください";
                break;

            case 196:
                atentionText = "回生ブレーキに注意!";
                break;

            case 198:
                atentionText = "加減速を減らして!";
                break;

            case 199:
                atentionText = "加減速を減らして!";
                break;

            case 205:
                atentionText = "加減速を減らして!";
                break;

            case 206:
                atentionText = "加減速を減らして!";
                break;

            case 207:
                atentionText = "加減速を減らして!";
                break;

            case 209:
                atentionText = "回生ブレーキに注意!";
                break;

            case 210:
                atentionText = "加減速と回生ブレーキに注意!";
                break;

            case 211:
                atentionText = "回生ブレーキに注意!";
                break;

            case 212:
                atentionText = "加減速を減らして!";
                break;

            case 213:
                atentionText = "加減速と回生ブレーキに注意!";
                break;

            case 215:
                atentionText = "加減速を減らして!";
                break;

            case 216:
                atentionText = "加減速を減らして!";
                break;

            case 217:
                atentionText = "加減速を減らして!";
                break;

            case 155:
                atentionText = "加減速を減らして!";
                break;

            default:
                atentionText = "SemanticLinkが見つかりません";
                break;
            }

            return(new ECGModel {
                GraphData = data, AtentionText = atentionText
            });
        }
        public static IList <EnergyStackModel> CreateEnergyStackSource(GraphDatum datum, SemanticLink semanticLink)
        {
            var data = Realm.GetInstance()
                       .All <GraphDatum>()
                       .Where(v => v.SemanticLinkId == semanticLink.SemanticLinkId)
                       .ToList();

            var quartilesEnergy     = MathUtil.Quartiles(data.OrderBy(d => d.LostEnergy).Select(d => (double)d.LostEnergy).ToArray());
            var firstQuartileEnergy = quartilesEnergy.Item1;
            var thirdQuartileEnergy = quartilesEnergy.Item3;
            var iqrEnergy           = thirdQuartileEnergy - firstQuartileEnergy;

            var quartilesTransitTime     = MathUtil.Quartiles(data.OrderBy(d => d.TransitTime).Select(d => (double)d.TransitTime).ToArray());
            var firstQuartileTransitTime = quartilesTransitTime.Item1;
            var thirdQuartileTransitTime = quartilesTransitTime.Item3;
            var iqrTransitTime           = thirdQuartileTransitTime - firstQuartileTransitTime;

            data = data.Where(d => d.LostEnergy > firstQuartileEnergy - 1.5 * iqrEnergy)
                   .Where(d => d.LostEnergy < thirdQuartileEnergy + 1.5 * iqrEnergy)
                   .ToList();

            data = data.Where(d => d.TransitTime > firstQuartileTransitTime - 1.5 * iqrTransitTime)
                   .Where(d => d.TransitTime < thirdQuartileTransitTime + 1.5 * iqrTransitTime)
                   .ToList();

            var regeneLossSigma        = data.Average(v => v.RegeneLoss) - data.StdDev(v => v.RegeneLoss);
            var airResistanceSigma     = data.Average(v => v.AirResistance) - data.StdDev(v => v.AirResistance);
            var rollingResistanceSigma = data.Average(v => v.RollingResistance) - data.StdDev(v => v.RollingResistance);
            var convertLossSigma       = data.Average(v => v.ConvertLoss) - data.StdDev(v => v.ConvertLoss);

            // DBに保存する仕組みを作成
            datum.SemanticLinkId = semanticLink.SemanticLinkId;
            datum.saveToDB();

            return(new List <EnergyStackModel>
            {
                new EnergyStackModel
                {
                    Category = "Defeat",
                    RegeneLossBlank = datum.RegeneLoss <= regeneLossSigma ? datum.RegeneLoss : regeneLossSigma,
                    RegeneLossDefeat = datum.RegeneLoss > regeneLossSigma ? datum.RegeneLoss - regeneLossSigma : 0,
                    AirResistanceBlank = datum.AirResistance <= airResistanceSigma ? datum.AirResistance : airResistanceSigma,
                    AirResistanceDefeat = datum.AirResistance > airResistanceSigma ? datum.AirResistance - airResistanceSigma : 0,
                    RollingResistanceBlank = datum.RollingResistance <= rollingResistanceSigma ? datum.RollingResistance : rollingResistanceSigma,
                    RollingResistanceDefeat = datum.RollingResistance > rollingResistanceSigma ? datum.RollingResistance - rollingResistanceSigma : 0,
                    ConvertLossBlank = datum.ConvertLoss <= convertLossSigma ? datum.ConvertLoss : convertLossSigma,
                    ConvertLossDefeat = datum.ConvertLoss > convertLossSigma ? datum.ConvertLoss - convertLossSigma : 0,
                },
                new EnergyStackModel
                {
                    Category = "Today",
                    RegeneLoss = datum.RegeneLoss,
                    AirResistance = datum.AirResistance,
                    RollingResistance = datum.RollingResistance,
                    ConvertLoss = datum.ConvertLoss,
                },
                new EnergyStackModel
                {
                    Category = "Win",
                    RegeneLossBlank = datum.RegeneLoss,
                    RegeneLossWin = datum.RegeneLoss <= regeneLossSigma ? regeneLossSigma - datum.RegeneLoss : 0,
                    AirResistanceBlank = datum.AirResistance - (datum.RegeneLoss <= regeneLossSigma ? regeneLossSigma - datum.RegeneLoss : 0),
                    AirResistanceWin = datum.AirResistance <= airResistanceSigma ? airResistanceSigma - datum.AirResistance : 0,
                    RollingResistanceBlank = datum.RollingResistance - (datum.AirResistance <= airResistanceSigma ? airResistanceSigma - datum.AirResistance : 0),
                    RollingResistanceWin = datum.RollingResistance <= rollingResistanceSigma ? rollingResistanceSigma - datum.RollingResistance : 0,
                    ConvertLossBlank = datum.ConvertLoss - (datum.RollingResistance <= rollingResistanceSigma ? rollingResistanceSigma - datum.RollingResistance : 0),
                    ConvertLossWin = datum.ConvertLoss <= convertLossSigma ? convertLossSigma - datum.ConvertLoss : 0
                },
            });
        }