Package nz.co.abrahams.asithappens.storage

Examples of nz.co.abrahams.asithappens.storage.DataPoint


        DataSetsDAO dataSetsDAO;
        DataSetDAO dataSetDAO;
        int sessionID;
        String[] headings;
        DataSet dataSet;
        DataPoint point;
       
        savedFile = null;
        dialog = new JOptionPane();
       
        sessionID = getSessionID();
        if ( sessionID == -1 )
            return;
       
        if ( ((JTable)(sessionsPane.getViewport().getView())).getSelectedRowCount() > 1 ) {
            dialog.showMessageDialog(this, "Please select a single session for data export", "Multiple sessions selected", JOptionPane.ERROR_MESSAGE);
            return;
        }
       
        try {
            //.testConnection();
            dataSetsDAO = DAOFactory.getDataSetsDAO();
            dataSetDAO = DAOFactory.getDataSetDAO();
            chooser = new JFileChooser();
            returnStatus = chooser.showSaveDialog(this);
            if ( returnStatus == JFileChooser.APPROVE_OPTION ) {
                savedFile = chooser.getSelectedFile();
                if ( ! savedFile.exists() || ( savedFile.exists() && dialog.showConfirmDialog(null,
                        "File already exists - are you sure you want to overwrite it?",
                        "Confirm file overwrite", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION ) ) {
                    out = new FileWriter(savedFile);
                   
                    out.write("Title: " + dataSetsDAO.retrieveSessionTitle(sessionID) + "\n");
                    out.write("Description: " + DataSets.retrieveDescription(sessionID) + "\n\n");
                   
                    headings = DAOFactory.getDataHeadingsDAO().retrieve(sessionID);
                   
                    for ( int set = 0 ; set < headings.length ; set++ ) {
                        out.write("Set " + set + ": " + headings[set] + "\n");
                    }
                    out.write("\n");
                   
                    out.write("Set,Time,Value\n");
                    for ( int set = 0; set < headings.length ; set++ ) {
                        dataSet = dataSetDAO.retrieve(sessionID, set);
                        //out.write("Set " + set + ": " + headings[set] + "\n");
                        for ( int i = 0 ; i < dataSet.size() ; i++ ) {
                            point = dataSet.elementAt(i);
                            out.write(set + "," + point.getTime() + "," + point.getValue() + "\n");
                        }
                        //out.write("\n");
                    }
                   
                    out.close();
View Full Code Here


    public void setUp() throws java.lang.Exception {
       
        emptySet = new DataSet();
       
        singleNanSet = new DataSet();
        singleNanSet.add(new DataPoint(START_TIME));
       
        multipleNanSet = new DataSet();
        multipleNanSet.add(new DataPoint(START_TIME));
        multipleNanSet.add(new DataPoint(START_TIME + TIME_INCREMENT));
        multipleNanSet.add(new DataPoint(START_TIME + 2 * TIME_INCREMENT));
       
        singlePointSet = new DataSet();
        singlePointSet.add(new DataPoint(START_TIME, INITIAL_VALUE));

        multiplePointSet = new DataSet();
        multiplePointSet.add(new DataPoint(START_TIME, INITIAL_VALUE));
        multiplePointSet.add(new DataPoint(START_TIME + TIME_INCREMENT, INITIAL_VALUE + VALUE_INCREMENT));
        multiplePointSet.add(new DataPoint(START_TIME + 2 * TIME_INCREMENT, INITIAL_VALUE + 2 * VALUE_INCREMENT));
       
    }
View Full Code Here

    public DataPointTest() {
    }

    @Before
    public void setUp() throws java.lang.Exception {
        nanPoint1 = new DataPoint(START_TIME);
        point1 = new DataPoint(START_TIME, 1);
        point2 = new DataPoint(START_TIME + INCREMENT, 2);
    }
View Full Code Here

    /**
     * Test of setValue method, of class nz.co.abrahams.asithappens.DataPoint.
     */
    @Test
    public void testSetValue() {
        DataPoint newPoint;
       
        System.out.println("testSetValue");
       
        newPoint = new DataPoint(START_TIME, 2);
        newPoint.setValue(3);
        Assert.assertEquals(3D, newPoint.getValue(), 0D);
    }
View Full Code Here

                    else
                        sum += newBytes[dir][i] - lastBytes[dir][i];
                    lastBytes[dir][i] = newBytes[dir][i];
                }
                if ( ! wrap )
                    returnData[dir] = new DataPoint(collectTime, sum * 8000 / (collectTime - lastTime[dir]) );
                else
                    returnData[dir] = new DataPoint(collectTime);
                lastTime[dir] = collectTime;
               
            } catch (SNMPException e) {
                returnData[dir] = new DataPoint(collectTime);
                logger.warn("Error collecting bandwith values from " + device);
            }
           
        }
        return new DataCollectorResponse(returnData, new String[0], setCount);
View Full Code Here

        point = new DataPoint[1];
        currentTime = System.currentTimeMillis();
       
        try {
            storageUsed = (double)snmp.getStorageUsed(storageIndex) * allocationUnits;
            point[0] = new DataPoint(currentTime, storageUsed);
            logger.debug("Adding value: " + storageUsed);
        } catch (SNMPException e) {
            point[0] = new DataPoint(currentTime);
            logger.warn("Timeout fetching storage used");
        }
       
        return new DataCollectorResponse(point, new String[0], dataType.initialSetCount());
    }
