Search in sources :

Example 1 with WeatherData

use of com.kresshy.weatherstation.weather.WeatherData in project Weather-Station by Kresshy.

the class CalibrationFragment method measurementReceived.

@Override
public void measurementReceived(Measurement measurement) {
    WeatherData data = measurement.getWeatherDataForNode(0);
    if (measurement.getNumberOfNodes() > 1) {
        WeatherData data2 = measurement.getWeatherDataForNode(1);
        windSpeedDiff = data.getWindSpeed() - data2.getWindSpeed();
        tempDiff = data.getTemperature() - data2.getTemperature();
    } else {
        Toast.makeText(getActivity().getApplicationContext(), "Skipping calibration, only one station", Toast.LENGTH_SHORT).show();
        mListener.startDashboardAfterCalibration();
    }
    windSpeedDiffView.setText(Double.toString(windSpeedDiff));
    tempDiffView.setText(Double.toString(tempDiff) + "°C");
}
Also used : WeatherData(com.kresshy.weatherstation.weather.WeatherData)

Example 2 with WeatherData

use of com.kresshy.weatherstation.weather.WeatherData 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)

Aggregations

WeatherData (com.kresshy.weatherstation.weather.WeatherData)2 GraphViewData (com.jjoe64.graphview.GraphView.GraphViewData)1