Skip to content

Commit

Permalink
created distinct value inp for int
Browse files Browse the repository at this point in the history
  • Loading branch information
Ltochon committed May 7, 2022
1 parent c74ac53 commit e86a63e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
4 changes: 2 additions & 2 deletions K-AnoTool/generalization/static/css/main.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.inputlvl{
width:45%;
width:30%;
}

.labellvl{
width : 45%;
width : 60%;
margin-top: 1em;
}

Expand Down
37 changes: 35 additions & 2 deletions K-AnoTool/generalization/templates/generalization.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@
}

function createinp(nblvl){
let lastlabel = document.getElementById("lastlbl");
let lastinp = document.getElementById("lastinp");
let d = document.getElementById("inplvl");
d.removeChild(lastlabel);
d.removeChild(lastinp);

let lab = document.createElement("label");
lab.classList.add("labellvl");
lab.setAttribute("id","lbl" + (nblvl-1).toString());
Expand All @@ -270,6 +276,8 @@
inp.setAttribute("id","inp" + (nblvl-1).toString())
document.getElementById("inplvl").appendChild(lab);
document.getElementById("inplvl").appendChild(inp);

createinptodistinct();
}


Expand Down Expand Up @@ -407,7 +415,12 @@
}
for(w in tabname){
let p = document.createElement("p");
p.innerHTML = '"' + tabname[w] + '"';
if(localStorage.getItem("type_" + localStorage.getItem("qid").replace("hiera_",'')) === "cat"){
p.innerHTML = '"' + dictotal[qid][elem] + '"';
}
else{
p.innerHTML = dictotal[qid][elem];
}
p.style.marginBottom = "2px";
if(localStorage.getItem("type_" + localStorage.getItem("qid").replace("hiera_",'')) === "cat"){
document.getElementById("printlaw").hidden = false;
Expand Down Expand Up @@ -743,6 +756,20 @@ <h6 id="txtnew" style="font-weight: bold; margin-top: 3px;"></h6>
</div>
<script>

function createinptodistinct(){
let lab = document.createElement("label");
lab.classList.add("labellvl");
lab.setAttribute("id","lastlbl");
lab.innerHTML = "Step " + (nblvl).toString() + " to distinct values";
let inp = document.createElement("input");
inp.type = "number";
inp.classList.add("inputlvl");
inp.addEventListener("change",saveweights)
inp.setAttribute("id","lastinp")
document.getElementById("inplvl").appendChild(lab);
document.getElementById("inplvl").appendChild(inp);
}

function list_to_tree(list) {
var map = {}, node, roots = [], i;

Expand Down Expand Up @@ -776,6 +803,7 @@ <h6 id="txtnew" style="font-weight: bold; margin-top: 3px;"></h6>
let qid = localStorage.getItem("qid").replace("hiera_",'');
let div = document.getElementById("original");
if(localStorage.getItem("type_" + localStorage.getItem("qid").replace("hiera_",'')) === "int"){
createinptodistinct()
dictotal[localStorage.getItem("qid").replace("hiera_",'')].sort()
}
else if(localStorage.getItem("type_" + localStorage.getItem("qid").replace("hiera_",'')) === "cat"){
Expand All @@ -785,7 +813,12 @@ <h6 id="txtnew" style="font-weight: bold; margin-top: 3px;"></h6>
}
for(elem in dictotal[qid]){
let p = document.createElement("p");
p.innerHTML = '"' + dictotal[qid][elem] + '"';
if(localStorage.getItem("type_" + localStorage.getItem("qid").replace("hiera_",'')) === "cat"){
p.innerHTML = '"' + dictotal[qid][elem] + '"';
}
else{
p.innerHTML = dictotal[qid][elem];
}
p.style.marginBottom = "2px";
if(localStorage.getItem("type_" + localStorage.getItem("qid").replace("hiera_",'')) === "cat"){
p.style.cursor = "pointer";
Expand Down
Binary file modified test_algo/__pycache__/ssw_web.cpython-39.pyc
Binary file not shown.
7 changes: 4 additions & 3 deletions test_algo/ssw_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def get_class(df,qid): #create equivalence classes

def generalize(df,qid,lvl,type_inp,lattice,max_gen,dictcatdone):
if(lvl != 0): #if a generalization is necessary
if type_inp == 'int':
if type_inp == 'int':
print(max_gen)
if(lvl != max_gen): #not max generalization
i = 0
rule = json.loads(lattice)[str(max_gen - lvl)] #load the 2D array of integer generalization law
Expand Down Expand Up @@ -95,6 +96,7 @@ def occu(df,qid):
def algo_web(df_init,qid,max_gen,weigths,k,max_supp,types,lattice):
dictcatdone = {}
list_comb = create_lattice(max_gen)
print(list_comb)
list_cost = []
current_level = [math.floor(len(list_comb)/2)] #start of binary search
stop = False
Expand All @@ -118,7 +120,7 @@ def algo_web(df_init,qid,max_gen,weigths,k,max_supp,types,lattice):
sum_w = 0
for q2 in range(0,len(qid)): #calculate total cost with custom weights
sum_w += sum(weigths[q2][0:c[q2]])
print(f"\nQID : {qid}, lattice : {current_level[len(current_level)-1]}, lvl of generalization : {c}, supp : {count_supp/len(df)*100}%, total cost : {count_supp * sum(sum(weigths,[])) + (len(df)-count_supp) * sum_w}, k before suppression = {check_ano(df,qid)}")
#print(f"\nQID : {qid}, lattice : {current_level[len(current_level)-1]}, lvl of generalization : {c}, supp : {count_supp/len(df)*100}%, total cost : {count_supp * sum(sum(weigths,[])) + (len(df)-count_supp) * sum_w}, k before suppression = {check_ano(df,qid)}")
if(found_no_supp):
cost.append([df,c,round(count_supp * sum(sum(weigths,[])) + (len(df)-count_supp) * sum_w,2),ano,round(count_supp/len(df)*100,2)]) #cost storage
if(found_no_supp): #if solution is OK
Expand All @@ -138,5 +140,4 @@ def algo_web(df_init,qid,max_gen,weigths,k,max_supp,types,lattice):
current_level.append((current_level[len(current_level)-1] + current_level[len(current_level)-1])/2)
else: #test if no more new lattice level available
stop = True
print(list_cost)
return list_cost

0 comments on commit e86a63e

Please sign in to comment.