Skip to content

Commit ba6542d

Browse files
author
vimsh
committed
Added calculation cells highlighting, fixed bug
1 parent 87c60a1 commit ba6542d

File tree

3 files changed

+127
-77
lines changed

3 files changed

+127
-77
lines changed

MafScaling.jar

1.25 KB
Binary file not shown.

src/com/vgi/mafscaling/MafScaling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
public class MafScaling {
3838
private static final Logger logger = Logger.getLogger(MafScaling.class);
39-
private static final String Title = "MAF Scaling - v2.6.1";
39+
private static final String Title = "MAF Scaling - v2.6.0";
4040
private static final String OLTabName = "<html>Open Loop</html>";
4141
private static final String CLTabName = "<html>Closed Loop</html>";
4242
private static final String MRTabName = "<html>MAF Rescale</html>";

src/com/vgi/mafscaling/ThrottleMaps.java

Lines changed: 126 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.awt.event.ActionEvent;
2626
import java.awt.event.ComponentAdapter;
2727
import java.awt.event.ComponentEvent;
28+
import java.awt.event.MouseAdapter;
29+
import java.awt.event.MouseEvent;
2830
import java.text.DecimalFormat;
2931
import java.text.Format;
3032
import java.util.ArrayList;
@@ -206,6 +208,29 @@ public void componentResized(ComponentEvent e) {
206208
tableColumn.setWidth(table.getWidth());
207209
}
208210
});
211+
212+
table.addMouseListener(new MouseAdapter() {
213+
public void mousePressed(MouseEvent event) {
214+
if (Utils.isTableEmpty(origTable) || Utils.isTableEmpty(newTable) || Utils.isTableEmpty(corrTable)) {
215+
return;
216+
}
217+
JTable eventTable =(JTable)event.getSource();
218+
int colIdx = eventTable.getSelectedColumn();
219+
int rowIdx = eventTable.getSelectedRow();
220+
ArrayList<Double> t3xAxisArray = new ArrayList<Double>();
221+
for (int i = 1; i < corrTable.getColumnCount(); ++i)
222+
t3xAxisArray.add(Double.valueOf(corrTable.getValueAt(0, i).toString()));
223+
224+
ArrayList<Double> t1yAxisArray = new ArrayList<Double>();
225+
for (int i = 0; i < origTable.getRowCount(); ++i)
226+
t1yAxisArray.add(Double.valueOf(origTable.getValueAt(i, 0).toString()));
227+
228+
ArrayList<Double> t3yAxisArray = new ArrayList<Double>();
229+
for (int i = 1; i < corrTable.getRowCount(); ++i)
230+
t3yAxisArray.add(Double.valueOf(corrTable.getValueAt(i, 0).toString()));
231+
calculate(t3xAxisArray, t1yAxisArray, t3yAxisArray, rowIdx, colIdx, true);
232+
}
233+
});
209234

