Skip to content

Commit

Permalink
-reset cumulated values at midnight, unless in debug mode
Browse files Browse the repository at this point in the history
-bugfix for weekforcast because values are for preceding hour
fixes #23
  • Loading branch information
woheller69 committed Jul 1, 2024
1 parent 71e9cbe commit 2974b4b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "org.woheller69.solxpect"
minSdkVersion 26
targetSdk 34
versionCode 23
versionName "2.3"
versionCode 24
versionName "2.4"

buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\""
buildConfigField "String", "TILES_URL","\"https://tile.openstreetmap.org/\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,26 @@ public void updateForecastData(List<HourlyForecast> hourlyForecasts) {
courseDayList = new ArrayList<>();

float energyCumulated=0;
for (HourlyForecast f : hourlyForecasts) {
energyCumulated+=f.getPower();
f.setEnergyCum(energyCumulated);
if (sp.getBoolean("pref_debug",false)) {
courseDayList.add(f);
} else {
if (f.getForecastTime() >= System.currentTimeMillis()) {
courseDayList.add(f);
}
}
boolean isDebugMode = sp.getBoolean("pref_debug", false);
int stepCounter = 0; // Counter to track the number of steps taken in the loop

for (HourlyForecast f : hourlyForecasts) {
float power = f.getPower();
if (stepCounter > 0) energyCumulated += power; //Ignore first value because power values are for preceding hour
f.setEnergyCum(energyCumulated);

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private List<WeekForecast> reanalyzeWeekIDs(List<WeekForecast> weekforecasts, Li
float totalEnergy = 0;
Long timeNoon = weekForecast.getForecastTime();
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();
}
}
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/24.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Reset cumulated values every 24h
Bugfix

0 comments on commit 2974b4b

Please sign in to comment.