View Full Code Here

            }
            if ( changedValues && ! clockedCounter ) {
                for ( int i = 0; i < USAGE_CATEGORIES; i++ ) {
                    if ( i < USAGE_CATEGORIES - 1 ) {
                        lastPercentages[i] = (double)( newTicks[i] - lastTicks[i] ) * 100 / totalTicks;
                        returnData[i] = new DataPoint(currentTime, lastPercentages[i]);
                    }
                    lastTicks[i] = newTicks[i];
                }
                lastTime = currentTime;
            } else {
                for ( int i = 0; i < dataType.initialSetCount(); i++ ) {
                    if ( Double.isNaN(lastPercentages[i]) )
                        returnData[i] = new DataPoint(currentTime);
                    else
                        returnData[i] = new DataPoint(currentTime, lastPercentages[i]);
                }
            }
        } catch (SNMPException e) {
            for ( int i = 0; i < dataType.initialSetCount(); i++ ) {
                returnData[i] = new DataPoint(currentTime);
            }
            logger.warn("Timeout fetching processor load");
        }
       
        return new DataCollectorResponse(returnData, new String[0], dataType.initialSetCount());
View Full Code Here

       
        // Reduce data set values representing the current x pixel
        for ( int set = Math.max(startPosition.getSetNumber(), 0) ; set <= endPosition.getSetNumber()  ; set++ ) {
            DataSet points;
            Iterator iterator;
            DataPoint point;
            double summaryPoint;
            double reductionNumerator;
           
            DataSet dataSet;
            int nextIndex;
            IntegerPair range;
           
            // Find numerator for fraction of summary point set value to keep
            summaryPoint = graphContext.getSummaryData().getValue(set, xPixel - xOffset);
            if ( set == startPosition.getSetNumber() && set == endPosition.getSetNumber() ) {
                reductionNumerator = Math.max(summaryPoint - ( endPosition.getSetOffset() - startPosition.getSetOffset() ), 0);
            } else if ( set == startPosition.getSetNumber() ) {
                reductionNumerator = startPosition.getSetOffset();
            } else if ( set == endPosition.getSetNumber() ) {
                reductionNumerator = Math.max(summaryPoint - endPosition.getSetOffset(), 0);
            } else {
                reductionNumerator = 0;
            }
           
            // Reduce data points whose time falls within the single summary pixel
           
            /*
            points = graphContext.getData().getDataSet(set).pointsBetween(graphContext.getTimeFromXPixel(xPixel), graphContext.getTimeFromXPixel(xPixel + 1));
            iterator = points.iterator();
            while ( iterator.hasNext() ) {
                point = (DataPoint)(iterator.next());
                if ( summaryPoint > 0 )
                    point.setValue(point.getValue() * reductionNumerator / summaryPoint);
                else
                    point.setValue(0);
            }
             */
           
            dataSet = graphContext.getData().getDataSet(set);
            if ( startIndicies[set] == -1 )
                range = dataSet.pointIndiciesBetween(graphContext.getTimeFromXPixel(xPixel), graphContext.getTimeFromXPixel(xPixel + 1));
            else
                range = dataSet.pointIndiciesBetween(graphContext.getTimeFromXPixel(xPixel), graphContext.getTimeFromXPixel(xPixel + 1), startIndicies[set]);
            nextIndex = range.first;
            while ( nextIndex <= range.second ) {
                point = dataSet.elementAt(nextIndex);
                if ( summaryPoint > 0 )
                    point.setValue(point.getValue() * reductionNumerator / summaryPoint);
                else
                    point.setValue(0);
                nextIndex++;
            }
            startIndicies[set] = range.second;
        }
        //logger.debug("Fragmented column after decimation:");
