mirror of
https://github.com/woheller69/solxpect.git
synced 2026-02-02 22:51:49 +01:00
add cumulated energy to course of day
This commit is contained in:
parent
428d59a2a5
commit
28aed88cea
9 changed files with 21 additions and 9 deletions
|
|
@ -17,6 +17,7 @@ public class HourlyForecast {
|
|||
private float diffuseRadiation;
|
||||
private float shortwaveRadiation;
|
||||
private float power;
|
||||
private float energyCum;
|
||||
private String city_name;
|
||||
|
||||
|
||||
|
|
@ -109,4 +110,8 @@ public class HourlyForecast {
|
|||
public void setShortwaveRadiation(float shortwaveRadiation) { this.shortwaveRadiation = shortwaveRadiation; }
|
||||
|
||||
public float getShortwaveRadiation() { return this.shortwaveRadiation; }
|
||||
|
||||
public float getEnergyCum() { return this.energyCum; }
|
||||
|
||||
public void setEnergyCum(float energy_cum) { this.energyCum = energy_cum;}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ public final class StringFormatUtils {
|
|||
return removeMinusIfZerosOnly(decimalFormat.format(decimal));
|
||||
}
|
||||
|
||||
public static String formatEnergyCum(Context context, float energyCum) {
|
||||
if (energyCum < 10000.0f) return formatInt(energyCum, context.getString(R.string.units_Wh));
|
||||
else if (energyCum < 100000.0f) return formatDecimal(energyCum/1000,context.getString(R.string.units_kWh));
|
||||
else return formatInt(energyCum/1000,context.getString(R.string.units_kWh));
|
||||
}
|
||||
|
||||
public static String formatInt(float decimal) {
|
||||
intFormat.setRoundingMode(RoundingMode.HALF_UP);
|
||||
return removeMinusIfZerosOnly(intFormat.format(decimal));
|
||||
|
|
|
|||
|
|
@ -100,7 +100,10 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
|
|||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -98,21 +98,16 @@ public class CourseOfDayAdapter extends RecyclerView.Adapter<CourseOfDayAdapter.
|
|||
if (sp.getBoolean("pref_debug",false)) {
|
||||
holder.diffuseRadiation.setVisibility(View.VISIBLE);
|
||||
holder.directRadiationNormal.setVisibility(View.VISIBLE);
|
||||
holder.energyCum.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.diffuseRadiation.setVisibility(View.GONE);
|
||||
holder.directRadiationNormal.setVisibility(View.GONE);
|
||||
holder.energyCum.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.time.setText(StringFormatUtils.formatTimeWithoutZone(context, courseOfDayList.get(position).getLocalForecastTime(context)));
|
||||
holder.directRadiationNormal.setText(StringFormatUtils.formatInt(courseOfDayList.get(position).getDirectRadiationNormal()," W/qm"));
|
||||
holder.diffuseRadiation.setText(StringFormatUtils.formatInt(courseOfDayList.get(position).getDiffuseRadiation()," W/qm"));
|
||||
holder.power.setText(StringFormatUtils.formatInt(courseOfDayList.get(position).getPower()," "+ context.getString(R.string.units_Wh)));
|
||||
float energyCumulated=0;
|
||||
for (int i=0; i<=position;i++)
|
||||
energyCumulated+=courseOfDayList.get(i).getPower();
|
||||
holder.energyCum.setText(StringFormatUtils.formatInt(energyCumulated," "+ context.getString(R.string.units_Wh)));
|
||||
holder.energyCum.setText("\u03a3\u2009"+StringFormatUtils.formatEnergyCum(context, courseOfDayList.get(position).getEnergyCum()));
|
||||
|
||||
updateRecyclerViewHeader(); //update header according to date in first visible item on the left
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class WeekWeatherAdapter extends RecyclerView.Adapter<WeekWeatherAdapter.
|
|||
this.context = context;
|
||||
this.cityID = cityID;
|
||||
this.weekForecastList = weekForecastList;
|
||||
if (!weekForecastList.isEmpty()) {
|
||||
if (weekForecastList!=null && !weekForecastList.isEmpty()) {
|
||||
this.courseOfDayHeaderDate = new Date(weekForecastList.get(0).getLocalForecastTime(context)); //init with date of first weekday
|
||||
} else this.courseOfDayHeaderDate = new Date(); //fallback if no data available
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ public class WeekWeatherAdapter extends RecyclerView.Adapter<WeekWeatherAdapter.
|
|||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (!weekForecastList.isEmpty())
|
||||
if (weekForecastList!=null && !weekForecastList.isEmpty())
|
||||
return weekForecastList.size();
|
||||
else
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue