Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-5722: Add table client-side sorting #55

Merged
merged 1 commit into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import edu.caltech.ipac.firefly.server.query.DataAccessException;
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupPart;
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupReader;
import edu.caltech.ipac.firefly.server.util.ipactable.TableDef;
import edu.caltech.ipac.util.AppProperties;
import edu.caltech.ipac.util.CollectionUtil;
import edu.caltech.ipac.util.DataGroup;
Expand Down Expand Up @@ -266,6 +267,16 @@ public static RawDataSet convertToRawDataset(DataGroup dg, int startIdx, int pag
return dataset;
}

public static DataGroupPart convertToDataGroupPart(DataGroup dg, int startIdx, int pageSize) {
DataGroup page = dg.subset(startIdx, startIdx+pageSize);
page.setRowIdxOffset(startIdx);
TableDef tableDef = new TableDef();
tableDef.setSource("unknown");
tableDef.setStatus(DataGroupPart.State.COMPLETED);
tableDef.setCols(Arrays.asList(page.getDataDefinitions()));

return new DataGroupPart(tableDef, dg, startIdx, page.size());
}

/**
* return Float.NaN if val is null or not a float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.caltech.ipac.firefly.data.SortInfo;
import edu.caltech.ipac.firefly.data.TableServerRequest;
import edu.caltech.ipac.firefly.data.table.TableMeta;
import edu.caltech.ipac.firefly.server.util.QueryUtil;
import edu.caltech.ipac.firefly.util.DataSetParser;
import edu.caltech.ipac.firefly.visualize.Band;
import edu.caltech.ipac.util.*;
Expand Down Expand Up @@ -46,8 +47,10 @@ public static JSONObject toJsonTableModel(DataGroupPart page, TableMeta meta, Ta
}
}
}
for (String key : request.getMeta().keySet()) {
meta.setAttribute(key, request.getMeta(key));
if (request != null && request.getMeta() != null) {
for (String key : request.getMeta().keySet()) {
meta.setAttribute(key, request.getMeta(key));
}
}
String tblId = meta.getAttribute(TableServerRequest.TBL_ID);

Expand All @@ -58,7 +61,7 @@ public static JSONObject toJsonTableModel(DataGroupPart page, TableMeta meta, Ta
tableModel.put("totalRows", page.getRowCount());

if (page.getData() != null ) {
tableModel.put("tableData", toJsonTableData(page.getData(), page.getTableDef(), meta));
tableModel.put("tableData", toJsonTableData(page.getData(), page.getTableDef(), meta));
}


Expand Down Expand Up @@ -203,37 +206,17 @@ private static Object guessType(TableMeta meta) {
//=============================

//LZ DM-4494
public static String toJsonString(DataGroup dataGroup, Long fileSize, String tableID) throws IOException {

DataGroupPart dp = new DataGroupPart();
dp.setData(dataGroup);

TableServerRequest request = new TableServerRequest("fitsHeaderTale");
request.setMeta(TableServerRequest.TBL_ID, tableID);

TableMeta meta = new TableMeta("fitsHeader");
meta.setFileSize((fileSize));

JSONObject jsonObj = JsonTableUtil.toJsonTableModel(dp, meta, request);



return jsonObj.toJSONString();


}

//LZ DM-4494
public static String dataGroupMapToJasonString(HashMap<Band, DataGroup> dataMap,HashMap<Band,Long> fileSizeMap, String tableID) throws IOException {


public static JSONObject toJsonTableModelMap(Map<String, DataGroup> dataMap, Map<String, TableMeta> metaMap, TableServerRequest request) throws IOException {
JSONObject jsoObj = new JSONObject();
for (Band band : dataMap.keySet()) {
jsoObj.put(band.name(), toJsonString(dataMap.get(band), fileSizeMap.get(band), tableID));
for (Object key : dataMap.keySet()) {
TableMeta meta = metaMap.get(key);
DataGroupPart dp = QueryUtil.convertToDataGroupPart(dataMap.get(key), 0, Integer.MAX_VALUE);
JSONObject aJsonTable = JsonTableUtil.toJsonTableModel(dp, meta, request);

}
jsoObj.put(key, aJsonTable);

return jsoObj.toJSONString();
}
return jsoObj;
}

//============================= //============================= //============================= //============================= //============================= //=============================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void addAttributes(DataGroup.Attribute... attributes) {
}
}
}
public void setCols(List<DataType> cols) { this.cols = cols; }

public List<DataType> getCols() {
return cols;
Expand Down Expand Up @@ -99,14 +100,6 @@ public void setRowCount(int rowCount) {
this.rowCount = rowCount < 0 ? 0 : rowCount;
}

public int getColCount() {
return colCount;
}

public void setColCount(int colCount) {
this.colCount = colCount;
}

public int getRowStartOffset() {
return rowStartOffset;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import edu.caltech.ipac.firefly.server.servlets.CommandService;
import edu.caltech.ipac.firefly.server.util.Logger;
import edu.caltech.ipac.firefly.server.util.ipactable.JsonTableUtil;
import edu.caltech.ipac.firefly.server.util.ipactable.TableDef;
import edu.caltech.ipac.firefly.visualize.Band;
import edu.caltech.ipac.firefly.visualize.FileAndHeaderInfo;
import edu.caltech.ipac.firefly.visualize.PlotState;
Expand Down Expand Up @@ -286,12 +285,13 @@ public String doCommand(Map<String, String[]> paramMap) throws IllegalArgumentEx
//TableServerRequest req=TableServerRequest.parse(sp.getRequired(ServerParams.FITS_HEADER));
PlotState state= sp.getState();

Object[] dataInfo = VisServerOps.getFitsHeader(state);
HashMap<Band, DataGroup> dataGroupMap= (HashMap<Band, DataGroup> ) dataInfo[0];
HashMap<Band, Long> fileSizeMap = ( HashMap<Band, Long> ) dataInfo[1];
Object[] dataInfo = VisServerOps.getFitsHeader(state, tableID);
HashMap<String, DataGroup> dataGroupMap= (HashMap<String, DataGroup> ) dataInfo[0];
HashMap<String, TableMeta> metaMap = ( HashMap<String, TableMeta> ) dataInfo[1];


return JsonTableUtil.dataGroupMapToJasonString(dataGroupMap, fileSizeMap,tableID);
TableServerRequest treq = new TableServerRequest("fitsHeaderTale");
treq.setPageSize(Integer.MAX_VALUE);
return JsonTableUtil.toJsonTableModelMap(dataGroupMap, metaMap, treq).toJSONString();


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import edu.caltech.ipac.firefly.data.BandInfo;
import edu.caltech.ipac.firefly.data.DataEntry;
import edu.caltech.ipac.firefly.data.TableServerRequest;
import edu.caltech.ipac.firefly.data.table.RawDataSet;
import edu.caltech.ipac.firefly.data.table.TableMeta;
import edu.caltech.ipac.firefly.server.Counters;
import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.firefly.server.cache.UserCache;
Expand Down Expand Up @@ -1014,7 +1016,7 @@ public static WebPlotResult getFitsHeaderInfo(PlotState state) {
*/

