Esempio n. 1
0
        public JsonResult Execute(HomeModel model)
        {
            var request = new EarthProfileRequestDto()
            {
                Distance          = Convert.ToDouble(model.DistanceFlow),
                InitLatitude      = Convert.ToDecimal(model.InitLatitude),
                InitLongitude     = Convert.ToDecimal(model.InitLongitude),
                EndLatitude       = Convert.ToDecimal(model.EndLatitude),
                EndLongitude      = Convert.ToDecimal(model.EndtLongitude),
                PartitionSeparate = model.SeparateDistance,
                H1            = Convert.ToDouble(model.H1),
                H2            = Convert.ToDouble(model.H2),
                At            = Convert.ToDouble(string.IsNullOrWhiteSpace(model.At) ? "0" : model.At),
                Bt            = Convert.ToDouble(string.IsNullOrWhiteSpace(model.Bt) ? "0" : model.Bt),
                Frequency     = Convert.ToDouble(string.IsNullOrWhiteSpace(model.Frequency) ? "0" : model.Frequency),
                PartitionList = model.PartitionList.Select(x => new Shared.Dto.CoordinateDto()
                {
                    DistanceFlow = x.Distance,
                    IndexFlow    = x.Index,
                    Latitude     = x.Latitude,
                    Longitude    = x.Longitude
                }).ToList()
            };
            var response = ProfileEarthFactory.HandleEarthProfileProcess().Execute(request);

            if (!response.Success)
            {
                return(Json(new
                {
                    Success = false,
                    ErrorMessage = response.ErrorList.Select(x => x.Message).Aggregate((x, y) => x + "," + y)
                }));
            }
            else
            {
                var lmList    = Content(JsonConvert.SerializeObject(response.EarthProfileList.Select(dp => new DataPoint(dp.DistanceInit, dp.Lm)).ToList(), _jsonSetting), "application/json");
                var laList    = Content(JsonConvert.SerializeObject(response.EarthProfileList.Select(dp => new DataPoint(dp.DistanceInit, dp.La)).ToList(), _jsonSetting), "application/json");
                var htList    = Content(JsonConvert.SerializeObject(response.EarthProfileList.Select(dp => new DataPoint(dp.DistanceInit, dp.Ht)).ToList(), _jsonSetting), "application/json");
                var zfList    = Content(JsonConvert.SerializeObject(response.EarthProfileList.Select(dp => new DataPoint(dp.DistanceInit, dp.Zf)).ToList(), _jsonSetting), "application/json");
                var tbTable   = ConvertViewToString("~/Views/Home/_ProfileDataTable.cshtml", response);
                var linkRadio = ConvertViewToString("~/Views/Home/_ViewRadioLink.cshtml", response);
                return(Json(new
                {
                    Success = true,
                    LmList = lmList,
                    LaList = laList,
                    HtList = htList,
                    ZfList = zfList,
                    TableData = tbTable,
                    LinkRadio = linkRadio
                }));
            }
        }
        public EarthProfileResponseDto Execute(EarthProfileRequestDto request)
        {
            var response         = new EarthProfileResponseDto();
            var processElevation = setElevationEarth.Execute(request);

            if (processElevation.Failure)
            {
                return(new EarthProfileResponseDto(processElevation.ErrorList));
            }
            var earthProfileList = processElevation.Result;

            earthProfileList          = new CalculateProfileEarth().Execute(earthProfileList, request);
            response.Distance         = request.Distance;
            response.EarthProfileList = earthProfileList;
            return(CalculateGoodLink(response));
        }
