public static string Of(SourceVariable variable) { DataType type = variable.Type; if (type == DataType.Number) { return("数值"); } else if (type == DataType.String) { return("字符串"); } else if (type == DataType.Matrix) { return("矩阵"); } else if (type == DataType.Vector) { string s = "向量"; } return(null); }
public JobStepAreaVM(EvaluationContext context, Step step, int stepIndex, int updateCount) { Index = stepIndex; Title = step.SourceExpression.Title; Description = step.SourceExpression.Description; ImageUrl = "/Home/GetStepImage?stepIndex=" + stepIndex + "&updateCount=" + updateCount; ResultVariables = new ResultVariableVM[step.OutVariables.Length]; for (int i = 0; i <= step.OutVariables.Length - 1; i++) { string variableName = step.OutVariables[i]; object value = context.GetValue(variableName); Style style = context.Plan.Styles.FirstOrDefault(j => j.Target == variableName); int columnCount = 0; string[] rowNames = null; string[] columnNames = null; string[][] cells = null; string displayText = null; string url = null; if (value == null) { displayText = "?"; } else if (value is Matrix || value is Vector) { Matrix m = value is Matrix ? value as Matrix : new Matrix(1, (value as Vector).Size, (value as Vector).Items); cells = new string[m.RowCount][]; string styleRowName = style == null || string.IsNullOrEmpty(style.RowName) ? null : style.RowName; string[] styleRowNames = styleRowName == null || !styleRowName.Contains(",") ? null : styleRowName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); rowNames = new string[m.RowCount]; for (int row = 0; row <= m.RowCount - 1; row++) { string rowName; if (styleRowNames != null) { rowName = row <= styleRowNames.Length - 1 ? styleRowNames[row] : string.Format(styleRowName, row + 1); } else { rowName = styleRowName == null ? (row + 1).ToString() : string.Format(style.RowName, row + 1); } rowNames[row] = rowName; } columnCount = m.ColumnCount; columnNames = new string[m.ColumnCount]; for (int column = 0; column <= m.ColumnCount - 1; column++) { columnNames[column] = style == null || style.ColumnNames == null || column > style.ColumnNames.Length - 1 ? (column + 1).ToString() : style.ColumnNames[column]; } for (int row = 0; row <= m.RowCount - 1; row++) { cells[row] = new string[m.ColumnCount]; for (int column = 0; column <= m.ColumnCount - 1; column++) { double d = m[row, column]; cells[row][column] = double.IsNaN(d) ? "-" : NumberFormatter.ForDecimalDigits(context.Settings.DecimalDigitCount).ToText(d); } } } else if (value is Bitmap) { url = string.Format("/Home/GetResultImage?stepIndex={0}&variableIndex={1}×tamp={2}", stepIndex, i, DateTime.Now.ToString()); } else if (value is double) { displayText = NumberFormatter.ForDecimalDigits(context.Settings.DecimalDigitCount).ToText((double)value); } else if (value is int[] || value is double[]) { Array items = value as Array; StringBuilder b = new StringBuilder(); b.Append("["); for (int j = 0; j <= items.Length - 1; j++) { b.Append(NumberFormatter.ForDecimalDigits(context.Settings.DecimalDigitCount).ToText(Convert.ToDouble(items.GetValue(j)))); b.Append(j < items.Length - 1 ? "," : ""); } b.Append("]"); displayText = b.ToString(); } else { displayText = value.ToString().Replace("\r\n", "<br />"); } ResultVariables[i] = new ResultVariableVM() { Name = step.OutVariables[i], ColumnCount = columnCount, RowNames = rowNames, ColumnNames = columnNames, Cells = cells, Value = displayText, Url = url, Description = context.Plan.Variables.FirstOrDefault(m => m.Name == step.OutVariables[i]) == null ? "" : context.Plan.Variables.FirstOrDefault(m => m.Name == step.OutVariables[i]).Description }; } InVariables = new InVariableVM[step.InSourceVariables.Length]; for (int i = 0; i <= step.InSourceVariables.Length - 1; i++) { SourceVariable variable = step.InSourceVariables[i]; InVariables[i] = new InVariableVM() { Index = i, Name = variable.Name, Type = Strings.Of(variable), IsMatrix = variable.Type == DataType.Matrix || variable.Type == DataType.Vector, Value = step.InValues[i] == null ? string.Empty : getValue(step.InValues[i], context), Description = step.InSourceVariables[i].Description, }; } }
public ActionResult GetGridContent(int stepIndex, int variableIndex) { EvaluationContext context = Session["Context"] as EvaluationContext; object value = context.Steps[stepIndex].InValues[variableIndex]; SourceVariable variable = context.Steps[stepIndex].InSourceVariables[variableIndex]; bool isMatrix = variable.Type == Planning.DataType.Matrix; Style style = context.Plan.Styles.FirstOrDefault(i => i.Target == variable.Name); string[] columnNames = style != null && style.ColumnNames != null ? style.ColumnNames : new string[] { }; string rowName = style != null ? style.RowName : ""; int rowHeaderWidth = style != null && style.RowHeaderWidth != 0 ? style.RowHeaderWidth : 50; int rowCount = isMatrix ? 2 : 1; int columnCount; bool allowEditRow; bool allowEditColumn; if (isMatrix) { allowEditRow = true; if (columnNames.Length == 0) { allowEditColumn = true; columnCount = 5; } else { allowEditColumn = false; columnCount = columnNames.Length; } } else { bool hasSize = style != null && style.Size > 0; allowEditRow = false; allowEditColumn = !hasSize; columnCount = !hasSize ? 5 : style.Size; } string[] cells = new string[] { }; if (value is Matrix) { Matrix matrix = value as Matrix; rowCount = matrix.RowCount; columnCount = matrix.ColumnCount; cells = matrix.Items.Select(i => !double.IsNaN(i) ? i.ToString() : "-").ToArray(); } else if (value is Vector) { Vector vector = value as Vector; columnCount = vector.Size; cells = vector.Items.Select(i => !double.IsNaN(i) ? i.ToString() : "-").ToArray(); } return(Json(new { rowCount = rowCount, columnCount = columnCount, cells = cells, rowHeaderWidth = rowHeaderWidth, rowName = rowName, columnNames = columnNames, allowEditRow = allowEditRow, allowEditColumn = allowEditColumn }, JsonRequestBehavior.AllowGet)); }
public override Array GetData(int[] strideOrigin, int[] strideStride, int[] strideShape) { int rank = Rank; if (rank == 0) { if (strideOrigin != null && strideOrigin.Length > 0) { throw new ArgumentException("Origin in GetData() for scalar variable must be null or empty", "origin"); } if (strideShape != null && strideShape.Length > 0) { throw new ArgumentException("Count in GetData() for scalar variable must be null or empty", "count"); } if (strideStride != null && strideStride.Length > 0) { throw new ArgumentException("Stride in GetData() for scalar variable must be null or empty", "stride"); } return(GetData(null, null)); } if (strideOrigin == null) { strideOrigin = new int[rank]; } if (strideOrigin.Length != rank) { throw new ArgumentException("origin is incorrect"); } if (strideShape != null && strideShape.Length != rank) { throw new ArgumentException("shape is incorrect"); } if (strideShape == null) { int[] actualShape = GetShape(SchemaVersion.Committed); strideShape = new int[rank]; for (int i = 0; i < strideShape.Length; i++) { strideShape[i] = 1 + (actualShape[i] - 1 - strideOrigin[i]) / strideStride[i]; } } else if (Array.IndexOf(strideShape, 0) >= 0) { return(Array.CreateInstance(TypeOfData, strideShape)); } int srcRank = SourceVariable.Rank; int[] srcOrigin = new int[srcRank]; int[] srcShape = new int[srcRank]; int[] srcStride = new int[srcRank]; for (int i = 0, j = 0; i < srcRank; i++) { if (stride[i] == 0) // dimension i is to be removed { srcOrigin[i] = this.origin[i]; srcShape[i] = 1; srcStride[i] = 1; // instead of 0 } else { srcOrigin[i] = this.origin[i] + this.stride[i] * strideOrigin[j]; srcStride[i] = this.stride[i] * strideStride[j]; srcShape[i] = strideShape[j]; j++; } } Array array = SourceVariable.GetData(srcOrigin, srcStride, srcShape); if (rank == srcRank) { return(array); } // Some dimensions are to be removed. return(RemoveDimensions(array)); }
public override Array GetData(int[] strideOrigin, int[] strideShape) { int rank = Rank; if (strideOrigin == null) { strideOrigin = new int[rank]; } if (strideOrigin.Length != rank) { throw new ArgumentException("origin is incorrect"); } if (strideShape != null && strideShape.Length != rank) { throw new ArgumentException("shape is incorrect"); } int[] actualShape = GetShape(SchemaVersion.Committed); if (strideShape == null) { strideShape = new int[rank]; for (int i = 0; i < strideShape.Length; i++) { strideShape[i] = actualShape[i] - strideOrigin[i]; } } else { for (int i = 0; i < strideShape.Length; i++) { if (strideOrigin[i] + strideShape[i] > actualShape[i]) { throw new ArgumentException("Specified origin and shape describe an area larger than the variable's shape"); } } } int srcRank = SourceVariable.Rank; int[] srcOrigin = new int[srcRank]; int[] srcShape = new int[srcRank]; int[] stride2; if (srcRank > rank) // reducing dimensions { stride2 = (int[])stride.Clone(); // will be updated } else { stride2 = stride; } for (int i = 0, j = 0; i < srcRank; i++) { if (stride[i] == 0) // dimension i is to be removed { srcOrigin[i] = this.origin[i]; srcShape[i] = 1; stride2[i] = 1; // instead of 0 } else { srcOrigin[i] = this.origin[i] + this.stride[i] * strideOrigin[j]; srcShape[i] = strideShape[j]; j++; } } Array array = SourceVariable.GetData(srcOrigin, stride2, srcShape); if (rank == srcRank) { return(array); } // Some dimensions are to be removed. return(RemoveDimensions(array)); }
/// <summary> /// Completely updates shape and affected rect when "origin" changes and /// possibly source variable changed. /// </summary> /// <param name="changes"></param> /// <param name="origin"></param> private void InnerUpdateChanges(DataSet.Changes changes, int[] origin) { int srank = SourceVariable.Rank; if (origin == null) { origin = new int[srank]; } if (origin.Length != srank) { throw new ArgumentException("Wrong origin indices"); } int[] sourceShape; Variable.Changes srcChanges = changes.GetVariableChanges(SourceVariable.ID); if (srcChanges == null) { sourceShape = SourceVariable.GetShape(); } else { sourceShape = srcChanges.Shape; } for (int i = 0; i < srank; i++) { if (origin[i] < 0) { throw new ArgumentOutOfRangeException("origin is negative"); } if ((count[i] == 0) && (origin[i] != this.origin[i])) { throw new ArgumentException("Can't set origin[" + i + "]new value because count[" + i + "]=0"); } if ((count[i] > 0) && ((origin[i] + stride[i] * (count[i] - 1)) >= sourceShape[i])) { // || (origin[i] > sourceShape[i]))) //if ((((count[i] > 0) && (origin[i] + stride[i] * (count[i] - 1)) >= sourceShape[i])) // || ((count[i] > 0) && origin[i] > sourceShape[i])) throw new ArgumentException("Source variable does not contain this range of data"); } } //********************************** int rank = Rank; int[] aorigin = new int[rank]; int[] ashape = new int[rank]; for (int i = 0, k = 0; i < stride.Length; i++) { if (stride[i] > 0) { if (count[i] > 0) { ashape[k] = count[i]; } else { int t = (sourceShape[i] - origin[i] - 1) / stride[i]; if (t < 0) { t = 0; } if (sourceShape[i] > origin[i]) { ashape[k] = 1 + t; } else { ashape[k] = 0; } } k++; } } Rectangle AffectedRect = new Rectangle(aorigin, ashape); /***********************************************************************/ // Making changes var myChanges = changes.GetVariableChanges(ID); myChanges.Shape = ashape; myChanges.AffectedRectangle = AffectedRect; changes.UpdateChanges(myChanges); }