Browse Source

optimizing ...

pull/1512/head
lumapu 10 months ago
parent
commit
1e5d788914
  1. 4
      src/app.h
  2. 2
      src/appInterface.h
  3. 14
      src/plugins/Display/Display_Mono.h
  4. 35
      src/plugins/history.h
  5. 9
      src/web/RestApi.h
  6. 18
      src/web/html/history.html
  7. 11
      src/web/html/style.css

4
src/app.h

@ -314,9 +314,9 @@ class app : public IApp, public ah::Scheduler {
#endif
}
uint32_t getHistoryPeriode(uint8_t type) override {
uint32_t getHistoryPeriod(uint8_t type) override {
#if defined(ENABLE_HISTORY)
return mHistory.getPeriode((HistoryStorageType)type);
return mHistory.getPeriod((HistoryStorageType)type);
#else
return 0;
#endif

2
src/appInterface.h

@ -67,7 +67,7 @@ class IApp {
virtual bool isProtected(const char *clientIp, const char *token, bool askedFromWeb) const = 0;
virtual uint16_t getHistoryValue(uint8_t type, uint16_t i) = 0;
virtual uint32_t getHistoryPeriode(uint8_t type) = 0;
virtual uint32_t getHistoryPeriod(uint8_t type) = 0;
virtual uint16_t getHistoryMaxDay() = 0;
virtual uint32_t getHistoryLastValueTs(uint8_t type) = 0;
#if defined(ENABLE_HISTORY_LOAD_DATA)

14
src/plugins/Display/Display_Mono.h

@ -110,7 +110,7 @@ class DisplayMono {
}
// add new value to power graph and maintain state engine for period times
void addPowerGraphEntry(float val) {
/*void addPowerGraphEntry(float val) {
if (nullptr == mPgData) // power graph not initialized
return;
@ -163,7 +163,7 @@ class DisplayMono {
mPgData[mPgLastPos] = std::max(mPgData[mPgLastPos], val); // update current datapoint to maximum of all seen values (= envelope curve)
mPgMaxPwr = std::max(mPgMaxPwr, val); // update max value of stored data for scaling of y-axis
}
}
}*/
// plot power graph to given display offset
void plotPowerGraph(uint8_t xoff, uint8_t yoff) {
@ -296,15 +296,15 @@ class DisplayMono {
uint8_t mPgWidth = 0;
private:
float *mPgData = nullptr;
//float *mPgData = nullptr;
uint8_t mPgHeight = 0;
float mPgMaxPwr = 0.0;
uint32_t mPgStartTime = 0;
uint32_t mPgEndTime = 0;
uint32_t mPgPeriod = 0; // seconds
//uint32_t mPgStartTime = 0;
//uint32_t mPgEndTime = 0;
//uint32_t mPgPeriod = 0; // seconds
uint8_t mPgLastPos = 0;
uint32_t mPgLastTime = 0;
PowerGraphState mPgState = PowerGraphState::NO_TIME_SYNC;
//PowerGraphState mPgState = PowerGraphState::NO_TIME_SYNC;
uint16_t mDispHeight = 0;
uint8_t mLuminance = 0;

35
src/plugins/history.h

@ -26,8 +26,8 @@ class HistoryData {
private:
struct storage_t {
uint16_t refreshCycle = 0;
uint16_t loopCnt;
uint16_t listIdx; // index for next Element to write into WattArr
uint16_t loopCnt = 0;
uint16_t listIdx = 0; // index for next Element to write into WattArr
// ring buffer for watt history
std::array<uint16_t, (HISTORY_DATA_ARR_LENGTH + 1)> data;
@ -45,12 +45,11 @@ class HistoryData {
mConfig = config;
mTs = ts;
mCurPwr.reset();
mCurPwr.refreshCycle = mConfig->inst.sendInterval;
mCurPwrDay.reset();
mCurPwrDay.refreshCycle = mConfig->inst.sendInterval;
mYieldDay.reset();
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
mYieldDay.refreshCycle = 60;
#endif
mLastValueTs = 0;
mPgPeriod=0;
mMaximumDay = 0;
@ -94,18 +93,18 @@ class HistoryData {
}
}
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
if((++mYieldDay.loopCnt % mYieldDay.refreshCycle) == 0) {
mYieldDay.loopCnt = 0;
if (*mTs > mApp->getSunset())
{
if (*mTs > mApp->getSunset()) {
if ((!mDayStored) && (yldDay > 0)) {
addValue(&mYieldDay, roundf(yldDay));
mDayStored = true;
}
}
else if (*mTs > mApp->getSunrise())
} else if (*mTs > mApp->getSunrise())
mDayStored = false;
}
#endif
}
uint16_t valueAt(HistoryStorageType type, uint16_t i) {
@ -113,10 +112,12 @@ class HistoryData {
uint16_t idx=i;
DPRINTLN(DBG_VERBOSE, F("valueAt ") + String((uint8_t)type) + " i=" + String(i));
idx = (s->listIdx + i) % HISTORY_DATA_ARR_LENGTH;
switch (type) {
default:
[[fallthrough]];
case HistoryStorageType::POWER:
s = &mCurPwr;
idx = (s->listIdx + i) % HISTORY_DATA_ARR_LENGTH;
break;
case HistoryStorageType::POWER_DAY:
s = &mCurPwrDay;
@ -124,12 +125,10 @@ class HistoryData {
break;
case HistoryStorageType::YIELD:
s = &mYieldDay;
idx = (s->listIdx + i) % HISTORY_DATA_ARR_LENGTH;
break;
}
if (s)
return s->data[idx];
return 0;
}
uint16_t getMaximumDay() {
@ -159,21 +158,29 @@ class HistoryData {
return 0;
}
bool isDataValid(void) {
return ((0 != mPgStartTime) && (0 != mPgEndTime));
}
#if defined(ENABLE_HISTORY_LOAD_DATA)
/* For filling data from outside */
void addValue(HistoryStorageType historyType, uint8_t valueType, uint32_t value) {
if (valueType<2) {
storage_t *s=NULL;
switch (historyType) {
default:
[[fallthrough]];
case HistoryStorageType::POWER:
s = &mCurPwr;
break;
case HistoryStorageType::POWER_DAY:
s = &mCurPwrDay;
break;
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
case HistoryStorageType::YIELD:
s = &mYieldDay;
break;
#endif
}
if (s)
{
@ -275,7 +282,9 @@ class HistoryData {
storage_t mCurPwr;
storage_t mCurPwrDay;
#if defined(ENABLE_HISTORY_YIELD_PER_DAY)
storage_t mYieldDay;
#endif
bool mDayStored = false;
uint16_t mMaximumDay = 0;
uint32_t mLastValueTs = 0;

9
src/web/RestApi.h

@ -50,7 +50,6 @@ class RestApi {
#endif
mConfig = config;
#if defined(ENABLE_HISTORY_LOAD_DATA)
//Vart67: Debugging history graph (loading data into graph storage
mSrv->on("/api/addYDHist",
HTTP_POST, std::bind(&RestApi::onApiPost, this, std::placeholders::_1),
std::bind(&RestApi::onApiPostYDHist,this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6));
@ -913,7 +912,7 @@ class RestApi {
void getPowerHistory(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic")));
#if defined(ENABLE_HISTORY)
obj[F("refresh")] = mApp->getHistoryPeriode((uint8_t)HistoryStorageType::POWER);
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER);
uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER, fld);
@ -930,7 +929,7 @@ class RestApi {
void getPowerHistoryDay(AsyncWebServerRequest *request, JsonObject obj){
getGeneric(request, obj.createNestedObject(F("generic")));
#if defined(ENABLE_HISTORY)
obj[F("refresh")] = mApp->getHistoryPeriode((uint8_t)HistoryStorageType::POWER_DAY);
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::POWER_DAY);
uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::POWER_DAY, fld);
@ -947,8 +946,8 @@ class RestApi {
void getYieldDayHistory(AsyncWebServerRequest *request, JsonObject obj) {
getGeneric(request, obj.createNestedObject(F("generic")));
#if defined(ENABLE_HISTORY)
obj[F("refresh")] = mApp->getHistoryPeriode((uint8_t)HistoryStorageType::YIELD);
#if defined(ENABLE_HISTORY) && defined(ENABLE_HISTORY_YIELD_PER_DAY)
obj[F("refresh")] = mApp->getHistoryPeriod((uint8_t)HistoryStorageType::YIELD);
uint16_t max = 0;
for (uint16_t fld = 0; fld < HISTORY_DATA_ARR_LENGTH; fld++) {
uint16_t value = mApp->getHistoryValue((uint8_t)HistoryStorageType::YIELD, fld);

18
src/web/html/history.html

@ -30,8 +30,7 @@
{#UPDATED} <span id="pwrDayRefresh"></span> {#SECONDS}
</p>
</div>
<!--
<!--IF_ENABLE_HISTORY_YIELD_PER_DAY-->
<h3>{#TOTAL_YIELD_PER_DAY}</h3>
<div class="chartDivContainer">
<div class="chartDiv" id="ydChart"> </div>
@ -39,7 +38,8 @@
{#MAXIMUM}: <span id="ydMax"></span> Wh<br />
</p>
</div>
<!--ENDIF_ENABLE_HISTORY_YIELD_PER_DAY-->
<!--IF_ENABLE_HISTORY_LOAD_DATA-->
<h4 style="margin-bottom:0px;">Insert data into Yield per day history</h4>
<fieldset style="padding: 1px;">
<legend class="des" style="margin-top: 0px;">Insert data (*.json) i.e. from a saved "/api/yieldDayHistory" call
@ -50,7 +50,7 @@
<input type="file" name="insert" style="width: 80%;">
</form>
</fieldset>
-->
<!--ENDIF_ENABLE_HISTORY_LOAD_DATA-->
</div>
</div>
{#HTML_FOOTER}
@ -151,19 +151,9 @@
}
this.svg.appendChild(defLg);
let chartFrame = document.createElementNS(svgns, "rect");
chartFrame.setAttribute("id", this.namePrefix + "_chartFrame");
chartFrame.setAttribute("class", "chartFrame");
chartFrame.setAttribute("x", "0");
chartFrame.setAttribute("y", "0");
chartFrame.setAttribute("width", String(this.datapoints * 2));
chartFrame.setAttribute("height", String(this.mChartHight));
this.svg.appendChild(chartFrame);
// Group chart content
let chartContent = document.createElementNS(svgns, "g");
chartContent.setAttribute("id", this.namePrefix + "_svgChartContent");
chartFrame.setAttribute("transform", "translate(29, 5)");
chartContent.setAttribute("transform", "translate(30, 5)");
// Graph values in a polyline

11
src/web/html/style.css

@ -33,16 +33,6 @@ textarea {
color: var(--fg2);
}
svg.container {
background:var(--chart-cont);
}
rect.chartFrame {
fill: var(--chart-bg);
stroke: gray;
stroke-width: 1px;
}
svg polyline {
fill-opacity: .5;
stroke-width: 1;
@ -53,7 +43,6 @@ svg text {
fill: var(--chart-text);
}
div.chartDivContainer {
padding: 1px;
margin: 1px;

Loading…
Cancel
Save