-
Notifications
You must be signed in to change notification settings - Fork 66
Averaging Measurements #241
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
Conversation
c9eda59 to
4c7e6a1
Compare
b5efa1c to
87a5e4d
Compare
marcemmers
left a comment
There was a problem hiding this 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.
Not sure what that means... you mean rename it to averaging? |
lib/ocpp/v201/evse.cpp
Outdated
| } | ||
|
|
||
| MeterValue Evse::get_idle_meter_value() { | ||
| std::lock_guard<std::recursive_mutex> lk(this->meter_value_mutex); |
There was a problem hiding this comment.
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 ;)
| 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) |
There was a problem hiding this comment.
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
lib/ocpp/v201/charge_point.cpp
Outdated
| // send evseID = 0 values | ||
| 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, |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
3ac3851 to
aa2b88e
Compare
| // Define a comparison operator for the struct | ||
| bool operator<(const MeterValueMeasurands& other) const { | ||
|
|
||
| return measurand < other.measurand || location.value() < other.location.value() || |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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?
lib/ocpp/v201/charge_point.cpp
Outdated
| // 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(); |
There was a problem hiding this comment.
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?
a43d9f5 to
b52a31d
Compare
…f a transaction Signed-off-by: Marc Emmers <m.emmers@alfen.com>
Signed-off-by: Marc Emmers <m.emmers@alfen.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> fix rebasign errors Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> fix formatting Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> intermidiate commit Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> PR changes Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> remove fake values Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> put back optional location and phase values Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> remove fake values Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> fix formatting Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> fix some more PR issues Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> revert unexpected changes Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> Pr changes
7c8bb1b to
f71b134
Compare
lib/ocpp/v201/evse.cpp
Outdated
| } | ||
|
|
||
| void Evse::clear_idle_meter_values() { | ||
| std::lock_guard<std::recursive_mutex> lk(this->meter_value_mutex); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 <s.subramanya@alfen.com>
No description provided.