210235
Utils.addTableHeaderHighlight(table);
211236
table.setName(tableName);
@@ -304,88 +329,13 @@ protected boolean processLog() {
304329
for (int i = 1; i < corrTable.getRowCount(); ++i)
305330
t3yAxisArray.add(Double.valueOf(corrTable.getValueAt(i, 0).toString()));
306331

307-
Double x, x1, x2, y, y1, y2, x1y1, x1y2, x2y1, x2y2, tmp, val1, val2, val3;
308-
int idx, idxX1, idxX2, idxY1, idxY2;
309332
for (int i = 0; i < newTable.getRowCount(); ++i) {
310333
for (int j = 0; j < newTable.getColumnCount(); ++j) {
311334
if (0 == i || j == 0) {
312335
logDataTable.setValueAt(newTable.getValueAt(i, j), i, j);
313336
}
314337
else {
315-
// get value from table 1
316-
x = Double.valueOf(newTable.getValueAt(i, 0).toString());
317-
idx = Utils.closestValueIndex(x, t1yAxisArray);
318-
tmp = Double.valueOf(origTable.getValueAt(idx, 0).toString());
319-
if (tmp > x && idx > 0) {
320-
x1 = Double.valueOf(origTable.getValueAt(idx - 1, 0).toString());
321-
x2 = tmp;
322-
y1 = Double.valueOf(origTable.getValueAt(idx - 1, 1).toString());
323-
y2 = Double.valueOf(origTable.getValueAt(idx, 1).toString());
324-
val1 = Utils.linearInterpolation(x, x1, x2, y1, y2);
325-
}
326-
else if (tmp < x && idx < t1yAxisArray.size() - 1) {
327-
x1 = tmp;
328-
x2 = Double.valueOf(origTable.getValueAt(idx + 1, 0).toString());
329-
y1 = Double.valueOf(origTable.getValueAt(idx, 1).toString());
330-
y2 = Double.valueOf(origTable.getValueAt(idx + 1, 1).toString());
331-
val1 = Utils.linearInterpolation(x, x1, x2, y1, y2);
332-
}
333-
else {
334-
val1 = Double.valueOf(origTable.getValueAt(idx, 1).toString());
335-
}
336-
337-
// get value from table 2
338-
val2 = Double.valueOf(newTable.getValueAt(i, j).toString());
339-
340-
// get value from table 3
341-
x = val2 / val1;
342-
idx = Utils.closestValueIndex(x, t3xAxisArray) + 1;
343-
tmp = Double.valueOf(corrTable.getValueAt(0, idx).toString());
344-
if (tmp > x && idx > 1) {
345-
idxX1 = idx - 1;
346-
idxX2 = idx;
347-
x1 = Double.valueOf(corrTable.getValueAt(0, idx - 1).toString());
348-
x2 = tmp;
349-
}
350-
else if (tmp < x && idx < t3xAxisArray.size()) {
351-
idxX1 = idx;
352-
idxX2 = idx + 1;
353-
x1 = tmp;
354-
x2 = Double.valueOf(corrTable.getValueAt(0, idx + 1).toString());
355-
}
356-
else {
357-
idxX1 = idxX2 = idx;
358-
x1 = x2 = tmp;
359-
}
360-
361-
y = Double.valueOf(newTable.getValueAt(i, 0).toString());
362-
idx = Utils.closestValueIndex(x, t3yAxisArray) + 1;
363-
tmp = Double.valueOf(corrTable.getValueAt(idx, 0).toString());
364-
if (tmp > x && idx > 1) {
365-
idxY1 = idx - 1;
366-
idxY2 = idx;
367-
y1 = Double.valueOf(corrTable.getValueAt(idx - 1, 0).toString());
368-
y2 = tmp;
369-
}
370-
else if (tmp < x && idx < t3yAxisArray.size()) {
371-
idxY1 = idx;
372-
idxY2 = idx + 1;
373-
y1 = tmp;
374-
y2 = Double.valueOf(corrTable.getValueAt(idx + 1, 0).toString());
375-
}
376-
else {
377-
idxY1 = idxY2 = idx;
378-
y1 = y2 = tmp;
379-
}
380-
381-
x1y1 = Double.valueOf(corrTable.getValueAt(idxY1, idxX1).toString());
382-
x1y2 = Double.valueOf(corrTable.getValueAt(idxY2, idxX1).toString());
383-
x2y1 = Double.valueOf(corrTable.getValueAt(idxY1, idxX2).toString());
384-
x2y2 = Double.valueOf(corrTable.getValueAt(idxY2, idxX2).toString());
385-
386-
val3 = Utils.bilinearInterpolation(x, y, x1, x2, y1, y2, x1y1, x1y2, x2y1, x2y2);
387-
388-
logDataTable.setValueAt(val3, i, j);
338+
logDataTable.setValueAt(calculate(t3xAxisArray, t1yAxisArray, t3yAxisArray, i, j, false), i, j);
389339
}
390340
}
391341
}
@@ -399,6 +349,106 @@ else if (tmp < x && idx < t3yAxisArray.size()) {
399349
}
400350
return false;
401351
}
352+
353+
private Double calculate(ArrayList<Double> t3xAxisArray, ArrayList<Double> t1yAxisArray, ArrayList<Double> t3yAxisArray, int row, int column, boolean highlight)
354+
{
355+
Double x, x1, x2, y, y1, y2, x1y1, x1y2, x2y1, x2y2, tmp, val1, val2;
356+
int idx, idxX1, idxX2, idxY1, idxY2;
357+
358+
// get value from table 1
359+
x = Double.valueOf(newTable.getValueAt(row, 0).toString());
360+
idx = Utils.closestValueIndex(x, t1yAxisArray);
361+
tmp = Double.valueOf(origTable.getValueAt(idx, 0).toString());
362+
if (tmp > x && idx > 0) {
363+
x1 = Double.valueOf(origTable.getValueAt(idx - 1, 0).toString());
364+
x2 = tmp;
365+
y1 = Double.valueOf(origTable.getValueAt(idx - 1, 1).toString());
366+
y2 = Double.valueOf(origTable.getValueAt(idx, 1).toString());
367+
val1 = Utils.linearInterpolation(x, x1, x2, y1, y2);
368+
if (highlight) {
369+
origTable.setColumnSelectionInterval(0, 1);
370+
origTable.setRowSelectionInterval(idx - 1, idx);
371+
}
372+
}
373+
else if (tmp < x && idx < t1yAxisArray.size() - 1) {
374+
x1 = tmp;
375+
x2 = Double.valueOf(origTable.getValueAt(idx + 1, 0).toString());
376+
y1 = Double.valueOf(origTable.getValueAt(idx, 1).toString());
377+
y2 = Double.valueOf(origTable.getValueAt(idx + 1, 1).toString());
378+
val1 = Utils.linearInterpolation(x, x1, x2, y1, y2);
379+
if (highlight) {
380+
origTable.setColumnSelectionInterval(1, 1);
381+
origTable.setRowSelectionInterval(idx, idx + 1);
382+
}
383+
}
384+
else {
385+
val1 = Double.valueOf(origTable.getValueAt(idx, 1).toString());
386+
if (highlight) {
387+
origTable.setColumnSelectionInterval(1, 1);
388+
origTable.setRowSelectionInterval(idx, idx);
389+
}
390+
}
391+
392+
// get value from table 2
393+
val2 = Double.valueOf(newTable.getValueAt(row, column).toString());
394+
395+
// get value from table 3
396+
x = val2 / val1;
397+
idx = Utils.closestValueIndex(x, t3xAxisArray) + 1;
398+
tmp = Double.valueOf(corrTable.getValueAt(0, idx).toString());
399+
if (tmp > x && idx > 1) {
400+
idxX1 = idx - 1;
401+
idxX2 = idx;
402+
x1 = Double.valueOf(corrTable.getValueAt(0, idx - 1).toString());
403+
x2 = tmp;
404+
}
405+
else if (tmp < x && idx < t3xAxisArray.size()) {
406+
idxX1 = idx;
407+
idxX2 = idx + 1;
408+
x1 = tmp;
409+
x2 = Double.valueOf(corrTable.getValueAt(0, idx + 1).toString());
410+
}
411+
else {
412+
idxX1 = idxX2 = idx;
413+
x1 = x2 = tmp;
414+
}
415+
416+
y = Double.valueOf(newTable.getValueAt(row, 0).toString());
417+
idx = Utils.closestValueIndex(y, t3yAxisArray) + 1;
418+
tmp = Double.valueOf(corrTable.getValueAt(idx, 0).toString());
419+
if (tmp > y && idx > 1) {
420+
idxY1 = idx - 1;
421+
idxY2 = idx;
422+
y1 = Double.valueOf(corrTable.getValueAt(idx - 1, 0).toString());
423+
y2 = tmp;
424+
}
425+
else if (tmp < y && idx < t3yAxisArray.size()) {
426+
idxY1 = idx;
427+
idxY2 = idx + 1;
428+
y1 = tmp;
429+
y2 = Double.valueOf(corrTable.getValueAt(idx + 1, 0).toString());
430+
}
431+
else {
432+
idxY1 = idxY2 = idx;
433+
y1 = y2 = tmp;
434+
}
435+
436+
x1y1 = Double.valueOf(corrTable.getValueAt(idxY1, idxX1).toString());
437+
x1y2 = Double.valueOf(corrTable.getValueAt(idxY2, idxX1).toString());
438+
x2y1 = Double.valueOf(corrTable.getValueAt(idxY1, idxX2).toString());
439+
x2y2 = Double.valueOf(corrTable.getValueAt(idxY2, idxX2).toString());
440+
441+
if (highlight) {
442+
corrTable.setColumnSelectionInterval(idxX1, idxX2);
443+
corrTable.setRowSelectionInterval(idxY1, idxY2);
444+
if (!Utils.isTableEmpty(logDataTable)) {
445+
logDataTable.setColumnSelectionInterval(column, column);
446+
logDataTable.setRowSelectionInterval(row, row);
447+
}
448+
}
449+
450+
return Utils.bilinearInterpolation(x, y, x1, x2, y1, y2, x1y1, x1y2, x2y1, x2y2);
451+
}
402452

403453
private void add3DPlot(JTable table) {
404454
int i;

0 commit comments

Comments
 (0)