Skip to content

Commit

Permalink
phase_switcher: Finalize chart
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsches1 committed Oct 22, 2023
1 parent 5e06939 commit e48c279
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 53 deletions.
31 changes: 14 additions & 17 deletions software/src/modules/phase_switcher/multi_value_history.cpp
Expand Up @@ -51,22 +51,19 @@ void MultiValueHistory::setup()

for(int j = 0; j < MULTI_VALUE_HISTORY_NUMBER_OF_VALUES; ++j){
for (size_t i = 0; i < history[i].size(); ++i) {
// !!! FIXME
float f = 5000.0f * sinf(static_cast<float>(PI)/120.0f * static_cast<float>(i)) + 5000.0f;
switch(j){
case 0:
val_min = static_cast<int16_t>(f);
break;

case 1:
val_min = static_cast<int16_t>(f * -1.0f + 10000.0f);
break;

default:
val_min = static_cast<int16_t>((i) / 240 * 3000);
}

// !!! FIXME
// float f = 5000.0f * sinf(static_cast<float>(PI)/120.0f * static_cast<float>(i)) + 5000.0f;
// switch(j){
// case 0:
// val_min = static_cast<int16_t>(f);
// break;

// case 1:
// val_min = static_cast<int16_t>(f * -1.0f + 10000.0f);
// break;

// default:
// val_min = static_cast<int16_t>((i) / 240 * 3000);
// }
// Use negative state to mark that these are pre-filled.
history[j].push(val_min);
}
Expand Down Expand Up @@ -173,7 +170,7 @@ void MultiValueHistory::add_sample(float sample[MULTI_VALUE_HISTORY_NUMBER_OF_VA

for(int j = 0; j < MULTI_VALUE_HISTORY_NUMBER_OF_VALUES; ++j){
val[j] = clamp(static_cast<MULTI_VALUE_HISTORY_VALUE_TYPE>(MULTI_VALUE_HISTORY_VALUE_MIN),
static_cast<MULTI_VALUE_HISTORY_VALUE_TYPE>(roundf(sample[MULTI_VALUE_HISTORY_NUMBER_OF_VALUES])),
static_cast<MULTI_VALUE_HISTORY_VALUE_TYPE>(roundf(sample[j])),
static_cast<MULTI_VALUE_HISTORY_VALUE_TYPE>(MULTI_VALUE_HISTORY_VALUE_MAX));
live[j].push(val[j]);
}
Expand Down
6 changes: 4 additions & 2 deletions software/src/modules/phase_switcher/multi_value_history.h
Expand Up @@ -29,8 +29,9 @@
#include "task_scheduler.h"
#include "web_server.h"

// !!! FIXME
// How many hours to keep the coarse history for
#define MULTI_VALUE_HISTORY_HOURS 48
#define MULTI_VALUE_HISTORY_HOURS 36
// How many minutes to keep the fine history for.
// This also controls the coarseness of the coarse history.
// For example 4 means that we accumulate 4 minutes of samples
Expand All @@ -39,7 +40,8 @@
// When we have 4 minutes worth of samples, we take the average
// and add it to the coarse history.
// #define MULTI_VALUE_HISTORY_MINUTE_INTERVAL 4
#define MULTI_VALUE_HISTORY_MINUTE_INTERVAL 4
// !!! FIXME
#define MULTI_VALUE_HISTORY_MINUTE_INTERVAL 3

#define MULTI_VALUE_RING_BUF_SIZE (MULTI_VALUE_HISTORY_HOURS * 60 / MULTI_VALUE_HISTORY_MINUTE_INTERVAL)

Expand Down
5 changes: 0 additions & 5 deletions software/src/modules/phase_switcher/phase_switcher.h
Expand Up @@ -27,7 +27,6 @@

#include "delay_timer.h"
#include "multi_value_history.h"
// #include "../meter/value_history.h"

#define EVSE_START_TIMEOUT 60000
#define EVSE_START_RETRIES 3
Expand Down Expand Up @@ -170,9 +169,5 @@ class PhaseSwitcher final : public IModule
bool contactor_error;

MultiValueHistory power_history;
// ValueHistory available_charging_power_history;
// ValueHistory actual_charging_power_history;
// ValueHistory requested_phases_history;

};

31 changes: 2 additions & 29 deletions software/web/src/modules/phase_switcher/main.tsx
Expand Up @@ -479,7 +479,7 @@ function calculate_live_data(offset: number, samples_per_second: number, samples
}

function calculate_history_data(offset: number, samples: number[][]): UplotData {
const HISTORY_MINUTE_INTERVAL = 4;
const HISTORY_MINUTE_INTERVAL = 3;

let data: UplotData = {timestamps: new Array(samples[0].length), samples: samples};
let now = Date.now();
Expand All @@ -491,14 +491,6 @@ function calculate_history_data(offset: number, samples: number[][]): UplotData
// sampling interval
let start = Math.round((now - (samples[0].length - 1) * step - offset) / step) * step;

// FIXME
for(let i = 1; i < samples.length; ++i){
if (samples[i].length != samples[0].length) {
console.log("ERROR: phase_switcher calculate_live_data: samples arrays do not have the same length!")
}
}
// FIXME

for(let i = 0; i < samples[0].length; ++i) {
data.timestamps[i] = (start + i * step) / 1000;
}
Expand Down Expand Up @@ -580,39 +572,20 @@ export class PhaseSwitcher extends ConfigComponent<'phase_switcher/config', {},
if (this.state.chart_selected == "history") {
this.update_uplot();
}
// !!! FIXME
console.log("phase_switcher/history:");
for (let i = 0; i<3; ++i){
console.log("phase_switcher/history:" + this.history_data.samples[i]);
console.log("--");
}
// !!! FIXME
});

util.addApiEventListener("phase_switcher/history_samples", () => {
let history = API.get("phase_switcher/history_samples");
let samples: number[][];
let samples: number[][] = [[], [], []];

console.log("phase_switcher/history_samples 1");
for(let value_index = 0; value_index < history.samples.length; ++value_index){
console.log("phase_switcher/history_samples 1 loop " + value_index);
samples[value_index] = array_append(this.history_data.samples[value_index], history.samples[value_index], 720);
}
console.log("phase_switcher/history_samples 2");
this.history_data = calculate_history_data(0, samples);

console.log("phase_switcher/history_samples 3");
if (this.state.chart_selected == "history") {
console.log("phase_switcher/history_samples 4");
this.update_uplot();
}
// !!! FIXME
console.log("phase_switcher/history_samples:");
for (let i = 0; i<3; ++i){
console.log("phase_switcher/history_samples:" + this.history_data.samples[i]);
console.log("--");
}
// !!! FIXME
});

this.state = {
Expand Down

0 comments on commit e48c279

Please sign in to comment.