// Convenience to build grid from array of HHisItem public static HGrid hisItemsToGrid(HDict meta, HHisItem[] items) { HGridBuilder b = new HGridBuilder(); b.Meta.add(meta); b.addCol("ts"); b.addCol("val"); for (int i = 0; i < items.Length; ++i) { b.addRow(new HVal[] { items[i].TimeStamp, items[i].hsVal }); } return(b.toGrid()); }
////////////////////////////////////////////////////////////////////////// // Utils ////////////////////////////////////////////////////////////////////////// // Convenience to build one row grid from HDict. public static HGrid dictToGrid(HDict dict) { HGridBuilder b = new HGridBuilder(); int iIndex = 0; List <HVal> cells = new List <HVal>(); for (iIndex = 0; iIndex < dict.size(); iIndex++) { string strKey = dict.getKeyAt(iIndex, false); if (strKey != null) { HVal val = dict.get(strKey); b.addCol(strKey); cells.Add(val); } } b.addRow(cells.ToArray()); return(b.toGrid()); }
// Convenience to build grid from array of HDict. // Any null entry will be row of all null cells. public static HGrid dictsToGrid(HDict meta, HDict[] dicts) { HCol colEmpty = new HCol(0, "empty", HDict.Empty); // If empty return an empty cols collection and no values Grid if (dicts.Length == 0) { List <List <HVal> > rowListEmpty = new List <List <HVal> >(); List <HCol> rowEmpty = new List <HCol>(); rowEmpty.Add(colEmpty); return(new HGrid(meta, rowEmpty, rowListEmpty)); } HGridBuilder b = new HGridBuilder(); b.Meta.add(meta); // collect column names - why does this need to be a dictionary (hashmap in the java code)? // it only stores the col name twice. Dictionary <string, string> colsByName = new Dictionary <string, string>(); for (int i = 0; i < dicts.Length; ++i) { HDict dict = dicts[i]; if (dict != null) { for (int it = 0; it < dict.size(); it++) { string name = dict.getKeyAt(it, false); if (name != null) { if (!colsByName.Keys.Contains(name)) { colsByName.Add(name, name); b.addCol(name); } } } } } // if all dicts were null, handle special case // by creating a dummy column if (colsByName.Count == 0) { colsByName.Add("empty", "empty"); b.addCol("empty"); } // now map rows int numCols = b.colCount; for (int ri = 0; ri < dicts.Length; ++ri) { HDict dict = dicts[ri]; HVal[] cells = new HVal[numCols]; for (int ci = 0; ci < numCols; ++ci) { if (dict == null) { cells[ci] = null; } else { BCol colatci = b.GetColAt(ci); if (colatci != null) { cells[ci] = dict.get(colatci.Name, false); } } } b.addRow(cells); } return(b.toGrid()); }