List of usage examples for java.util ArrayDeque addFirst
public void addFirst(E e)
From source file:com.vgi.mafscaling.VECalc.java
protected void loadLogFile() { fileChooser.setMultiSelectionEnabled(true); if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this)) return;/*from www . j av a2 s .c o m*/ File[] files = fileChooser.getSelectedFiles(); for (File file : files) { BufferedReader br = null; ArrayDeque<String[]> buffer = new ArrayDeque<String[]>(); try { br = new BufferedReader(new FileReader(file.getAbsoluteFile())); String line = br.readLine(); if (line != null) { String[] elements = line.split("(\\s*)?,(\\s*)?", -1); getColumnsFilters(elements); boolean resetColumns = false; if (logThrottleAngleColIdx >= 0 || logFfbColIdx >= 0 || logSdColIdx >= 0 || (logWbAfrColIdx >= 0 && isOl) || (logStockAfrColIdx >= 0 && !isOl) || (logAfLearningColIdx >= 0 && !isOl) || (logAfCorrectionColIdx >= 0 && !isOl) || logRpmColIdx >= 0 || logMafColIdx >= 0 || logIatColIdx >= 0 || logMpColIdx >= 0) { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Would you like to reset column names or filter values?", "Columns/Filters Reset", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE)) resetColumns = true; } if (resetColumns || logThrottleAngleColIdx < 0 || logFfbColIdx < 0 || logSdColIdx < 0 || (logWbAfrColIdx < 0 && isOl) || (logStockAfrColIdx < 0 && !isOl) || (logAfLearningColIdx < 0 && !isOl) || (logAfCorrectionColIdx < 0 && !isOl) || logRpmColIdx < 0 || logMafColIdx < 0 || logIatColIdx < 0 || logMpColIdx < 0) { ColumnsFiltersSelection selectionWindow = new VEColumnsFiltersSelection(false); if (!selectionWindow.getUserSettings(elements) || !getColumnsFilters(elements)) return; } if (logClOlStatusColIdx == -1) clValue = -1; String[] flds; String[] afrflds; boolean removed = false; int i = 2; int clol = -1; int row = getLogTableEmptyRow(); double thrtlMaxChange2 = thrtlMaxChange + thrtlMaxChange / 2.0; double throttle = 0; double pThrottle = 0; double ppThrottle = 0; double afr = 0; double rpm; double ffb; double iat; clearRunTables(); setCursor(new Cursor(Cursor.WAIT_CURSOR)); for (int k = 0; k <= afrRowOffset && line != null; ++k) { line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); } try { while (line != null && buffer.size() > afrRowOffset) { afrflds = buffer.getFirst(); flds = buffer.removeLast(); line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); ppThrottle = pThrottle; pThrottle = throttle; throttle = Double.valueOf(flds[logThrottleAngleColIdx]); try { if (row > 0 && Math.abs(pThrottle - throttle) > thrtlMaxChange) { if (!removed) Utils.removeRow(row--, logDataTable); removed = true; } else if (row <= 0 || Math.abs(ppThrottle - throttle) <= thrtlMaxChange2) { // Filters afr = (isOl ? Double.valueOf(afrflds[logWbAfrColIdx]) : Double.valueOf(afrflds[logStockAfrColIdx])); rpm = Double.valueOf(flds[logRpmColIdx]); ffb = Double.valueOf(flds[logFfbColIdx]); iat = Double.valueOf(flds[logIatColIdx]); if (clValue != -1) clol = Integer.valueOf(flds[logClOlStatusColIdx]); boolean flag = isOl ? ((afr <= afrMax || throttle >= thrtlMin) && afr <= afrMax) : (afrMin <= afr); if (flag && clol == clValue && rpmMin <= rpm && ffbMin <= ffb && ffb <= ffbMax && iat <= iatMax) { removed = false; if (!isOl) trims.add(Double.valueOf(flds[logAfLearningColIdx]) + Double.valueOf(flds[logAfCorrectionColIdx])); Utils.ensureRowCount(row + 1, logDataTable); logDataTable.setValueAt(rpm, row, 0); logDataTable.setValueAt(iat, row, 1); logDataTable.setValueAt(Double.valueOf(flds[logMpColIdx]), row, 2); logDataTable.setValueAt(ffb, row, 3); logDataTable.setValueAt(afr, row, 4); logDataTable.setValueAt(Double.valueOf(flds[logMafColIdx]), row, 5); logDataTable.setValueAt(Double.valueOf(flds[logSdColIdx]), row, 6); row += 1; } else removed = true; } else removed = true; } catch (NumberFormatException e) { logger.error(e); JOptionPane.showMessageDialog(null, "Error parsing number at " + file.getName() + " line " + i + ": " + e, "Error processing file", JOptionPane.ERROR_MESSAGE); return; } i += 1; } } finally { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } } catch (Exception e) { logger.error(e); JOptionPane.showMessageDialog(null, e, "Error opening file", JOptionPane.ERROR_MESSAGE); } finally { if (br != null) { try { br.close(); } catch (IOException e) { logger.error(e); } } } } }
From source file:com.vgi.mafscaling.OpenLoop.java
protected void loadLogFile() { fileChooser.setMultiSelectionEnabled(true); if (JFileChooser.APPROVE_OPTION != fileChooser.showOpenDialog(this)) return;/*from w w w .j av a2s.c om*/ boolean isPolSet = polfTable.isSet(); File[] files = fileChooser.getSelectedFiles(); for (File file : files) { BufferedReader br = null; ArrayDeque<String[]> buffer = new ArrayDeque<String[]>(); try { br = new BufferedReader(new FileReader(file.getAbsoluteFile())); String line = br.readLine(); if (line != null) { String[] elements = line.split("(\\s*)?,(\\s*)?", -1); getColumnsFilters(elements, false); boolean resetColumns = false; if (logThtlAngleColIdx >= 0 || logAfLearningColIdx >= 0 || logAfCorrectionColIdx >= 0 || logMafvColIdx >= 0 || logAfrColIdx >= 0 || logRpmColIdx >= 0 || logLoadColIdx >= 0 || logCommandedAfrCol >= 0) { if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, "Would you like to reset column names or filter values?", "Columns/Filters Reset", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE)) resetColumns = true; } if (resetColumns || logThtlAngleColIdx < 0 || logAfLearningColIdx < 0 || logAfCorrectionColIdx < 0 || logMafvColIdx < 0 || logAfrColIdx < 0 || logRpmColIdx < 0 || logLoadColIdx < 0 || (logCommandedAfrCol < 0 && !isPolSet)) { ColumnsFiltersSelection selectionWindow = new OLColumnsFiltersSelection(isPolSet); if (!selectionWindow.getUserSettings(elements) || !getColumnsFilters(elements, isPolSet)) return; } String[] flds; String[] afrflds; boolean wotFlag = true; boolean foundWot = false; double throttle; double stft; double ltft; double afr; double rpm; double load; double mafv; double cmdafr = 0; double afrErr = 0; int skipRowCount = 0; int row = 0; int i = 0; int j = 0; for (; i < runTables.length; ++i) { if (runTables[i].getValueAt(0, 0).toString().isEmpty()) break; } if (i == runTables.length) return; setCursor(new Cursor(Cursor.WAIT_CURSOR)); for (int k = 0; k <= afrRowOffset && line != null; ++k) { line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); } while (line != null && buffer.size() > afrRowOffset) { afrflds = buffer.getFirst(); flds = buffer.removeLast(); line = br.readLine(); if (line != null) buffer.addFirst(line.split(",", -1)); try { throttle = Double.valueOf(flds[logThtlAngleColIdx]); if (row == 0 && throttle < 99) wotFlag = false; if (throttle < wotPoint) { if (wotFlag == true) { wotFlag = false; skipRowCount = 0; j -= 1; while (j > 0 && skipRowCount < skipRowsOnTransition) { runTables[i].setValueAt("", j, 0); runTables[i].setValueAt("", j, 1); runTables[i].setValueAt("", j, 2); skipRowCount += 1; j -= 1; } skipRowCount = 0; } } else { if (wotFlag == false) { wotFlag = true; skipRowCount = 0; if (foundWot) { i += 1; if (i == runTables.length) return; } if (row > 0) j = 0; } if (skipRowCount >= skipRowsOnTransition) { mafv = Double.valueOf(flds[logMafvColIdx]); if (minMafV <= mafv) { foundWot = true; stft = Double.valueOf(flds[logAfCorrectionColIdx]); ltft = Double.valueOf(flds[logAfLearningColIdx]); afr = Double.valueOf(afrflds[logAfrColIdx]); rpm = Double.valueOf(flds[logRpmColIdx]); load = Double.valueOf(flds[logLoadColIdx]); afr = afr / ((100.0 - (ltft + stft)) / 100.0); if (logCommandedAfrCol >= 0) cmdafr = Double.valueOf(flds[logCommandedAfrCol]); else if (isPolSet) cmdafr = Utils.calculateCommandedAfr(rpm, load, minWotEnrichment, polfTable); else { JOptionPane.showMessageDialog(null, "Please set either \"Commanded AFR\" column or \"Primary Open Loop Fueling\" table", "Error", JOptionPane.ERROR_MESSAGE); return; } afrErr = (afr - cmdafr) / cmdafr * 100.0; if (Math.abs(afrErr) <= afrErrPrct) { Utils.ensureRowCount(j + 1, runTables[i]); runTables[i].setValueAt(rpm, j, 0); runTables[i].setValueAt(mafv, j, 1); runTables[i].setValueAt(afrErr, j, 2); j += 1; } } } skipRowCount += 1; } } catch (NumberFormatException e) { logger.error(e); JOptionPane.showMessageDialog(null, "Error parsing number at " + file.getName() + " line " + (row + 1) + ": " + e, "Error processing file", JOptionPane.ERROR_MESSAGE); return; } row += 1; } if (!foundWot) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); JOptionPane.showMessageDialog(null, "Sorry, no WOT pulls were found in the log file", "No WOT data", JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception e) { logger.error(e); JOptionPane.showMessageDialog(null, e, "Error opening file", JOptionPane.ERROR_MESSAGE); } finally { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (br != null) { try { br.close(); } catch (IOException e) { logger.error(e); } } } } }