Skip to content

IRSA-540, IRSA-541:Add PTF case to Time Series Tool #409

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

Merged
merged 8 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
109 changes: 29 additions & 80 deletions src/firefly/js/tables/TableUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import {take, fork, cancel} from 'redux-saga/effects';
import {get, set, unset, has, isEmpty, isUndefined, uniqueId, cloneDeep, omit, omitBy, isNil, isPlainObject, isArray, padEnd} from 'lodash';
import Enum from 'enum';

import * as TblCntlr from './TablesCntlr.js';
import {SortInfo, SORT_ASC, UNSORTED} from './SortInfo.js';
Expand All @@ -17,10 +18,13 @@ import {ServerParams} from '../data/ServerParams.js';
import {doUpload} from '../ui/FileUpload.jsx';
import {dispatchAddSaga} from '../core/MasterSaga.js';

export const COL_TYPE = new Enum(['NUMBER', 'TEXT']);
export const MAX_ROW = Math.pow(2,31) - 1;
/* TABLE_REQUEST should match QueryUtil on the server-side */

const LSSTQueryPID = 'LSSTCataLogSearch';


/**
* @public
*/
Expand Down Expand Up @@ -928,6 +932,31 @@ export function watchTableChanges(tbl_id, actions, callback) {
return () => stopWatching = true;
}


/**
* @summary returns the columns array of the given table.
* @param {TableModel} tableModel
* @returns {Array<TableColumn>}
*/
export function getColumns(tableModel) {
return get(tableModel, 'tableData.columns', []);
}

/**
* @summary returns only the visible columns matching the given type.
* @param {Array<TableColumn>} tblColumns
* @param {COL_TYPE} type one of predefined COL_TYPE('NUMBER' | 'TEXT'). defaults to 'NUMBER'.
* @returns {Array<TableColumn>}
*/
export function getColsByType(tblColumns=[], type=COL_TYPE.NUMBER) {
const charTypes = ['char', 'c', 's', 'str'];
const numTypes = ['double', 'd', 'long', 'l', 'int', 'i', 'float', 'f'];
const matcher = type === COL_TYPE.TEXT ? charTypes : numTypes;
return tblColumns.filter((col) => get(col, 'visibility') !== 'hidden' && matcher.includes(col.type));
}



/*-------------------------------------private------------------------------------------------*/
/**
* this saga watches for table update and invoke the given callback when
Expand Down Expand Up @@ -955,83 +984,3 @@ function* doOnTblLoaded({tbl_id, callback}) {
}
callback && callback(getTblInfoById(tbl_id));
}



/**
* Returns only numerical column names form raw lc table
* @param {Object} rawTbl
* @returns {string[]} - array of table columns objects
*/
export function getOnlyNumericalColNames(rawTbl) {
const cols = get(rawTbl, ['tableData', 'columns']);
const colType = getColumnTypes(cols, 'numeric');
return get(rawTbl, ['tableData', 'columns']).reduce((prev, col) => {
if ((colType.includes(col.type)) ) {
prev.push(col.name);
}
return prev;
}, []);
}


/**
* @summary get column names from the column of string or char type
* @param {Array} tblColumns
* @returns {Array}
*/
export function getStringColNames(tblColumns) {
const CharTypes = ['char', 'c', 's', 'str'];

return isEmpty(tblColumns) ? [] :
tblColumns.filter((tblCol) => (get(tblCol, 'visibility', '') !== 'hidden'))
.filter((tblCol) => (CharTypes.includes(tblCol.type)))
.map((tblCol) => (tblCol.name));
}

/**
* @summary get column names from the column of numeric type
* @param {Array} tblColumns
* @returns {Array}
*/
export function getNumericColNames(tblColumns) {
const NumTypes = ['double', 'd', 'long', 'l', 'int', 'i', 'float', 'f'];

return isEmpty(tblColumns) ? [] :
tblColumns.filter((tblCol) => (get(tblCol, 'visibility', '') !== 'hidden'))
.filter((tblCol) => (NumTypes.includes(tblCol.type)))
.map((tblCol) => (tblCol.name));
}

export function getColNames(tblColumns, colTypes) {
return isEmpty(tblColumns)?[]:
tblColumns.reduce((prev, col) => {
if ( colTypes && colTypes.includes(col.type) ) {
prev.push(col.name);
}
else {
prev.push(col.name);
}
return prev;
}, []);
}

