handling old and missing data on wind rose and station summary

pull/1/head
Mateusz Lubecki 2021-01-02 14:30:46 +01:00
rodzic 43c9ddc45d
commit 5eee31fc41
16 zmienionych plików z 211 dodań i 37 usunięć

Wyświetl plik

@ -5,7 +5,6 @@ import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
@ -25,10 +24,7 @@ import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.FormatStyle; import org.threeten.bp.format.FormatStyle;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import cc.pogoda.mobile.pogodacc.R; import cc.pogoda.mobile.pogodacc.R;
import cc.pogoda.mobile.pogodacc.activity.handler.WindPlotClickEvent; import cc.pogoda.mobile.pogodacc.activity.handler.WindPlotClickEvent;

Wyświetl plik

@ -43,6 +43,8 @@ public class StationDetailsSummaryActivity extends AppCompatActivity {
elems.wind_speed_val = findViewById(R.id.textViewWindSpeedValue); elems.wind_speed_val = findViewById(R.id.textViewWindSpeedValue);
elems.temperature_val = findViewById(R.id.textViewTemperatureValue); elems.temperature_val = findViewById(R.id.textViewTemperatureValue);
elems.qnh_val = findViewById(R.id.textViewQnhVaue); elems.qnh_val = findViewById(R.id.textViewQnhVaue);
elems.humidity_val = findViewById(R.id.textViewHumidityValue);
elems.message = findViewById(R.id.textViewSummaryMessage);
summary = summary_dao.getStationSummary(station.getSystemName()); summary = summary_dao.getStationSummary(station.getSystemName());

Wyświetl plik

@ -7,6 +7,8 @@ import cc.pogoda.mobile.pogodacc.type.StationActivityElements;
import cc.pogoda.mobile.pogodacc.type.StationSummaryActElements; import cc.pogoda.mobile.pogodacc.type.StationSummaryActElements;
import cc.pogoda.mobile.pogodacc.type.web.Summary; import cc.pogoda.mobile.pogodacc.type.web.Summary;
/** /**
* Class used to update the content of Wind Rose Activity * Class used to update the content of Wind Rose Activity
*/ */

Wyświetl plik

@ -2,6 +2,7 @@ package cc.pogoda.mobile.pogodacc.dao;
import java.io.IOException; import java.io.IOException;
import cc.pogoda.mobile.pogodacc.type.web.QualityFactor;
import cc.pogoda.mobile.pogodacc.type.web.Summary; import cc.pogoda.mobile.pogodacc.type.web.Summary;
import cc.pogoda.mobile.pogodacc.web.RestClientConfig; import cc.pogoda.mobile.pogodacc.web.RestClientConfig;
import cc.pogoda.mobile.pogodacc.web.SummaryConsumer; import cc.pogoda.mobile.pogodacc.web.SummaryConsumer;
@ -46,6 +47,12 @@ public class SummaryDao {
if (response != null) { if (response != null) {
out = response.body(); out = response.body();
if (out != null) {
out.temperature_qf_native = QualityFactor.valueOf(out.temperature_qf);
out.wind_qf_native = QualityFactor.valueOf(out.wind_qf);
out.humidity_qf_native = QualityFactor.valueOf(out.humidity_qf);
}
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();

Wyświetl plik

@ -1,8 +1,20 @@
package cc.pogoda.mobile.pogodacc.type; package cc.pogoda.mobile.pogodacc.type;
import android.app.Activity; import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.graphics.ColorUtils;
import org.threeten.bp.Duration;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.temporal.ChronoUnit;
import cc.pogoda.mobile.pogodacc.R;
import cc.pogoda.mobile.pogodacc.type.web.Summary; import cc.pogoda.mobile.pogodacc.type.web.Summary;
public class StationSummaryActElements implements StationActivityElements { public class StationSummaryActElements implements StationActivityElements {
@ -14,6 +26,7 @@ public class StationSummaryActElements implements StationActivityElements {
public TextView temperature_val = null; public TextView temperature_val = null;
public TextView qnh_val = null; public TextView qnh_val = null;
public TextView humidity_val = null; public TextView humidity_val = null;
public TextView message = null;
private String convertDegreesToDir(int directionInDegrees) { private String convertDegreesToDir(int directionInDegrees) {
String out = null; String out = null;
@ -57,6 +70,43 @@ public class StationSummaryActElements implements StationActivityElements {
} }
public void updateFromSummary(Summary s) { public void updateFromSummary(Summary s) {
if (s == null) {
// print a message in case there is no data available
wind_speed_val.setText(R.string.no_data);
wind_gusts_val.setText(R.string.no_data);
wind_dir_val.setText(R.string.no_data);
temperature_val.setText(R.string.no_data);
qnh_val.setText(R.string.no_data);
humidity_val.setText(R.string.no_data);
message.setText(R.string.no_data);
return;
}
// convert the integer with unix epoch timestamp to LocalDateTime in current system Time Zone
LocalDateTime last_station_data = LocalDateTime.ofEpochSecond(s.last_timestamp, 0, ZonedDateTime.now().getOffset());
// current date and time (in current time zone set in system configuration)
LocalDateTime current = LocalDateTime.now();
long minutes_difference = last_station_data.until(current, ChronoUnit.MINUTES);
// calculate the duration between
Duration duration = Duration.between(last_station_data, current);
// check how old the last data from stations is
if (duration.getSeconds() < 7200) {
// if the last data is no older than 2 hours
message.setText(R.string.auto_refresh);
message.setTextColor(Color.BLACK);
}
else {
message.setText(R.string.station_not_comm);
message.setTextColor(Color.argb(0xFF, 0xFF, 0x0, 0x0));
}
if (wind_speed_val != null) if (wind_speed_val != null)
wind_speed_val.setText(String.format("%.1f m/s", s.average_speed)); wind_speed_val.setText(String.format("%.1f m/s", s.average_speed));
@ -73,7 +123,7 @@ public class StationSummaryActElements implements StationActivityElements {
qnh_val.setText(String.format("%d hPa", s.qnh)); qnh_val.setText(String.format("%d hPa", s.qnh));
if (humidity_val != null) if (humidity_val != null)
humidity_val.setText(String.format("%d %", s.humidity)); humidity_val.setText(String.format("%d %%", s.humidity));
} }
@Override @Override

Wyświetl plik

@ -2,12 +2,17 @@ package cc.pogoda.mobile.pogodacc.type;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.threeten.bp.Duration;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZonedDateTime;
import org.w3c.dom.Text; import org.w3c.dom.Text;
import cc.pogoda.mobile.pogodacc.R; import cc.pogoda.mobile.pogodacc.R;
import cc.pogoda.mobile.pogodacc.type.web.QualityFactor;
import cc.pogoda.mobile.pogodacc.type.web.Summary; import cc.pogoda.mobile.pogodacc.type.web.Summary;
public class StationWindRoseActElements implements StationActivityElements { public class StationWindRoseActElements implements StationActivityElements {
@ -46,42 +51,107 @@ public class StationWindRoseActElements implements StationActivityElements {
@Override @Override
public void updateFromSummary(Summary s) { public void updateFromSummary(Summary s) {
if (activity == null ) { // data to be displayed
Summary data;
// set to true if no_data string shall be displayed instead of parameters
boolean no_data = false;
LocalDateTime last_station_data;
// set to true if the data is old (older than 2 hours)
boolean old_data = false;
if (activity == null) {
return; return;
} }
if (windArrow != null) { // check if any data has been passed to this method
windArrow.setRotation(s.direction - 225.0f); if (s == null) {
data = new Summary();
// set to 180 to rotate the arrow towards the top of a screen
data.direction = 180;
// set the flag to true to show '---' or 'no data' instead of zeros
no_data = true;
}
else {
data = s;
// convert the integer with unix epoch timestamp to LocalDateTime in current system Time Zone
last_station_data = LocalDateTime.ofEpochSecond(data.last_timestamp, 0, ZonedDateTime.now().getOffset());
// current date and time (in current time zone set in system configuration)
LocalDateTime current = LocalDateTime.now();
// calculate the duration between
Duration duration = Duration.between(last_station_data, current);
// if station is not communicating for longer than 2 hours
if (duration.getSeconds() > 7200) {
old_data = true;
}
} }
if (windSpeed != null) { // check if wind data is avaliable in the input data set
windSpeed.setText(activity.getResources().getString(R.string.mean_value) + '\n' + s.average_speed + "m/s"); if (!no_data && !data.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
windArrow.setRotation(data.direction - 225.0f);
}
else {
// if now wind data is avaliable in the input set move the arrow
// to point towards the N
windArrow.setRotation(180.0f - 225.0f);
} }
if (windGusts != null) { if (!no_data && !data.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
windGusts.setText(activity.getResources().getString(R.string.wind_gust_short) + '\n' + s.gusts + "m/s"); windSpeed.setText(activity.getResources().getString(R.string.mean_value) + '\n' + data.average_speed + "m/s");
}
else {
windSpeed.setText(activity.getResources().getString(R.string.mean_value) + '\n' + "---");
} }
if (windDirection != null) { if (!no_data && !data.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
windDirection.setText(activity.getResources().getString(R.string.wind_direction_short) + '\n' + s.direction + activity.getResources().getString(R.string.degrees_sign)); windGusts.setText(activity.getResources().getString(R.string.wind_gust_short) + '\n' + data.gusts + "m/s");
} }
else {
if (temperature != null) { windGusts.setText(activity.getResources().getString(R.string.wind_gust_short) + '\n' + "---");
temperature.setText(activity.getResources().getString(R.string.temperature_short) + '\n' + String.format("%.1f", s.avg_temperature) + "°C");
} }
if (pressure != null) { if (!no_data && !data.wind_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
pressure.setText(activity.getResources().getString(R.string.qnh) + ": " + String.format("%d hPa", s.qnh)); windDirection.setText(activity.getResources().getString(R.string.wind_direction_short) + '\n' + data.direction + activity.getResources().getString(R.string.degrees_sign));
}
else {
windDirection.setText(activity.getResources().getString(R.string.wind_direction_short) + '\n' + "---");
} }
if (maxGust != null) { // check if temperature is avaliable in input data set
maxGust.setText(activity.getResources().getString(R.string.max_1h_gust) + ": " + s.hour_gusts + "m/s"); if (!no_data && !data.temperature_qf_native.equals(QualityFactor.NOT_AVALIABLE)) {
temperature.setText(activity.getResources().getString(R.string.temperature_short) + '\n' + String.format("%.1f", data.avg_temperature) + "°C");
}
else {
temperature.setText(activity.getResources().getString(R.string.temperature_short) + '\n' + "---");
} }
if (minAverage != null) { if (!no_data && !old_data) {
minAverage.setText(activity.getResources().getString(R.string.min_1h_avg) + ": " + s.hour_min_average_speed + "m/s"); pressure.setText(activity.getResources().getString(R.string.qnh) + ": " + String.format("%d hPa", data.qnh));
maxGust.setText(activity.getResources().getString(R.string.max_1h_gust) + ": " + data.hour_gusts + "m/s");
minAverage.setText(activity.getResources().getString(R.string.min_1h_avg) + ": " + data.hour_min_average_speed + "m/s");
}
else if (!no_data && old_data) {
maxGust.setText(activity.getResources().getString(R.string.warning));
maxGust.setTextColor(Color.RED);
minAverage.setText(activity.getResources().getString(R.string.station_doesnt_transmit));
pressure.setText(activity.getResources().getString(R.string.for_longer_than_2_hours));
}
else {
maxGust.setText(activity.getResources().getString(R.string.no_data));
maxGust.setTextColor(Color.RED);
minAverage.setText("");
minAverage.setTextColor(Color.RED);
pressure.setText("");
pressure.setTextColor(Color.RED);
} }
} }

Wyświetl plik

@ -0,0 +1,9 @@
package cc.pogoda.mobile.pogodacc.type.web;
public enum QualityFactor {
UNSET,
FULL,
DEGRADED,
NOT_AVALIABLE;
}

Wyświetl plik

@ -10,14 +10,20 @@ public class Summary {
public String temperature_qf; public String temperature_qf;
public QualityFactor temperature_qf_native;
public short qnh; public short qnh;
public String qnh_qf; public String qnh_qf;
public QualityFactor qnh_qf_native;
public byte humidity; public byte humidity;
public String humidity_qf; public String humidity_qf;
public QualityFactor humidity_qf_native;
public short direction; public short direction;
public float average_speed; public float average_speed;
@ -32,4 +38,12 @@ public class Summary {
public String wind_qf; public String wind_qf;
public QualityFactor wind_qf_native;
public Summary() {
temperature_qf_native = QualityFactor.UNSET;
humidity_qf_native = QualityFactor.UNSET;
wind_qf_native = QualityFactor.UNSET;
}
} }

Wyświetl plik

@ -163,7 +163,7 @@
android:layout_span="2"> android:layout_span="2">
<TextView <TextView
android:id="@+id/textView14" android:id="@+id/textViewSummaryMessage"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:scrollIndicators="right" android:scrollIndicators="right"

Wyświetl plik

@ -48,7 +48,7 @@
android:id="@+id/textViewWindRoseWindSpeed" android:id="@+id/textViewWindRoseWindSpeed"
android:layout_width="152dp" android:layout_width="152dp"
android:layout_height="69dp" android:layout_height="69dp"
android:text="Średnia" android:text="@string/mean_value"
android:textAlignment="center" android:textAlignment="center"
android:textSize="28sp" android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown" app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown"
@ -62,7 +62,7 @@
android:id="@+id/textViewWindRoseWindDirection" android:id="@+id/textViewWindRoseWindDirection"
android:layout_width="152dp" android:layout_width="152dp"
android:layout_height="69dp" android:layout_height="69dp"
android:text="Kierunek" android:text="@string/wind_direction_short"
android:textAlignment="center" android:textAlignment="center"
android:textSize="28sp" android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown" app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown"
@ -76,7 +76,7 @@
android:id="@+id/textViewWindRoseTemperatura" android:id="@+id/textViewWindRoseTemperatura"
android:layout_width="152dp" android:layout_width="152dp"
android:layout_height="69dp" android:layout_height="69dp"
android:text="Temp" android:text="@string/temperature_short"
android:textAlignment="center" android:textAlignment="center"
android:textSize="28sp" android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown" app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown"
@ -90,7 +90,7 @@
android:id="@+id/textViewWindRoseWindGusts" android:id="@+id/textViewWindRoseWindGusts"
android:layout_width="152dp" android:layout_width="152dp"
android:layout_height="70dp" android:layout_height="70dp"
android:text="Poryw" android:text="@string/wind_gust_short"
android:textAlignment="center" android:textAlignment="center"
android:textSize="28sp" android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown" app:layout_constraintBottom_toBottomOf="@id/guidelineRoseSDown"

Wyświetl plik

@ -19,7 +19,7 @@
<string name="add">Add</string> <string name="add">Add</string>
<string name="delete">Delete</string> <string name="delete">Delete</string>
<string name="delete_fav">Delete from favourities</string> <string name="delete_fav">Delete from favourities</string>
<string name="station_not_comm">Warning! This station doesn\'t send any data for longer than 4 hours</string> <string name="station_not_comm">Warning! This station doesn\'t send any data for longer than 2 hours</string>
<string name="station_disabled">Warning! This station has been temporarily disabled or it is not functional for long time</string> <string name="station_disabled">Warning! This station has been temporarily disabled or it is not functional for long time</string>
<string name="archive_data">Archival Data</string> <string name="archive_data">Archival Data</string>
<string name="export_from">Export From</string> <string name="export_from">Export From</string>
@ -46,6 +46,10 @@
<string name="wind_direction_short">Direction</string> <string name="wind_direction_short">Direction</string>
<string name="temperature_short">Tempr</string> <string name="temperature_short">Tempr</string>
<string name="degress">Degrees</string> <string name="degress">Degrees</string>
<string name="max_1h_gust">Maximum gust in last 1h</string> <string name="max_1h_gust">Max gust in last hour</string>
<string name="min_1h_avg">Minimum average in last 1h</string> <string name="min_1h_avg">Min average in last hour</string>
<string name="no_data">No data</string>
<string name="warning">Warning!</string>
<string name="station_doesnt_transmit">Station doesn\'t transmit data</string>
<string name="for_longer_than_2_hours">for longer than 2 hours</string>
</resources> </resources>

Wyświetl plik

@ -48,4 +48,8 @@
<string name="degress">-</string> <string name="degress">-</string>
<string name="max_1h_gust">-</string> <string name="max_1h_gust">-</string>
<string name="min_1h_avg">-</string> <string name="min_1h_avg">-</string>
<string name="no_data">-</string>
<string name="warning">-</string>
<string name="station_doesnt_transmit">-</string>
<string name="for_longer_than_2_hours">-</string>
</resources> </resources>

Wyświetl plik

@ -48,5 +48,9 @@
<string name="degress">-</string> <string name="degress">-</string>
<string name="max_1h_gust">-</string> <string name="max_1h_gust">-</string>
<string name="min_1h_avg">-</string> <string name="min_1h_avg">-</string>
<string name="no_data">-</string>
<string name="warning">-</string>
<string name="station_doesnt_transmit">-</string>
<string name="for_longer_than_2_hours">-</string>
</resources> </resources>

Wyświetl plik

@ -19,7 +19,7 @@
<string name="add">Dodaj</string> <string name="add">Dodaj</string>
<string name="delete">Usuń</string> <string name="delete">Usuń</string>
<string name="delete_fav">Usuń z ulubionych</string> <string name="delete_fav">Usuń z ulubionych</string>
<string name="station_not_comm">Uwaga! Ta stacja nie wysyła żadnych danych dłużej niż od 4 godzin</string> <string name="station_not_comm">Uwaga! Ta stacja nie wysyła żadnych danych dłużej niż od 2 godzin</string>
<string name="station_disabled">Uwaga! Stacja została tymczasowo wyłączona bądź nie pracuje od dłuższego czasu</string> <string name="station_disabled">Uwaga! Stacja została tymczasowo wyłączona bądź nie pracuje od dłuższego czasu</string>
<string name="archive_data">Dane Archiwalne</string> <string name="archive_data">Dane Archiwalne</string>
<string name="export_from">Exportuj do</string> <string name="export_from">Exportuj do</string>
@ -48,4 +48,8 @@
<string name="degress">Stopni</string> <string name="degress">Stopni</string>
<string name="max_1h_gust">Maks poryw w ost godzinie</string> <string name="max_1h_gust">Maks poryw w ost godzinie</string>
<string name="min_1h_avg">Min prędkość w ost godzinie</string> <string name="min_1h_avg">Min prędkość w ost godzinie</string>
<string name="no_data">Brak Danych</string>
<string name="warning">Uwaga!</string>
<string name="station_doesnt_transmit">Stacja nie wysyła danych</string>
<string name="for_longer_than_2_hours">dłużej niż dwie godziny</string>
</resources> </resources>

Wyświetl plik

@ -19,7 +19,7 @@
<string name="add">Dodaj</string> <string name="add">Dodaj</string>
<string name="delete">Usuń</string> <string name="delete">Usuń</string>
<string name="delete_fav">Usuń z ulubionych</string> <string name="delete_fav">Usuń z ulubionych</string>
<string name="station_not_comm">Uwaga! Ta stacja nie wysyła żadnych danych dłużej niż od 4 godzin</string> <string name="station_not_comm">Uwaga! Ta stacja nie wysyła żadnych danych dłużej niż od 2 godzin</string>
<string name="station_disabled">Uwaga! Stacja została tymczasowo wyłączona bądź nie pracuje od dłuższego czasu</string> <string name="station_disabled">Uwaga! Stacja została tymczasowo wyłączona bądź nie pracuje od dłuższego czasu</string>
<string name="archive_data">Dane Archiwalne</string> <string name="archive_data">Dane Archiwalne</string>
<string name="export_from">Eksportuj od</string> <string name="export_from">Eksportuj od</string>
@ -48,4 +48,8 @@
<string name="degress">Stopni</string> <string name="degress">Stopni</string>
<string name="max_1h_gust">Maks poryw w ost godzinie</string> <string name="max_1h_gust">Maks poryw w ost godzinie</string>
<string name="min_1h_avg">Min prędkość w ost godzinie</string> <string name="min_1h_avg">Min prędkość w ost godzinie</string>
<string name="no_data">Brak Danych</string>
<string name="warning">Uwaga!</string>
<string name="station_doesnt_transmit">Stacja nie wysyła danych</string>
<string name="for_longer_than_2_hours">dłużej niż dwie godziny</string>
</resources> </resources>

Wyświetl plik

@ -18,7 +18,7 @@
<string name="add">Add</string> <string name="add">Add</string>
<string name="delete">Delete</string> <string name="delete">Delete</string>
<string name="delete_fav">Delete from favourities</string> <string name="delete_fav">Delete from favourities</string>
<string name="station_not_comm">Warning! This station doesn\'t send any data for longer than 4 hours</string> <string name="station_not_comm">Warning! This station doesn\'t send any data for longer than 2 hours</string>
<string name="station_disabled">Warning! This station has been temporarily disabled or it is not functional for long time</string> <string name="station_disabled">Warning! This station has been temporarily disabled or it is not functional for long time</string>
<string name="archive_data">Archival Data</string> <string name="archive_data">Archival Data</string>
<string name="export_from">Export From</string> <string name="export_from">Export From</string>
@ -50,6 +50,10 @@
<string name="temperature_short">Tempr</string> <string name="temperature_short">Tempr</string>
<string name="degress">Degrees</string> <string name="degress">Degrees</string>
<string name="degrees_sign" translatable="false">°</string> <string name="degrees_sign" translatable="false">°</string>
<string name="max_1h_gust">Maximum gust in last 1h</string> <string name="max_1h_gust">Max gust in last hour</string>
<string name="min_1h_avg">Minimum average in last 1h</string> <string name="min_1h_avg">Min average in last hour</string>
<string name="no_data">No data</string>
<string name="warning">Warning!</string>
<string name="station_doesnt_transmit">Station doesn\'t transmit data</string>
<string name="for_longer_than_2_hours">for longer than 2 hours</string>
</resources> </resources>