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++;
}
}
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);
}
}
Aggregations