我有一个日志表:第一列是日期时间,第二列是应用名称,下一列是指标(CPU时间,内存,......)。 我需要按app对指标进行分组,然后按日期时间加入所有指标(每个指标加入一个新表)。
表:
结果(与度量列一样多的表):
class Table
{
public int nrows { get; protected set; }
public int ncols { get; protected set; }
public List<Row> rows { get; protected set; }
public List<Column> cols { get; protected set; }
public Table (List<string[]> data)
{
nrows = data.Count;
ncols = data[0].Length;
rows = data;
cols = new List<Column>(data[0].Length
for (int i = 0; i < rows[0].data.Length; i++)
cols.Add(new Column(rows.Select(row => row.data[i]).ToArray()));
}
}
class Column
{
public string[] data{ get; protected set; }
public Column(string[] _data)
{
data = _data;
}
}
class Row : IComparable, IComparer<Row>
{
public string time;
public string[] data;
public Row(string _date, params string[] _data)
{
time = _date;
data = _data;
}
public int CompareTo( object obj )
{
if(obj is Row)
return time.CompareTo( ( obj as Row ).time );
else
throw new ArgumentException("Wrong data type.");
}
int IComparer<Row>.Compare(Row x, Row y)
{
return string.Compare( x.time , y.time );
}
public override bool Equals(object obj) {
Row row = obj as Row;
return row != null && time.Equals(row.time);
}
public override int GetHashCode() {
return time.GetHashCode();
}
}
我有桌子,我已经按应用名称创建了一个分组列表:
List<Row[]> groups = table.rows.GroupBy(row => row.data[1]).Select( group => group.Distinct().ToArray() ).ToList();
List<Column[]> columns = new List<Column[]>(table.ncols);
for (int i = 0; i < table.ncols; i++)
columns.Add(groups.Select(group => new Column(group.Select(row => row.data[i]).ToArray())).ToArray());
我有一个列数组列表。我需要在日期时间为列表中的每个位置加入数组。我被困在这里。我怎样才能加入这些专栏?我不知道列是否是个好主意......