Search in sources :

Example 1 with GraphViewData

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

the class GraphViewFragment method createViewForWindSpeedGraph.

private void createViewForWindSpeedGraph(LinearLayout container) {
    Timber.d("Creating GraphView For WindSpeed");
    windSpeedGraph = new LineGraphView(getActivity().getApplicationContext(), "Wind Speed");
    windSpeedGraph.setScrollable(true);
    // windSpeedGraph.setScalable(true);
    windSpeedGraph.setViewPort(0, numberOfSamples);
    windSpeedGraph.setGraphViewStyle(getGraphViewStyle());
    windSpeedGraph.setHorizontalLabels(getHorizontalLabelsForGraph(numberOfSamples));
    GraphViewData[] windSpeedData = new GraphViewData[1];
    windSpeedData[0] = new GraphViewData(0, 0);
    windSpeedDataList.add(windSpeedData);
    GraphViewSeries windSpeedSeries = new GraphViewSeries("Wind Speed", new GraphViewSeries.GraphViewSeriesStyle(Color.BLUE, getLineWidthByNode(0)), windSpeedData);
    windSpeedSeriesList.add(windSpeedSeries);
    windSpeedGraph.addSeries(windSpeedSeries);
    Timber.d("Adding GraphView For WindSpeed to LayoutContainer");
    container.addView(windSpeedGraph);
}
Also used : LineGraphView(com.jjoe64.graphview.LineGraphView) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries)

Example 2 with GraphViewData

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

the class GraphViewFragment method handleIncomingMeasurement.

private void handleIncomingMeasurement(Measurement measurement) {
    // prevent adding false zero temperature measurements
    Timber.d("Filtering wrong measurements and load previous values");
    for (int j = 0; j < measurement.getNumberOfNodes(); j++) {
        if (previousMeasurement.hasNodeId(j) && measurement.hasNodeId(j)) {
            if (measurement.getWeatherDataForNode(j).getTemperature() == 0.0 || (measurement.getWeatherDataForNode(j).getTemperature() - previousMeasurement.getWeatherDataForNode(j).getTemperature() > 3.0)) {
                measurement.getWeatherDataForNode(j).setTemperature(previousMeasurement.getWeatherDataForNode(j).getTemperature());
            }
        }
    }
    previousMeasurement = measurement;
    // maintaining bucket for average calculation
    if (lastMeasurementsList.size() == averageBucketSize + 1) {
        lastMeasurementsList.remove(0);
    }
    lastMeasurementsList.add(measurement);
    for (int i = 0; i < measurement.getNumberOfNodes(); i++) {
        double sumWindSpeed = 0;
        double sumTemperature = 0;
        int missingMeasurements = 0;
        for (Measurement m : lastMeasurementsList) {
            if (!(m.getNumberOfNodes() < i)) {
                // if measurement has missing data of nodes
                if (m.hasNodeId(i)) {
                    // ensuring node exists
                    if (i > 0) {
                        sumWindSpeed += (m.getWeatherDataForNode(i).getWindSpeed() + correctionWind);
                        sumTemperature += (m.getWeatherDataForNode(i).getTemperature() + correctionTemp);
                    } else {
                        sumWindSpeed += m.getWeatherDataForNode(i).getWindSpeed();
                        sumTemperature += m.getWeatherDataForNode(i).getTemperature();
                    }
                } else {
                    // else doesn't count in the average calc
                    missingMeasurements++;
                }
            }
        }
        double averageWindSpeed = sumWindSpeed / (lastMeasurementsList.size() - missingMeasurements);
        double averageTemperature = sumTemperature / (lastMeasurementsList.size() - missingMeasurements);
        Timber.d("SumWindSpeed: " + sumWindSpeed + ", sumTemp: " + sumTemperature);
        Timber.d("Missing measurements: " + missingMeasurements);
        Timber.d("LastMeasurementList: " + lastMeasurementsList.toString());
        Timber.d("AverageWindSpeed: " + averageWindSpeed + ", AverageTemp: " + averageTemperature);
        Timber.d("Adding data in Series for nodeId: " + i);
        Timber.d("Number of samples: " + numberOfSamples);
        try {
            windSpeedSeriesList.get(i).appendData(new GraphViewData(measurementCount, averageWindSpeed), true, numberOfSamples);
        } catch (IndexOutOfBoundsException e) {
            Timber.d("Cannot find windSpeedSeries for nodeId: " + i + " creating new GraphViewSeries");
            GraphViewData[] windSpeedData = new GraphViewData[1];
            windSpeedData[0] = new GraphViewData(measurementCount, measurement.getWeatherDataForNode(i).getWindSpeed());
            windSpeedDataList.add(i, windSpeedData);
            GraphViewSeries windSpeedSeries = new GraphViewSeries("Wind Speed", new GraphViewSeries.GraphViewSeriesStyle(getColorForWindSpeedByNode(i), getLineWidthByNode(i)), windSpeedDataList.get(i));
            windSpeedSeriesList.add(i, windSpeedSeries);
            windSpeedSeriesList.get(i).resetData(windSpeedDataList.get(i));
            windSpeedGraph.addSeries(windSpeedSeriesList.get(i));
        }
        try {
            temperatureSeriesList.get(i).appendData(new GraphViewData(measurementCount, averageTemperature), true, numberOfSamples);
        } catch (IndexOutOfBoundsException e) {
            Timber.d("Cannot find windSpeedSeries for nodeId: " + i + " creating new GraphViewSeries");
            GraphViewData[] temperatureData = new GraphViewData[1];
            temperatureData[0] = new GraphViewData(measurementCount, measurement.getWeatherDataForNode(i).getTemperature());
            temperatureDataList.add(i, temperatureData);
            GraphViewSeries temperatureSeries = new GraphViewSeries("Temperature", new GraphViewSeries.GraphViewSeriesStyle(getColorForTemperatureByNode(i), getLineWidthByNode(i)), temperatureDataList.get(i));
            temperatureSeriesList.add(i, temperatureSeries);
            temperatureSeriesList.get(i).resetData(temperatureDataList.get(i));
            temperatureGraph.addSeries(temperatureSeriesList.get(i));
        }
    }
    measurementCount++;
}
Also used : Measurement(com.kresshy.weatherstation.weather.Measurement) Paint(android.graphics.Paint) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries)

