-reset cumulated values at midnight, unless in debug mode

-bugfix for weekforcast because values are for preceding hour
fixes #23
This commit is contained in:
woheller69 2024-07-01 09:30:31 +02:00
parent 71e9cbe08d
commit 2974b4b156
4 changed files with 24 additions and 14 deletions

View file

@ -8,8 +8,8 @@ android {
applicationId "org.woheller69.solxpect" applicationId "org.woheller69.solxpect"
minSdkVersion 26 minSdkVersion 26
targetSdk 34 targetSdk 34
versionCode 23 versionCode 24
versionName "2.3" versionName "2.4"
buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\"" buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\""
buildConfigField "String", "TILES_URL","\"https://tile.openstreetmap.org/\"" buildConfigField "String", "TILES_URL","\"https://tile.openstreetmap.org/\""

View file

@ -100,18 +100,26 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
courseDayList = new ArrayList<>(); courseDayList = new ArrayList<>();
float energyCumulated=0; float energyCumulated=0;
for (HourlyForecast f : hourlyForecasts) { boolean isDebugMode = sp.getBoolean("pref_debug", false);
energyCumulated+=f.getPower(); int stepCounter = 0; // Counter to track the number of steps taken in the loop
f.setEnergyCum(energyCumulated);
if (sp.getBoolean("pref_debug",false)) { for (HourlyForecast f : hourlyForecasts) {
courseDayList.add(f); float power = f.getPower();
} else { if (stepCounter > 0) energyCumulated += power; //Ignore first value because power values are for preceding hour
if (f.getForecastTime() >= System.currentTimeMillis()) { f.setEnergyCum(energyCumulated);
courseDayList.add(f);
} // In debug mode show all values, otherwise only future values
} if (isDebugMode || f.getForecastTime() >= System.currentTimeMillis()) {
courseDayList.add(f);
} }
notifyDataSetChanged();
stepCounter++;
// if not in debug mode: Reset energyCumulated after every 24 hours if next step is 01:00 am because values are for previous hour
if (!isDebugMode && stepCounter % 24 == 1) {
energyCumulated = 0;
}
}
notifyDataSetChanged();
} }
// function for week forecast list // function for week forecast list

View file

@ -198,7 +198,7 @@ public class ProcessOMweatherAPIRequest implements IProcessHttpRequest {
float totalEnergy = 0; float totalEnergy = 0;
Long timeNoon = weekForecast.getForecastTime(); Long timeNoon = weekForecast.getForecastTime();
for (HourlyForecast hourlyForecast: hourlyforecasts){ for (HourlyForecast hourlyForecast: hourlyforecasts){
if ((hourlyForecast.getForecastTime()>=timeNoon-12*3600*1000L) && (hourlyForecast.getForecastTime()< timeNoon + 12*3600*1000L)){ if ((hourlyForecast.getForecastTime()>=timeNoon-11*3600*1000L) && (hourlyForecast.getForecastTime()< timeNoon + 13*3600*1000L)){ //values are for preceding hour!
totalEnergy+=hourlyForecast.getPower(); totalEnergy+=hourlyForecast.getPower();
} }
} }

View file

@ -0,0 +1,2 @@
Reset cumulated values every 24h
Bugfix