View Full Code Here

           
            //points = new DataPoint[data.getNumberOfSets()];
            points = new DataPoint[setCount];
           
            for ( i = 0; i < setCount; i++ ) {
                points[i] = new DataPoint(currentTime, 0);
            }
            for ( i = 0; i < fetchedTableSize; i++ ) {
                if ( mappings[i] != -1 )
                    points[mappings[i]].setValue(rates[i]);
            }
            //return new DataCollectorResponse(points, (String[])newSets.toArray(), setCount);
            return new DataCollectorResponse(points, (String[])newSets.toArray(new String[newSets.size()]), setCount);
        } catch (Exception e) {
            logger.warn("Exception collecting values: " + e);
            e.printStackTrace();
            points = new DataPoint[setCount];
            for (int set = 0; set < setCount; set++ )
                points[set] = new DataPoint(currentTime, 0);
            //return new DataCollectorResponse(points, (String[])newSets.toArray(), setCount);
            return new DataCollectorResponse(points, (String[])newSets.toArray(new String[newSets.size()]), setCount);
        }
    }
View Full Code Here

                newCollectionTimes[i] = System.currentTimeMillis();
                newValues[i] = fetchOIDValue(oids.elementAt(i));
            }
            for (int i = 0; i < oids.size(); i++) {
                if ( oids.elementAt(i).type == SNMPType.Integer32 || oids.elementAt(i).type == SNMPType.Gauge32 ) {
                    returnData[i] = new DataPoint(newCollectionTimes[i], newValues[i]);
                } else if ( oids.elementAt(i).type == SNMPType.Counter32 || oids.elementAt(i).type == SNMPType.Counter64 ) {
                    long difference;
                    difference = newValues[i] - lastValues[i];
                    if ( difference < 0 ) {
                        if ( oids.elementAt(i).type == SNMPType.Counter32 ) {
                            difference += Integer.MAX_VALUE;
                        } else if ( oids.elementAt(i).type == SNMPType.Counter32 ) {
                            difference += Long.MAX_VALUE;
                        }
                    }
                    returnData[i] = new DataPoint(newCollectionTimes[i], (double)difference / ((double)(newCollectionTimes[i] - lastCollectionTimes[i]) / 1000) );
                }
                lastCollectionTimes[i] = newCollectionTimes[i];
                lastValues[i] = newValues[i];
            }
        } catch (SNMPTypeException e) {
            for (int i = 0; i < oids.size(); i++) {
                returnData[i] = new DataPoint(currentTime);
            }
            logger.warn("SNMP type problem fetching OID values");
        } catch (SNMPException e) {
            for (int i = 0; i < oids.size(); i++) {
                returnData[i] = new DataPoint(currentTime);
            }
            logger.warn("Timeout fetching OID values");
        }
        return new DataCollectorResponse(returnData,
                new String[0], oids.size());
View Full Code Here

TOP

Related Classes of nz.co.abrahams.asithappens.storage.DataPoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.