Example 3 with GraphViewData

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

the class GraphViewFragment method createViewForTemperatureGraph.

private void createViewForTemperatureGraph(LinearLayout container) {
    Timber.d("Creating GraphView For Temperature");
    temperatureGraph = new LineGraphView(getActivity().getApplicationContext(), "Temperature");
    temperatureGraph.setScrollable(true);
    // temperatureGraph.setScalable(true);
    temperatureGraph.setViewPort(0, numberOfSamples);
    temperatureGraph.setGraphViewStyle(getGraphViewStyle());
    temperatureGraph.setHorizontalLabels(getHorizontalLabelsForGraph(numberOfSamples));
    temperatureGraph.setShowHorizontalLabels(false);
    GraphViewData[] temperatureData = new GraphViewData[1];
    temperatureData[0] = new GraphViewData(0, 0);
    temperatureDataList.add(temperatureData);
    GraphViewSeries temperatureSeries = new GraphViewSeries("Temperature", new GraphViewSeries.GraphViewSeriesStyle(Color.RED, getLineWidthByNode(0)), temperatureData);
    temperatureSeriesList.add(temperatureSeries);
    temperatureGraph.addSeries(temperatureSeries);
    Timber.d("Adding GraphView For Temperature to LayoutContainer");
    container.addView(temperatureGraph);
}
Also used : LineGraphView(com.jjoe64.graphview.LineGraphView) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries)

Example 4 with GraphViewData

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

the class GraphViewFragment method handleFirstIncomingMeasurement.

private void handleFirstIncomingMeasurement(Measurement measurement) {
    Timber.d("Handling the (1st) first incoming message");
    previousMeasurement = measurement;
    Timber.d("Cleaning the graphViews");
    windSpeedGraph.removeAllSeries();
    temperatureGraph.removeAllSeries();
    windSpeedDataList = new ArrayList<>();
    temperatureDataList = new ArrayList<>();
    windSpeedSeriesList = new ArrayList<>();
    temperatureSeriesList = new ArrayList<>();
    for (int i = 0; i < measurement.getNumberOfNodes(); i++) {
        GraphViewData[] windSpeedData = new GraphViewData[1];
        GraphViewData[] temperatureData = new GraphViewData[1];
        if (i > 0) {
            windSpeedData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getWindSpeed() + correctionWind);
            temperatureData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getTemperature() + correctionTemp);
        } else {
            windSpeedData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getWindSpeed());
            temperatureData[0] = new GraphViewData(0, measurement.getWeatherDataForNode(i).getTemperature());
        }
        try {
            windSpeedData = windSpeedDataList.get(i);
        } catch (IndexOutOfBoundsException e) {
            Timber.d("Cannot find windSpeedData for nodeId: " + i + " creating new GraphViewDataArray");
            windSpeedDataList.add(i, windSpeedData);
        }
        try {
            temperatureData = temperatureDataList.get(i);
        } catch (IndexOutOfBoundsException e) {
            Timber.d("Cannot find temperatureData for nodeId: " + i + " creating new GraphViewDataArray");
            temperatureDataList.add(i, temperatureData);
        }
        GraphViewSeries windSpeedSeries;
        GraphViewSeries temperatureSeries;
        windSpeedSeries = new GraphViewSeries("Wind Speed", new GraphViewSeries.GraphViewSeriesStyle(getColorForWindSpeedByNode(i), getLineWidthByNode(i)), windSpeedDataList.get(i));
        temperatureSeries = new GraphViewSeries("Temperature", new GraphViewSeries.GraphViewSeriesStyle(getColorForTemperatureByNode(i), getLineWidthByNode(i)), temperatureDataList.get(i));
        try {
            windSpeedSeries = windSpeedSeriesList.get(i);
        } catch (IndexOutOfBoundsException e) {
            Timber.d("Cannot find windSpeedSeries for nodeId: " + i + " creating new GraphViewSeries");
            windSpeedSeriesList.add(i, windSpeedSeries);
        }
        try {
            temperatureSeries = temperatureSeriesList.get(i);
        } catch (IndexOutOfBoundsException e) {
            Timber.d("Cannot find temperatureSeries for nodeId: " + i + " creating new GraphViewSeries");
            temperatureSeriesList.add(i, temperatureSeries);
        }
        Timber.d("Reset data in new Series for nodeId: " + i);
        windSpeedSeriesList.get(i).resetData(windSpeedDataList.get(i));
        temperatureSeriesList.get(i).resetData(temperatureDataList.get(i));
        Timber.d("Adding Series for GraphView for nodeId: " + i);
        windSpeedGraph.addSeries(windSpeedSeriesList.get(i));
        temperatureGraph.addSeries(temperatureSeriesList.get(i));
    }
    lastMeasurementsList.add(measurement);
    measurementCount++;
}
Also used : Paint(android.graphics.Paint) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries)

