Skip to content

Commit

Permalink
feat(eda.create_report): add sort by approximate unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Pham authored and jinglinpeng committed Feb 17, 2022
1 parent 0c82c9c commit 5738db2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
38 changes: 28 additions & 10 deletions dataprep/eda/create_report/templates/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,22 @@

function sortBy(e){
const selectedOption = e.options[e.selectedIndex].value;
const isReverseOrder = document.getElementById("id-variable-reverse-order").checked ? true : false;
const isReverseOrder = !!document.getElementById("id-variable-reverse-order").checked;
let variableSection = document.getElementById("id-variable-section");
let variables = originalVariables.slice();

if (selectedOption === 'original'){
//do nothing if it is the original feature order
}
else if (selectedOption === 'alphabetical'){
variables.sort(alphabeticalComparator);
}
else if (selectedOption === 'missing'){
variables.sort(missingComparator);
switch (selectedOption){
case 'original':
break;
case 'alphabetical':
variables.sort(alphabeticalComparator);
break;
case 'missing':
variables.sort(missingComparator);
break;
case 'unique':
variables.sort(uniqueComparator);
break;
}

if(isReverseOrder){
Expand Down Expand Up @@ -166,7 +170,21 @@
}

function missingAttributeExtractor(x){
return x.childNodes[3].childNodes[3].childNodes[1].childNodes[1].childNodes[1].childNodes[6].childNodes[3].innerHTML;
return parseFloat(x.childNodes[3].childNodes[3].childNodes[1].childNodes[1].childNodes[1].childNodes[6].childNodes[3].innerHTML);
}

function uniqueComparator(a, b){
const x = uniqueAttributeExtractor(a);
const y = uniqueAttributeExtractor(b);
if (x > y)
return -1;
if (x < y)
return 1;
return 0;
}

function uniqueAttributeExtractor(x){
return parseFloat(x.childNodes[3].childNodes[3].childNodes[1].childNodes[1].childNodes[1].childNodes[2].childNodes[3].innerHTML);
}

function onReverseClick(){
Expand Down
1 change: 1 addition & 0 deletions dataprep/eda/create_report/templates/variables.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<option value="original" >Feature order</option>
<option value="alphabetical">Alphabetical</option>
<option value="missing">Amount missing</option>
<option value="unique">Approximate unique</option>
</select>
<input type="checkbox" onchange="onReverseClick()" id="id-variable-reverse-order">
<label for="id-variable-reverse-order">Reverse order</label><br>
Expand Down

0 comments on commit 5738db2

Please sign in to comment.