private async Task <SyncResponseViewModel> GetChanges(Application app, Device device, SyncRequestViewModel request) { var response = new SyncResponseViewModel() { Groups = new List <SyncResponseViewModel.GroupViewModel>() }; Stopwatch sw = new Stopwatch(); sw.Start(); if (request.Groups != null) { foreach (var group in request.Groups) { sw.Restart(); string partition = $"{app.Id}-{group.Group}"; var queryParams = new List <object>(); string whereClause = null; if (!string.IsNullOrWhiteSpace(group.Tidemark)) { Logger.LogInformation($"Getting changes for group: {group.Group} after tidemark: {group.Tidemark}"); queryParams.Add(group.Tidemark); whereClause = "tidemark > ?"; } else { Logger.LogInformation($"Getting all changes for group: {group.Group}"); } List <Change> results = await ScaleContext.Query <Change>(partition, "change", whereClause, queryParams, orderBy : "tidemark", limit : 50); Logger.LogInformation($"Retrieved changes from database in {sw.ElapsedMilliseconds}ms count: {results.Count}"); if (results != null && results.Any()) { response.Groups.Add(new SyncResponseViewModel.GroupViewModel() { Group = group.Group, Tidemark = results.Last().Tidemark, Changes = results.Select(r => new SyncResponseViewModel.ChangeViewModel() { Modified = r.Modified, Value = r.Value, Path = r.Path }).ToList() }); } } } sw.Stop(); return(response); }
private async Task ProcessChanges(Application app, Device device, SyncRequestViewModel request) { if (request.Changes != null && request.Changes.Any()) { Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var batch in request.Changes.Batch(50)) { var changes = new List <SendContextModel <UpsetModel <Change> > >(); foreach (var change in batch) { if (change != null) { Guid recordId = Guid.Empty; string path = null; // Path should contain a / in format <guid>/property.name if (!string.IsNullOrWhiteSpace(change.Path) && change.Path.IndexOf("/") > -1) { recordId = Guid.Parse(change.Path.Substring(0, change.Path.IndexOf("/"))); path = change.Path.Substring(change.Path.IndexOf("/") + 1); } DateTime modifiedUTC = requestStartTimeUTC.AddSeconds(-change.SecondsAgo); var dbChange = new Change() { Id = Guid.NewGuid(), RecordId = recordId, Path = change.Path, DeviceId = device.Id, Modified = modifiedUTC, Tidemark = "%clustertime%", Value = change.Value }; string partition = $"{app.Id}-{change.Group}"; changes.Add(ScaleContext.MakeUpsertModel(partition, "change", dbChange)); } } Logger.LogInformation($"Generated changes in {sw.ElapsedMilliseconds}ms count: {changes.Count}"); sw.Restart(); await ScaleContext.UpsertBulk(changes); Logger.LogInformation($"Saved changes to database in {sw.ElapsedMilliseconds}ms count: {changes.Count}"); } sw.Stop(); } }
public override void Measure( CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> secondaryAxis, IAxis <TDrawingContext> primaryAxis) { var drawLocation = chart.DrawMaringLocation; var drawMarginSize = chart.DrawMarginSize; var secondaryScale = new ScaleContext(drawLocation, drawMarginSize, primaryAxis.Orientation, primaryAxis.DataBounds); var primaryScale = new ScaleContext(drawLocation, drawMarginSize, secondaryAxis.Orientation, secondaryAxis.DataBounds); float uw = secondaryScale.ScaleToUi(1f) - secondaryScale.ScaleToUi(0f); float uwm = 0.5f * uw; float sw = Stroke?.StrokeWidth ?? 0; float p = primaryScale.ScaleToUi(pivot); var pos = chart.SeriesContext.GetStackedColumnPostion(this); var count = chart.SeriesContext.GetStackedColumnSeriesCount(); float cp = 0f; if (count > 1) { uw = uw / count; uwm = 0.5f * uw; cp = (pos - (count / 2f)) * uw + uwm; } if (uw > MaxColumnWidth) { uw = unchecked ((float)MaxColumnWidth); uwm = uw / 2f; } if (Fill != null) { chart.Canvas.AddDrawableTask(Fill); } if (Stroke != null) { chart.Canvas.AddDrawableTask(Stroke); } if (DataLabelsBrush != null) { chart.Canvas.AddDrawableTask(DataLabelsBrush); } var dls = unchecked ((float)DataLabelsSize); var chartAnimation = new Animation(chart.EasingFunction, chart.AnimationsSpeed); var ts = OnPointCreated ?? DefaultOnPointCreated; var stacker = chart.SeriesContext.GetStackPosition(this, GetStackGroup()); if (stacker == null) { throw new NullReferenceException("Unexpected null stacker"); } foreach (var point in Fetch(chart)) { var secondary = secondaryScale.ScaleToUi(point.SecondaryValue); if (point.IsNull) { if (point.Context.Visual != null) { point.Context.Visual.X = p; point.Context.Visual.Y = secondary - uwm + cp; point.Context.Visual.Width = 0; point.Context.Visual.Height = uw; point.Context.Visual.RemoveOnCompleted = true; point.Context.Visual = null; } continue; } if (point.Context.Visual == null) { var r = new TVisual { X = p, Y = secondary - uwm + cp, Width = 0, Height = uw }; ts(r, chart.View); r.CompleteAllTransitions(); point.Context.Visual = r; if (Fill != null) { Fill.AddGeometyToPaintTask(r); } if (Stroke != null) { Stroke.AddGeometyToPaintTask(r); } } var sizedGeometry = point.Context.Visual; var sy = stacker.GetStack(point); var primaryI = primaryScale.ScaleToUi(sy.Start); var primaryJ = primaryScale.ScaleToUi(sy.End); var y = secondary - uwm + cp; sizedGeometry.X = primaryJ; sizedGeometry.Y = y; sizedGeometry.Width = primaryI - primaryJ; sizedGeometry.Height = uw; sizedGeometry.RemoveOnCompleted = false; point.Context.HoverArea = new RectangleHoverArea().SetDimensions(secondary - uwm + cp, primaryJ, uw, primaryI - primaryJ); OnPointMeasured(point, sizedGeometry); chart.MeasuredDrawables.Add(sizedGeometry); if (DataLabelsBrush != null) { if (point.Context.Label == null) { var l = new TLabel { X = secondary - uwm + cp, Y = p }; l.TransitionateProperties(nameof(l.X), nameof(l.Y)) .WithAnimation(a => a.WithDuration(chart.AnimationsSpeed) .WithEasingFunction(chart.EasingFunction)); l.CompleteAllTransitions(); point.Context.Label = l; DataLabelsBrush.AddGeometyToPaintTask(l); } point.Context.Label.Text = DataLabelFormatter(point); point.Context.Label.TextSize = dls; point.Context.Label.Padding = DataLabelsPadding; var labelPosition = GetLabelPosition( primaryJ, y, primaryI - primaryJ, uw, point.Context.Label.Measure(DataLabelsBrush), DataLabelsPosition, SeriesProperties, point.PrimaryValue > Pivot); point.Context.Label.X = labelPosition.X; point.Context.Label.Y = labelPosition.Y; chart.MeasuredDrawables.Add(point.Context.Label); } } }
public override void Measure( CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> xAxis, IAxis <TDrawingContext> yAxis) { var drawLocation = chart.DrawMaringLocation; var drawMarginSize = chart.DrawMarginSize; var xScale = new ScaleContext(drawLocation, drawMarginSize, xAxis.Orientation, xAxis.DataBounds); var yScale = new ScaleContext(drawLocation, drawMarginSize, yAxis.Orientation, yAxis.DataBounds); float uw = xScale.ScaleToUi(1f) - xScale.ScaleToUi(0f); float uwm = 0.5f * uw; float sw = Stroke?.StrokeWidth ?? 0; float p = yScale.ScaleToUi(unchecked ((float)Pivot)); var pos = chart.SeriesContext.GetColumnPostion(this); var count = chart.SeriesContext.GetColumnSeriesCount(); float cp = 0f; if (!IgnoresColumnPosition && count > 1) { uw = uw / count; uwm = 0.5f * uw; cp = (pos - (count / 2f)) * uw + uwm; } if (uw > MaxColumnWidth) { uw = unchecked ((float)MaxColumnWidth); uwm = uw / 2f; } if (Fill != null) { chart.Canvas.AddDrawableTask(Fill); } if (Stroke != null) { chart.Canvas.AddDrawableTask(Stroke); } var chartAnimation = new Animation(chart.EasingFunction, chart.AnimationsSpeed); var ts = TransitionsSetter ?? SetDefaultTransitions; foreach (var point in Fetch(chart)) { var x = xScale.ScaleToUi(point.SecondaryValue); var y = yScale.ScaleToUi(point.PrimaryValue); float b = Math.Abs(y - p); if (point.PointContext.Visual == null) { var r = new TVisual { X = x - uwm + cp, Y = p, Width = uw, Height = 0 }; ts(r, chartAnimation); point.PointContext.Visual = r; if (Fill != null) { Fill.AddGeometyToPaintTask(r); } if (Stroke != null) { Stroke.AddGeometyToPaintTask(r); } } var sizedGeometry = point.PointContext.Visual; var cy = point.PrimaryValue > Pivot ? y : y - b; sizedGeometry.X = x - uwm + cp; sizedGeometry.Y = cy; sizedGeometry.Width = uw; sizedGeometry.Height = b; point.PointContext.HoverArea = new RectangleHoverArea().SetDimensions(x - uwm + cp, cy, uw, b); OnPointMeasured(point, sizedGeometry); chart.MeasuredDrawables.Add(sizedGeometry); } if (HighlightFill != null) { chart.Canvas.AddDrawableTask(HighlightFill); } if (HighlightStroke != null) { chart.Canvas.AddDrawableTask(HighlightStroke); } }
public override void Measure( IChartView <TDrawingContext> view, IAxis <TDrawingContext> xAxis, IAxis <TDrawingContext> yAxis, SeriesContext <TDrawingContext> context, HashSet <IDrawable <TDrawingContext> > drawBucket) { var drawLocation = view.Core.DrawMaringLocation; var drawMarginSize = view.Core.DrawMarginSize; var xScale = new ScaleContext(drawLocation, drawMarginSize, xAxis.Orientation, xAxis.DataBounds); var yScale = new ScaleContext(drawLocation, drawMarginSize, yAxis.Orientation, yAxis.DataBounds); float uw = xScale.ScaleToUi(1f) - xScale.ScaleToUi(0f); float uwm = 0.5f * uw; float sw = Stroke?.StrokeWidth ?? 0; float p = yScale.ScaleToUi(unchecked ((float)Pivot)); var pos = context.GetColumnPostion(this); var count = context.GetColumnSeriesCount(); float cp = 0f; if (!IgnoresColumnPosition && count > 1) { uw = uw / count; uwm = 0.5f * uw; cp = (pos - (count / 2f)) * uw + uwm; } if (uw > MaxColumnWidth) { uw = unchecked ((float)MaxColumnWidth); uwm = uw / 2f; } if (Fill != null) { view.CoreCanvas.AddPaintTask(Fill); } if (Stroke != null) { view.CoreCanvas.AddPaintTask(Stroke); } var chartAnimation = new Animation(view.EasingFunction, view.AnimationsSpeed); var ts = TransitionsSetter ?? SetDefaultTransitions; foreach (var point in GetPonts()) { var x = xScale.ScaleToUi(point.X); var y = yScale.ScaleToUi(point.Y); float b = Math.Abs(y - p); if (point.Visual == null) { var r = new TVisual { X = x - uwm + cp, Y = p, Width = uw, Height = 0 }; ts(r, chartAnimation); point.HoverArea = new HoverArea(); point.Visual = r; if (Fill != null) { Fill.AddGeometyToPaintTask(r); } if (Stroke != null) { Stroke.AddGeometyToPaintTask(r); } } var sizedGeometry = (TVisual)point.Visual; var cy = point.Y > Pivot ? y : y - b; sizedGeometry.X = x - uwm + cp; sizedGeometry.Y = cy; sizedGeometry.Width = uw; sizedGeometry.Height = b; point.HoverArea.SetDimensions(x - uwm + cp, cy, uw, b); OnPointMeasured(point, sizedGeometry); drawBucket.Add(sizedGeometry); } if (HighlightFill != null) { view.CoreCanvas.AddPaintTask(HighlightFill); } if (HighlightStroke != null) { view.CoreCanvas.AddPaintTask(HighlightStroke); } }
public override void Measure( CartesianChart <TDrawingContext> chart, IAxis <TDrawingContext> secondaryAxis, IAxis <TDrawingContext> primaryAxis) { var drawLocation = chart.DrawMaringLocation; var drawMarginSize = chart.DrawMarginSize; var secondaryScale = new ScaleContext(drawLocation, drawMarginSize, primaryAxis.Orientation, primaryAxis.DataBounds); var primaryScale = new ScaleContext(drawLocation, drawMarginSize, secondaryAxis.Orientation, secondaryAxis.DataBounds); float uw = secondaryScale.ScaleToUi(1f) - secondaryScale.ScaleToUi(0f); float uwm = 0.5f * uw; float sw = Stroke?.StrokeThickness ?? 0; float p = primaryScale.ScaleToUi(unchecked ((float)Pivot)); var pos = chart.SeriesContext.GetColumnPostion(this); var count = chart.SeriesContext.GetColumnSeriesCount(); float cp = 0f; if (!IgnoresBarPosition && count > 1) { uw = uw / count; uwm = 0.5f * uw; cp = (pos - count / 2f) * uw + uwm; } if (uw < -1 * MaxBarWidth) { uw = unchecked ((float)MaxBarWidth * -1); uwm = uw / 2f; } if (Fill != null) { chart.Canvas.AddDrawableTask(Fill); } if (Stroke != null) { chart.Canvas.AddDrawableTask(Stroke); } if (DataLabelsDrawableTask != null) { chart.Canvas.AddDrawableTask(DataLabelsDrawableTask); } var dls = unchecked ((float)DataLabelsSize); foreach (var point in Fetch(chart)) { var primary = primaryScale.ScaleToUi(point.PrimaryValue); var secondary = secondaryScale.ScaleToUi(point.SecondaryValue); float b = Math.Abs(primary - p); if (point.IsNull) { if (point.Context.Visual != null) { point.Context.Visual.X = p; point.Context.Visual.Y = secondary - uwm + cp; point.Context.Visual.Width = 0; point.Context.Visual.Height = uw; point.Context.Visual.RemoveOnCompleted = true; } continue; } if (point.Context.Visual == null) { var r = new TVisual { X = p, Y = secondary - uwm + cp, Width = 0, Height = uw }; point.Context.Visual = r; OnPointCreated(point); r.CompleteAllTransitions(); if (Fill != null) { Fill.AddGeometyToPaintTask(r); } if (Stroke != null) { Stroke.AddGeometyToPaintTask(r); } } var sizedGeometry = point.Context.Visual; var cx = point.PrimaryValue > Pivot ? primary - b : primary; var y = secondary - uwm + cp; sizedGeometry.X = cx; sizedGeometry.Y = y; sizedGeometry.Width = b; sizedGeometry.Height = uw; point.Context.HoverArea = new RectangleHoverArea().SetDimensions(primary, secondary - uwm + cp, b, uw); OnPointMeasured(point); chart.MeasuredDrawables.Add(sizedGeometry); if (DataLabelsDrawableTask != null) { if (point.Context.Label == null) { var l = new TLabel { X = p, Y = secondary - uwm + cp }; l.TransitionateProperties(nameof(l.X), nameof(l.Y)) .WithAnimation(a => a.WithDuration(chart.AnimationsSpeed) .WithEasingFunction(chart.EasingFunction)); l.CompleteAllTransitions(); point.Context.Label = l; DataLabelsDrawableTask.AddGeometyToPaintTask(l); } point.Context.Label.Text = DataLabelFormatter(point); point.Context.Label.TextSize = dls; point.Context.Label.Padding = DataLabelsPadding; var labelPosition = GetLabelPosition( cx, y, b, uw, point.Context.Label.Measure(DataLabelsDrawableTask), DataLabelsPosition, SeriesProperties, point.PrimaryValue > Pivot); point.Context.Label.X = labelPosition.X; point.Context.Label.Y = labelPosition.Y; chart.MeasuredDrawables.Add(point.Context.Label); } } }