Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
Macro21 committed Apr 2, 2018
1 parent f15bc5f commit 2332c34
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Practica 2/public/javascripts/data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ lluvioso,templado,normal,falso,si
soleado,templado,normal,verdad,si
nublado,templado,alta,verdad,si
nublado,caluroso,normal,falso,si
lluvioso,templado,alta,verdad,no
lluvioso,templado,alta,verdad,no
41 changes: 23 additions & 18 deletions Practica 2/public/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ let event;
let positiveDecision = 'si';
let nFinalDecision = 2;
let N = 0;
let infoCount = 1;

let para = 0;
let attributes;
//let attributes;

$(()=> {
data = new MyFileReader();

//TEMP

data = [
/* data = [
//TempExter, Temperatura, Humed, Viento, Jugar
["soleado", "caluroso", "alta", "falso", "no"],
["soleado", "caluroso", "alta", "verdad", "no"],
Expand All @@ -34,22 +32,25 @@ $(()=> {
];
N = data.length;
attributes = ["TiempoExterior", "Temperatura", "Humedad", "Viento", "Jugar"];
createTree(id3(attributes,data));
//
// putInTree(null);
createTree(id3(attributes,data));*/

});

function dataReader(ev){
event = ev;
var filename = $('#dataFile').val().replace(/C:\\fakepath\\/i, '');
$('#dataFileLbl').text(filename);
};

function attributesReader(ev){
var filename = $('#attrFile').val().replace(/C:\\fakepath\\/i, '');
$('#attrFileLbl').text(filename);
data.readAttributes(ev,(err,attributes)=>{
if(attributes && event){
data.readData(event,attributes.length,(err,data,dataLen)=>{
if(data){
N = dataLen;
id3(attributes,data);
createTree(id3(attributes,data));
}
else{
alert("Choose a data file and then attributes file!");
Expand All @@ -63,7 +64,7 @@ function attributesReader(ev){
};

function id3(attributes, data){
para++;

let nodeStructure = {
text: '',
children : []
Expand Down Expand Up @@ -96,9 +97,7 @@ function id3(attributes, data){
children: []
};
newNode.text = {name: i.attrName};

let idVal = id3(attributes,newData);
newNode.children.push(idVal);
newNode.children.push(id3(attributes,newData));
nodeStructure.children.push(newNode);
}
else{
Expand All @@ -109,19 +108,25 @@ function id3(attributes, data){
};

function createTree(nodeStructure){

let div = $('<div>').attr('id','tree-simple').appendTo('.container');

var simple_chart_config = {
chart: {
container: "#tree-simple"
container: "#tree-simple",
connectors: {
type: 'bCurve',
style: {
"stroke": 'green'
}
},
},
nodeStructure: {
text: { name: nodeStructure.text.name },
children: nodeStructure.children
}
};
var my_chart = new Treant(simple_chart_config);

};

function prepareNextData(attrName, data){
Expand Down Expand Up @@ -196,9 +201,9 @@ function showTables(attrInfo){
};

function showDataInfo(attributes,data){
let div = $('<div>').attr('id','info'+ infoCount);
let div = $('<div>');
div.css('text-align','center');
infoCount++;

let table = $('<table>');
//Header
let head = $('<thead>');
Expand Down Expand Up @@ -289,12 +294,12 @@ function calculateGains(attrInfo){
}

gainsInfo = sortByGain(gainsInfo);
showGains(attrInfo,gainsInfo,gainsInfo[0].type);
showGains(attrInfo,gainsInfo);
return gainsInfo[0];
};


function showGains(attrInfo,gainsInfo,mainType){
function showGains(attrInfo,gainsInfo){
//infor(p,n) = p log2(p) n log2(n)
//am: mérito (am) = E(ri*x infor (pi, ni))
//ri = ai/N;
Expand Down
16 changes: 11 additions & 5 deletions Practica 2/public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ h3{
height: 160px;
}

/*
.space{
padding-left: 60px;
padding-right: 60px;
}*/
.node {
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: bold;
border: 2px solid black;
padding-left: 4px;
padding-right: 4px;
padding-top: 12px;
padding-bottom: 0px;
background-color: blueviolet;
color: black;
}

0 comments on commit 2332c34

Please sign in to comment.