export function getColumnTypes (cols, type=undefined){
// const cols = get(tblModel, ['tableData', 'columns']);
var types =[];
for (let i=0; i<cols.length; i++){
if (types.indexOf(cols[i].type)>-1) continue;
if(!has(cols[i], 'visibility') || get(cols[i], 'visibility') !== 'hidden') {
if (!type || type === 'numeric') {
if (cols[i].type!=='char' && cols[i].type.toLowerCase()!=='string' ) {
types[i] = cols[i].type;
}
}
else {
types[i] = cols[i].type;
}
}
}
return types;

}
14 changes: 6 additions & 8 deletions src/firefly/js/templates/lightcurve/LcUtil.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import {get, has, set, isEmpty} from 'lodash';
import {LC} from './LcManager.js';
import {getConverter} from './LcConverterFactory.js';
import {getCellValue, getTblById, findIndex, getColumnTypes,getColNames,getColumnIdx} from '../../tables/TableUtil.js';
import {getCellValue, getTblById, findIndex, getColsByType, getColumnIdx, COL_TYPE} from '../../tables/TableUtil.js';
import {dispatchTableHighlight} from '../../tables/TablesCntlr.js';
import {ValidationField} from '../../ui/ValidationField.jsx';
import {SuggestBoxInputField} from '../../ui/SuggestBoxInputField.jsx';
Expand Down Expand Up @@ -146,10 +146,10 @@ export function getInitialDefaultValues(labelWidth, missionName) {
return commonDefault;
case 'wise':
const wiseDefault = {
[LC.META_FLUX_BAND]: Object.assign(getTypeData(LC.META_FLUX_BAND, '', '' +
'Select WISE band for images to be displayed', 'Image display:', 70)),
[LC.META_ERR_CNAME]: Object.assign(getTypeData(LC.META_ERR_CNAME, '',
'value error column name', 'Error Column:', labelWidth))
[LC.META_FLUX_BAND]: Object.assign(getTypeData(LC.META_FLUX_BAND, '', '' +
'Select WISE band for images to be displayed', 'Image display:', 70)),
[LC.META_ERR_CNAME]: Object.assign(getTypeData(LC.META_ERR_CNAME, '',
'value error column name', 'Error Column:', labelWidth))
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: I removed a few non-ascii characters from here. However, the code could use some cleaning up. Object.assign() is used with only 1 parameter, why? Also, why is there a '' + 'Select...'

};
return Object.assign ({},commonDefault, wiseDefault );
case 'ptf':
Expand Down Expand Up @@ -187,9 +187,7 @@ export function getMissionEntries(generalEntries, missionEntries,tblColumns,wrap

if (isEmpty(generalEntries) || isEmpty(missionEntries)) return false;

const numericColTypes = getColumnTypes( tblColumns, 'numeric');

const numColumns = getColNames(tblColumns, numericColTypes);
const numColumns = getColsByType(tblColumns, COL_TYPE.NUMBER).map( (c) => c.name);

var allCommonEntries = Object.keys(generalEntries).map((key) =>
<ValidationField key={key} fieldKey={key} wrapperStyle={wrapperStyle}
Expand Down
4 changes: 2 additions & 2 deletions src/firefly/js/templates/lightcurve/PTF/PTFMissionOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {get, set, isNil} from 'lodash';
import {RadioGroupInputField} from '../../../ui/RadioGroupInputField.jsx';
import {makeFileRequest, getCellValue, getTblById, getColumnIdx, smartMerge,getOnlyNumericalColNames} from '../../../tables/TableUtil.js';
import {makeFileRequest, getCellValue, getTblById, getColumnIdx, smartMerge, getColumns, getColsByType, COL_TYPE} from '../../../tables/TableUtil.js';
import {sortInfoString} from '../../../tables/SortInfo.js';
import {getInitialDefaultValues,renderMissionView,validate,getTimeAndYColInfo,fileUpdateOnTimeColumn,setValueAndValidator} from '../LcUtil.jsx';
import {LC} from '../LcManager.js';
Expand Down Expand Up @@ -102,7 +102,7 @@ export function ptfOnNewRawTable(rawTable, missionEntries, generalEntries, conve
// Update default values AND sortInfo and
const metaInfo = rawTable && rawTable.tableMeta;

const numericalCols = getOnlyNumericalColNames(rawTable);
const numericalCols = getColsByType(getColumns(rawTable), COL_TYPE.NUMBER).map((c) => c.name);
const defaultDataSource = (getColumnIdx(rawTable, converterData.dataSource) > 0) ? converterData.dataSource : numericalCols[3];

const {defaultCTimeName,defaultYColName } = getTimeAndYColInfo(numericalCols,xyColPattern,rawTable,converterData );
Expand Down
12 changes: 5 additions & 7 deletions src/firefly/js/templates/lightcurve/SettingBox.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PureComponent} from 'react';
import { getColNames,getColumnTypes,getStringColNames} from '../../tables/TableUtil.js';
import { getColsByType, COL_TYPE} from '../../tables/TableUtil.js';
import {getLayouInfo} from '../../core/LayoutCntlr.js';
import {flux} from '../../Firefly.js';
import {get} from 'lodash';
Expand All @@ -17,9 +17,8 @@ export class SettingBox extends PureComponent {
};

const {tblColumns} = this.getNextState();
const numericColTypes = getColumnTypes(tblColumns, 'numeric');
const numColumns = getColNames(tblColumns, numericColTypes);
const charColumns = getStringColNames(tblColumns);//(tblColumns, ['char', 'c', 's', 'str']);
const numColumns = getColsByType(tblColumns, COL_TYPE.NUMBER).map((c) => c.name);
const charColumns = getColsByType(tblColumns, COL_TYPE.TEXT).map((c) => c.name);//(tblColumns, ['char', 'c', 's', 'str']);
this.state = {tblColumns, charColumns, numColumns};
}

Expand All @@ -38,9 +37,8 @@ export class SettingBox extends PureComponent {
const {tblColumns} = this.getNextState();

if (tblColumns !== this.state.tblColumns) {
const numericColTypes = getColumnTypes(tblColumns, 'numeric');
const numColumns = getColNames(tblColumns, numericColTypes);
const charColumns = getStringColNames(tblColumns);
const numColumns = getColsByType(tblColumns, COL_TYPE.NUMBER).map((c) => c.name);
const charColumns = getColsByType(tblColumns, COL_TYPE.TEXT).map((c) => c.name);
;//getColNames(tblColumns, ['char', 'c', 's', 'str']);
this.setState({tblColumns, charColumns, numColumns});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import {get,isEmpty} from 'lodash';
import {FieldGroup} from '../../../ui/FieldGroup.jsx';
import {makeFileRequest} from '../../../tables/TableUtil.js';
import {getColumnIdx, smartMerge, getColNames,getColumnTypes} from '../../../tables/TableUtil.js';
import {getColumnIdx, smartMerge, getColsByType, COL_TYPE} from '../../../tables/TableUtil.js';
import {ReadOnlyText, getInitialDefaultValues,getMissionInput,getMissionInfo,validate,fileUpdateOnTimeColumn, setValueAndValidator} from '../LcUtil.jsx';
import {LC, getViewerGroupKey} from '../LcManager.js';
import {getMissionName} from '../LcConverterFactory.js';
Expand Down Expand Up @@ -133,8 +133,7 @@ export function basicOnNewRawTable(rawTable, missionEntries, generalEntries, con
// Update default values AND sortInfo and
const metaInfo = rawTable && rawTable.tableMeta;
const tblColumns = get(rawTable, ['tableData', 'columns'], []);
const numericColTypes = getColumnTypes(tblColumns, 'numeric');
const numericalCols = getColNames(tblColumns,numericColTypes);
const numericalCols = getColsByType(tblColumns, COL_TYPE.NUMBER).map((c) => c.name);

//let strCols = getStringCol(rawTable);
//strCols.push('');// Empty means no images
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {get, set, isNil} from 'lodash';
import {RadioGroupInputField} from '../../../ui/RadioGroupInputField.jsx';
import {makeFileRequest, getCellValue, getTblById, getColumnIdx, smartMerge,getOnlyNumericalColNames} from '../../../tables/TableUtil.js';
import {makeFileRequest, getCellValue, getTblById, getColumnIdx, smartMerge, getColumns, getColsByType, COL_TYPE} from '../../../tables/TableUtil.js';
import {sortInfoString} from '../../../tables/SortInfo.js';
import {getInitialDefaultValues,renderMissionView,validate,getTimeAndYColInfo,fileUpdateOnTimeColumn,setValueAndValidator} from '../LcUtil.jsx';
import {LC} from '../LcManager.js';
Expand Down Expand Up @@ -116,7 +116,7 @@ export function wiseOnNewRawTable(rawTable, missionEntries, generalEntries, conv

// Update default values AND sortInfo and
const metaInfo = rawTable && rawTable.tableMeta;
const numericalCols = getOnlyNumericalColNames(rawTable);
const numericalCols = getColsByType(getColumns(rawTable), COL_TYPE.NUMBER).map((c) => c.name);
let defaultDataSource = (getColumnIdx(rawTable, converterData.dataSource) > 0) ? converterData.dataSource : numericalCols[3];

const {defaultCTimeName,defaultYColName } = getTimeAndYColInfo(numericalCols,xyColPattern,rawTable,converterData );
Expand Down