Skip to main content

Session

Struct Session 

Source
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: SessionId

Which session.

§evse_id: EvseId

Where it happened.

§authorization: Authorization

How it was authorised, and for whom.

§started_at: OffsetDateTime

When 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

Source

pub fn open( id: SessionId, evse_id: EvseId, authorization: Authorization, started_at: OffsetDateTime, ) -> Self

Open a session in SessionState::Pending.

Source

pub fn negotiated(self, protocol: V2gProtocol) -> Self

Record which vehicle-communication generation this session negotiated.

Source

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.

Source

pub fn state(&self) -> SessionState

Where the session is now.

Source

pub fn history(&self) -> &[StateChange]

Every state it has been in, in order.

Source

pub fn state_at(&self, at: OffsetDateTime) -> Option<SessionState>

The state the session was in at an instant.

None before it started.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn series_for(&self, direction: Direction) -> Option<&MeterSeries>

The series for a direction.

Source

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.

Source

pub fn duration(&self) -> Option<Duration>

How long the session lasted, once it has ended.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Session

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Session

Source§

impl PartialEq for Session

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Session

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Session

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.