Example 5 with GraphViewData

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

the class DashboardFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_dashboard, container, false);
    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
    NUM_SAMPLES = Integer.parseInt(sharedPreferences.getString(SettingsFragment.KEY_PREF_INTERVAL, "300"));
    String[] horizontalLabels;
    switch(NUM_SAMPLES) {
        case 60:
            horizontalLabels = new String[] { "1min", "45sec", "30sec", "15sec", "0min" };
            Timber.d("Number of samples: 60");
            break;
        case 120:
            horizontalLabels = new String[] { "2min", "1min", "0min" };
            Timber.d("Number of samples: 120");
            break;
        case 300:
            horizontalLabels = new String[] { "5min", "4min", "3min", "2min", "1min", "0min" };
            Timber.d("Number of samples: 300");
            break;
        case 600:
            horizontalLabels = new String[] { "10min", "8min", "6min", "4min", "2min", "0min" };
            Timber.d("Number of samples: 600");
            break;
        case 1200:
            horizontalLabels = new String[] { "20min", "15min", "10min", "5min", "0min" };
            Timber.d("Number of samples: 1200");
            break;
        default:
            horizontalLabels = new String[] { "5min", "4min", "3min", "2min", "1min", "0min" };
            Timber.d("Number of samples: 300");
    }
    LinearLayout windSpeedContainer = (LinearLayout) view.findViewById(R.id.windSpeedContainer);
    LinearLayout temperatureContainer = (LinearLayout) view.findViewById(R.id.temperatureContainer);
    graphViewStyle = new GraphViewStyle(Color.BLACK, Color.BLACK, Color.GRAY);
    graphViewStyle.setVerticalLabelsAlign(Paint.Align.LEFT);
    graphViewStyle.setVerticalLabelsWidth(80);
    windSpeedGraph = new LineGraphView(getActivity().getApplicationContext(), "Wind Speed");
    windSpeedGraph.setScrollable(true);
    // windSpeedGraph.setScalable(true);
    windSpeedGraph.setViewPort(0, NUM_SAMPLES);
    windSpeedGraph.setGraphViewStyle(graphViewStyle);
    windSpeedGraph.setHorizontalLabels(horizontalLabels);
    temperatureGraph = new LineGraphView(getActivity().getApplicationContext(), "Temperature");
    temperatureGraph.setScrollable(true);
    // temperatureGraph.setScalable(true);
    temperatureGraph.setViewPort(0, NUM_SAMPLES);
    temperatureGraph.setGraphViewStyle(graphViewStyle);
    temperatureGraph.setHorizontalLabels(horizontalLabels);
    temperatureGraph.setShowHorizontalLabels(false);
    windSpeedData = new GraphViewData[1];
    temperatureData = new GraphViewData[1];
    windSpeedData[0] = new GraphViewData(0, 0);
    temperatureData[0] = new GraphViewData(0, 0);
    windSpeedSeries = new GraphViewSeries("Wind Speed", new GraphViewSeries.GraphViewSeriesStyle(Color.BLUE, 7), windSpeedData);
    temperatureSeries = new GraphViewSeries("Temperature", new GraphViewSeries.GraphViewSeriesStyle(Color.RED, 7), temperatureData);
    windSpeedGraph.addSeries(windSpeedSeries);
    temperatureGraph.addSeries(temperatureSeries);
    windSpeedContainer.addView(windSpeedGraph);
    temperatureContainer.addView(temperatureGraph);
    return view;
}
Also used : LineGraphView(com.jjoe64.graphview.LineGraphView) GraphViewStyle(com.jjoe64.graphview.GraphViewStyle) LineGraphView(com.jjoe64.graphview.LineGraphView) View(android.view.View) LinearLayout(android.widget.LinearLayout) GraphViewData(com.jjoe64.graphview.GraphView.GraphViewData) GraphViewSeries(com.jjoe64.graphview.GraphViewSeries)

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