pub struct Session {
pub id: SessionId,
pub evse_id: EvseId,
pub authorization: Authorization,
pub started_at: OffsetDateTime,
pub ended_at: Option<OffsetDateTime>,
pub end_reason: Option<EndReason>,
pub series: Vec<MeterSeries>,
pub negotiated: Option<V2gProtocol>,
/* private fields */
}Expand description
A charging session.
Fields§
§id: SessionIdWhich session.
evse_id: EvseIdWhere it happened.
How it was authorised, and for whom.
started_at: OffsetDateTimeWhen it began.
ended_at: Option<OffsetDateTime>When it ended, once it has.
end_reason: Option<EndReason>Why it ended.
series: Vec<MeterSeries>The energy it moved, by direction.
A vector rather than one series because a bidirectional session has two registers counting two quantities, and they never net.
negotiated: Option<V2gProtocol>The vehicle-communication generation this session actually negotiated.
§A different fact from the one the compliance calendar reads
emob_core::V2gCommunication says what a charger implements, which
is what every [DA-656 Anh. 2.1.x] duty is judged on. This says what
two parties agreed on the wire, once, at an instant. A point that
implements -2 and -20 and negotiates -2 with a 2018 car is compliant and
had a -2 session, and until there was a Plug & Charge crate there was
nothing to put the second fact on.
None for a session that negotiated nothing high-level — an RFID card
on a PWM point — which is not the same as “nobody recorded it” and is
why Self::contradicts_its_own_protocol asks about the pair rather
than about this field alone.
Implementations§
Source§impl Session
impl Session
Sourcepub fn open(
id: SessionId,
evse_id: EvseId,
authorization: Authorization,
started_at: OffsetDateTime,
) -> Self
pub fn open( id: SessionId, evse_id: EvseId, authorization: Authorization, started_at: OffsetDateTime, ) -> Self
Open a session in SessionState::Pending.
Sourcepub fn negotiated(self, protocol: V2gProtocol) -> Self
pub fn negotiated(self, protocol: V2gProtocol) -> Self
Record which vehicle-communication generation this session negotiated.
Sourcepub fn contradicts_its_own_protocol(&self) -> bool
pub fn contradicts_its_own_protocol(&self) -> bool
Whether the session’s authorisation and its negotiated protocol are two stories about one event.
Plug & Charge is ISO 15118’s. DIN SPEC 70121 is external identification
only — a card or an app — so a session recorded as din70121 and
authorised by a contract certificate is a claim no charger can have
made, and the pair is the only place it becomes checkable: each half on
its own is a perfectly ordinary value.
The same shape as the cross-check between an authorisation path and a
signed record’s identification level, one field along — and it answers
false where the protocol was not recorded, because a fact nobody
stated contradicts nothing.
Sourcepub fn state(&self) -> SessionState
pub fn state(&self) -> SessionState
Where the session is now.
Sourcepub fn history(&self) -> &[StateChange]
pub fn history(&self) -> &[StateChange]
Every state it has been in, in order.
Sourcepub fn state_at(&self, at: OffsetDateTime) -> Option<SessionState>
pub fn state_at(&self, at: OffsetDateTime) -> Option<SessionState>
The state the session was in at an instant.
None before it started.
Sourcepub fn activity_throughout(
&self,
from: OffsetDateTime,
to: OffsetDateTime,
) -> Option<Activity>
pub fn activity_throughout( &self, from: OffsetDateTime, to: OffsetDateTime, ) -> Option<Activity>
What the session says it was doing across the whole of [from, to).
None for an interval the record does not answer with one word: one
that spans a transition, one before the session started, one after it
ended, an empty one — and one in SessionState::Pending, which is
authorised with no vehicle demand yet and no operator refusal either.
This is the question emob-cdr asks of every period it prices, and it
is deliberately one question rather than two booleans. Asking
“was it charging” and “was it suspended” separately leaves the third
answer — the operator withholding power from a vehicle that is asking —
indistinguishable from the second, which is exactly the conflation
[OCPI 2.3.0 §mod_cdrs_chargingperiod_class] corrected its own
definition of PARKING_TIME to remove. See Activity.
Sourcepub fn suspended_throughout(
&self,
from: OffsetDateTime,
to: OffsetDateTime,
) -> bool
pub fn suspended_throughout( &self, from: OffsetDateTime, to: OffsetDateTime, ) -> bool
Whether the session was suspended for the whole of [from, to), for
either reason.
The protocol’s question. Which reason is the one money turns on, and
that is Self::activity_throughout.
Sourcepub fn charging_throughout(
&self,
from: OffsetDateTime,
to: OffsetDateTime,
) -> bool
pub fn charging_throughout( &self, from: OffsetDateTime, to: OffsetDateTime, ) -> bool
Whether the session was charging for the whole of [from, to).
§Not the negation of Self::suspended_throughout
There are four states and two of them are neither: a Pending session
is authorised with no energy moving, and an Ended one is over. Both
are “connected and not charging” — which is what [AFIR Art. 5(4)]’s
occupancy fee prices — and neither is suspended.
This is the question emob-cdr asks of every period it prices, metered
or not: a period is charging when the operator’s own record says it was,
and occupancy otherwise. Asking !suspended_throughout instead reads
“the session never said suspended” as “the vehicle was charging”, which
is an absence standing in for a claim — and bills the minute a car sat
EVConnected before its charge began as charging time.
Sourcepub fn transition_to(
&mut self,
next: SessionState,
at: OffsetDateTime,
) -> Result<(), SessionError>
pub fn transition_to( &mut self, next: SessionState, at: OffsetDateTime, ) -> Result<(), SessionError>
Move to a new state at an instant.
§Errors
SessionError::IllegalTransition when the protocol forbids it —
above all, anything at all after the session ended.
SessionError::TimeWentBackwards when the instant precedes the last
transition, because a history that is not ordered cannot be read as
intervals.
Sourcepub fn end(
&mut self,
at: OffsetDateTime,
reason: EndReason,
) -> Result<(), SessionError>
pub fn end( &mut self, at: OffsetDateTime, reason: EndReason, ) -> Result<(), SessionError>
End the session.
§Errors
SessionError::IllegalTransition when it has already ended,
SessionError::EndsBeforeItStarts when the end precedes the start, or
SessionError::TimeWentBackwards when it precedes the last
transition.
Sourcepub fn attach_series(&mut self, series: MeterSeries) -> Result<(), SessionError>
pub fn attach_series(&mut self, series: MeterSeries) -> Result<(), SessionError>
Attach a meter series.
§Errors
SessionError::AlreadyEnded once the session is final — a series
arriving after the end is either a late duplicate or a different
session, and guessing which is how energy gets double-billed.
SessionError::DuplicateDirection when a direction already has one.
Sourcepub fn series_for(&self, direction: Direction) -> Option<&MeterSeries>
pub fn series_for(&self, direction: Direction) -> Option<&MeterSeries>
The series for a direction.
Sourcepub fn total(&self, direction: Direction) -> Option<Energy>
pub fn total(&self, direction: Direction) -> Option<Energy>
Total energy in a direction.
None when the session recorded nothing in that direction — which is
not the same as zero, and a caller that treats it as zero will invoice a
session it has no readings for.
Sourcepub fn idle_intervals(&self) -> Vec<(OffsetDateTime, OffsetDateTime)>
pub fn idle_intervals(&self) -> Vec<(OffsetDateTime, OffsetDateTime)>
The intervals in which this session says no energy flowed — every
stretch of its history in a state other than SessionState::Charging,
as [from, to) pairs in time order.
A Pending session is authorised with nothing flowing, a Suspended
one is held at zero, and an Ended one is over; none of them moves the
register. The last interval — the time after the end, or the current
state of a session still running — is open-ended.
This is what Self::split hands the interpolation, so a gap between
two readings spreads its energy over the seconds the session was
charging rather than in a straight line across a suspension. A meter
cannot tell a taper from a pause; the state machine can, and it is the
operator’s own record of which was which.
Sourcepub fn split(&self, direction: Direction) -> Result<SessionSplit, SessionError>
pub fn split(&self, direction: Direction) -> Result<SessionSplit, SessionError>
Split a direction’s energy across the quarter hours it touched, cut also wherever the session changed state, with the energy of every gap between two readings spread over the time the session was charging in it.
The input mako-emob needs to assign each quarter hour to the balance
group of the supplier the driver chose [A6 §IV.1] —
SessionSplit::market_series sums the slices of a quarter hour back
together for exactly that.
§Why the state changes cut it
A quarter hour is where the energy settles. It is not where the price
changes: [AFIR Art. 5(4)] prices time connected and not charging
separately from the energy, and a vehicle stops charging when it stops
charging rather than at :15:00. Split on the grid alone, the quarter
hour a charge finishes in carries one charging flag for fifteen
minutes that were not all the same — so up to a quarter hour of
occupancy is billed as charging, or the reverse, at every transition.
The session’s own history says where the line falls, so it is drawn
there.
§…and why the state changes shape the interpolation too
The same history says where the register could have moved. A
transaction that opens EVConnected, starts charging thirty seconds
later and sends its next meter value at the quarter hour — the ordinary
OCPP 2.0.1 shape — has a register that did not move for those thirty
seconds, and a straight line from the opening reading attributes energy
to an interval the operator’s own record calls suspended. So the split
is handed Self::idle_intervals and holds the register flat across
them; see crate::split::into_periods.
§Errors
SessionError::NoSeries when the direction has no readings, or
SessionError::Split when the readings cannot be split.