-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an option to weight elements by the # of siblings instead o…
…f # of subnodes If two JSONs has only two keys, and one of them is in both JSON a single number, let's say `3`, but in the other key, they both have a four-level nested json with thousands of arrays, sub-objects, sub-arrays and text and numbers, for which they are only completely different, would you say they are 50% equal (1 out of 2 keys) or almost completely different? Options are: * All the nodes weight the same, so a root node with several nested nodes would weight more than the other siblings. * Each node at a given level have a weight in the total equal to 1 / the number of sibblings. And its sub-tree nodes add to that fraction only.
- Loading branch information
1 parent
e656f02
commit 4792dd8
Showing
13 changed files
with
277 additions
and
82 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { OptionsTabPanel } from '~/components/OptionsPanel/OptionsTabPanel'; | ||
import { SCORE_SETTINGS_VALUES, SCORING_SETTINGS_KEYS } from '~/utils/score/constants'; | ||
|
||
const { ELEMENT_WEIGHT } = SCORING_SETTINGS_KEYS; | ||
const { SIBLINGS_PROPORTION, DESCENDANTS_COUNT } = SCORE_SETTINGS_VALUES[ELEMENT_WEIGHT]; | ||
|
||
const alternatives = [ | ||
{ label: 'Descendants Count', value: DESCENDANTS_COUNT }, | ||
{ label: 'Siblings Proportion', value: SIBLINGS_PROPORTION }, | ||
]; | ||
|
||
const explanation = 'If two JSONs has only two keys, and one of them is in both JSON a single number, let\'s say `3`,' | ||
+ ' but in the other key, they both have a four-level nested json with thousands of arrays, sub-objects, sub-arrays' | ||
+ ' and text and numbers, for which they are only completely different, would you say they are 50% equal' | ||
+ ' (1 out of 2 keys) or almost completely different? This setting allows you to control exactly that.'; | ||
|
||
// const explanation = 'This setting ' | ||
export const ElementWeightOptionPanel = ({ value, index }) => ( | ||
<OptionsTabPanel | ||
value={value} | ||
index={index} | ||
explanation={explanation} | ||
alternatives={alternatives} | ||
optionKey={ELEMENT_WEIGHT} | ||
/> | ||
); | ||
|
||
ElementWeightOptionPanel.propTypes = { | ||
index: PropTypes.number.isRequired, | ||
value: PropTypes.number.isRequired, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import Box from '@material-ui/core/Box'; | ||
import { | ||
CardContent, CardHeader, Grid, useTheme, | ||
} from '@material-ui/core'; | ||
import Card from '@material-ui/core/Card'; | ||
import { OptionsAlternatives } from '~/components/OptionsPanel/OptionsAlternatives'; | ||
import { SCORING_SETTINGS_KEYS } from '~/utils/score/constants'; | ||
|
||
export const OptionsTabPanel = ({ | ||
children, value, index, explanation, alternatives, optionKey, ...other | ||
}) => { | ||
const theme = useTheme(); | ||
return ( | ||
<div | ||
role="tabpanel" | ||
hidden={value !== index} | ||
id={`tabpanel-${index}`} | ||
aria-labelledby={`tab-${index}`} | ||
dir={theme.direction} | ||
{...other} | ||
> | ||
{value === index && ( | ||
<Box p={3}> | ||
<Box p={3}> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12} sm={4}> | ||
<Card> | ||
<CardHeader title="Explanation" /> | ||
<CardContent>{explanation}</CardContent> | ||
</Card> | ||
</Grid> | ||
<Grid item xs={12} sm={8}> | ||
<Card> | ||
<CardHeader title="Select Option" /> | ||
<CardContent> | ||
<OptionsAlternatives optionKey={optionKey} alternatives={alternatives} /> | ||
</CardContent> | ||
</Card> | ||
</Grid> | ||
</Grid> | ||
</Box> | ||
</Box> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
OptionsTabPanel.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
index: PropTypes.number.isRequired, | ||
value: PropTypes.number.isRequired, | ||
explanation: PropTypes.string.isRequired, | ||
optionKey: PropTypes.oneOf(Object.values(SCORING_SETTINGS_KEYS)).isRequired, | ||
alternatives: PropTypes.arrayOf(PropTypes.shape({ | ||
value: PropTypes.string.isRequired, | ||
label: PropTypes.string.isRequired, | ||
})).isRequired, | ||
}; |
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
const OptionalHeaderTitle = 'Options'; | ||
// ToDo: Add simpler yet more evident tests for the difference in the algorithm. | ||
describe('the Array Order option', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
cy.contains('.MuiCardHeader-root', OptionalHeaderTitle).find('button').click(); | ||
cy.contains('Depth Weight').click(); | ||
}); | ||
it('should have an explanation section', () => { | ||
cy.contains('Explanation'); | ||
}); | ||
it('should have a "Select Option" section', () => { | ||
cy.contains('Select Option'); | ||
}); | ||
it('should have two options', () => { | ||
cy.contains('.MuiCard-root', OptionalHeaderTitle).find('input[type="radio"]').should('have.length', 2); | ||
}); | ||
describe('when selecting descendant count', () => { | ||
it('should return a higher score', () => { | ||
// arrange | ||
const fileNameA = 'BreweriesMaster.json'; | ||
const fileNameB = 'BreweriesSample4.json'; | ||
cy.drop('File A', fileNameA); | ||
cy.drop('File B', fileNameB); | ||
// act | ||
cy.contains('Descendants Count').click(); | ||
cy.contains('Compare').click(); | ||
// assert | ||
cy.contains('35.7%'); | ||
}); | ||
}); | ||
describe('when selecting siblings proportion', () => { | ||
it('should return a lower score', () => { | ||
// arrange | ||
const fileNameA = 'BreweriesMaster.json'; | ||
const fileNameB = 'BreweriesSample4.json'; | ||
cy.drop('File A', fileNameA); | ||
cy.drop('File B', fileNameB); | ||
// act | ||
cy.contains('Siblings Proportion').click(); | ||
cy.contains('Compare').click(); | ||
// assert | ||
cy.contains('34.2%'); | ||
}); | ||
}); | ||
}); |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.