Esempio n. 3
0
        public OperationResult <List <EarthProfileDto> > Execute(EarthProfileRequestDto request)
        {
            decimal distanceRunInit  = 0;
            decimal distanceRunEnd   = (decimal)request.Distance;
            var     earthProfileList = new List <EarthProfileDto>()
            {
                new EarthProfileDto()
                {
                    DistanceInit = (double)distanceRunInit,
                    DistanceEnd  = (double)distanceRunEnd,
                    Latitude     = request.InitLatitude,
                    Longitude    = request.InitLongitude,
                    IndexFlow    = 0
                }
            };


            request.PartitionList.ForEach(x => {
                distanceRunInit = distanceRunInit + request.PartitionSeparate;
                distanceRunEnd  = distanceRunEnd - request.PartitionSeparate;

                earthProfileList.Add(new EarthProfileDto()
                {
                    DistanceInit = (double)distanceRunInit,
                    DistanceEnd  = (double)distanceRunEnd,
                    Latitude     = x.Latitude,
                    Longitude    = x.Longitude,
                    IndexFlow    = x.IndexFlow
                });
            });
            earthProfileList.Add(new EarthProfileDto()
            {
                DistanceInit = request.Distance,
                DistanceEnd  = 0,
                Latitude     = request.EndLatitude,
                Longitude    = request.EndLongitude,
                IndexFlow    = earthProfileList.Max(x => x.IndexFlow) + 1
            });

            //seteamos elevacion terreno

            var elevationProcess = openElevationService.GetElevationList(new OpenElevationRequestDto()
            {
                CoordinateList = earthProfileList.Select(x => new CoordinateDto()
                {
                    IndexFlow = x.IndexFlow,
                    Latitude  = x.Latitude,
                    Longitude = x.Longitude
                }).ToList()
            });

            if (elevationProcess.Failure)
            {
                return(new OperationResult <List <EarthProfileDto> >(elevationProcess.ErrorList));
            }
            var elevationList = elevationProcess.Result.ResultList;

            var join = (from req in earthProfileList
                        join res in elevationList on new { req.Latitude, req.Longitude } equals new { res.Latitude, res.Longitude }
                        select new EarthProfileDto()
            {
                DistanceEnd = req.DistanceEnd,
                DistanceInit = req.DistanceInit,
                Latitude = req.Latitude,
                Longitude = req.Longitude,
                IndexFlow = req.IndexFlow,
                Lm = res.Elevation
            }).ToList();

            return(new OperationResult <List <EarthProfileDto> >(join));
        }
        internal List <EarthProfileDto> Execute(List <EarthProfileDto> earthProfileList, EarthProfileRequestDto earthProfileRequest)
        {
            if (earthProfileRequest.At != 0)
            {
                A = earthProfileRequest.At;
            }
            if (earthProfileRequest.Bt != 0)
            {
                B = earthProfileRequest.Bt;
            }
            if (earthProfileRequest.Frequency != 0)
            {
                Fc = earthProfileRequest.Frequency;
            }
            H1  = earthProfileRequest.H1;
            H2  = earthProfileRequest.H2;
            Nd  = earthProfileList.Count();
            RKm = earthProfileRequest.Distance;

            var indexMin = earthProfileList.Min(z => z.IndexFlow);
            var indexMax = earthProfileList.Max(z => z.IndexFlow);

            HA = H1 + (earthProfileList.Where(x => x.IndexFlow == indexMin).FirstOrDefault().Lm);
            HB = H2 + (earthProfileList.Where(x => x.IndexFlow == indexMax).FirstOrDefault().Lm);
            CalculateConst();

            var earthPorfileArray = earthProfileList.OrderBy(x => x.IndexFlow).ToArray();

            for (int i = 0; i < earthPorfileArray.Count(); i++)
            {
                //Calculate La(m)
                if (earthPorfileArray[i].IndexFlow == indexMin)
                {
                    earthPorfileArray[i].La = HA;
                }
                else
                {
                    earthPorfileArray[i].La = earthPorfileArray[i - 1].La + Ic;
                }

                //Calculate h(m)
                // ((d1 * d2) / 12.75) / K
                earthPorfileArray[i].H = ((earthPorfileArray[i].DistanceInitKm * earthPorfileArray[i].DistanceEndKm) / 12.75) / K;

                //Calculate Ht(m)
                //Lm + h;
                earthPorfileArray[i].Ht = earthPorfileArray[i].Lm + earthPorfileArray[i].H;

                //Calculate Rf
                // 17.32 * (RAIZ ( (d1*d2) / (Fc * d) ))
                var rf1 = (earthPorfileArray[i].DistanceInitKm * earthPorfileArray[i].DistanceEndKm);
                var rf2 = rf1 / (Fc * d);
                earthPorfileArray[i].Rf = 17.32 * Math.Sqrt(rf2);

                //Calculate Zf
                //La - Rf
                earthPorfileArray[i].Zf = earthPorfileArray[i].La - earthPorfileArray[i].Rf;

                //Calculate e(m)
                //La - ht
                earthPorfileArray[i].E = earthPorfileArray[i].La - earthPorfileArray[i].Ht;

                //Calculate e/zf
                earthPorfileArray[i].EZf = earthPorfileArray[i].E / earthPorfileArray[i].Zf;
            }

            return(earthPorfileArray.ToList());
        }