Search in sources :

Example 6 with GraphViewData

use of com.jjoe64.graphview.GraphView.GraphViewData in project Weather-Station by Kresshy.

the class DashboardFragment method weatherDataReceived.

@Override
public void weatherDataReceived(WeatherData weatherData) {
    Timber.d("weatherDataCount: " + weatherDataCount);
    if (weatherDataCount == 1) {
        previousData = weatherData;
        windSpeedData = new GraphViewData[1];
        temperatureData = new GraphViewData[1];
        windSpeedData[0] = new GraphViewData(0, weatherData.getWindSpeed());
        temperatureData[0] = new GraphViewData(0, weatherData.getTemperature());
        windSpeedSeries.resetData(windSpeedData);
        temperatureSeries.resetData(temperatureData);
        slidingScreen.add(weatherData);
        weatherDataCount++;
    } else {
        // prevent adding false measurements
        if (weatherData.getTemperature() == 0.0 || (weatherData.getTemperature() - previousData.getTemperature() > 1.0)) {
            weatherData.setTemperature(previousData.getTemperature());
        } else {
            previousData = weatherData;
        }
        // the windspeed is an avarage of 5 measurements
        if (slidingScreen.size() == screenSize + 1) {
            slidingScreen.remove(0);
        }
        slidingScreen.add(weatherData);
        double sumWindSpeed = 0;
        double sumTemperature = 0;
        for (WeatherData wData : slidingScreen) {
            sumWindSpeed += wData.getWindSpeed();
            sumTemperature += wData.getTemperature();
        }
        double avarageWindSpeed = sumWindSpeed / slidingScreen.size();
        double avarageTemperature = sumTemperature / slidingScreen.size();
        Timber.d("windspeed: " + avarageWindSpeed);
        Timber.d("temperature: " + avarageTemperature);
        windSpeedSeries.appendData(new GraphViewData(weatherDataCount, avarageWindSpeed), true, NUM_SAMPLES);
        temperatureSeries.appendData(new GraphViewData(weatherDataCount, avarageTemperature), true, NUM_SAMPLES);
        weatherDataCount++;
    }
}
Also used : GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData) WeatherData(com.kresshy.weatherstation.weather.WeatherData)

Example 7 with GraphViewData

use of com.jjoe64.graphview.GraphView.GraphViewData in project netxms by netxms.

the class LineChartElement method refresh.

/* (non-Javadoc)
	 * @see org.netxms.ui.android.main.dashboards.elements.AbstractDashboardElement#refresh()
	 */
@Override
public void refresh() {
    final ChartDciConfig[] items = config.getDciList();
    Log.v(TAG, "refresh(): " + items.length + " items to load");
    if (items.length == 0)
        return;
    final long endTime = System.currentTimeMillis();
    final long startTime = endTime - config.getTimeRangeMillis();
    graphView.setCustomLabelFormatter(new CustomLabel(Integer.parseInt(sp.getString("global.multipliers", "1")), (endTime - startTime) > 86400 * 1000));
    try {
        final DciData[] dciData = new DciData[items.length];
        for (int i = 0; i < dciData.length; i++) {
            dciData[i] = service.getSession().getCollectedData(items[i].nodeId, items[i].dciId, new Date(startTime), new Date(endTime), 0);
        }
        Log.v(TAG, "refresh(): data retrieved from server");
        post(new Runnable() {

            @Override
            public void run() {
                graphView.removeAllSeries();
                for (int i = 0; i < dciData.length && i < Colors.DEFAULT_ITEM_COLORS.length; i++) {
                    DciDataRow[] dciDataRow = dciData[i].getValues();
                    GraphViewData[] gvData = new GraphViewData[dciDataRow.length];
                    for (int j = dciDataRow.length - 1, k = 0; j >= 0; j--, k++) // dciData are reversed!
                    gvData[k] = new GraphViewData(dciDataRow[j].getTimestamp().getTime(), dciDataRow[j].getValueAsDouble());
                    int color = items[i].getColorAsInt();
                    color = color == -1 ? Colors.DEFAULT_ITEM_COLORS[i] : swapRGB(color);
                    GraphViewSeries series = new GraphViewSeries(items[i].getName(), new GraphViewSeriesStyle(color | 0xFF000000, 3), gvData);
                    graphView.addSeries(series);
                }
                graphView.setViewPort(startTime, endTime - startTime + 1);
                Log.v(TAG, "refresh(): " + dciData.length + " series added; viewport set to " + startTime + "/" + (endTime - startTime + 1));
                if (getChildCount() == 0)
                    addView(graphView);
                else
                    graphView.redrawAll();
            }
        });
    } catch (Exception e) {
        Log.e(TAG, "Exception while reading data from server", e);
    }
}
Also used : CustomLabel(org.netxms.ui.android.helpers.CustomLabel) ChartDciConfig(org.netxms.ui.android.main.activities.helpers.ChartDciConfig) DciData(org.netxms.client.datacollection.DciData) Date(java.util.Date) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries) GraphViewSeriesStyle(com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData)

Aggregations

GraphViewData (com.jjoe64.graphview.GraphView.GraphViewData)7 GraphViewSeries (com.jjoe64.graphview.GraphViewSeries)6 LineGraphView (com.jjoe64.graphview.LineGraphView)3 Paint (android.graphics.Paint)2 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 GraphViewSeriesStyle (com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle)1 GraphViewStyle (com.jjoe64.graphview.GraphViewStyle)1 Measurement (com.kresshy.weatherstation.weather.Measurement)1 WeatherData (com.kresshy.weatherstation.weather.WeatherData)1 Date (java.util.Date)1 DciData (org.netxms.client.datacollection.DciData)1 CustomLabel (org.netxms.ui.android.helpers.CustomLabel)1 ChartDciConfig (org.netxms.ui.android.main.activities.helpers.ChartDciConfig)1