mirror of
https://github.com/woheller69/solxpect.git
synced 2025-09-22 00:40:46 +02:00
processing simplified (processNewWeekForecasts removed)
add option to specify inverter as central inverter and apply limits when summarizing in adapter #24
This commit is contained in:
parent
2974b4b156
commit
5337da4e67
18 changed files with 79 additions and 92 deletions
|
@ -19,12 +19,13 @@ public class SolarPowerPlant {
|
||||||
double diffuseEfficiency;
|
double diffuseEfficiency;
|
||||||
double inverterPowerLimit;
|
double inverterPowerLimit;
|
||||||
double inverterEfficiency;
|
double inverterEfficiency;
|
||||||
|
boolean isCentralInverter;
|
||||||
double azimuthAngle;
|
double azimuthAngle;
|
||||||
double tiltAngle;
|
double tiltAngle;
|
||||||
private final int[] shadingElevation;
|
private final int[] shadingElevation;
|
||||||
private final int[] shadingOpacity;
|
private final int[] shadingOpacity;
|
||||||
|
|
||||||
public SolarPowerPlant(double latitude, double longitude, double cellsMaxPower, double cellsArea, double cellsEfficiency, double cellsTempCoeff, double diffuseEfficiency, double inverterPowerLimit, double inverterEfficiency, double azimuthAngle, double tiltAngle, int[] shadingElevation, int[] shadingOpacity, double albedo ) {
|
public SolarPowerPlant(double latitude, double longitude, double cellsMaxPower, double cellsArea, double cellsEfficiency, double cellsTempCoeff, double diffuseEfficiency, double inverterPowerLimit, double inverterEfficiency,boolean isCentralInverter, double azimuthAngle, double tiltAngle, int[] shadingElevation, int[] shadingOpacity, double albedo ) {
|
||||||
this.albedo = albedo;
|
this.albedo = albedo;
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
|
@ -39,6 +40,7 @@ public class SolarPowerPlant {
|
||||||
this.shadingElevation = shadingElevation;
|
this.shadingElevation = shadingElevation;
|
||||||
this.shadingOpacity = shadingOpacity;
|
this.shadingOpacity = shadingOpacity;
|
||||||
this.cellsTempCoeff = cellsTempCoeff / 100;
|
this.cellsTempCoeff = cellsTempCoeff / 100;
|
||||||
|
this.isCentralInverter = isCentralInverter;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +113,11 @@ public class SolarPowerPlant {
|
||||||
dcPower = totalRadiationOnCell/1000 * (1+(cellTemperature - 25)*cellsTempCoeff) * cellsMaxPower;
|
dcPower = totalRadiationOnCell/1000 * (1+(cellTemperature - 25)*cellsTempCoeff) * cellsMaxPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
double acPower = Math.min(dcPower * inverterEfficiency, inverterPowerLimit);
|
double acPower;
|
||||||
|
if (!isCentralInverter)
|
||||||
|
acPower = Math.min(dcPower * inverterEfficiency, inverterPowerLimit);
|
||||||
|
else
|
||||||
|
acPower = dcPower * inverterEfficiency; //do limiting on system level
|
||||||
|
|
||||||
return (float) acPower;
|
return (float) acPower;
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,12 +219,7 @@ public class ForecastCityActivity extends NavigationActivity implements IUpdatea
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewWeekForecasts(List<WeekForecast> forecasts) {
|
public void processNewForecasts(List<HourlyForecast> hourlyForecasts, List<WeekForecast> weekForecasts) {
|
||||||
stopRefreshAnimation();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNewForecasts(List<HourlyForecast> hourlyForecasts) {
|
|
||||||
stopRefreshAnimation();
|
stopRefreshAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -202,6 +203,7 @@ public class ManageLocationsActivity extends NavigationActivity {
|
||||||
EditText editAlbedo = (EditText) dialogView.findViewById(R.id.EditLocation_Albedo);
|
EditText editAlbedo = (EditText) dialogView.findViewById(R.id.EditLocation_Albedo);
|
||||||
EditText editInverterPowerLimit = (EditText) dialogView.findViewById(R.id.EditLocation_Inverter_Power_Limit);
|
EditText editInverterPowerLimit = (EditText) dialogView.findViewById(R.id.EditLocation_Inverter_Power_Limit);
|
||||||
EditText editInverterEfficiency = (EditText) dialogView.findViewById(R.id.EditLocation_Inverter_Efficiency);
|
EditText editInverterEfficiency = (EditText) dialogView.findViewById(R.id.EditLocation_Inverter_Efficiency);
|
||||||
|
CheckBox editIsCentralInverter = (CheckBox) dialogView.findViewById(R.id.EditLocation_Central_Inverter);
|
||||||
TextView currentAzimuth = (TextView) dialogView.findViewById(R.id.edit_current_azi_ele);
|
TextView currentAzimuth = (TextView) dialogView.findViewById(R.id.edit_current_azi_ele);
|
||||||
|
|
||||||
Long time = System.currentTimeMillis()/1000;
|
Long time = System.currentTimeMillis()/1000;
|
||||||
|
@ -251,6 +253,7 @@ public class ManageLocationsActivity extends NavigationActivity {
|
||||||
editAlbedo.setFilters(new InputFilter[]{ new InputFilterMinMax(0,1)});
|
editAlbedo.setFilters(new InputFilter[]{ new InputFilterMinMax(0,1)});
|
||||||
editInverterPowerLimit.setText(Float.toString(city.getInverterPowerLimit()));
|
editInverterPowerLimit.setText(Float.toString(city.getInverterPowerLimit()));
|
||||||
editInverterEfficiency.setText(Float.toString(city.getInverterEfficiency()));
|
editInverterEfficiency.setText(Float.toString(city.getInverterEfficiency()));
|
||||||
|
editIsCentralInverter.setChecked(city.isCentralInverter());
|
||||||
editInverterEfficiency.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 100)});
|
editInverterEfficiency.setFilters(new InputFilter[]{ new InputFilterMinMax(0, 100)});
|
||||||
editTilt.addTextChangedListener(new TextWatcher() {
|
editTilt.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -285,6 +288,7 @@ public class ManageLocationsActivity extends NavigationActivity {
|
||||||
Float.parseFloat(editAlbedo.getText().toString().isEmpty() ? "0" : editAlbedo.getText().toString()),
|
Float.parseFloat(editAlbedo.getText().toString().isEmpty() ? "0" : editAlbedo.getText().toString()),
|
||||||
Float.parseFloat(editInverterPowerLimit.getText().toString().isEmpty() ? "0" : editInverterPowerLimit.getText().toString()),
|
Float.parseFloat(editInverterPowerLimit.getText().toString().isEmpty() ? "0" : editInverterPowerLimit.getText().toString()),
|
||||||
Float.parseFloat(editInverterEfficiency.getText().toString().isEmpty() ? "0" : editInverterEfficiency.getText().toString()),
|
Float.parseFloat(editInverterEfficiency.getText().toString().isEmpty() ? "0" : editInverterEfficiency.getText().toString()),
|
||||||
|
editIsCentralInverter.isChecked(),
|
||||||
shadingElevation,
|
shadingElevation,
|
||||||
shadingOpacity
|
shadingOpacity
|
||||||
);
|
);
|
||||||
|
@ -321,6 +325,7 @@ public class ManageLocationsActivity extends NavigationActivity {
|
||||||
Float.parseFloat(editAlbedo.getText().toString().isEmpty() ? "0" : editAlbedo.getText().toString()),
|
Float.parseFloat(editAlbedo.getText().toString().isEmpty() ? "0" : editAlbedo.getText().toString()),
|
||||||
Float.parseFloat(editInverterPowerLimit.getText().toString().isEmpty() ? "0" : editInverterPowerLimit.getText().toString()),
|
Float.parseFloat(editInverterPowerLimit.getText().toString().isEmpty() ? "0" : editInverterPowerLimit.getText().toString()),
|
||||||
Float.parseFloat(editInverterEfficiency.getText().toString().isEmpty() ? "0" : editInverterEfficiency.getText().toString()),
|
Float.parseFloat(editInverterEfficiency.getText().toString().isEmpty() ? "0" : editInverterEfficiency.getText().toString()),
|
||||||
|
editIsCentralInverter.isChecked(),
|
||||||
shadingElevation,
|
shadingElevation,
|
||||||
shadingOpacity
|
shadingOpacity
|
||||||
);
|
);
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class CityToWatch {
|
||||||
private float azimuthAngle;
|
private float azimuthAngle;
|
||||||
private float tiltAngle;
|
private float tiltAngle;
|
||||||
private float albedo;
|
private float albedo;
|
||||||
|
private boolean isCentralInverter;
|
||||||
private int rank;
|
private int rank;
|
||||||
private int[] shadingElevation = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
private int[] shadingElevation = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||||
private int[] shadingOpacity = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
private int[] shadingOpacity = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
||||||
|
@ -147,6 +148,11 @@ public class CityToWatch {
|
||||||
this.inverterPowerLimit = inverterPowerLimit;
|
this.inverterPowerLimit = inverterPowerLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIsCentralInverter(boolean isCentralInverter) {
|
||||||
|
this.isCentralInverter = isCentralInverter;
|
||||||
|
}
|
||||||
|
public boolean isCentralInverter() {return isCentralInverter;}
|
||||||
|
|
||||||
public void setDiffuseEfficiency(float diffuseEfficiency) {
|
public void setDiffuseEfficiency(float diffuseEfficiency) {
|
||||||
this.diffuseEfficiency = diffuseEfficiency;
|
this.diffuseEfficiency = diffuseEfficiency;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import static androidx.core.app.JobIntentService.enqueueWork;
|
||||||
*/
|
*/
|
||||||
public class SQLiteHelper extends SQLiteOpenHelper {
|
public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 3;
|
private static final int DATABASE_VERSION = 4;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private List<City> allCities = new ArrayList<>();
|
private List<City> allCities = new ArrayList<>();
|
||||||
|
@ -55,6 +55,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
private static final String CITIES_TO_WATCH_SHADING_OPACITY = "shading_opacity";
|
private static final String CITIES_TO_WATCH_SHADING_OPACITY = "shading_opacity";
|
||||||
private static final String CITIES_TO_WATCH_CELLS_TEMP_COEFF = "cells_temp_coeff";
|
private static final String CITIES_TO_WATCH_CELLS_TEMP_COEFF = "cells_temp_coeff";
|
||||||
private static final String CITIES_TO_WATCH_ALBEDO = "albedo";
|
private static final String CITIES_TO_WATCH_ALBEDO = "albedo";
|
||||||
|
private static final String CITIES_TO_WATCH_IS_CENTRAL_INVERTER = "is_central_inverter";
|
||||||
|
|
||||||
//Names of columns in TABLE_FORECAST
|
//Names of columns in TABLE_FORECAST
|
||||||
private static final String FORECAST_ID = "forecast_id";
|
private static final String FORECAST_ID = "forecast_id";
|
||||||
|
@ -139,7 +140,8 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
CITIES_TO_WATCH_SHADING_ELEVATION + " VARCHAR(255) NOT NULL," +
|
CITIES_TO_WATCH_SHADING_ELEVATION + " VARCHAR(255) NOT NULL," +
|
||||||
CITIES_TO_WATCH_SHADING_OPACITY + " VARCHAR(255) NOT NULL," +
|
CITIES_TO_WATCH_SHADING_OPACITY + " VARCHAR(255) NOT NULL," +
|
||||||
CITIES_TO_WATCH_CELLS_TEMP_COEFF + " REAL NOT NULL," +
|
CITIES_TO_WATCH_CELLS_TEMP_COEFF + " REAL NOT NULL," +
|
||||||
CITIES_TO_WATCH_ALBEDO + " REAL NOT NULL)";
|
CITIES_TO_WATCH_ALBEDO + " REAL NOT NULL," +
|
||||||
|
CITIES_TO_WATCH_IS_CENTRAL_INVERTER + " INTEGER)";
|
||||||
|
|
||||||
public static SQLiteHelper getInstance(Context context) {
|
public static SQLiteHelper getInstance(Context context) {
|
||||||
if (instance == null && context != null) {
|
if (instance == null && context != null) {
|
||||||
|
@ -170,6 +172,8 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
// we want both updates, so no break statement here...
|
// we want both updates, so no break statement here...
|
||||||
case 2:
|
case 2:
|
||||||
db.execSQL("ALTER TABLE "+TABLE_CITIES_TO_WATCH+" ADD COLUMN "+CITIES_TO_WATCH_ALBEDO+" REAL DEFAULT 0");
|
db.execSQL("ALTER TABLE "+TABLE_CITIES_TO_WATCH+" ADD COLUMN "+CITIES_TO_WATCH_ALBEDO+" REAL DEFAULT 0");
|
||||||
|
case 3:
|
||||||
|
db.execSQL("ALTER TABLE "+TABLE_CITIES_TO_WATCH+" ADD COLUMN "+CITIES_TO_WATCH_IS_CENTRAL_INVERTER+" INTEGER DEFAULT 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -199,6 +203,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
values.put(CITIES_TO_WATCH_SHADING_OPACITY,city.getShadingOpacityString());
|
values.put(CITIES_TO_WATCH_SHADING_OPACITY,city.getShadingOpacityString());
|
||||||
values.put(CITIES_TO_WATCH_CELLS_TEMP_COEFF,city.getCellsTempCoeff());
|
values.put(CITIES_TO_WATCH_CELLS_TEMP_COEFF,city.getCellsTempCoeff());
|
||||||
values.put(CITIES_TO_WATCH_ALBEDO,city.getAlbedo());
|
values.put(CITIES_TO_WATCH_ALBEDO,city.getAlbedo());
|
||||||
|
values.put(CITIES_TO_WATCH_IS_CENTRAL_INVERTER,city.isCentralInverter() ? 1 : 0);
|
||||||
|
|
||||||
long id=database.insert(TABLE_CITIES_TO_WATCH, null, values);
|
long id=database.insert(TABLE_CITIES_TO_WATCH, null, values);
|
||||||
|
|
||||||
|
@ -234,6 +239,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
", " + CITIES_TO_WATCH_SHADING_OPACITY +
|
", " + CITIES_TO_WATCH_SHADING_OPACITY +
|
||||||
", " + CITIES_TO_WATCH_CELLS_TEMP_COEFF +
|
", " + CITIES_TO_WATCH_CELLS_TEMP_COEFF +
|
||||||
", " + CITIES_TO_WATCH_ALBEDO +
|
", " + CITIES_TO_WATCH_ALBEDO +
|
||||||
|
", " + CITIES_TO_WATCH_IS_CENTRAL_INVERTER +
|
||||||
", " + CITIES_TO_WATCH_COLUMN_RANK +
|
", " + CITIES_TO_WATCH_COLUMN_RANK +
|
||||||
" FROM " + TABLE_CITIES_TO_WATCH +
|
" FROM " + TABLE_CITIES_TO_WATCH +
|
||||||
" WHERE " + CITIES_TO_WATCH_CITY_ID + " = ?", arguments);
|
" WHERE " + CITIES_TO_WATCH_CITY_ID + " = ?", arguments);
|
||||||
|
@ -258,7 +264,8 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
cityToWatch.setShadingOpacity(cursor.getString(14));
|
cityToWatch.setShadingOpacity(cursor.getString(14));
|
||||||
cityToWatch.setCellsTempCoeff(Float.parseFloat(cursor.getString(15)));
|
cityToWatch.setCellsTempCoeff(Float.parseFloat(cursor.getString(15)));
|
||||||
cityToWatch.setAlbedo(Float.parseFloat(cursor.getString(16)));
|
cityToWatch.setAlbedo(Float.parseFloat(cursor.getString(16)));
|
||||||
cityToWatch.setRank(Integer.parseInt(cursor.getString(17)));
|
cityToWatch.setIsCentralInverter(Integer.parseInt(cursor.getString(17)) == 1);
|
||||||
|
cityToWatch.setRank(Integer.parseInt(cursor.getString(18)));
|
||||||
|
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
@ -291,6 +298,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
", " + CITIES_TO_WATCH_SHADING_OPACITY +
|
", " + CITIES_TO_WATCH_SHADING_OPACITY +
|
||||||
", " + CITIES_TO_WATCH_CELLS_TEMP_COEFF +
|
", " + CITIES_TO_WATCH_CELLS_TEMP_COEFF +
|
||||||
", " + CITIES_TO_WATCH_ALBEDO +
|
", " + CITIES_TO_WATCH_ALBEDO +
|
||||||
|
", " + CITIES_TO_WATCH_IS_CENTRAL_INVERTER +
|
||||||
", " + CITIES_TO_WATCH_COLUMN_RANK +
|
", " + CITIES_TO_WATCH_COLUMN_RANK +
|
||||||
" FROM " + TABLE_CITIES_TO_WATCH
|
" FROM " + TABLE_CITIES_TO_WATCH
|
||||||
, new String[]{});
|
, new String[]{});
|
||||||
|
@ -317,7 +325,8 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
cityToWatch.setShadingOpacity(cursor.getString(14));
|
cityToWatch.setShadingOpacity(cursor.getString(14));
|
||||||
cityToWatch.setCellsTempCoeff(Float.parseFloat(cursor.getString(15)));
|
cityToWatch.setCellsTempCoeff(Float.parseFloat(cursor.getString(15)));
|
||||||
cityToWatch.setAlbedo(Float.parseFloat(cursor.getString(16)));
|
cityToWatch.setAlbedo(Float.parseFloat(cursor.getString(16)));
|
||||||
cityToWatch.setRank(Integer.parseInt(cursor.getString(17)));
|
cityToWatch.setIsCentralInverter(Integer.parseInt(cursor.getString(17)) == 1);
|
||||||
|
cityToWatch.setRank(Integer.parseInt(cursor.getString(18)));
|
||||||
|
|
||||||
cityToWatchList.add(cityToWatch);
|
cityToWatchList.add(cityToWatch);
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
|
@ -349,6 +358,7 @@ public class SQLiteHelper extends SQLiteOpenHelper {
|
||||||
values.put(CITIES_TO_WATCH_SHADING_OPACITY,cityToWatch.getShadingOpacityString());
|
values.put(CITIES_TO_WATCH_SHADING_OPACITY,cityToWatch.getShadingOpacityString());
|
||||||
values.put(CITIES_TO_WATCH_CELLS_TEMP_COEFF,cityToWatch.getCellsTempCoeff());
|
values.put(CITIES_TO_WATCH_CELLS_TEMP_COEFF,cityToWatch.getCellsTempCoeff());
|
||||||
values.put(CITIES_TO_WATCH_ALBEDO,cityToWatch.getAlbedo());
|
values.put(CITIES_TO_WATCH_ALBEDO,cityToWatch.getAlbedo());
|
||||||
|
values.put(CITIES_TO_WATCH_IS_CENTRAL_INVERTER,cityToWatch.isCentralInverter() ? 1 : 0);
|
||||||
|
|
||||||
database.update(TABLE_CITIES_TO_WATCH, values, CITIES_TO_WATCH_ID + " = ?",
|
database.update(TABLE_CITIES_TO_WATCH, values, CITIES_TO_WATCH_ID + " = ?",
|
||||||
new String[]{String.valueOf(cityToWatch.getId())});
|
new String[]{String.valueOf(cityToWatch.getId())});
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.db.chart.Tools;
|
import com.db.chart.Tools;
|
||||||
import com.db.chart.model.BarSet;
|
import com.db.chart.model.BarSet;
|
||||||
|
@ -62,27 +63,30 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
|
||||||
List<HourlyForecast> hourlyForecasts = database.getForecastsByCityId(generalDataList.getCity_id());
|
List<HourlyForecast> hourlyForecasts = database.getForecastsByCityId(generalDataList.getCity_id());
|
||||||
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(generalDataList.getCity_id());
|
List<WeekForecast> weekforecasts = database.getWeekForecastsByCityId(generalDataList.getCity_id());
|
||||||
|
|
||||||
updateForecastData(hourlyForecasts);
|
updateForecastData(hourlyForecasts, weekforecasts);
|
||||||
updateWeekForecastData(weekforecasts);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// function update 3-hour or 1-hour forecast list
|
// function update 3-hour or 1-hour forecast list
|
||||||
public void updateForecastData(List<HourlyForecast> hourlyForecasts) {
|
public void updateForecastData(List<HourlyForecast> hourlyForecasts, List<WeekForecast> weekForecasts) {
|
||||||
if (hourlyForecasts.isEmpty()) return;
|
if (hourlyForecasts.isEmpty() || weekForecasts.isEmpty()) return;
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
int cityId = hourlyForecasts.get(0).getCity_id();
|
||||||
|
SQLiteHelper dbHelper = SQLiteHelper.getInstance(context.getApplicationContext());
|
||||||
|
CityToWatch requestedCity = dbHelper.getCityToWatch(cityId);
|
||||||
|
|
||||||
|
Float centralInverterLimit = requestedCity.isCentralInverter() ? requestedCity.getInverterPowerLimit() : 0;
|
||||||
|
|
||||||
if (sp.getBoolean("pref_summarize",false)){
|
if (sp.getBoolean("pref_summarize",false)){
|
||||||
int cityId = hourlyForecasts.get(0).getCity_id();
|
|
||||||
ArrayList<Integer> CityIDList = new ArrayList<Integer>();
|
ArrayList<Integer> CityIDList = new ArrayList<Integer>();
|
||||||
SQLiteHelper dbHelper = SQLiteHelper.getInstance(context.getApplicationContext());
|
|
||||||
hourlyForecasts = dbHelper.getForecastsByCityId(cityId); //get fresh values from database to make sure we do add new values to sum values from last update
|
hourlyForecasts = dbHelper.getForecastsByCityId(cityId); //get fresh values from database to make sure we do add new values to sum values from last update
|
||||||
List<CityToWatch> citiesToWatch = dbHelper.getAllCitiesToWatch();
|
List<CityToWatch> citiesToWatch = dbHelper.getAllCitiesToWatch();
|
||||||
CityToWatch requestedCity = dbHelper.getCityToWatch(cityId);
|
|
||||||
for (int i = 0; i < citiesToWatch.size(); i++) {
|
for (int i = 0; i < citiesToWatch.size(); i++) {
|
||||||
CityToWatch city = citiesToWatch.get(i);
|
CityToWatch city = citiesToWatch.get(i);
|
||||||
if (city.getCityId()!=requestedCity.getCityId() && city.getLatitude() == requestedCity.getLatitude() && city.getLongitude() == requestedCity.getLongitude()) {
|
if (city.getCityId()!=requestedCity.getCityId() && city.getLatitude() == requestedCity.getLatitude() && city.getLongitude() == requestedCity.getLongitude()) {
|
||||||
CityIDList.add(city.getCityId());
|
CityIDList.add(city.getCityId());
|
||||||
|
if (city.isCentralInverter()) centralInverterLimit += city.getInverterPowerLimit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (CityIDList.size()>0){
|
if (CityIDList.size()>0){
|
||||||
|
@ -97,6 +101,7 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Toast.makeText(context, "Central Inverter Limit: "+centralInverterLimit, Toast.LENGTH_SHORT).show();
|
||||||
courseDayList = new ArrayList<>();
|
courseDayList = new ArrayList<>();
|
||||||
|
|
||||||
float energyCumulated=0;
|
float energyCumulated=0;
|
||||||
|
@ -104,6 +109,7 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
|
||||||
int stepCounter = 0; // Counter to track the number of steps taken in the loop
|
int stepCounter = 0; // Counter to track the number of steps taken in the loop
|
||||||
|
|
||||||
for (HourlyForecast f : hourlyForecasts) {
|
for (HourlyForecast f : hourlyForecasts) {
|
||||||
|
if (centralInverterLimit>0) f.setPower(Math.min(f.getPower(),centralInverterLimit)); //apply central inverter limit if there is one
|
||||||
float power = f.getPower();
|
float power = f.getPower();
|
||||||
if (stepCounter > 0) energyCumulated += power; //Ignore first value because power values are for preceding hour
|
if (stepCounter > 0) energyCumulated += power; //Ignore first value because power values are for preceding hour
|
||||||
f.setEnergyCum(energyCumulated);
|
f.setEnergyCum(energyCumulated);
|
||||||
|
@ -119,47 +125,25 @@ public class CityWeatherAdapter extends RecyclerView.Adapter<CityWeatherAdapter.
|
||||||
energyCumulated = 0;
|
energyCumulated = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
|
||||||
|
//Now calculate weekForecasts from hourlyForecasts
|
||||||
|
for (WeekForecast weekForecast: weekForecasts){
|
||||||
|
float totalEnergy = 0;
|
||||||
|
long timeNoon = weekForecast.getForecastTime();
|
||||||
|
for (HourlyForecast hourlyForecast: hourlyForecasts){
|
||||||
|
if ((hourlyForecast.getForecastTime()>=timeNoon-11*3600*1000L) && (hourlyForecast.getForecastTime()< timeNoon + 13*3600*1000L)){ //values are for preceding hour!
|
||||||
|
totalEnergy+=hourlyForecast.getPower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
weekForecast.setEnergyDay(totalEnergy/1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function for week forecast list
|
weekForecastList = weekForecasts;
|
||||||
public void updateWeekForecastData(List<WeekForecast> forecasts) {
|
|
||||||
if (forecasts.isEmpty()) return;
|
|
||||||
int cityId = forecasts.get(0).getCity_id();
|
|
||||||
|
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
if (sp.getBoolean("pref_summarize",false)){
|
|
||||||
ArrayList<Integer> CityIDList = new ArrayList<Integer>();
|
|
||||||
SQLiteHelper dbHelper = SQLiteHelper.getInstance(context.getApplicationContext());
|
|
||||||
forecasts = dbHelper.getWeekForecastsByCityId(cityId); //get fresh values from database to make sure we do add new values to sum values from last update
|
|
||||||
List<CityToWatch> citiesToWatch = dbHelper.getAllCitiesToWatch();
|
|
||||||
CityToWatch requestedCity = dbHelper.getCityToWatch(cityId);
|
|
||||||
for (int i = 0; i < citiesToWatch.size(); i++) {
|
|
||||||
CityToWatch city = citiesToWatch.get(i);
|
|
||||||
if (city.getCityId()!=requestedCity.getCityId() && city.getLatitude() == requestedCity.getLatitude() && city.getLongitude() == requestedCity.getLongitude()) {
|
|
||||||
CityIDList.add(city.getCityId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CityIDList.size()>0){
|
|
||||||
for (int c=0; c<CityIDList.size();c++) {
|
|
||||||
int iteratorCityId = CityIDList.get(c);
|
|
||||||
List<WeekForecast> wfc = dbHelper.getWeekForecastsByCityId(iteratorCityId);
|
|
||||||
if (wfc.size() != forecasts.size()) break; //maybe something went wrong during update or city is not yet updated
|
|
||||||
for (int i=0;i<wfc.size();i++){
|
|
||||||
forecasts.get(i).setEnergyDay(forecasts.get(i).getEnergyDay()+wfc.get(i).getEnergyDay());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
weekForecastList = forecasts;
|
|
||||||
|
|
||||||
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
ViewHolder(View v) {
|
ViewHolder(View v) {
|
||||||
super(v);
|
super(v);
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class RecyclerOverviewListAdapter extends RecyclerView.Adapter<ItemViewHo
|
||||||
public CityToWatch getCitytoWatch(int position){
|
public CityToWatch getCitytoWatch(int position){
|
||||||
return cities.get(position);
|
return cities.get(position);
|
||||||
}
|
}
|
||||||
public void updateCity(CityToWatch cityToWatch, String cityName, float latitude, float longitude, float azimuth, float tilt, float cellsMaxPower, float cellsArea, float cellsEfficiency, float cellsTempCoeff, float diffuseEfficiency, float albedo, float inverterPowerLimit, float inverterEfficiency, int[] shadingElevation, int[] shadingOpacity) {
|
public void updateCity(CityToWatch cityToWatch, String cityName, float latitude, float longitude, float azimuth, float tilt, float cellsMaxPower, float cellsArea, float cellsEfficiency, float cellsTempCoeff, float diffuseEfficiency, float albedo, float inverterPowerLimit, float inverterEfficiency, boolean isCentralInverter, int[] shadingElevation, int[] shadingOpacity) {
|
||||||
cityToWatch.setCityName(cityName);
|
cityToWatch.setCityName(cityName);
|
||||||
cityToWatch.setLatitude(latitude);
|
cityToWatch.setLatitude(latitude);
|
||||||
cityToWatch.setLongitude(longitude);
|
cityToWatch.setLongitude(longitude);
|
||||||
|
@ -142,6 +142,7 @@ public class RecyclerOverviewListAdapter extends RecyclerView.Adapter<ItemViewHo
|
||||||
cityToWatch.setAlbedo(albedo);
|
cityToWatch.setAlbedo(albedo);
|
||||||
cityToWatch.setInverterPowerLimit(inverterPowerLimit);
|
cityToWatch.setInverterPowerLimit(inverterPowerLimit);
|
||||||
cityToWatch.setInverterEfficiency(inverterEfficiency);
|
cityToWatch.setInverterEfficiency(inverterEfficiency);
|
||||||
|
cityToWatch.setIsCentralInverter(isCentralInverter);
|
||||||
cityToWatch.setShadingElevation(shadingElevation);
|
cityToWatch.setShadingElevation(shadingElevation);
|
||||||
cityToWatch.setShadingOpacity(shadingOpacity);
|
cityToWatch.setShadingOpacity(shadingOpacity);
|
||||||
database.updateCityToWatch(cityToWatch);
|
database.updateCityToWatch(cityToWatch);
|
||||||
|
|
|
@ -128,19 +128,10 @@ public class WeatherCityFragment extends Fragment implements IUpdateableCityUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewForecasts(List<HourlyForecast> hourlyForecasts) {
|
public void processNewForecasts(List<HourlyForecast> hourlyForecasts, List<WeekForecast> weekForecasts) {
|
||||||
if (hourlyForecasts != null && hourlyForecasts.size() > 0 && hourlyForecasts.get(0).getCity_id() == mCityId) {
|
if (hourlyForecasts != null && hourlyForecasts.size() > 0 && hourlyForecasts.get(0).getCity_id() == mCityId) {
|
||||||
if (mAdapter != null) {
|
if (mAdapter != null) {
|
||||||
mAdapter.updateForecastData(hourlyForecasts);
|
mAdapter.updateForecastData(hourlyForecasts, weekForecasts);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNewWeekForecasts(List<WeekForecast> forecasts) {
|
|
||||||
if (forecasts != null && forecasts.size() > 0 && forecasts.get(0).getCity_id() == mCityId) {
|
|
||||||
if (mAdapter != null) {
|
|
||||||
mAdapter.updateWeekForecastData(forecasts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import java.util.List;
|
||||||
public interface IUpdateableCityUI {
|
public interface IUpdateableCityUI {
|
||||||
void processNewGeneralData(GeneralData data);
|
void processNewGeneralData(GeneralData data);
|
||||||
|
|
||||||
void processNewForecasts(List<HourlyForecast> hourlyForecasts);
|
void processNewForecasts(List<HourlyForecast> hourlyForecasts, List<WeekForecast> weekForecasts);
|
||||||
|
|
||||||
void processNewWeekForecasts(List<WeekForecast> forecasts);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,11 @@ public class ViewUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateWeekForecasts(List<WeekForecast> forecasts) {
|
|
||||||
ArrayList<IUpdateableCityUI> subcopy = new ArrayList<>(subscribers);
|
|
||||||
for (IUpdateableCityUI sub : subcopy) {
|
|
||||||
sub.processNewWeekForecasts(forecasts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateForecasts(List<HourlyForecast> hourlyForecasts) {
|
public static void updateForecasts(List<HourlyForecast> hourlyForecasts, List<WeekForecast> weekForecasts) {
|
||||||
ArrayList<IUpdateableCityUI> subcopy = new ArrayList<>(subscribers);
|
ArrayList<IUpdateableCityUI> subcopy = new ArrayList<>(subscribers);
|
||||||
for (IUpdateableCityUI sub : subcopy) {
|
for (IUpdateableCityUI sub : subcopy) {
|
||||||
sub.processNewForecasts(hourlyForecasts);
|
sub.processNewForecasts(hourlyForecasts, weekForecasts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,14 +118,10 @@ public class WeatherPagerAdapter extends FragmentStateAdapter implements IUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processNewForecasts(List<HourlyForecast> hourlyForecasts) {
|
public void processNewForecasts(List<HourlyForecast> hourlyForecasts, List<WeekForecast> weekForecasts) {
|
||||||
//empty because Fragments are subscribers themselves
|
//empty because Fragments are subscribers themselves
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processNewWeekForecasts(List<WeekForecast> forecasts) {
|
|
||||||
//empty because Fragments are subscribers themselves
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCityIDForPos(int pos) {
|
public int getCityIDForPos(int pos) {
|
||||||
CityToWatch city = cities.get(pos);
|
CityToWatch city = cities.get(pos);
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class OMDataExtractor implements IDataExtractor {
|
||||||
|
|
||||||
SQLiteHelper dbhelper = SQLiteHelper.getInstance(context);
|
SQLiteHelper dbhelper = SQLiteHelper.getInstance(context);
|
||||||
CityToWatch city = dbhelper.getCityToWatch(cityID);
|
CityToWatch city = dbhelper.getCityToWatch(cityID);
|
||||||
SolarPowerPlant spp = new SolarPowerPlant(city.getLatitude(), city.getLongitude(), city.getCellsMaxPower(), city.getCellsArea(), city.getCellsEfficiency(), city.getCellsTempCoeff(), city.getDiffuseEfficiency(), city.getInverterPowerLimit(), city.getInverterEfficiency(), city.getAzimuthAngle(), city.getTiltAngle(), city.getShadingElevation(), city.getShadingOpacity(), city.getAlbedo());
|
SolarPowerPlant spp = new SolarPowerPlant(city.getLatitude(), city.getLongitude(), city.getCellsMaxPower(), city.getCellsArea(), city.getCellsEfficiency(), city.getCellsTempCoeff(), city.getDiffuseEfficiency(), city.getInverterPowerLimit(), city.getInverterEfficiency(), city.isCentralInverter(), city.getAzimuthAngle(), city.getTiltAngle(), city.getShadingElevation(), city.getShadingOpacity(), city.getAlbedo());
|
||||||
|
|
||||||
|
|
||||||
IApiToDatabaseConversion conversion = new OMToDatabaseConversion();
|
IApiToDatabaseConversion conversion = new OMToDatabaseConversion();
|
||||||
|
|
|
@ -141,8 +141,7 @@ public class ProcessOMweatherAPIRequest implements IProcessHttpRequest {
|
||||||
dbHelper.addWeekForecasts(weekforecasts);
|
dbHelper.addWeekForecasts(weekforecasts);
|
||||||
|
|
||||||
if (c == CityIDList.size()-1) ViewUpdater.updateGeneralDataData(generalData); // Call Viewupdater if last (requested) city is updated
|
if (c == CityIDList.size()-1) ViewUpdater.updateGeneralDataData(generalData); // Call Viewupdater if last (requested) city is updated
|
||||||
if (c == CityIDList.size()-1) ViewUpdater.updateWeekForecasts(weekforecasts);
|
if (c == CityIDList.size()-1) ViewUpdater.updateForecasts(hourlyforecasts, weekforecasts);
|
||||||
if (c == CityIDList.size()-1) ViewUpdater.updateForecasts(hourlyforecasts);
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -194,17 +193,6 @@ public class ProcessOMweatherAPIRequest implements IProcessHttpRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WeekForecast weekForecast: weekforecasts){
|
|
||||||
float totalEnergy = 0;
|
|
||||||
Long timeNoon = weekForecast.getForecastTime();
|
|
||||||
for (HourlyForecast hourlyForecast: hourlyforecasts){
|
|
||||||
if ((hourlyForecast.getForecastTime()>=timeNoon-11*3600*1000L) && (hourlyForecast.getForecastTime()< timeNoon + 13*3600*1000L)){ //values are for preceding hour!
|
|
||||||
totalEnergy+=hourlyForecast.getPower();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
weekForecast.setEnergyDay(totalEnergy/1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return weekforecasts;
|
return weekforecasts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,15 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="numberDecimal"
|
android:inputType="numberDecimal"
|
||||||
android:hint="@string/edit_location_hint_inverter_efficiency"/>
|
android:hint="@string/edit_location_hint_inverter_efficiency"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:hint="@string/edit_location_hint_central_inverter"/>
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/EditLocation_Central_Inverter"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/edit_Location_shading"
|
android:id="@+id/edit_Location_shading"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -110,4 +110,5 @@
|
||||||
<string name="edit_location_hint_albedo">Albedo [0..1]</string>
|
<string name="edit_location_hint_albedo">Albedo [0..1]</string>
|
||||||
<string name="settings_server_urls">Server URLs</string>
|
<string name="settings_server_urls">Server URLs</string>
|
||||||
<string name="settings_server_summary">Nur ändern, wenn Sie Ihre eigenen Server betreiben wollen</string>
|
<string name="settings_server_summary">Nur ändern, wenn Sie Ihre eigenen Server betreiben wollen</string>
|
||||||
|
<string name="edit_location_hint_central_inverter">Zentralwechselrichter</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -113,5 +113,6 @@
|
||||||
<string name="github" translatable="false">GitHub</string>
|
<string name="github" translatable="false">GitHub</string>
|
||||||
<string name="settings_server_urls">Server URLs</string>
|
<string name="settings_server_urls">Server URLs</string>
|
||||||
<string name="settings_server_summary">Cambia solo se vuoi ospitare un tuo server</string>
|
<string name="settings_server_summary">Cambia solo se vuoi ospitare un tuo server</string>
|
||||||
|
<string name="edit_location_hint_central_inverter">Invertitore centrale</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -109,4 +109,5 @@
|
||||||
<string name="edit_location_hint_albedo">Albedo [0..1]</string>
|
<string name="edit_location_hint_albedo">Albedo [0..1]</string>
|
||||||
<string name="settings_server_urls">Sunucu URL\'leri</string>
|
<string name="settings_server_urls">Sunucu URL\'leri</string>
|
||||||
<string name="settings_server_summary">Yalnızca kendi sunucularınızı barındırmak istiyorsanız değiştirin</string>
|
<string name="settings_server_summary">Yalnızca kendi sunucularınızı barındırmak istiyorsanız değiştirin</string>
|
||||||
|
<string name="edit_location_hint_central_inverter">Merkezi invertör</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -113,5 +113,6 @@
|
||||||
<string name="github" translatable="false">GitHub</string>
|
<string name="github" translatable="false">GitHub</string>
|
||||||
<string name="settings_server_urls">Server URLs</string>
|
<string name="settings_server_urls">Server URLs</string>
|
||||||
<string name="settings_server_summary">Only change if you want to host your own servers</string>
|
<string name="settings_server_summary">Only change if you want to host your own servers</string>
|
||||||
|
<string name="edit_location_hint_central_inverter">Central Inverter</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue