forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIP-5] Refactor Paired t-test (apache#5762)
* extract TTestTable into another file. * Move into directory. * update proptypes
- Loading branch information
1 parent
b284788
commit 68e7794
Showing
4 changed files
with
118 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
superset/assets/src/visualizations/PairedTTest/PairedTTest.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
import PropTypes from 'prop-types'; | ||
import ReactDOM from 'react-dom'; | ||
import React from 'react'; | ||
import TTestTable, { dataPropType } from './TTestTable'; | ||
import './PairedTTest.css'; | ||
|
||
const propTypes = { | ||
className: PropTypes.string, | ||
metrics: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
groups: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
data: PropTypes.objectOf(dataPropType).isRequired, | ||
alpha: PropTypes.number, | ||
liftValPrec: PropTypes.number, | ||
pValPrec: PropTypes.number, | ||
}; | ||
|
||
const defaultProps = { | ||
className: '', | ||
alpha: 0.05, | ||
liftValPrec: 4, | ||
pValPrec: 6, | ||
}; | ||
|
||
class PairedTTest extends React.PureComponent { | ||
render() { | ||
const { | ||
className, | ||
metrics, | ||
groups, | ||
data, | ||
alpha, | ||
pValPrec, | ||
liftValPrec, | ||
} = this.props; | ||
return ( | ||
<div className={`paired-ttest-table scrollbar-container ${className}`}> | ||
<div className="scrollbar-content"> | ||
{metrics.map((metric, i) => ( | ||
<TTestTable | ||
key={i} | ||
metric={metric} | ||
groups={groups} | ||
data={data[metric]} | ||
alpha={alpha} | ||
pValPrec={Math.min(pValPrec, 32)} | ||
liftValPrec={Math.min(liftValPrec, 32)} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
PairedTTest.propTypes = propTypes; | ||
PairedTTest.defaultProps = defaultProps; | ||
|
||
function adaptor(slice, payload) { | ||
const { formData, selector } = slice; | ||
const element = document.querySelector(selector); | ||
const { | ||
groupby: groups, | ||
metrics, | ||
liftvalue_precision: liftValPrec, | ||
pvalue_precision: pValPrec, | ||
significance_level: alpha, | ||
} = formData; | ||
|
||
console.log('groups', groups, payload.data); | ||
|
||
ReactDOM.render( | ||
<PairedTTest | ||
metrics={metrics} | ||
groups={groups} | ||
data={payload.data} | ||
alpha={alpha} | ||
pValPrec={parseInt(pValPrec, 10)} | ||
liftValPrec={parseInt(liftValPrec, 10)} | ||
/>, | ||
element, | ||
); | ||
} | ||
|
||
export default adaptor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters