Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Averaging Measurements #241

Merged
merged 10 commits into from
Nov 20, 2023
Merged

Averaging Measurements #241

merged 10 commits into from
Nov 20, 2023

Conversation

SNSubramanya
Copy link
Contributor

No description provided.

@SNSubramanya SNSubramanya force-pushed the clock-aligned-values branch 2 times, most recently from c9eda59 to 4c7e6a1 Compare November 3, 2023 12:02
@SNSubramanya SNSubramanya marked this pull request as ready for review November 7, 2023 14:52
Copy link
Contributor

@marcemmers marcemmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please take another look to remove all the unrelated changes, debug stuff etc?

Also take a closer look at the mutex uses especially since the AlignedData has its own mutex now.

I am wondering if AlignedData is the best name. It says something currently about what it is used for, not what it is. I normally think that naming something what it is, is a bit clearer and allows for more general use of classes.

@SNSubramanya
Copy link
Contributor Author

Can you please take another look to remove all the unrelated changes, debug stuff etc?

Also take a closer look at the mutex uses especially since the AlignedData has its own mutex now.

I am wondering if AlignedData is the best name. It says something currently about what it is used for, not what it is. I normally think that naming something what it is, is a bit clearer and allows for more general use of classes.

Not sure what that means... you mean rename it to averaging?

@@ -221,6 +221,16 @@ MeterValue Evse::get_meter_value() {
return this->meter_value;
}

MeterValue Evse::get_idle_meter_value() {
std::lock_guard<std::recursive_mutex> lk(this->meter_value_mutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some mutexes here that are no longer needed ;)

@@ -112,16 +112,13 @@ void Evse::open_transaction(const std::string& transaction_id, const int32_t con
if (aligned_data_tx_updated_interval > 0s) {
transaction->aligned_tx_updated_meter_values_timer.interval_starting_from(
[this] {
if (this->device_model.get_optional_value<bool>(ControllerComponentVariables::AlignedDataSendDuringIdle)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably still check on the AlignedDataSendDuringIdle flag

const auto meter_value =
get_latest_meter_value_filtered(this->get_meter_value(), ReadingContextEnum::Sample_Clock,
get_latest_meter_value_filtered(this->aligned_data_evse0.get_values(), ReadingContextEnum::Sample_Clock,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you clearing the evse0 averaging as well?

Maybe you can still do the clearing in the get so you don't always have to group a get and clear function together. Only get is probably not the best name then since you will be changing the internal state which you normally don't do on a get

}

void AverageMeterValues::set_values(const MeterValue& meter_value) {
EVLOG_debug << " Setting the aligned values";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove these log lines? Even for debugging this is not really useful IHMO. You'd just get spammed with this line, maybe even a couple of times a second with a fast meter.

At the very least remove the log from the constructor. It is assumed a constructor just works so does not really need logging like this.

bool AverageMeterValues::is_avg_meas(const SampledValue& sample) {

// TODO: check up on location values and how they impact the averaging
if (sample.measurand.has_value() && sample.phase.has_value()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we have a single phase system and there is no phase set? Or we want to average the total power value which also does not have a phase?

I think a more close look is needed at this still

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree this is a bit tricky at the moment

// Define a comparison operator for the struct
bool operator<(const MeterValueMeasurands& other) const {

return measurand < other.measurand || location.value() < other.location.value() ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this with measurands that don't have a location or a phase?

Also, they prefer or to ||

// avg all the possible measurerands
for (auto element : meter_value.sampledValue) {
if (is_avg_meas(element)) {
MeterValueCalc temp =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make this a reference you can edit the value inside the map instead of having to copy it twice

return true;
} else {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you'd get a warning of this as well, but you have a return without value path here I think?

ControllerComponentVariables::AlignedDataMeasurands);

if (!meter_value.sampledValue.empty()) {
// J01.FR.14 this is the only case where we send a MeterValue.req
this->meter_values_req(evse_id, std::vector<ocpp::v201::MeterValue>(1, meter_value));
// clear the values
evse->clear_idle_meter_values();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we clear regardless of if we actually have filtered data?

marcemmers and others added 9 commits November 16, 2023 14:01
Signed-off-by: Marc Emmers <[email protected]>
Signed-off-by: Soumya Subramanya <[email protected]>
Signed-off-by: Soumya Subramanya <[email protected]>
Signed-off-by: Soumya Subramanya <[email protected]>
Signed-off-by: Soumya Subramanya <[email protected]>
Signed-off-by: Soumya Subramanya <[email protected]>
Signed-off-by: Soumya Subramanya <[email protected]>

fix rebasign errors

Signed-off-by: Soumya Subramanya <[email protected]>

fix formatting

Signed-off-by: Soumya Subramanya <[email protected]>

intermidiate commit

Signed-off-by: Soumya Subramanya <[email protected]>

PR changes

Signed-off-by: Soumya Subramanya <[email protected]>

remove fake values

Signed-off-by: Soumya Subramanya <[email protected]>

put back optional location and phase values

Signed-off-by: Soumya Subramanya <[email protected]>

remove fake values

Signed-off-by: Soumya Subramanya <[email protected]>

fix formatting

Signed-off-by: Soumya Subramanya <[email protected]>

fix some more PR issues

Signed-off-by: Soumya Subramanya <[email protected]>

revert unexpected changes

Signed-off-by: Soumya Subramanya <[email protected]>

Pr changes
}

void Evse::clear_idle_meter_values() {
std::lock_guard<std::recursive_mutex> lk(this->meter_value_mutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No mutex needed here right?

EVLOG_debug << " loc: " << element.location.value();
}

EVLOG_debug << " sum:" << temp.sum << "#num" << temp.num_elements << "AVG: " << element.value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please remove these debug lines? I get that they are useful to test with. But this makes it impossible to enable debug on a system without getting spammed. And now it is working we can remove these right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Signed-off-by: Soumya Subramanya <[email protected]>
@SNSubramanya SNSubramanya merged commit 8a4a971 into main Nov 20, 2023
@SNSubramanya SNSubramanya deleted the clock-aligned-values branch November 20, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants