pub struct Data(/* private fields */);Expand description
A named collection of tables, changed in place by patches.
Cloning is O(1) and a clone is a snapshot: apply changes only self, and every
page it does not write stays shared with earlier snapshots.
let mut grid = Data::new("grid");
grid.apply(
Patch::new()
.axis("time", "s")
.replace(Table::new("Bus", vec![1_u64, 2]).field("kv", vec![230.0, 115.0]))
.replace(Table::new("Branch", Ids::count(1)).reference("from", "Bus", vec![1_u64]).reference("to", "Bus", vec![2_u64])),
)?;
grid.apply(Patch::new().append([0.0], "Bus", [("vm", vec![1.01, 0.99])]))?;Implementations§
Source§impl Data
impl Data
Sourcepub fn axis(&self) -> Option<(&str, &str)>
pub fn axis(&self) -> Option<(&str, &str)>
The name and unit of the axis sampled fields are recorded over.
Sourcepub fn get(&self, row: &Row, field: &str) -> Option<Value>
pub fn get(&self, row: &Row, field: &str) -> Option<Value>
The value of field for row; a sampled field reads its last frame.
Sourcepub fn get_at(&self, row: &Row, field: &str, at: f64) -> Option<Value>
pub fn get_at(&self, row: &Row, field: &str, at: f64) -> Option<Value>
The value of field for row at axis coordinate at: the last frame at or before it.
Sourcepub fn apply(&mut self, patch: impl Into<Patch>) -> Result<()>
pub fn apply(&mut self, patch: impl Into<Patch>) -> Result<()>
Applies every change in patch, or none of them when one is invalid. A patch to another
dataset is an error.
The error’s path names the change and part, such as patch[1].Bus.kv.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Data>
pub fn from_bytes(bytes: &[u8]) -> Result<Data>
A dataset from to_bytes, or any bytes of a patch to a dataset.
Sourcepub fn read(bytes: &[u8], name: Option<&str>) -> Result<Data>
pub fn read(bytes: &[u8], name: Option<&str>) -> Result<Data>
A dataset from bytes: latkit’s own, as to_bytes writes them, or GeoJSON,
gzip-compressed or not. GeoJSON’s features become rows of tables points, lines, and
polygons by their geometry, each with its geometry as field geometry and its properties as
fields. name names the dataset, as GeoJSON needs; latkit’s bytes name their own unless given
one.
let city = latkit::Data::read(br#"{"type": "Feature", "properties": {"name": "Hall"},
"geometry": {"type": "Point", "coordinates": [-97.74, 30.27]}}"#, Some("city"))?;
assert_eq!(city.table("points").map(latkit::Table::len), Some(1));Source§impl Data
impl Data
Sourcepub fn describe(&self) -> Description
pub fn describe(&self) -> Description
What the dataset holds: tables, rows, fields and their kinds, the axis and its span.
Source§impl Data
impl Data
Sourcepub fn to_tiles(
&self,
chunk: u32,
write: impl FnMut(&str, &[u8]) -> Result<()>,
) -> Result<()>
pub fn to_tiles( &self, chunk: u32, write: impl FnMut(&str, &[u8]) -> Result<()>, ) -> Result<()>
The dataset as time tiles, each file’s path and bytes handed to write: frames.json, the
manifest a view’s tiles open; base.latk, the dataset with its sampled fields reading their
frames but holding none; and a patch for each span of chunk entries of each level of each
sampled field that holds any, at {field}/{level}/{index}.latk. A view given the manifest as
Tiles fetches the spans its lines draw, at the level of detail its plot
window asks, and those about the coordinate it shows; until a span lands, the span above it
draws.
The manifest is written last, so a reader finding it finds every file it names.
Source§impl Data
impl Data
Sourcepub fn query(&self, query: &Query) -> Result<(Table, usize)>
pub fn query(&self, query: &Query) -> Result<(Table, usize)>
The rows of a table query asks for, as a table of their own: their ids, and their fields or
what the query computes, sampled fields read at its coordinate; and how many rows its filter
kept, before the page. A limit picks its rows in linear time before sorting only them.
Trait Implementations§
Source§impl JsonSchema for Data
A dataset’s JSON document.
impl JsonSchema for Data
A dataset’s JSON document.
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more