Search in sources :

Example 1 with WifiState

use of com.att.aro.core.peripheral.pojo.WifiInfo.WifiState in project VideoOptimzer by attdevsupport.

the class WifiInfoReaderImpl method readData.

@Override
public List<WifiInfo> readData(String directory, double startTime, double traceDuration) {
    this.wifiActiveDuration = 0;
    List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>();
    String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.WIFI_FILE;
    if (!filereader.fileExist(filepath)) {
        return wifiInfos;
    }
    double dLastTimeStamp = 0.0;
    double dActiveDuration = 0.0;
    double beginTime = 0.0;
    double endTime = 0.0;
    String prevMacAddress = null;
    String prevRssi = null;
    String prevSsid = null;
    WifiState prevWifiState = null;
    WifiState lastWifiState = null;
    String firstLine;
    String strLineBuf;
    String[] lines = null;
    try {
        lines = filereader.readAllLine(filepath);
    } catch (IOException e1) {
        LOGGER.error("failed to read Wifi info file: " + filepath);
    }
    if (lines != null && lines.length > 0) {
        firstLine = lines[0];
        try {
            String[] strFieldsFirstLine = firstLine.split(" ");
            if (strFieldsFirstLine.length >= 2) {
                beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime);
                if (TraceDataConst.WIFI_OFF.equals(strFieldsFirstLine[1])) {
                    prevWifiState = WifiState.WIFI_DISABLED;
                } else if (TraceDataConst.WIFI_CONNECTED.equals(strFieldsFirstLine[1])) {
                    prevWifiState = WifiState.WIFI_CONNECTED;
                    Matcher matcher = wifiPattern.matcher(firstLine);
                    if (matcher.lookingAt()) {
                        prevMacAddress = matcher.group(1);
                        prevRssi = matcher.group(2);
                        prevSsid = matcher.group(3);
                    } else {
                        LOGGER.warn("Unable to parse wifi connection params: " + firstLine);
                    }
                } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFieldsFirstLine[1])) {
                    prevWifiState = WifiState.WIFI_DISCONNECTED;
                } else if (TraceDataConst.WIFI_CONNECTING.equals(strFieldsFirstLine[1])) {
                    prevWifiState = WifiState.WIFI_CONNECTING;
                } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFieldsFirstLine[1])) {
                    prevWifiState = WifiState.WIFI_DISCONNECTING;
                } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFieldsFirstLine[1])) {
                    prevWifiState = WifiState.WIFI_SUSPENDED;
                } else {
                    LOGGER.warn("Unknown wifi state: " + firstLine);
                    prevWifiState = WifiState.WIFI_UNKNOWN;
                }
                // FIXME Flawed logic lastWifiState is always null
                // if (!prevWifiState.equals(lastWifiState)) {
                // if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) {
                // dActiveDuration += (beginTime - dLastTimeStamp);
                // }
                lastWifiState = prevWifiState;
                dLastTimeStamp = beginTime;
            // }
            } else {
                LOGGER.warn("Invalid WiFi trace entry: " + firstLine);
            }
        } catch (Exception e) {
            LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e);
        }
        for (int i = 1; i < lines.length; i++) {
            strLineBuf = lines[i];
            String[] strFields = strLineBuf.split(" ");
            try {
                if (strFields.length >= 2) {
                    String macAddress = null;
                    String rssi = null;
                    String ssid = null;
                    WifiState wifiState = null;
                    endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime);
                    if (TraceDataConst.WIFI_OFF.equals(strFields[1])) {
                        wifiState = WifiState.WIFI_DISABLED;
                    } else if (TraceDataConst.WIFI_CONNECTED.equals(strFields[1])) {
                        wifiState = WifiState.WIFI_CONNECTED;
                        Matcher matcher = wifiPattern.matcher(strLineBuf);
                        if (matcher.lookingAt()) {
                            macAddress = matcher.group(1);
                            rssi = matcher.group(2);
                            ssid = matcher.group(3);
                        } else {
                            LOGGER.warn("Unable to parse wifi connection params: " + strLineBuf);
                        }
                    } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFields[1])) {
                        wifiState = WifiState.WIFI_DISCONNECTED;
                    } else if (TraceDataConst.WIFI_CONNECTING.equals(strFields[1])) {
                        wifiState = WifiState.WIFI_CONNECTING;
                    } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFields[1])) {
                        wifiState = WifiState.WIFI_DISCONNECTING;
                    } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFields[1])) {
                        wifiState = WifiState.WIFI_SUSPENDED;
                    } else {
                        LOGGER.warn("Unknown wifi state: " + strLineBuf);
                        wifiState = WifiState.WIFI_UNKNOWN;
                    }
                    if (!wifiState.equals(lastWifiState)) {
                        wifiInfos.add(new WifiInfo(beginTime, endTime, prevWifiState, prevMacAddress, prevRssi, prevSsid));
                        if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) {
                            dActiveDuration += (endTime - dLastTimeStamp);
                        }
                        lastWifiState = wifiState;
                        dLastTimeStamp = endTime;
                        beginTime = endTime;
                        prevWifiState = wifiState;
                        prevMacAddress = macAddress;
                        prevRssi = rssi;
                        prevSsid = ssid;
                    }
                } else {
                    LOGGER.warn("Invalid WiFi trace entry: " + strLineBuf);
                }
            } catch (Exception e) {
                LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e);
            }
        }
        wifiInfos.add(new WifiInfo(beginTime, traceDuration, prevWifiState, prevMacAddress, prevRssi, prevSsid));
        // Duration calculation should probably be done in analysis
        if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) {
            dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp);
        }
        this.wifiActiveDuration = dActiveDuration;
        Collections.sort(wifiInfos);
    }
    return wifiInfos;
}
Also used : WifiState(com.att.aro.core.peripheral.pojo.WifiInfo.WifiState) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) WifiInfo(com.att.aro.core.peripheral.pojo.WifiInfo) IOException(java.io.IOException)