public static Map getFitsHeaderExtend(PlotState state) throws FitsException {
HashMap<Band, DataGroup> dataMap = new HashMap<Band, DataGroup>();
HashMap<String, DataGroup> dataMap = new HashMap<String, DataGroup>();
ActiveCallCtx ctx = null;

try {
Expand All @@ -1025,7 +1027,7 @@ public static Map getFitsHeaderExtend(PlotState state) throws FitsException {
FitsRead fr = plot.getHistogramOps(band, ctx.getFitsReadGroup()).getFitsRead();
DataGroup dg = getFitsHeaders(fr.getHeader(), plot.getPlotDesc());

dataMap.put(band, dg);
dataMap.put(band.name(), dg);

}
return dataMap;
Expand All @@ -1045,31 +1047,38 @@ public static Map getFitsHeaderExtend(PlotState state) throws FitsException {
* @return
*/

public static Object[] getFitsHeader(PlotState state) throws FitsException {
public static Object[] getFitsHeader(PlotState state, String tableID) throws FitsException {


HashMap<Band, DataGroup> dataMap = new HashMap< Band, DataGroup>();
HashMap<String, DataGroup> dataMap = new HashMap<String, DataGroup>();

HashMap<Band, Long> fileSizeMap = new HashMap<Band, Long>();
HashMap<String, TableMeta> metaMap = new HashMap<String, TableMeta>();
try {
for (Band band : state.getBands()) {
File f = PlotStateUtil.getWorkingFitsFile(state, band);
if (f == null) f = PlotStateUtil.getOriginalFile(state, band);
Fits fits = new Fits(f);
fileSizeMap.put(band,f.length() );
TableServerRequest request = new TableServerRequest("fitsHeaderTale");
request.setMeta(TableServerRequest.TBL_ID, tableID);

TableMeta meta = new TableMeta("fitsHeader");
meta.setFileSize(f.length());
meta.setAttribute(TableServerRequest.TBL_ID, tableID + '-' + band.name());

metaMap.put(band.name(), meta);
BasicHDU hdu[] = fits.read();
Header header = hdu[0].getHeader();
if (header.containsKey("EXTEND") && header.getBooleanValue("EXTEND")) {
dataMap = (HashMap<Band, DataGroup>) getFitsHeaderExtend(state);
dataMap = (HashMap<String, DataGroup>) getFitsHeaderExtend(state);
} else {
DataGroup dg = getFitsHeaders(header, "fits data");

dataMap.put(band, dg);
dataMap.put(band.name(), dg);
}
}

////LZcounters.incrementVis("Fits header");
Object[] mapObj = {dataMap, fileSizeMap};
Object[] mapObj = {dataMap, metaMap};
return mapObj;

}
Expand Down
5 changes: 1 addition & 4 deletions src/firefly/java/edu/caltech/ipac/util/IpacTableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,7 @@ public static TableDef getMetaInfo(BufferedReader reader, File src) throws IOExc
meta.addAttributes(attribs.toArray(new DataGroup.Attribute[attribs.size()]));
}
if (cols != null) {
for (DataType c : cols) {
meta.addCols(c);
}
meta.setColCount(cols.size());
meta.setCols(cols);
}
if (src != null) {
long totalRow = meta.getLineWidth() == 0 ? 0 :
Expand Down
10 changes: 8 additions & 2 deletions src/firefly/js/tables/SortInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ export const UNSORTED = '';
**/
export class SortInfo {
constructor(direction=UNSORTED, sortColumns=[]) {
this.direction = direction !== SORT_DESC ? SORT_ASC : direction;
this.direction = direction;
this.sortColumns = sortColumns;
}

/**
* returns the sort direction of the given column name based on
* this SortInfo.
* @param colName
* @returns {*}
*/
getDirection(colName) {
if (this.sortColumns.includes(colName)) {
return this.direction;
Expand All @@ -33,7 +39,7 @@ export const UNSORTED = '';
const dir = this.getDirection(colName);
this.direction = dir === UNSORTED ? SORT_ASC :
dir === SORT_ASC ? SORT_DESC : UNSORTED;
this.sortColumns = [colName];
this.sortColumns = UNSORTED ? [] : [colName];
return this;
}

Expand Down
47 changes: 31 additions & 16 deletions src/firefly/js/tables/TableStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import * as TblUtil from './TableUtil.js';
import {SelectInfo} from './SelectInfo.js';

export class TableStore {

/**
*
* @param props props from Table
* @param changeListener function called when data changed
*/
constructor(props, changeListener) {
this.init(props);
this.changeListener = changeListener;
Expand Down Expand Up @@ -39,15 +45,17 @@ export class TableStore {
}
}

onUnmount() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is onUnmount a place holder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually being called. But in this case, it does nothing.


onSort(sortInfoString) {
const {request} = this.cState.tableModel;
request.sortInfo = sortInfoString;
var {request} = this.cState.tableModel;
request = Object.assign({}, request, {sortInfo: sortInfoString});
this.handleAction(TblCntlr.TABLE_FETCH, {request});
}

onFilter(filterIntoString) {
const {request} = this.cState.tableModel;
request.filters = filterIntoString;
var {request} = this.cState.tableModel;
request = Object.assign({}, request, {filters: filterIntoString});
this.handleAction(TblCntlr.TABLE_FETCH, {request});
}

Expand Down Expand Up @@ -93,15 +101,14 @@ export class TableStore {
this.handleAction(TblCntlr.TABLE_SELECT, {tbl_id, selectInfo});
}

onOptionUpdate({pageSize, columns, showUnits, showFilters}) {
onOptionUpdate({pageSize, columns, showUnits, showFilters, colSortDir}) {
if (pageSize) {
this.onPageSizeChange(pageSize);
} else {
const changes = omitBy({columns, showUnits, showFilters}, isUndefined);
if ( !isEmpty(changes) ) {
changes.tbl_ui_id = this.cState.tbl_ui_id;
this.handleAction(TblUiCntlr.TBL_UI_STATE_UPDATE, changes);
}
}
const changes = omitBy({columns, showUnits, showFilters, colSortDir}, isUndefined);
if ( !isEmpty(changes) ) {
changes.tbl_ui_id = this.cState.tbl_ui_id;
this.handleAction(TblUiCntlr.TBL_UI_STATE_UPDATE, changes);
}
}

Expand All @@ -116,17 +123,25 @@ export class TableStore {
}

handleAction(type, payload) {
var {tableModel, origTableModel} = this.cState;
if (! origTableModel && tableModel) {
// for localStore
// need to save orig tableModel when user wants to reset.
this.cState.origTableModel = cloneDeep(tableModel);
origTableModel = this.cState.origTableModel;
}
switch (type) {
case (TblCntlr.TABLE_FETCH_UPDATE) :
throw new Error('sorting and filtering is not implemented for localstore, yet.');
case (TblCntlr.TABLE_FETCH) :
if (get(payload, ['request', 'sortInfo']) !== get(tableModel, ['request', 'sortInfo'])) {
tableModel = TblUtil.sortTable(origTableModel, payload.request.sortInfo);
}
this.updateState({tableModel});
break;

default:
var tableModel = Object.assign({}, this.cState.tableModel, payload);
tableModel = Object.assign({}, this.cState.tableModel, payload);
this.updateState({tableModel});
}


}

/**
Expand Down
Loading