/// <summary> /// Normalize a saw tooth like series due to overflows or resets /// </summary> /// <typeparam name="T"></typeparam> /// <param name="resetValue">let it null to take the first value after the overflow, otherwise set the value explicitly</param> /// <returns></returns> public IQuerySerie <T> NormalizeOverflows(double?resetValue = null) { if (Rows.Any()) { var newRows = new List <ISingleDataRow <T> >(Rows.Count); double offset = 0; double previousValue = Rows.First().Value.ToDouble(); foreach (var row in Rows) { double rowValue = row.Value.ToDouble(); if (previousValue > rowValue) { if (resetValue != null) { offset += previousValue - (rowValue - resetValue.Value); } else { offset += previousValue; } } newRows.Add(new SingleDataRow <T>(row.TimeUtc, (rowValue + offset).ToType <T>())); previousValue = rowValue; } return(new QuerySerie <T>(newRows, this)); } return(this); }
public DashboardViewModel() { Product = TestProduct(); TaskHeaders = TestHeaders(); Rows = TestRows(); AreaRowVM firstRecord = Rows.First(x => x.Area == "Area1"); //making row with same area AreaRowVM rowsWithDifferentMileStone = firstRecord.ShallowCopy(); rowsWithDifferentMileStone.MileStoneId = 2; rowsWithDifferentMileStone.RowKey = "1.2"; // Task1AreaIDTaskID "11/28/2017 12:00:00 AM-1-2" System.String rowsWithDifferentMileStone.DynamicTask.Task1AreaIDTaskID = $"11/28/2017 12:00:00 AM-1-1"; Rows.Insert(1, rowsWithDifferentMileStone); AreaRowVM secondRow = Rows.First(x => x.Area == "Area2"); //AreaRowVM thirdRow = Rows.First(x => x.Area == "Area3"); //thirdRow.ActivitysList.Clear(); //thirdRow.ActivitysList.AddRange(secondRow.ActivitysList); // Rows.Find(x => x.Area == "Area3").DynamicTask = secondRow.DynamicTask; }
public T?Difference() { if (!Rows.Any()) { return(null); } return ((Rows.Last().Value.ToDouble() - (PreviousRow?.Value.ToDouble() ?? Rows.First().Value.ToDouble())) .ToType <T>()); }
void calc() { if (Rows.Any()) { for (int i = 0; i < Rows.First().Count; i++) { dict[i] = Rows.Max(r => r[i].MyLength()); } } }
private void DivideRegular() { List <Container> toDivide = ContainersToDivide.Where(e => e.Type == ContainerType.Regular).ToList(); foreach (Container container in toDivide) { if (Rows.First(e => e.GetRowWeight() == Rows.Min(e => e.GetRowWeight())).AddToRow(container)) { ContainersToDivide.Remove(container); } } }
public T?Derivative(TimeSpan timeSpan) { if (!Rows.Any()) { return(null); } var firstValue = PreviousRow ?? Rows.First(); var lastValue = Rows.Last(); var diffTime = lastValue.TimeUtc - firstValue.TimeUtc; double diffValue = lastValue.Value.ToDouble() - firstValue.Value.ToDouble(); var result = diffValue * timeSpan.Ticks / diffTime.Ticks; return(result.ToType <T>()); }
public ISingleDataRow <T> MinItem() { if (!Rows.Any()) { return(null); } var minItem = Rows.First(); foreach (var row in Rows) { if (row.Value.ToDouble() < minItem.Value.ToDouble()) { minItem = row; } } return(minItem); }
public Application(string file) { Rows = HelperMethods.GetRows(file, row => { var positions = new List <Position>(); foreach (var position in row.ToCharArray()) { positions.Add(new Position(position)); } return(positions); }).ToList(); RowsCount = Rows.Count; RowPosCount = Rows.First().Count; }
public static void Run() { Rows = File.ReadAllLines("day03Input.txt").ToList(); RowLength = Rows.First().Length; int threeOne = SlopeCheck(3, 1); Console.WriteLine($"Slope (3,1) hits {3_1} trees."); int oneOne = SlopeCheck(1, 1); int fiveOne = SlopeCheck(5, 1); int sevenOne = SlopeCheck(7, 1); int oneTwo = SlopeCheck(1, 2); Console.WriteLine($"(1,1): {oneOne}"); Console.WriteLine($"(3,1): {threeOne}"); Console.WriteLine($"(5,1): {fiveOne}"); Console.WriteLine($"(7,1): {sevenOne}"); Console.WriteLine($"(1,2): {oneTwo}"); Console.WriteLine($"All slopes multiplied provides {oneOne * threeOne * fiveOne * sevenOne * oneTwo}"); }
private void IterateCells() { for (int rowIdx = 0; rowIdx < RowCount; rowIdx++) { for (int colIdx = 0; colIdx < ColCount; colIdx++) { if (!WorkingGrid[rowIdx, colIdx].Equals(Color.Empty)) { continue; } var row = Rows.First(r => r.Index == rowIdx); var col = Columns.First(c => c.Index == colIdx); var rowColors = row.Colors.Where(c => !c.IsDone).ToList(); var colColors = col.Colors.Where(c => !c.IsDone).ToList(); var possibleColorClassifiersForCell = rowColors.Intersect(colColors, new ColorClassifierIsSameColorComparer()).ToList(); if (possibleColorClassifiersForCell.Count == 1) { FillCellAndSetDirty(rowIdx, colIdx, possibleColorClassifiersForCell.Single().MyColor); } else if (possibleColorClassifiersForCell.Count > 1) { var actualPossibleColorsForCell = possibleColorClassifiersForCell.Select(cc => cc.MyColor).ToList(); foreach (var possibleColor in possibleColorClassifiersForCell) { var rowCc = rowColors.First(cc => cc.MyColor.Equals(possibleColor.MyColor)); if (!rowCc.IsConnected) { var count = CountNumberOfElementsBeforeAndAfterInRow(rowIdx, colIdx, rowCc.MyColor); if (count + 1 == rowCc.Count) { actualPossibleColorsForCell.Remove(rowCc.MyColor); } } else { if (!CanConnectedColorReachCellInRow(rowIdx, colIdx, rowCc)) { actualPossibleColorsForCell.Remove(rowCc.MyColor); } } var colCc = colColors.First(cc => cc.MyColor.Equals(possibleColor.MyColor)); if (!colCc.IsConnected) { var count = CountNumberOfElementsBeforeAndAfterInColumn(rowIdx, colIdx, colCc.MyColor); if (count + 1 == colCc.Count) { actualPossibleColorsForCell.Remove(colCc.MyColor); } } else { if (!CanConnectedColorReachCellInColumn(rowIdx, colIdx, colCc)) { actualPossibleColorsForCell.Remove(colCc.MyColor); } } } if (actualPossibleColorsForCell.Count == 1) { FillCellAndSetDirty(rowIdx, colIdx, actualPossibleColorsForCell.Single()); } } } } }
/// <summary> /// returns the row for the given input /// </summary> /// <param name="input"></param> /// <returns></returns> public Row RowForInput(Input input) => Rows.First(b => b.Contains(input));
public HorizontalMatrix(IEnumerable <string> rows) { Rows = rows.ToList(); Height = Rows.Count(); Length = Height != 0 ? Rows.First().Length : 0; }
public void Remove_RowIsRemoved() { rows.Remove(rows.First()); rows.Count.Should().Be(2, "because there were 3 sample rows before we removed this one."); rowsXml.Elements().Count().Should().Be(2); }