open-standards/eoc/eoc-rs/crates/eoc-carbon/tests/region_scheduler.rs
Transaction Science 781c331288 ingest batch 5 (salvage): 2 crates from 9-agent dispatch (session-limit hit mid-batch)
OpenPay (1 crate)
  op-revrec      ASC 606 / IFRS 15 revenue recognition (5-step model,
                 multi-element allocation, deferred revenue ledger,
                 variable consideration with constraint, principal vs agent,
                 contract modifications, multi-currency translation)
                 27 tests across 6 FASB worked examples + SaaS lifecycle.

EOC (1 crate)
  eoc-carbon     Carbon intensity → joules → gCO2e accounting.
                 Electricity Maps, WattTime, CO2 Signal adapters; IEA
                 baseline fallback; PUE tables (AWS/GCP/Azure); region-aware
                 scheduling + demand shifting; SCI-for-AI bridge into eoc-eval.
                 21 tests passing.

Seven other crates (op-dispute-evidence, op-ewallets-asia, smart-byte-zk,
smart-byte-atproto, smart-byte-edv, eoc-agent, eoc-rag) were scoped in this
batch but the parallel agents hit session-limit before completing. They are
deferred to a follow-up batch.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-24 09:28:38 -04:00

39 lines
1.2 KiB
Rust

//! Picks the greenest of three regions over a 6-hour horizon.
use chrono::{Duration, Utc};
use eoc_carbon::intensity::{ForecastPoint, Zone};
use eoc_carbon::scheduler::{RegionForecast, RegionScheduler};
fn region(name: &str, now: chrono::DateTime<Utc>, values: &[f64]) -> RegionForecast {
RegionForecast {
zone: Zone::new(name),
forecast: values
.iter()
.enumerate()
.map(|(i, g)| ForecastPoint {
at: now + Duration::hours(i as i64 + 1),
g_co2e_per_kwh: *g,
})
.collect(),
}
}
#[test]
fn picks_lowest_mean_region() {
let now = Utc::now();
let candidates = vec![
region("US-VA", now, &[400.0, 410.0, 420.0, 430.0, 440.0, 450.0]),
region("EU-FR", now, &[ 60.0, 65.0, 55.0, 70.0, 62.0, 58.0]),
region("AU-NSW", now, &[600.0, 610.0, 620.0, 630.0, 640.0, 650.0]),
];
let s = RegionScheduler::new(Duration::hours(6));
let pick = s.pick_at(&candidates, now).expect("ok");
assert_eq!(pick.zone.as_str(), "EU-FR");
}
#[test]
fn empty_candidate_set_errors() {
let s = RegionScheduler::new(Duration::hours(1));
let r = s.pick_at(&[], Utc::now());
assert!(r.is_err());
}