private Table CreateMasterDataTable(Table data, Table facts, HashSet<string> selIds) { if (data == null) return new Table(); if (data.Rows == 0) return data; HashSet<int> factCols = new HashSet<int>(); foreach (string id in selIds) { int col = data.ColumnDefinitions.IndexOf(id); if (col < 0) { col = facts.ColumnDefinitions.IndexOf(id); if (col < 0) { throw new Exception("No such column: " + id); } factCols.Add(col); } } if (factCols.Count == 0) return data; int dataCols = data.Cols; foreach (int c in factCols) { data.ColumnDefinitions.Add(facts.ColumnDefinitions[c]); } TableIndex idx = facts.GetIndex(new string[3] { "LogTypeID", "ResID", "AttrID" }); for (int i = 0; i < data.Rows; i++) { Element[] row = data.Row(i); string key = data[i, "LogTypeID"].ToString() + "," + data[i, "ResID"].ToString() + "," + data[i, "AttrID"].ToString(); int m = idx.FindEqual(new Element(key))[0]; Element[] r = facts.Row(m); int j = 0; foreach (int c in factCols) { row[dataCols + j] = r[c]; j++; } } return data; }
List<List<int>> Partition(Table data, List<int> source, List<Mapper> mappers) { List<List<int>> s = new List<List<int>>(); s.Add(source); foreach (Mapper m in mappers) { Dictionary<string, List<int>> groups = new Dictionary<string, List<int>>(); foreach (List<int> q in s) { foreach (int row in q) { string key = m.Map(data.Row(row)); List<int> l; if (!groups.TryGetValue(key.ToString(), out l)) { l = new List<int>(); groups.Add(key.ToString(), l); } l.Add(row); } } s.Clear(); foreach (var p in groups) { s.Add(p.Value); } } return s; }
public virtual void UnionWith(Table b) { if (this.Cols != b.Cols) { throw new Exception("Table columns must agree."); } for (int i = 0; i < this.Cols; i++) { if (b.ColumnDefinitions[i].DataType != b.ColumnDefinitions[i].DataType) { throw new Exception("Table column definitions must agree."); } } Dictionary<string, Element[]> rows = new Dictionary<string, Element[]>(); for (int i = 0; i < this.Rows; i++) { Element[] row = this.Row(i); string key = MakeRowKey(row); if (!rows.ContainsKey(key)) { rows.Add(key, row); } } for (int i = 0; i < b.Rows; i++) { Element[] row = b.Row(i); string key = MakeRowKey(row); if (!rows.ContainsKey(key)) { rows.Add(key, row); } } List<Element[]> newRows = new List<Element[]>(); foreach (Element[] row in rows.Values) { newRows.Add(row); } _rows = newRows; }
private List<List<int>> Group(Table data, List<int> source, Mapper mapper) { Dictionary<string, List<int>> groups = new Dictionary<string, List<int>>(); foreach (int p in source) { string key = mapper.Map(data.Row(p)); if (!groups.ContainsKey(key)) groups.Add(key, new List<int>()); groups[key].Add(p); } List<List<int>> r = new List<List<int>>(); foreach (var g in groups.Values) { r.Add(g); } return r; }