public static bool ToDateTimeValue(this Metric metric, out List <string> name, out List <List <object> > value, out List <DateTime> timeStamp, out bool isHistorical) { value = null; var rows = metric.dataset_value.rows.Count; var columns = (int)metric.dataset_value.num_of_columns; isHistorical = metric.is_historical; timeStamp = new List <DateTime>(); // get the name name = metric.dataset_value.columns; // get the time stamp for (var index = 0; index < rows; index++) { var raw = metric.dataset_value.rows[index].elements[0].long_value; timeStamp.Add(raw.FromUnixTimeULong()); } // get the value value = new List <List <object> >(); for (var jndex = 1; jndex < columns; jndex++) { value.Add(new List <object>()); for (var index = 0; index < rows; index++) { value[jndex - 1].Add( DataSetValue.FromDataSetType(metric.dataset_value.rows[index].elements[jndex], metric.dataset_value.types[jndex])); } } return(true); }
public static object FromDataSetType(DataSetValue dataSetValue, uint dataType) { switch (dataType) { case (int)DataType.Boolean: return(dataSetValue.boolean_value); case (int)DataType.Double: return(dataSetValue.double_value); case (int)DataType.Float: return(dataSetValue.float_value); case (int)DataType.UInt64: return(dataSetValue.long_value); case (int)DataType.UInt32: return(dataSetValue.int_value); case (int)DataType.String: return(dataSetValue.string_value); default: return(dataSetValue.string_value); } }
public static void New(this Metric metric, List <string> name, List <List <object> > value, List <DateTime> timeStamp, bool isHistorical) { metric.name = "datatable"; metric.is_historical = isHistorical; if (value == null || timeStamp == null) { metric.is_null = true; return; } metric.SetTimeStamp(timeStamp[0]); metric.dataset_value = new DataSet { num_of_columns = (ulong)(value.Count + 1), columns = new List <string> { "timestamp" }, types = new List <uint> { 8 } }; metric.dataset_value.columns.AddRange(name); value.ForEach(n => { var dataType = DataTypeClass.DataTypeLookUp.ContainsKey(n[0].GetType()) ? DataTypeClass.DataTypeLookUp[n[0].GetType()] : (uint)12; metric.dataset_value.types.Add(dataType); }); var row = new Row { elements = new List <DataSetValue>() }; value.ForEach(m => { for (var index = 0; index < m.Count; index++) { row.elements.Add(DataSetValue.ToDataSetValue( timeStamp[index].ToUnixTimeULong())); row.elements.Add(DataSetValue.ToDataSetValue(m[index])); } }); metric.datatype = 16; metric.dataset_value.rows.Add(row); }
public static DataSetValue ToDataSetValue(object value) { var dataSetValue = new DataSetValue(); if (value == null) { return(dataSetValue); } //dataSetValue.timestamp = (ulong)(new DateTimeOffset(timeStamp).ToUnixTimeMilliseconds()); switch (value) { case bool b: dataSetValue.boolean_value = b; break; case double d: dataSetValue.double_value = d; break; case float f: dataSetValue.float_value = f; break; case long l: dataSetValue.long_value = (ulong)value; break; case int _: case short _: dataSetValue.int_value = (uint)value; break; case string s: dataSetValue.string_value = s; break; default: dataSetValue.string_value = value.ToString(); break; } return(dataSetValue); }