private void btnGraphType_Click(object sender, EventArgs e) { currentViewType = DataViewType.Graph; }
private static CountAggregator GetOneAggregator <T>(DataViewRow row, DataViewType colType, int colSrc) { return(new CountAggregator <T>(colType, row.GetGetter <T>(row.Schema[colSrc]))); }
public ColInfo(string name, string inputColumnName, DataViewType inType, DataViewType outType) { Name = name; InputColumnName = inputColumnName; InputType = inType; OutputType = outType; InputIsNA = GetIsNADelegate(InputType); }
public static bool IsValidRangeFilterColumnType(IExceptionContext ectx, DataViewType type) { ectx.CheckValue(type, nameof(type)); return(type == NumberDataViewType.Single || type == NumberDataViewType.Double || type.GetKeyCount() > 0); }
/// <summary> /// Returns the feature selection scores for each slot of each column. /// </summary> /// <param name="env">The host environment.</param> /// <param name="input">The input dataview.</param> /// <param name="columns">The columns for which to compute the feature selection scores.</param> /// <param name="colSizes">Outputs an array containing the vector sizes of the input columns</param> /// <returns>A list of scores.</returns> public static long[][] Train(IHostEnvironment env, IDataView input, string[] columns, out int[] colSizes) { Contracts.CheckValue(env, nameof(env)); env.CheckValue(input, nameof(input)); env.CheckParam(Utils.Size(columns) > 0, nameof(columns)); var schema = input.Schema; var size = columns.Length; var activeCols = new List <DataViewSchema.Column>(); var colSrcs = new int[size]; var colTypes = new DataViewType[size]; colSizes = new int[size]; for (int i = 0; i < size; i++) { int colSrc; var colName = columns[i]; if (!schema.TryGetColumnIndex(colName, out colSrc)) { throw env.ExceptUserArg(nameof(CountFeatureSelectingEstimator.Options.Columns), "Source column '{0}' not found", colName); } var colType = schema[colSrc].Type; if (colType is VectorDataViewType vectorType && !vectorType.IsKnownSize) { throw env.ExceptUserArg(nameof(CountFeatureSelectingEstimator.Options.Columns), "Variable length column '{0}' is not allowed", colName); } activeCols.Add(schema[colSrc]); colSrcs[i] = colSrc; colTypes[i] = colType; colSizes[i] = colType.GetValueCount(); } var aggregators = new CountAggregator[size]; long rowCur = 0; double rowCount = input.GetRowCount() ?? double.NaN; using (var pch = env.StartProgressChannel("Aggregating counts")) using (var cursor = input.GetRowCursor(activeCols)) { var header = new ProgressHeader(new[] { "rows" }); pch.SetHeader(header, e => { e.SetProgress(0, rowCur, rowCount); }); for (int i = 0; i < size; i++) { if (colTypes[i] is VectorDataViewType vectorType) { aggregators[i] = GetVecAggregator(cursor, vectorType, colSrcs[i]); } else { aggregators[i] = GetOneAggregator(cursor, colTypes[i], colSrcs[i]); } } while (cursor.MoveNext()) { for (int i = 0; i < size; i++) { aggregators[i].ProcessValue(); } rowCur++; } pch.Checkpoint(rowCur); } return(aggregators.Select(a => a.Count).ToArray()); }
private static IDataTransform CreateLambdaTransform(IHost host, IDataView input, string inputColumnName, string outputColumnName, string forecastingConfidenceIntervalMinOutputColumnName, string forecastingConfidenceIntervalMaxOutputColumnName, Action <TState> initFunction, bool hasBuffer, DataViewType outputColTypeOverride) { var inputSchema = SchemaDefinition.Create(typeof(DataBox <TInput>)); inputSchema[0].ColumnName = inputColumnName; SchemaDefinition outputSchema; if (!string.IsNullOrEmpty(forecastingConfidenceIntervalMinOutputColumnName)) { outputSchema = SchemaDefinition.Create(typeof(DataBoxForecastingWithConfidenceIntervals <TOutput>)); outputSchema[0].ColumnName = outputColumnName; if (outputColTypeOverride != null) { outputSchema[0].ColumnType = outputSchema[1].ColumnType = outputSchema[2].ColumnType = outputColTypeOverride; } outputSchema[1].ColumnName = forecastingConfidenceIntervalMinOutputColumnName; outputSchema[2].ColumnName = forecastingConfidenceIntervalMaxOutputColumnName; Action <DataBox <TInput>, DataBoxForecastingWithConfidenceIntervals <TOutput>, TState> lambda; if (hasBuffer) { lambda = MapFunction; } else { lambda = MapFunctionWithoutBuffer; } return(LambdaTransform.CreateMap(host, input, lambda, initFunction, inputSchema, outputSchema)); } else { outputSchema = SchemaDefinition.Create(typeof(DataBox <TOutput>)); outputSchema[0].ColumnName = outputColumnName; if (outputColTypeOverride != null) { outputSchema[0].ColumnType = outputColTypeOverride; } Action <DataBox <TInput>, DataBox <TOutput>, TState> lambda; if (hasBuffer) { lambda = MapFunction; } else { lambda = MapFunctionWithoutBuffer; } return(LambdaTransform.CreateMap(host, input, lambda, initFunction, inputSchema, outputSchema)); } }
/// <summary> /// Returns the isNA predicate for the respective type. /// </summary> private Delegate GetIsNADelegate(DataViewType type) { Func <DataViewType, Delegate> func = GetIsNADelegate <int>; return(Utils.MarshalInvoke(func, type.GetItemType().RawType, type)); }
public static ModelArgs GetModelArgs(DataViewType type, string colName, List <long> dims = null, List <bool> dimsParams = null) { Contracts.CheckValue(type, nameof(type)); Contracts.CheckNonEmpty(colName, nameof(colName)); Type rawType; if (type is VectorDataViewType vectorType) { rawType = vectorType.ItemType.RawType; } else { rawType = type.RawType; } var dataType = ConvertToTensorProtoType(rawType); string name = colName; List <long> dimsLocal = null; List <bool> dimsParamLocal = null; if (dims != null) { dimsLocal = dims; dimsParamLocal = dimsParams; } else { dimsLocal = new List <long>(); int valueCount = type.GetValueCount(); if (valueCount == 0) //Unknown size. { dimsLocal.Add(1); dimsParamLocal = new List <bool>() { false, true }; //false for batch size, true for dims. } else if (valueCount == 1) { dimsLocal.Add(1); } else if (valueCount > 1) { var vec = (VectorDataViewType)type; for (int i = 0; i < vec.Dimensions.Length; i++) { dimsLocal.Add(vec.Dimensions[i]); } } } // Set batch size to -1. The ONNX docs, https://github.com/onnx/onnx/blob/master/docs/IR.md#static-tensor-shapes, state that if // dim_param is used instead of dim_value, that the size of the dimension "is not statically constrained to a particular number" // "This is useful for declaring the interfaces that care about the number of dimensions, but not the exact size of each dimension" // This file, https://github.com/onnx/onnx/blob/master/onnx/tools/update_model_dims.py, explains that if the dim value is negative // than it treats that as a dim_param instead of a dim_value. This allows ML.NET to run 1 row at a time in a streaming fassion, // but allows the ONNX model the flexibility to be run in batch mode if that is desired. dimsLocal?.Insert(0, -1); return(new ModelArgs(name, dataType, dimsLocal, dimsParamLocal)); }
public ColInfo(string name, string inputColumnName, DataViewType type) { Name = name; InputColumnName = inputColumnName; TypeSrc = type; }
public static ModelArgs GetModelArgs(DataViewType type, string colName, List <long> dims = null, List <bool> dimsParams = null) { Contracts.CheckValue(type, nameof(type)); Contracts.CheckNonEmpty(colName, nameof(colName)); TensorProto.Types.DataType dataType = TensorProto.Types.DataType.Undefined; Type rawType; if (type is VectorType vectorType) { rawType = vectorType.ItemType.RawType; } else { rawType = type.RawType; } if (rawType == typeof(bool)) { dataType = TensorProto.Types.DataType.Float; } else if (rawType == typeof(ReadOnlyMemory <char>)) { dataType = TensorProto.Types.DataType.String; } else if (rawType == typeof(sbyte)) { dataType = TensorProto.Types.DataType.Int8; } else if (rawType == typeof(byte)) { dataType = TensorProto.Types.DataType.Uint8; } else if (rawType == typeof(short)) { dataType = TensorProto.Types.DataType.Int16; } else if (rawType == typeof(ushort)) { dataType = TensorProto.Types.DataType.Uint16; } else if (rawType == typeof(int)) { dataType = TensorProto.Types.DataType.Int32; } else if (rawType == typeof(uint)) { dataType = TensorProto.Types.DataType.Int64; } else if (rawType == typeof(long)) { dataType = TensorProto.Types.DataType.Int64; } else if (rawType == typeof(ulong)) { dataType = TensorProto.Types.DataType.Uint64; } else if (rawType == typeof(float)) { dataType = TensorProto.Types.DataType.Float; } else if (rawType == typeof(double)) { dataType = TensorProto.Types.DataType.Double; } else { string msg = "Unsupported type: " + type.ToString(); Contracts.Check(false, msg); } string name = colName; List <long> dimsLocal = null; List <bool> dimsParamLocal = null; if (dims != null) { dimsLocal = dims; dimsParamLocal = dimsParams; } else { dimsLocal = new List <long>(); int valueCount = type.GetValueCount(); if (valueCount == 0) //Unknown size. { dimsLocal.Add(1); dimsParamLocal = new List <bool>() { false, true }; //false for batch size, true for dims. } else if (valueCount == 1) { dimsLocal.Add(1); } else if (valueCount > 1) { var vec = (VectorType)type; for (int i = 0; i < vec.Dimensions.Length; i++) { dimsLocal.Add(vec.Dimensions[i]); } } } //batch size. dimsLocal?.Insert(0, 1); return(new ModelArgs(name, dataType, dimsLocal, dimsParamLocal)); }
internal abstract string[] GetLabelInfo(IHostEnvironment env, out DataViewType labelType);
/// <summary> /// Establishes a new mapping from an data view column in the context, if necessary generates a unique name, and /// returns that newly allocated name. /// </summary> /// <param name="type">The data view type associated with this column name</param> /// <param name="colName">The data view column name</param> /// <param name="skip">Whether we should skip the process of establishing the mapping from data view column to /// ONNX variable name.</param> /// <returns>The returned value is the name of the variable corresponding </returns> public abstract string AddIntermediateVariable(DataViewType type, string colName, bool skip = false);
/// <summary> /// Hàm hiển thị, tùy vào viewType là List/Graph và timeType là 5Min/60Min để hiển thị cho phù hợp. /// </summary> /// <param name="_viewType"></param> /// <param name="_timeType"></param> private void reloadViewDataCustom(DataViewType _viewType, DataTimeType _timeType) { DataLoggerParam.PARAMETER_LIST.ForEach(p => p.Selected = false); foreach (Object item in checkedListBoxParameters.CheckedItems) { string _key = item.ToString(); ParamInfo _pinfo = DataLoggerParam.PARAMETER_LIST.FirstOrDefault(p => p.NameDisplay == _key); if (_pinfo != null) { _pinfo.Selected = true; } } IEnumerable <string> _statusNameList = DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected && p.HasStatus).Select(p => p.StatusNameDB).ToList(); IEnumerable <string> _paramNameList = DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected).Select(p => p.NameDB).ToList(); List <string> _paramListForQuery = _paramNameList.Concat(_statusNameList).ToList(); if (_viewType == DataViewType.List) { chtData.Visible = false; dgvData.Columns.Clear(); dgvData.Visible = true; DataTable dt_source = null; if (_timeType == DataTimeType._5Minute) { dt_source = db5m.get_all_custom(dtpDateFrom.Value, dtpDateTo.Value, _paramListForQuery); } else //if (_timeType == DataTimeType._60Minute) { dt_source = db60m.get_all_custom(dtpDateFrom.Value, dtpDateTo.Value, _paramListForQuery); } // Do dt_source chứa date,hour,minute riêng nhau nên phải tạo một dt_view mới gộp các thành phần lại hiển thị cho đẹp hơn DataTable dt_view = new DataTable(); dt_view.Columns.Add("Date"); dt_view.Columns.Add("Time"); foreach (ParamInfo item in DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected)) { dt_view.Columns.Add(item.NameDisplay); if (item.HasStatus) { dt_view.Columns.Add(item.StatusNameVisible); } } // dữ liệu dt_source sang dt_view để hiển thị DataRow viewrow = null; if (dt_source == null) { return; } foreach (DataRow row in dt_source.Rows) { viewrow = dt_view.NewRow(); //viewrow["Date"] = row["stored_date"].ToString().Substring(0, 10); //viewrow["Date"] = (Convert.ToDateTime(row["stored_date"].ToString())).ToString("dd/MM/yyyy"); //viewrow["Time"] = ((int)row["stored_hour"]).ToString("00") + ":" + ((int)row["stored_minute"]).ToString("00") + ":00"; string created = (Convert.ToDateTime(row["created"].ToString())).ToString("yyyyMMddHHmmss"); string time = created.Substring(8, 2) + ":" + created.Substring(10, 2) + ":" + created.Substring(12, 2); viewrow["Date"] = (Convert.ToDateTime(row["created"].ToString())).ToString("dd/MM/yyyy"); viewrow["Time"] = time; foreach (ParamInfo item in DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected)) { viewrow[item.NameDisplay] = String.Format("{0:0.00}", row[item.NameDB]); if (item.HasStatus) { viewrow[item.StatusNameVisible] = row[item.StatusNameDB]; } } dt_view.Rows.Add(viewrow); } dgvData.DataSource = dt_view; // thêm cột Status có màu phù hợp với status foreach (ParamInfo item in DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected)) { if (item.HasStatus) { int cindex = dgvData.Columns[item.StatusNameVisible].Index; DataGridViewImageColumn imgColumnStatus = new DataGridViewImageColumn(); imgColumnStatus.Name = item.StatusNameDisplay; dgvData.Columns.Insert(cindex, imgColumnStatus); dgvData.Columns[item.StatusNameVisible].Visible = false; // ẩn cột status bằng số, chỉ để lại cột status có màu } } // chuẩn hóa dữ liệu hiển thị: chọn màu status, lọc giá trị âm int status_val = 0; foreach (DataGridViewRow row in dgvData.Rows) { foreach (ParamInfo item in DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected)) { // chọn màu status if (item.HasStatus) { if (row.Cells[item.StatusNameVisible].Value != null) { Int32.TryParse(row.Cells[item.StatusNameVisible].Value.ToString(), out status_val); if (status_val == 0) { row.Cells[item.StatusNameDisplay].Value = (System.Drawing.Image)Properties.Resources.Normal_status_x16; } else if (status_val == 4) { row.Cells[item.StatusNameDisplay].Value = (System.Drawing.Image)Properties.Resources.bottle_position_18x18; } else { row.Cells[item.StatusNameDisplay].Value = (System.Drawing.Image)Properties.Resources.Fault_status_x16; } } } // lọc giá trị âm if (Convert.ToDouble(row.Cells[item.NameDisplay].Value) < 0) { row.Cells[item.NameDisplay].Value = "---"; } else { double tempValue = Convert.ToDouble(row.Cells[item.NameDisplay].Value); string displayValueTemp = Convert.ToString(row.Cells[item.NameDisplay].Value); switch (item.NameDB) { case "module_power": if (tempValue == 1) { displayValueTemp = "ON"; } else { displayValueTemp = "OFF"; } break; case "module_ups": if (tempValue == 1) { displayValueTemp = "ON"; } else { displayValueTemp = "OFF"; } break; case "module_door": if (tempValue == 1) { displayValueTemp = "CLOSE"; } else { displayValueTemp = "OPEN"; } break; case "module_fire": if (tempValue == 1) { displayValueTemp = "NORMAL"; } else { displayValueTemp = "FIRE"; } break; case "module_flow": if (tempValue == 1) { displayValueTemp = "OPEN"; } else { displayValueTemp = "CLOSE"; } break; case "module_pumplam": if (tempValue == 1) { displayValueTemp = "AUTO"; } else { displayValueTemp = "MANUAL"; } break; case "module_pumplrs": if (tempValue == 1) { displayValueTemp = "STOP"; } else { displayValueTemp = "RUN"; } break; case "module_pumplflt": if (tempValue == 1) { displayValueTemp = "FAULT"; } else { displayValueTemp = "NORMAL"; } break; case "module_pumpram": if (tempValue == 1) { displayValueTemp = "AUTO"; } else { displayValueTemp = "MANUAL"; } break; case "module_pumprrs": if (tempValue == 1) { displayValueTemp = "STOP"; } else { displayValueTemp = "RUN"; } break; case "module_pumprflt": if (tempValue == 1) { displayValueTemp = "FAULT"; } else { displayValueTemp = "NORMAL"; } break; case "module_air1": if (tempValue == 1) { displayValueTemp = "ON"; } else { displayValueTemp = "OFF"; } break; case "module_air2": if (tempValue == 1) { displayValueTemp = "ON"; } else { displayValueTemp = "OFF"; } break; case "module_cleaning": if (tempValue == 1) { displayValueTemp = "ON"; } else { displayValueTemp = "OFF"; } break; default: break; } row.Cells[item.NameDisplay].Value = displayValueTemp; } } } } else //if(_viewType == DataViewType.Graph) { dgvData.Visible = false; chtData.Series.Clear(); chtData.Visible = true; DataTable dt_source = null; if (_timeType == DataTimeType._5Minute) { dt_source = db5m.get_all_custom(dtpDateFrom.Value, dtpDateTo.Value, _paramListForQuery); } else //if (_timeType == DataTimeType._60Minute) { dt_source = db60m.get_all_custom(dtpDateFrom.Value, dtpDateTo.Value, _paramListForQuery); } DataTable dt_view = new DataTable(); dt_view.Columns.Add("CreatedDate"); foreach (ParamInfo item in DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected)) { dt_view.Columns.Add(item.NameDisplay); } // chuyển dữ liệu dt_source sang dt_view để hiển thị DataRow viewrow = null; if (dt_source == null) { return; } foreach (DataRow row in dt_source.Rows) { bool allowAdd = true; viewrow = dt_view.NewRow(); //DateTime _date = (DateTime)row["stored_date"]; //int _hour = (int)row["stored_hour"]; //int _minute = (int)row["stored_minute"]; //DateTime _rdate = new DateTime(_date.Year, _date.Month, _date.Day, _hour, _minute, 0); string created = (Convert.ToDateTime(row["created"].ToString())).ToString("yyyyMMddHHmmss"); DateTime _rdate = new DateTime(Int32.Parse(created.Substring(0, 4)), Int32.Parse(created.Substring(4, 2)), Int32.Parse(created.Substring(6, 2)), Int32.Parse(created.Substring(8, 2)), Int32.Parse(created.Substring(10, 2)), Int32.Parse(created.Substring(12, 2))); viewrow["CreatedDate"] = _rdate; foreach (ParamInfo item in DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected)) { if (item.HasStatus) { // kiểm tra status, chỉ lấy chững status normal int _status = (int)row[item.StatusNameDB]; //if (_status == 0) //{ //DateTime _date = (DateTime)row["stored_date"]; //int _hour = (int)row["stored_hour"]; //int _minute = (int)row["stored_minute"]; //DateTime _rdate = new DateTime(_date.Year, _date.Month, _date.Day, _hour, _minute, 0); //viewrow["StoredDate"] = _rdate; viewrow[item.NameDisplay] = String.Format("{0:0.00}", row[item.NameDB]); //} //else //{ // allowAdd = false; // break; //} } } if (allowAdd) { dt_view.Rows.Add(viewrow); } } // tạo biểu đồ mới foreach (ParamInfo item in DataLoggerParam.PARAMETER_LIST.Where(p => p.Selected)) { chtData.Series.Add(item.NameDisplay); chtData.Series[item.NameDisplay].XValueMember = "CreatedDate"; chtData.Series[item.NameDisplay].YValueMembers = item.NameDisplay; chtData.Series[item.NameDisplay].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chtData.Series[item.NameDisplay].Color = item.GraphColor;// Color.Blue; chtData.Series[item.NameDisplay].BorderWidth = 3; } chtData.ChartAreas[0].AxisX.MajorGrid.Enabled = true; chtData.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray; chtData.ChartAreas[0].AxisX.MinorGrid.Enabled = true; chtData.ChartAreas[0].AxisX.MinorGrid.LineColor = Color.WhiteSmoke; chtData.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot; chtData.ChartAreas[0].AxisX.Title = "Date"; chtData.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines; chtData.ChartAreas[0].AxisY.MajorGrid.Enabled = true; chtData.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray; chtData.ChartAreas[0].AxisY.MinorGrid.Enabled = true; chtData.ChartAreas[0].AxisY.MinorGrid.LineColor = Color.WhiteSmoke; chtData.ChartAreas[0].AxisY.Title = "Data"; chtData.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines; chtData.DataSource = dt_view; chtData.DataBind(); } }
private void reloadViewDataMPS(DataViewType _viewType, DataTimeType _timeType) { GlobalVar.moduleSettings = new module_repository().get_all(); if (_viewType == DataViewType.List) { chtData.Visible = false; dgvData.Columns.Clear(); dgvData.Visible = true; DataTable dt_source = null; if (_timeType == DataTimeType._5Minute) { dt_source = db5m.get_all_mps(dtpDateFrom.Value, dtpDateTo.Value); } else //if (_timeType == DataTimeType._60Minute) { dt_source = db60m.get_all_mps(dtpDateFrom.Value, dtpDateTo.Value); } // Do dt_source chứa date,hour,minute riêng nhau nên phải tạo một dt_view mới gộp các thành phần lại hiển thị cho đẹp hơn DataTable dt_view = new DataTable(); dt_view.Columns.Add("Date"); dt_view.Columns.Add("Time"); foreach (var item in GlobalVar.moduleSettings) { dt_view.Columns.Add(item.display_name); } dt_view.Columns.Add("Status_Val"); // dữ liệu dt_source sang dt_view để hiển thị DataRow viewrow = null; if (dt_source == null) { return; } foreach (DataRow row in dt_source.Rows) { viewrow = dt_view.NewRow(); //viewrow["Date"] = row["stored_date"].ToString().Substring(0, 10); //viewrow["Date"] = (Convert.ToDateTime(row["stored_date"].ToString().Substring(0, 10))).ToString("dd/MM/yyyy"); //viewrow["Date"] = (Convert.ToDateTime(row["stored_date"].ToString().Substring(0, 10))).ToString("dd/MM/yyyy"); string created = (Convert.ToDateTime(row["created"].ToString())).ToString("yyyyMMddHHmmss"); string time = created.Substring(8, 2) + ":" + created.Substring(10, 2) + ":" + created.Substring(12, 2); viewrow["Date"] = (Convert.ToDateTime(row["created"].ToString())).ToString("dd/MM/yyyy"); viewrow["Time"] = time; //viewrow["Date"] = (Convert.ToDateTime((row["stored_date"].ToString().Split(' '))[0])).ToString("dd/MM/yyyy"); //viewrow["Time"] = ((int)row["stored_hour"]).ToString("00") + ":" + ((int)row["stored_minute"]).ToString("00") + ":00"; foreach (var item in GlobalVar.moduleSettings) { viewrow[item.display_name] = String.Format("{0:0.00}", row[item.value_column]); } viewrow["Status_Val"] = row["mps_status"]; dt_view.Rows.Add(viewrow); } dgvData.DataSource = dt_view; // thêm cột Status có màu phù hợp với status DataGridViewImageColumn imgColumnStatus = new DataGridViewImageColumn(); imgColumnStatus.Name = "Status"; dgvData.Columns.Add(imgColumnStatus); dgvData.Columns["Status_Val"].Visible = false; // ẩn cột status bằng số, chỉ để lại cột status có màu int status_val = 0; foreach (DataGridViewRow row in dgvData.Rows) { if (row.Cells["Status_Val"].Value != null) { Int32.TryParse(row.Cells["Status_Val"].Value.ToString(), out status_val); if (status_val == 0) { row.Cells["Status"].Value = (System.Drawing.Image)Properties.Resources.Normal_status_x16; } else if (status_val == 4) { row.Cells["Status"].Value = (System.Drawing.Image)Properties.Resources.bottle_position_18x18; } else { row.Cells["Status"].Value = (System.Drawing.Image)Properties.Resources.Fault_status_x16; } } //if (row.Cells["MPS_pH"].Value != null) //{ // if (Convert.ToDouble(row.Cells["MPS_pH"].Value) < 0) // { // row.Cells["MPS_pH"].Value = "---"; // } //} //if (row.Cells["MPS_EC"].Value != null) //{ // if (Convert.ToDouble(row.Cells["MPS_EC"].Value) < 0) // { // row.Cells["MPS_EC"].Value = "---"; // } //} //if (row.Cells["MPS_DO"].Value != null) //{ // if (Convert.ToDouble(row.Cells["MPS_DO"].Value) < 0) // { // row.Cells["MPS_DO"].Value = "---"; // } //} //if (row.Cells["MPS_TSS"].Value != null) //{ // if (Convert.ToDouble(row.Cells["MPS_TSS"].Value) < 0) // { // row.Cells["MPS_TSS"].Value = "---"; // } //} //if (row.Cells["MPS_ORP"].Value != null) //{ // if (Convert.ToDouble(row.Cells["MPS_ORP"].Value) < 0) // { // row.Cells["MPS_ORP"].Value = "---"; // } //} //if (row.Cells["MPS_Temp"].Value != null) //{ // if (Convert.ToDouble(row.Cells["MPS_Temp"].Value) < 0) // { // row.Cells["MPS_Temp"].Value = "---"; // } //} } } else //if(_viewType == DataViewType.Graph) { dgvData.Visible = false; chtData.Series.Clear(); chtData.Visible = true; DataTable dt_source = null; if (_timeType == DataTimeType._5Minute) { dt_source = db5m.get_all_mps(dtpDateFrom.Value, dtpDateTo.Value); } else //if (_timeType == DataTimeType._60Minute) { dt_source = db60m.get_all_mps(dtpDateFrom.Value, dtpDateTo.Value); } DataTable dt_view = new DataTable(); dt_view.Columns.Add("CreatedDate"); foreach (var item in GlobalVar.moduleSettings) { dt_view.Columns.Add(item.display_name); } // chuyển dữ liệu dt_source sang dt_view để hiển thị DataRow viewrow = null; if (dt_source == null) { return; } foreach (DataRow row in dt_source.Rows) { // kiểm tra status, chỉ lấy chững status normal int _status = (int)row["mps_status"]; //if (_status == 0) //{ viewrow = dt_view.NewRow(); //DateTime _date = (DateTime)row["stored_date"]; //int _hour = (int)row["stored_hour"]; //int _minute = (int)row["stored_minute"]; //DateTime _rdate = new DateTime(_date.Year, _date.Month, _date.Day, _hour, _minute, 0); string created = (Convert.ToDateTime(row["created"].ToString())).ToString("yyyyMMddHHmmss"); DateTime _rdate = new DateTime(Int32.Parse(created.Substring(0, 4)), Int32.Parse(created.Substring(4, 2)), Int32.Parse(created.Substring(6, 2)), Int32.Parse(created.Substring(8, 2)), Int32.Parse(created.Substring(10, 2)), Int32.Parse(created.Substring(12, 2))); viewrow["CreatedDate"] = _rdate; foreach (var item in GlobalVar.moduleSettings) { viewrow[item.display_name] = String.Format("{0:0.00}", row[item.value_column]); } dt_view.Rows.Add(viewrow); //} } foreach (var item in GlobalVar.moduleSettings) { Random rand = new Random(); chtData.Series.Add(item.display_name); chtData.Series["MPS_pH"].XValueMember = "CreatedDate"; chtData.Series["MPS_pH"].YValueMembers = "item.display_name"; chtData.Series["MPS_pH"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chtData.Series["MPS_pH"].Color = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)); chtData.Series["MPS_pH"].BorderWidth = 3; } chtData.ChartAreas[0].AxisX.MajorGrid.Enabled = true; chtData.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray; chtData.ChartAreas[0].AxisX.MinorGrid.Enabled = true; chtData.ChartAreas[0].AxisX.MinorGrid.LineColor = Color.WhiteSmoke; chtData.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot; chtData.ChartAreas[0].AxisX.Title = "Date"; chtData.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines; chtData.ChartAreas[0].AxisY.MajorGrid.Enabled = true; chtData.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray; chtData.ChartAreas[0].AxisY.MinorGrid.Enabled = true; chtData.ChartAreas[0].AxisY.MinorGrid.LineColor = Color.WhiteSmoke; chtData.ChartAreas[0].AxisY.Title = "MPS (mg/L)"; chtData.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines; chtData.DataSource = dt_view; chtData.DataBind(); } }
/// <summary> /// The main constructor for the sequential transform /// </summary> /// <param name="host">The host.</param> /// <param name="windowSize">The size of buffer used for windowed buffering.</param> /// <param name="initialWindowSize">The number of datapoints picked from the beginning of the series for training the transform parameters if needed.</param> /// <param name="outputColumnName">The name of the dst column.</param> /// <param name="inputColumnName">The name of the input column.</param> /// <param name="outputColType"></param> private protected SequentialTransformerBase(IHost host, int windowSize, int initialWindowSize, string outputColumnName, string inputColumnName, DataViewType outputColType) { Host = host; Host.CheckParam(initialWindowSize >= 0, nameof(initialWindowSize), "Must be non-negative."); Host.CheckParam(windowSize >= 0, nameof(windowSize), "Must be non-negative."); // REVIEW: Very bad design. This base class is responsible for reporting errors on // the arguments, but the arguments themselves are not derived form any base class. Host.CheckNonEmpty(inputColumnName, nameof(PercentileThresholdTransform.Arguments.Source)); Host.CheckNonEmpty(outputColumnName, nameof(PercentileThresholdTransform.Arguments.Source)); InputColumnName = inputColumnName; OutputColumnName = outputColumnName; OutputColumnType = outputColType; InitialWindowSize = initialWindowSize; WindowSize = windowSize; }
private SchemaShape.Column CheckInputsAndMakeColumn( SchemaShape inputSchema, string name, string[] sources) { _host.AssertNonEmpty(sources); var cols = new SchemaShape.Column[sources.Length]; // If any input is a var vector, so is the output. bool varVector = false; // If any input is not normalized, the output is not normalized. bool isNormalized = true; // If any input has categorical indices, so will the output. bool hasCategoricals = false; // If any is scalar or had slot names, then the output will have slot names. bool hasSlotNames = false; // We will get the item type from the first column. DataViewType itemType = null; for (int i = 0; i < sources.Length; ++i) { if (!inputSchema.TryFindColumn(sources[i], out var col)) { throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", sources[i]); } if (i == 0) { itemType = col.ItemType; } // For the sake of an estimator I am going to have a hard policy of no keys. // Appending keys makes no real sense anyway. if (col.IsKey) { throw _host.Except($"Column '{sources[i]}' is key." + $"Concatenation of keys is unsupported."); } if (!col.ItemType.Equals(itemType)) { throw _host.Except($"Column '{sources[i]}' has values of {col.ItemType}" + $"which is not the same as earlier observed type of {itemType}."); } varVector |= col.Kind == SchemaShape.Column.VectorKind.VariableVector; isNormalized &= col.IsNormalized(); hasCategoricals |= HasCategoricals(col); hasSlotNames |= col.Kind == SchemaShape.Column.VectorKind.Scalar || col.HasSlotNames(); } var vecKind = varVector ? SchemaShape.Column.VectorKind.VariableVector : SchemaShape.Column.VectorKind.Vector; List <SchemaShape.Column> meta = new List <SchemaShape.Column>(); if (isNormalized) { meta.Add(new SchemaShape.Column(AnnotationUtils.Kinds.IsNormalized, SchemaShape.Column.VectorKind.Scalar, BooleanDataViewType.Instance, false)); } if (hasCategoricals) { meta.Add(new SchemaShape.Column(AnnotationUtils.Kinds.CategoricalSlotRanges, SchemaShape.Column.VectorKind.Vector, NumberDataViewType.Int32, false)); } if (hasSlotNames) { meta.Add(new SchemaShape.Column(AnnotationUtils.Kinds.SlotNames, SchemaShape.Column.VectorKind.Vector, TextDataViewType.Instance, false)); } return(new SchemaShape.Column(name, vecKind, itemType, false, new SchemaShape(meta))); }
private protected SequentialTransformerBase(IHost host, int windowSize, int initialWindowSize, string outputColumnName, string confidenceLowerBoundColumn, string confidenceUpperBoundColumn, string inputColumnName, DataViewType outputColType) : this(host, windowSize, initialWindowSize, outputColumnName, inputColumnName, outputColType) { ConfidenceLowerBoundColumn = confidenceLowerBoundColumn; ConfidenceUpperBoundColumn = confidenceUpperBoundColumn; }
/// <summary> /// Hàm hiển thị, tùy vào viewType là List/Graph và timeType là 5Min/60Min để hiển thị cho phù hợp. /// </summary> /// <param name="_viewType"></param> /// <param name="_timeType"></param> private void reloadViewData(DataViewType _viewType, DataTimeType _timeType) { if (_viewType == DataViewType.List) { chtData.Visible = false; dgvData.Columns.Clear(); dgvData.Visible = true; DataTable dt_source = null; if (_timeType == DataTimeType._5Minute) { dt_source = db5m.get_all_sampler(dtpDateFrom.Value, dtpDateTo.Value); } else //if (_timeType == DataTimeType._60Minute) { dt_source = db60m.get_all_sampler(dtpDateFrom.Value, dtpDateTo.Value); } // Do dt_source chứa date,hour,minute riêng nhau nên phải tạo một dt_view mới gộp các thành phần lại hiển thị cho đẹp hơn DataTable dt_view = new DataTable(); dt_view.Columns.Add("Date"); dt_view.Columns.Add("Time"); dt_view.Columns.Add("Refrigeration_Temperature"); dt_view.Columns.Add("Bottle_Position"); dt_view.Columns.Add("Door_Status"); dt_view.Columns.Add("Equipment_Status"); dt_view.Columns.Add("Status_Val"); // dữ liệu dt_source sang dt_view để hiển thị DataRow viewrow = null; if (dt_source == null) { return; } foreach (DataRow row in dt_source.Rows) { viewrow = dt_view.NewRow(); //viewrow["Date"] = row["stored_date"].ToString().Substring(0, 10); //viewrow["Date"] = (Convert.ToDateTime(row["stored_date"].ToString().Substring(0, 10))).ToString("dd/MM/yyyy"); //viewrow["Date"] = (Convert.ToDateTime(row["stored_date"].ToString().Substring(0, 10))).ToString("dd/MM/yyyy"); viewrow["Date"] = (Convert.ToDateTime(row["stored_date"].ToString())).ToString("dd/MM/yyyy"); //viewrow["Date"] = (Convert.ToDateTime((row["stored_date"].ToString().Split(' '))[0])).ToString("dd/MM/yyyy"); viewrow["Time"] = ((int)row["stored_hour"]).ToString("00") + ":" + ((int)row["stored_minute"]).ToString("00") + ":00"; viewrow["Refrigeration_Temperature"] = row["refrigeration_temperature"]; viewrow["Bottle_Position"] = row["bottle_position"]; viewrow["Door_Status"] = row["door_status"]; viewrow["Equipment_Status"] = row["equipment_status"]; viewrow["Status_Val"] = row["equipment_status"]; dt_view.Rows.Add(viewrow); } dgvData.DataSource = dt_view; // thêm cột Status có màu phù hợp với status DataGridViewImageColumn imgColumnStatus = new DataGridViewImageColumn(); imgColumnStatus.Name = "Status"; dgvData.Columns.Add(imgColumnStatus); dgvData.Columns["Status_Val"].Visible = false; // ẩn cột status bằng số, chỉ để lại cột status có màu int status_val = 0; foreach (DataGridViewRow row in dgvData.Rows) { if (row.Cells["Status_Val"].Value != null) { Int32.TryParse(row.Cells["Status_Val"].Value.ToString(), out status_val); if (status_val == 0) { row.Cells["Status"].Value = (System.Drawing.Image)Properties.Resources.Normal_status_x16; } else if (status_val == 4) { row.Cells["Status"].Value = (System.Drawing.Image)Properties.Resources.bottle_position_18x18; } else { row.Cells["Status"].Value = (System.Drawing.Image)Properties.Resources.Fault_status_x16; } } if (row.Cells["Refrigeration_Temperature"].Value != null) { if (Convert.ToDouble(row.Cells["Refrigeration_Temperature"].Value) < 0) { row.Cells["Refrigeration_Temperature"].Value = "---"; } } if (row.Cells["Bottle_Position"].Value != null) { if (Convert.ToDouble(row.Cells["Bottle_Position"].Value) < 0) { row.Cells["Bottle_Position"].Value = "---"; } } if (row.Cells["Door_Status"].Value != null) { if (Convert.ToDouble(row.Cells["Door_Status"].Value) < 0) { row.Cells["Door_Status"].Value = "---"; } } if (row.Cells["Equipment_Status"].Value != null) { if (Convert.ToDouble(row.Cells["Equipment_Status"].Value) < 0) { row.Cells["Equipment_Status"].Value = "---"; } } } } else //if(_viewType == DataViewType.Graph) { dgvData.Visible = false; chtData.Series.Clear(); chtData.Visible = true; DataTable dt_source = null; if (_timeType == DataTimeType._5Minute) { dt_source = db5m.get_all_sampler(dtpDateFrom.Value, dtpDateTo.Value); } else //if (_timeType == DataTimeType._60Minute) { dt_source = db60m.get_all_sampler(dtpDateFrom.Value, dtpDateTo.Value); } DataTable dt_view = new DataTable(); dt_view.Columns.Add("StoredDate"); dt_view.Columns.Add("Refrigeration_Temperature"); dt_view.Columns.Add("Bottle_Position"); dt_view.Columns.Add("Door_Status"); dt_view.Columns.Add("Equipment_Status"); dt_view.Columns.Add("Status_Val"); // chuyển dữ liệu dt_source sang dt_view để hiển thị DataRow viewrow = null; if (dt_source == null) { return; } foreach (DataRow row in dt_source.Rows) { // kiểm tra status, chỉ lấy chững status normal int _status = (int)row["equipment_status"]; if (_status == 0) { viewrow = dt_view.NewRow(); DateTime _date = (DateTime)row["stored_date"]; int _hour = (int)row["stored_hour"]; int _minute = (int)row["stored_minute"]; DateTime _rdate = new DateTime(_date.Year, _date.Month, _date.Day, _hour, _minute, 0); viewrow["StoredDate"] = _rdate; viewrow["Refrigeration_Temperature"] = row["refrigeration_temperature"]; viewrow["Bottle_Position"] = row["bottle_position"]; viewrow["Door_Status"] = row["door_status"]; viewrow["Equipment_Status"] = row["equipment_status"]; viewrow["Status_Val"] = row["equipment_status"]; dt_view.Rows.Add(viewrow); } } // tạo biểu đồ mới chtData.Series.Add("Refrigeration_Temperature"); chtData.Series["Refrigeration_Temperature"].XValueMember = "StoredDate"; chtData.Series["Refrigeration_Temperature"].YValueMembers = "Refrigeration_Temperature"; chtData.Series["Refrigeration_Temperature"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chtData.Series["Refrigeration_Temperature"].Color = Color.Blue; chtData.Series["Refrigeration_Temperature"].BorderWidth = 3; chtData.Series.Add("Bottle_Position"); chtData.Series["Bottle_Position"].XValueMember = "StoredDate"; chtData.Series["Bottle_Position"].YValueMembers = "Bottle_Position"; chtData.Series["Bottle_Position"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline; chtData.Series["Bottle_Position"].Color = Color.Red; chtData.Series["Bottle_Position"].BorderWidth = 3; chtData.ChartAreas[0].AxisX.MajorGrid.Enabled = true; chtData.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray; chtData.ChartAreas[0].AxisX.MinorGrid.Enabled = true; chtData.ChartAreas[0].AxisX.MinorGrid.LineColor = Color.WhiteSmoke; chtData.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot; chtData.ChartAreas[0].AxisX.Title = "Date"; chtData.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines; chtData.ChartAreas[0].AxisY.MajorGrid.Enabled = true; chtData.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray; chtData.ChartAreas[0].AxisY.MinorGrid.Enabled = true; chtData.ChartAreas[0].AxisY.MinorGrid.LineColor = Color.WhiteSmoke; chtData.ChartAreas[0].AxisY.Title = "Auto Sampler (mg/L)"; chtData.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines; chtData.DataSource = dt_view; chtData.DataBind(); } }
private void GetLabels(Transposer trans, DataViewType labelType, int labelCol) { int min; int lim; var labels = default(VBuffer <int>); // Note: NAs have their own separate bin. if (labelType == NumberDataViewType.Int32) { var tmp = default(VBuffer <int>); trans.GetSingleSlotValue(labelCol, ref tmp); BinInts(in tmp, ref labels, _numBins, out min, out lim); _numLabels = lim - min; } else if (labelType == NumberDataViewType.Single) { var tmp = default(VBuffer <Single>); trans.GetSingleSlotValue(labelCol, ref tmp); BinSingles(in tmp, ref labels, _numBins, out min, out lim); _numLabels = lim - min; } else if (labelType == NumberDataViewType.Double) { var tmp = default(VBuffer <Double>); trans.GetSingleSlotValue(labelCol, ref tmp); BinDoubles(in tmp, ref labels, _numBins, out min, out lim); _numLabels = lim - min; } else if (labelType is BooleanDataViewType) { var tmp = default(VBuffer <bool>); trans.GetSingleSlotValue(labelCol, ref tmp); BinBools(in tmp, ref labels); _numLabels = 3; min = -1; lim = 2; } else { ulong labelKeyCount = labelType.GetKeyCount(); Contracts.Assert(labelKeyCount < Utils.ArrayMaxSize); KeyLabelGetter <int> del = GetKeyLabels <int>; var methodInfo = del.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod(labelType.RawType); var parameters = new object[] { trans, labelCol, labelType }; _labels = (VBuffer <int>)methodInfo.Invoke(this, parameters); _numLabels = labelType.GetKeyCountAsInt32(_host) + 1; // No need to densify or shift in this case. return; } // Densify and shift labels. VBufferUtils.Densify(ref labels); Contracts.Assert(labels.IsDense); var labelsEditor = VBufferEditor.CreateFromBuffer(ref labels); for (int i = 0; i < labels.Length; i++) { labelsEditor.Values[i] -= min; Contracts.Assert(labelsEditor.Values[i] < _numLabels); } _labels = labelsEditor.Commit(); }
public OnnxVariableInfo(string name, OnnxShape shape, Type typeInOnnxRuntime, DataViewType mlnetType, Func <NamedOnnxValue, object> caster) { Name = name; Shape = shape; TypeInOnnxRuntime = typeInOnnxRuntime; DataViewType = mlnetType; Caster = caster; }
private Delegate GetIsNADelegate <T>(DataViewType type) => Data.Conversion.Conversions.Instance.GetIsNAPredicate <T>(type.GetItemType());
/// <summary> /// Adds an output variable to the list. /// </summary> public void AddOutputVariable(DataViewType type, string variableName, List <long> dim = null) { _host.CheckValue(type, nameof(type)); _host.CheckParam(IsVariableDefined(variableName), nameof(variableName)); _outputs.Add(OnnxUtils.GetModelArgs(type, variableName, dim)); }
protected Func <bool> GetColumnComparer(DataViewRow r1, DataViewRow r2, int col, DataViewType type, bool exactDoubles) { if (type is VectorDataViewType vecType) { int size = vecType.Size; Contracts.Assert(size >= 0); var result = vecType.ItemType.RawType.TryGetDataKind(out var kind); Contracts.Assert(result); switch (kind) { case InternalDataKind.I1: return(GetComparerVec <sbyte>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.U1: return(GetComparerVec <byte>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.I2: return(GetComparerVec <short>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.U2: return(GetComparerVec <ushort>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.I4: return(GetComparerVec <int>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.U4: return(GetComparerVec <uint>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.I8: return(GetComparerVec <long>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.U8: return(GetComparerVec <ulong>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.R4: return(GetComparerVec <Single>(r1, r2, col, size, (x, y) => FloatUtils.GetBits(x) == FloatUtils.GetBits(y))); case InternalDataKind.R8: if (exactDoubles) { return(GetComparerVec <Double>(r1, r2, col, size, (x, y) => FloatUtils.GetBits(x) == FloatUtils.GetBits(y))); } else { return(GetComparerVec <Double>(r1, r2, col, size, EqualWithEps)); } case InternalDataKind.Text: return(GetComparerVec <ReadOnlyMemory <char> >(r1, r2, col, size, (a, b) => a.Span.SequenceEqual(b.Span))); case InternalDataKind.Bool: return(GetComparerVec <bool>(r1, r2, col, size, (x, y) => x == y)); case InternalDataKind.TimeSpan: return(GetComparerVec <TimeSpan>(r1, r2, col, size, (x, y) => x.Ticks == y.Ticks)); case InternalDataKind.DT: return(GetComparerVec <DateTime>(r1, r2, col, size, (x, y) => x.Ticks == y.Ticks)); case InternalDataKind.DZ: return(GetComparerVec <DateTimeOffset>(r1, r2, col, size, (x, y) => x.Equals(y))); case InternalDataKind.UG: return(GetComparerVec <DataViewRowId>(r1, r2, col, size, (x, y) => x.Equals(y))); } } else { var result = type.RawType.TryGetDataKind(out var kind); Contracts.Assert(result); switch (kind) { case InternalDataKind.I1: return(GetComparerOne <sbyte>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.U1: return(GetComparerOne <byte>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.I2: return(GetComparerOne <short>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.U2: return(GetComparerOne <ushort>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.I4: return(GetComparerOne <int>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.U4: return(GetComparerOne <uint>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.I8: return(GetComparerOne <long>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.U8: return(GetComparerOne <ulong>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.R4: return(GetComparerOne <Single>(r1, r2, col, (x, y) => FloatUtils.GetBits(x) == FloatUtils.GetBits(y))); case InternalDataKind.R8: if (exactDoubles) { return(GetComparerOne <Double>(r1, r2, col, (x, y) => FloatUtils.GetBits(x) == FloatUtils.GetBits(y))); } else { return(GetComparerOne <Double>(r1, r2, col, EqualWithEps)); } case InternalDataKind.Text: return(GetComparerOne <ReadOnlyMemory <char> >(r1, r2, col, (a, b) => a.Span.SequenceEqual(b.Span))); case InternalDataKind.Bool: return(GetComparerOne <bool>(r1, r2, col, (x, y) => x == y)); case InternalDataKind.TimeSpan: return(GetComparerOne <TimeSpan>(r1, r2, col, (x, y) => x.Ticks == y.Ticks)); case InternalDataKind.DT: return(GetComparerOne <DateTime>(r1, r2, col, (x, y) => x.Ticks == y.Ticks)); case InternalDataKind.DZ: return(GetComparerOne <DateTimeOffset>(r1, r2, col, (x, y) => x.Equals(y))); case InternalDataKind.UG: return(GetComparerOne <DataViewRowId>(r1, r2, col, (x, y) => x.Equals(y))); } } #if !CORECLR // REVIEW: Port Picture type to CoreTLC. if (type is PictureType) { var g1 = r1.GetGetter <Picture>(col); var g2 = r2.GetGetter <Picture>(col); Picture v1 = null; Picture v2 = null; return (() => { g1(ref v1); g2(ref v2); return ComparePicture(v1, v2); }); } #endif throw Contracts.Except("Unknown type in GetColumnComparer: '{0}'", type); }
internal override IColumnFunctionBuilder MakeBuilder(IHost host, int srcIndex, DataViewType srcType, DataViewRowCursor cursor) => NormalizeTransform.LogMeanVarUtils.CreateBuilder(this, host, srcIndex, srcType, cursor);
public static bool IsValidColumnType(DataViewType type) => type == NumberDataViewType.Single || type == NumberDataViewType.Double || type is TextDataViewType;
internal override IColumnFunctionBuilder MakeBuilder(IHost host, int srcIndex, DataViewType srcType, DataViewRowCursor cursor) => NormalizeTransform.SupervisedBinUtils.CreateBuilder(this, host, LabelColumnName, srcIndex, srcType, cursor);
private BoundColumn MakeColumn(DataViewSchema inputSchema, int iinfo) { Contracts.AssertValue(inputSchema); Contracts.Assert(0 <= iinfo && iinfo < _parent._columns.Length); DataViewType itemType = null; int[] sources = new int[_parent._columns[iinfo].Sources.Count]; // Go through the columns, and establish the following: // - indices of input columns in the input schema. Throw if they are not there. // - output type. Throw if the types of inputs are not the same. // - how many slots are there in the output vector (or variable). Denoted by totalSize. // - total size of CategoricalSlotRanges metadata, if present. Denoted by catCount. // - whether the column is normalized. // It is true when ALL inputs are normalized (and of numeric type). // - whether the column has slot names. // It is true if ANY input is a scalar, or has slot names. // - whether the column has categorical slot ranges. // It is true if ANY input has this metadata. int totalSize = 0; int catCount = 0; bool isNormalized = true; bool hasSlotNames = false; bool hasCategoricals = false; for (int i = 0; i < _parent._columns[iinfo].Sources.Count; i++) { var(srcName, srcAlias) = _parent._columns[iinfo].Sources[i]; if (!inputSchema.TryGetColumnIndex(srcName, out int srcCol)) { throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", srcName); } sources[i] = srcCol; var curType = inputSchema[srcCol].Type; VectorDataViewType curVectorType = curType as VectorDataViewType; DataViewType currentItemType = curVectorType?.ItemType ?? curType; int currentValueCount = curVectorType?.Size ?? 1; if (itemType == null) { itemType = currentItemType; totalSize = currentValueCount; } else if (currentItemType.Equals(itemType)) { // If any one input is variable length, then the output is variable length. if (totalSize == 0 || currentValueCount == 0) { totalSize = 0; } else { totalSize += currentValueCount; } } else { throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", srcName, itemType.ToString(), curType.ToString()); } if (isNormalized && !inputSchema[srcCol].IsNormalized()) { isNormalized = false; } if (AnnotationUtils.TryGetCategoricalFeatureIndices(inputSchema, srcCol, out int[] typeCat))
internal abstract IColumnFunctionBuilder MakeBuilder(IHost host, int srcIndex, DataViewType srcType, DataViewRowCursor cursor);
/// <summary> /// Returns whether a type is a U4 key of known cardinality, and if so, sets /// <paramref name="keyType"/> to a non-null value. /// </summary> private static bool TryMarshalGoodRowColumnType(DataViewType type, out KeyDataViewType keyType) { keyType = type as KeyDataViewType; return(keyType?.Count > 0 && type.RawType == typeof(uint)); }
private void btnListType_Click(object sender, EventArgs e) { currentViewType = DataViewType.List; }