Example 2 with WifiState

use of com.att.aro.core.peripheral.pojo.WifiInfo.WifiState in project VideoOptimzer by attdevsupport.

the class WifiPlot method populate.

@Override
public void populate(XYPlot plot, AROTraceData analysis) {
    wifiData = new XYIntervalSeriesCollection();
    if (analysis == null) {
        LOGGER.info("didn't get analysis trace data!  ");
    } else {
        TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
        if (resultType.equals(TraceResultType.TRACE_FILE)) {
            LOGGER.info("it is not contain the file ");
        } else {
            TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult().getTraceresult();
            Map<WifiState, XYIntervalSeries> seriesMap = new EnumMap<WifiState, XYIntervalSeries>(WifiState.class);
            for (WifiState eventType : WifiState.values()) {
                XYIntervalSeries series = new XYIntervalSeries(eventType);
                seriesMap.put(eventType, series);
                switch(eventType) {
                    case WIFI_UNKNOWN:
                    case WIFI_DISABLED:
                        // Don't chart these
                        break;
                    default:
                        wifiData.addSeries(series);
                        break;
                }
            }
            // Populate the data set
            List<WifiInfo> wifiInfos = traceresult.getWifiInfos();
            final Map<Double, WifiInfo> eventMap = new HashMap<Double, WifiInfo>(wifiInfos.size());
            Iterator<WifiInfo> iter = wifiInfos.iterator();
            if (iter.hasNext()) {
                while (iter.hasNext()) {
                    WifiInfo wifiEvent = iter.next();
                    seriesMap.get(wifiEvent.getWifiState()).add(wifiEvent.getBeginTimeStamp(), wifiEvent.getBeginTimeStamp(), wifiEvent.getEndTimeStamp(), 0.5, 0, 1);
                    eventMap.put(wifiEvent.getBeginTimeStamp(), wifiEvent);
                }
            }
            XYItemRenderer renderer = plot.getRenderer();
            for (WifiState eventType : WifiState.values()) {
                Color paint;
                switch(eventType) {
                    case WIFI_CONNECTED:
                    case WIFI_CONNECTING:
                    case WIFI_DISCONNECTING:
                        paint = new Color(34, 177, 76);
                        break;
                    case WIFI_DISCONNECTED:
                    case WIFI_SUSPENDED:
                        paint = Color.YELLOW;
                        break;
                    default:
                        paint = Color.WHITE;
                        break;
                }
                int index = wifiData.indexOf(eventType);
                if (index >= 0) {
                    renderer.setSeriesPaint(index, paint);
                }
            }
            // Assign ToolTip to renderer
            renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {

                @Override
                public String generateToolTip(XYDataset dataset, int series, int item) {
                    WifiState eventType = (WifiState) wifiData.getSeries(series).getKey();
                    StringBuffer message = new StringBuffer(ResourceBundleHelper.getMessageString("wifi.tooltip.prefix"));
                    message.append(MessageFormat.format(ResourceBundleHelper.getMessageString("wifi.tooltip"), dataset.getX(series, item), ResourceBundleHelper.getEnumString(eventType)));
                    switch(eventType) {
                        case WIFI_CONNECTED:
                            WifiInfo info = eventMap.get(dataset.getX(series, item));
                            if (info != null && info.getWifiState() == WifiState.WIFI_CONNECTED) {
                                message.append(MessageFormat.format(ResourceBundleHelper.getMessageString("wifi.connTooltip"), info.getWifiMacAddress(), info.getWifiRSSI(), info.getWifiSSID()));
                            }
                            break;
                        default:
                            break;
                    }
                    message.append(ResourceBundleHelper.getMessageString("wifi.tooltip.suffix"));
                    return message.toString();
                }
            });
        }
    }
    plot.setDataset(wifiData);
// return plot;
}
Also used : HashMap(java.util.HashMap) Color(java.awt.Color) TraceResultType(com.att.aro.core.packetanalysis.pojo.TraceResultType) WifiInfo(com.att.aro.core.peripheral.pojo.WifiInfo) XYIntervalSeriesCollection(org.jfree.data.xy.XYIntervalSeriesCollection) WifiState(com.att.aro.core.peripheral.pojo.WifiInfo.WifiState) XYIntervalSeries(org.jfree.data.xy.XYIntervalSeries) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) XYDataset(org.jfree.data.xy.XYDataset) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) EnumMap(java.util.EnumMap)

Aggregations

WifiInfo (com.att.aro.core.peripheral.pojo.WifiInfo)2 WifiState (com.att.aro.core.peripheral.pojo.WifiInfo.WifiState)2 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)1 TraceResultType (com.att.aro.core.packetanalysis.pojo.TraceResultType)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)1 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)1 XYDataset (org.jfree.data.xy.XYDataset)1 XYIntervalSeries (org.jfree.data.xy.XYIntervalSeries)1 XYIntervalSeriesCollection (org.jfree.data.xy.XYIntervalSeriesCollection)1