public void ChangeCourierLocation_CorrectData() { CourierDto courier = new CourierDto() { FirstName = "Courier", LastName = "change location", PhoneNumber = "testphone", Location = new PointDto() { Latitude = 23.02, Longitude = 54.03 } }; Guid id = courierService.AddCourierAsync(courier).Result; PointDto newLocation = new PointDto() { Latitude = 27.34, Longitude = 43.15 }; courierService.ChangeCourierLocationAsync(courier.Id, newLocation).Wait(); CourierDto courierWithNewLocation = courierService.GetCourierById(courier.Id); Assert.IsTrue(courier.Location.Latitude != courierWithNewLocation.Location.Latitude && courier.Location.Longitude != courierWithNewLocation.Location.Longitude); }
/// <summary> /// Creates new location from PointDto. /// </summary> /// <param name="model">PointDto</param> /// <returns></returns> public async Task <Result <int> > CreateAsync(PointDto model) { try { if (model == null) { return(Result <int> .Failure("Model is empty.")); } var location = new Location(model); this.Db.Locations.Add(location); await this.Db.SaveChangesAsync(); return(Result <int> .Success(location.Id)); } catch (ArgumentException argumentException) { return(Result <int> .Failure(argumentException.Message)); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Location Create Point method."); return(Result <int> .Failure($"Error in Location Create Point method.")); } }
public List <CourierDto> GetNearestCouriers(PointDto pointDto, int count = 5) { using (var db = new CourierHelperDb(_connectionString)) { var nearestPoints = db.ActivePointsRepo.Query .Where(point => (point.Courier != null && point.Courier.Deleted == null) || point.Route != null) .AsEnumerable() .OrderBy(point => point.Coordinates.Distance(new Point(pointDto.Longitude, pointDto.Latitude))) .ToList(); var couriers = nearestPoints .Select(point => { if (point.Courier != null) { return(point.Courier); } else { return(point.Route.Courier); } }) .Where(courier => courier.State != CourierState.NotAccessible) .Distinct() .OrderBy(courier => courier.Orders.Count()) .ThenBy(courier => courier.State) .Take(count) .ToList(); var couriersDto = Mapper.Map <List <CourierDto> >(couriers); return(couriersDto); } }
public static DilutionSampleDto Map(DilutionSampleDto dilutionSampleDto, DiluicaoAmostra diluicaoAmostra) { dilutionSampleDto.Id = diluicaoAmostra.Id; dilutionSampleDto.Homogenizer = diluicaoAmostra.Homogeneizador; dilutionSampleDto.Micropipette = diluicaoAmostra.Micropipeta; dilutionSampleDto.Pipette = diluicaoAmostra.Pipeta; dilutionSampleDto.Shaker = diluicaoAmostra.Agitador; dilutionSampleDto.Board = diluicaoAmostra.Placa; dilutionSampleDto.Others = diluicaoAmostra.Outros; dilutionSampleDto.WaterDilutions = new List <WaterDilutionDto>(); dilutionSampleDto.Points = new List <PointDto>(); dilutionSampleDto.Sample = AmostraMapToSampleDto.Map(new SampleDto(), diluicaoAmostra.fkAmostra); foreach (var x in diluicaoAmostra.Ponteiras) { var point = new PointDto((EnumPoints)x.Codigo); point.Value = (int)x.Valor; dilutionSampleDto.Points.Add(point); } foreach (var x in diluicaoAmostra.AguaDiluicaos) { var waterDilution = new WaterDilutionDto((EnumWaterDilution)x.Codigo); waterDilution.Value = (int)x.Valor; dilutionSampleDto.WaterDilutions.Add(waterDilution); } return(dilutionSampleDto); }
public FeatureDto ConvertFeatureToDto(Feature feature) { var pointDto = new PointDto( feature.Geometry.Coordinate.X, feature.Geometry.Coordinate.Y); var address = feature.Attributes["address"].ToString(); var attributesNames = feature.Attributes.GetNames(); string name = string.Empty; if (attributesNames.Contains("name")) { name = feature.Attributes["name"].ToString(); } string category = string.Empty; if (attributesNames.Contains("category")) { category = feature.Attributes["category"].ToString(); } var featureDto = new FeatureDto( address, name, category, pointDto); return(featureDto); }
private static int ClosestPointIndex(List <PointDto> points, PointDto startPoint) { int indxClosestPoint = 0; double distance = 0d; for (int i = 0; i < points.Count; i++) { var tempPoint = points[i]; double distanceTemp = Math.Sqrt(Math.Pow(startPoint.X - tempPoint.X, 2) + Math.Pow(startPoint.Y - tempPoint.Y, 2)); if (i == 0) { indxClosestPoint = i; distance = distanceTemp; } else { if (distanceTemp < distance) { indxClosestPoint = i; distance = distanceTemp; } } } return(indxClosestPoint); }
/// <summary> /// Update existing location from PointDto. /// </summary> /// <param name="model">PointDto</param> /// <returns></returns> public async Task <ResultBase> UpdateAsync(PointDto model) { try { if (model == null) { return(ResultBase.Failure("Model is empty.")); } var location = await this.Db.Locations.SingleOrDefaultAsync(x => x.Id == model.Id); if (location == null) { return(ResultBase.Failure("Location not found.")); } location.Update(model); await this.Db.SaveChangesAsync(); return(ResultBase.Success()); } catch (ArgumentException argumentException) { return(ResultBase.Failure(argumentException.Message)); } catch (Exception exception) { Log.Logger.Error(exception, "Error in Location Update PointDto method."); return(ResultBase.Failure($"Error in Location Update PointDto method.")); } }
public void DoFitCalculation(string stockName, string fitMethod) { CurveEntity curveInfo = this._iCurveDao.GetCurveByName(stockName); if (curveInfo == null) { LogHelper.Warn(typeof(ValueComplementBusinessImpl), "Cannot find certain stock information"); return; } List <CurveDataEntity> curveDataList = this._iCurveDataDao.GetCurveDataByCurveId(curveInfo.CurveId); if (ListHelper.IsNullOrEmpty(curveDataList)) { LogHelper.Warn(typeof(ValueComplementBusinessImpl), "Stock " + curveInfo.CurveName + " doesnot have any data"); return; } int missIdx = FindMissingValueIdx(curveDataList); CurveDataEntity missingCurveDataEntity = curveDataList[missIdx]; List <PointDto> modelPoints = ConvertValueItemsToPoints(curveDataList); if (missIdx != -1 && !ListHelper.IsNullOrEmpty(modelPoints)) { IFitStrategy fitStrategy = StrategyFactory.GetStrategyByName(fitMethod); PointDto fitResultPoint = fitStrategy.FitCalculation(modelPoints, missIdx); missingCurveDataEntity.Value = System.Convert.ToDecimal(fitResultPoint.Y); //更新至db this._iCurveDataDao.Update(missingCurveDataEntity); } }
public Location(PointDto model) { if (model != null && (model.Latitude.HasValue || model.Longitude.HasValue)) { this.Validate(model); this.Latitude = model.Latitude; this.Longitude = model.Longitude; } }
public static bool EqualValues(this PointDto pointDto, Point point) { bool equal = pointDto.ActivityID == point.ActivityID && pointDto.ID == point.ID && pointDto.Lat == point.Lat && pointDto.Lng == point.Lng; return(equal); }
public void Update(PointDto model) { if (model != null) { this.Validate(model); this.Latitude = model.Latitude; this.Longitude = model.Longitude; } }
private CourierDto CourierFactory(PointDto location) { return(new CourierDto() { Location = location, FirstName = $"Courier", State = CourierStateDto.Idle, PhoneNumber = "testnumber" }); }
public IHttpActionResult PostPoint(Point m) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } psvc.CreatePoint(m); uow.Save(); return(CreatedAtRoute("DefaultApi", new { id = m.ID }, PointDto.FromPoint(m))); }
/// <summary> /// 公司地图定位管理页面 /// </summary> /// <returns></returns> public async Task <IActionResult> CompanyMapManager() { var data = await _db.Company.FirstOrDefaultAsync(); PointDto dto = new PointDto(); dto.Lng = data.Lng; dto.Lat = data.Lat; return(View(dto)); }
public IHttpActionResult GetPoint(long id) { var b = psvc.GetPoint(id); if (b == null) { return(NotFound()); } return(Ok(PointDto.FromPoint(b))); }
public async Task <ActionResult <Point> > Create(PointDto point) { bool validLimit = _pointService.ValidateLimit(await _pointRepository.GetAll()); bool isDublicate = _pointService.IsDublicate(await _pointRepository.GetAll(), point); if (validLimit && !isDublicate) { return(await _pointRepository.Add(point)); } return(null); }
public async Task <Point> Add(PointDto point) { var pointAdd = new Point(); pointAdd.Xcoordinate = point.Xcoordinate; pointAdd.Ycoordinate = point.Ycoordinate; _context.Points.Add(pointAdd); await _context.SaveChangesAsync(); return(pointAdd); }
public async Task <ActionResult> DeletePoint([FromBody] PointDto clientDto) { HttpClient client = new HttpClient(); HttpResponseMessage response = await client.DeleteAsync( $"{baseURL}/points/{clientDto.id}"); // return URI of the created resource. return(Json(clientDto.id)); }
public static Point ToSqlModel(this PointDto pointDto) { return(new Point { Id = pointDto.Id, CreatorId = pointDto.CreatorId, Current = pointDto.Current, PointCoordinates = pointDto.PointCoordinates, PointName = pointDto.PointName, User = pointDto.User.ToSqlModel() }); }
private void Validate(PointDto model) { if (!model.Latitude.HasValue) { throw new ArgumentException("Latitude is required."); } if (!model.Longitude.HasValue) { throw new ArgumentException("Longitude is required."); } }
public static PointViewModel ToViewModel(PointDto pointDto) { return(new PointViewModel { Id = pointDto.Id, CreatorId = pointDto.CreatorId, Current = pointDto.Current, PointCoordinates = pointDto.PointCoordinates, PointName = pointDto.PointName, User = pointDto.User.ToViewModel() }); }
/// <summary> /// 更新公司信息 /// </summary> /// <param name="companyInfo"></param> /// <returns></returns> public async Task <JsonResult> UpdateCompanyLocation(PointDto point) { var company = await _db.Company.FirstOrDefaultAsync(); company.Lng = point.Lng; company.Lat = point.Lat; ResponseTemplate response = new ResponseTemplate(); response.Success = true; response.Data = await _db.SaveChangesAsync(); return(Json(response)); }
public bool IsDublicate(List <Point> points, PointDto point) { bool isDublicate = false; foreach (var item in points) { if (item.Xcoordinate == point.Xcoordinate && item.Ycoordinate == point.Ycoordinate) { isDublicate = true; break; } } return(isDublicate); }
public async Task <ActionResult> UpdatePoint([FromBody] PointDto pointData) { HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PutAsJsonAsync( $"{baseURL}/points/{pointData.id}", pointData); response.EnsureSuccessStatusCode(); // return URI of the created resource. return(Json(null)); }
private OrderDto OrderFactory(PointDto destination, int warehouseId) { return(new OrderDto() { WarehouseId = warehouseId, Destination = destination, State = OrderStateDto.NotAssigned, Receiver = new CustomerDto { FirstName = "Receiver", PhoneNumber = "testnumber" }, Sender = new CustomerDto { FirstName = "Sender", PhoneNumber = "testnumber" } }); }
public async Task ProceedNextOrderAsync() { if (_ordersQueue.Count == 0) { return; } OrderDto order = _ordersQueue.Dequeue(); if (order == null) { return; } await _orderService.ChangeOrderStateAsync(order, OrderStateDto.Assignment); //2. Change order state to Assignment PointDto orderLocationPoint = _pointService.GetOrderLocation(order.Id); //3. Get order destination point coordinates IEnumerable <CourierDto> couriers = _courierService.GetNearestCouriers(orderLocationPoint); //4. Find nearest couriers by next criterias (distance to point > number of assigned orders > courier state) var possibleCandidate = couriers.FirstOrDefault(courier => courier.State == CourierStateDto.Idle); if (possibleCandidate != null) { await _orderService.ChangeOrderStateAsync(order, OrderStateDto.WaitingOnWarehouse); await _courierService.AssignOrder(possibleCandidate.Id, order.Id); } else { RouteCandidate bestRoute = await FindBestCandidateAsync(couriers, orderLocationPoint); if (bestRoute == null) { await _orderService.ChangeOrderStateAsync(order, OrderStateDto.NotAssigned); _ordersQueue.Enqueue(order); } else { await _orderService.ChangeOrderStateAsync(order, OrderStateDto.WaitingOnWarehouse); await _courierService.AssignOrder(bestRoute.Courier.Id, order.Id); await _routeService.ChangeCourierCurrentRouteAsync(bestRoute.Courier.Id, bestRoute.GetRoute()); } } }
//最小二乘法进行线性回归 public PointDto FitCalculation(List <PointDto> points, int targetX) { if (points.Count < 2) { LogHelper.Warn(typeof(LinearRegFitStrategy), "Not Enough Point to Perform Linear Regression!"); return(null); } PointDto fitPoint = new PointDto(targetX, 0.0); //求出横纵坐标的平均值 double averagex = 0, averagey = 0; foreach (PointDto p in points) { averagex += p.X; averagey += p.Y; } //点List包含将要补全的点 averagex /= points.Count - 1; averagey /= points.Count - 1; //经验回归系数的分子与分母 double numerator = 0; double denominator = 0; foreach (PointDto p in points) { numerator += (p.X - averagex) * (p.Y - averagey); denominator += (p.X - averagex) * (p.X - averagex); } //回归系数b(Regression Coefficient) double RCB = numerator / denominator; //回归系数a double RCA = averagey - RCB * averagex; LogHelper.Info(typeof(LinearRegFitStrategy), "回归系数A: " + RCA.ToString("0.0000")); LogHelper.Info(typeof(LinearRegFitStrategy), "回归系数B: " + RCB.ToString("0.0000")); LogHelper.Info(typeof(LinearRegFitStrategy), string.Format("方程为: y = {0} + {1} * x", RCA.ToString("0.0000"), RCB.ToString("0.0000"))); fitPoint.Y = RCB * targetX + RCA; LogHelper.Info(typeof(SimpleLinearFitStrategy), "LinearRegFitStrategy Result: " + JsonConvert.SerializeObject(fitPoint)); return(fitPoint); }
public async Task <ActionResult> GetPoint([FromBody] PointDto clientDto) { HttpClient client = new HttpClient(); PointDto resPoint = null; HttpResponseMessage response = await client.GetAsync($"{baseURL}/points/{clientDto.id}"); Console.WriteLine(response); if (response.IsSuccessStatusCode) { resPoint = await response.Content.ReadAsAsync <PointDto>(); } // return URI of the created resource. return(Json(resPoint)); }
private static PointDto GetStartingPoint(List <PointDto> list) { PointDto minPoint = null; foreach (var item in list) { if (minPoint == null) { minPoint = item; continue; } if (minPoint.X > item.X || (minPoint.X.Equals(item.X) && minPoint.Y > item.Y)) { minPoint = item; } } return(minPoint); }
public async Task <ActionResult> Point_Update([DataSourceRequest] DataSourceRequest request, PointDto pointData) { PointDto result = null; HttpClient client = new HttpClient(); if (pointData != null && ModelState.IsValid) { HttpResponseMessage response = await client.PutAsJsonAsync( $"{baseURL}/points/{pointData.id}", pointData); response.EnsureSuccessStatusCode(); // Deserialize the updated product from the response body. result = await response.Content.ReadAsAsync <PointDto>(); } return(Json(new[] { result }.ToDataSourceResult(request, ModelState))); }
internal Point CreatePointFromPointDto(PointDto dto) { return new Point(dto.X, dto.Y); // todo IsUnknown is missing in Dto??? }