Skip to content

Commit

Permalink
Node efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
smariel committed Apr 1, 2023
1 parent f6ba8f2 commit 639ab8e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions html/PTree.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
<td class="totalcell totaleff max">100</td>
<td class="totalcell">%</td>
</tr>
<tr class="totalcell_node hidden">
<td class="totalcell">Node Eff.</td>
<td class="totalcell nodeeff typ">0</td>
<td class="totalcell nodeeff max">0</td>
<td class="totalcell">%</td>
</tr>
<!--<tr>
<td class="totalcell">DC/DC loss</td>
<td class="totalcell totaldcdcloss typ">0</td>
Expand Down
17 changes: 17 additions & 0 deletions js/class.Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,19 @@ class Canvas {
$('.totaleff.typ').text(Util.numberToSi(efficiency.typ,3));
$('.totaleff.max').text(Util.numberToSi(efficiency.max,3));

// refrech the node power
let selectedItem = this.getSelectedItem();
if(null !== selectedItem && selectedItem.isSource()) {
const nodeEff = selectedItem.getNodeEfficiency();
$('.nodeeff.typ').text(Util.numberToSi(nodeEff.typ,3));
$('.nodeeff.max').text(Util.numberToSi(nodeEff.max,3));

$('.totalcell_node').removeClass('hidden');
}
else {
$('.totalcell_node').addClass('hidden');
}


/*
// refresh the total losses
Expand Down Expand Up @@ -676,6 +689,8 @@ class Canvas {

// save a ref to the precedent item
this.selectedItem = item;

this.refreshTotalPower();
}


Expand All @@ -686,6 +701,8 @@ class Canvas {
this.fabricCanvas.renderAll();
}
this.selectedItem = null;

this.refreshTotalPower();
}


Expand Down
35 changes: 35 additions & 0 deletions js/class.Item.Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,41 @@ class Source extends Item {
}



// return the power of all load
getLoadPower(typmax='both') {
// get the total usefull power
let loadpower = {typ:0, max:0};
let itemIDs = this.getDescendants();
this.tree.forEachLoad((load) => {
if(itemIDs.includes(load.id)) {
loadpower.typ += load.getInputPower('typ');
loadpower.max += load.getInputPower('max');
}
});

// return the typ or max or both
if('both' === typmax) return loadpower;
else return loadpower[typmax];
}


// get the total efficiency = load_power / input_power
getNodeEfficiency(typmax='both') {
// refresh the total efficiency
let totalpower = {typ: this.getInputPower('typ'), max:this.getInputPower('max')};
let loadpower = this.getLoadPower();
const efficiency = {
typ: (0 == totalpower.typ) ? 100 : (loadpower.typ / totalpower.typ) * 100,
max: (0 == totalpower.max) ? 100 : (loadpower.max / totalpower.max) * 100
};

// return the typ or max or both
if('both' === typmax) return efficiency;
else return efficiency[typmax];
}


// add a new data to chart_type (efficiency or dropout)
addToChart(chart_datas, new_data) {
// add the data to the array, keeping ordered by ascending currend
Expand Down

0 comments on commit 639ab8e

Please sign in to comment.