Skip to content

Commit

Permalink
new snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Oct 22, 2024
1 parent a86ff18 commit 39df0a0
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
6 changes: 3 additions & 3 deletions docs/snippets/all/reference/dataframe_query.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Query and display the first 10 rows of a recording.

#![allow(clippy::unwrap_used)]

use rerun::{
dataframe::{QueryCache, QueryEngine, QueryExpression, SparseFillStrategy, Timeline},
ChunkStore, ChunkStoreConfig, VersionPolicy,
Expand All @@ -18,7 +16,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
path_to_rrd,
VersionPolicy::Warn,
)?;
let (_, store) = stores.first_key_value().unwrap();
let Some((_, store)) = stores.first_key_value() else {
return Ok(());
};

let query_cache = QueryCache::new(store);
let query_engine = QueryEngine {
Expand Down
17 changes: 17 additions & 0 deletions docs/snippets/all/reference/dataframe_save_blueprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Craft a blueprint with the python API and save it to a file for future use."""

import sys

import rerun.blueprint as rrb

path_to_rbl = sys.argv[1]

rrb.Blueprint(
rrb.DataframeView(
origin="/",
query=rrb.archetypes.DataframeQuery(
timeline="log_time",
apply_latest_at=True,
),
),
).save("rerun_example_dataframe_view_query", path_to_rbl)
24 changes: 24 additions & 0 deletions docs/snippets/all/reference/dataframe_view_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Query and display the first 10 rows of a recording in a dataframe view."""

import sys

import rerun as rr
import rerun.blueprint as rrb

path_to_rrd = sys.argv[1]

rr.init("rerun_example_dataframe_view_query", spawn=True)

rr.log_file_from_path(path_to_rrd)

blueprint = rrb.Blueprint(
rrb.DataframeView(
origin="/",
query=rrb.archetypes.DataframeQuery(
timeline="log_time",
apply_latest_at=True,
),
),
)

rr.send_blueprint(blueprint)
27 changes: 27 additions & 0 deletions docs/snippets/all/reference/dataframe_view_query_external.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Query and display the first 10 rows of a recording in a dataframe view.
//!
//! The blueprint is being loaded from an existing blueprint recording file.

// ./dataframe_view_query_external /tmp/dna.rrd /tmp/dna.rbl

#include <string>

#include <rerun.hpp>

int main(int argc, char** argv) {
if (argc < 3) {
return 1;
}

std::string path_to_rrd = argv[1];
std::string path_to_rbl = argv[2];

const auto rec = rerun::RecordingStream("rerun_example_dataframe_view_query_external");
rec.spawn().exit_on_failure();

// Log the files
rec.log_file_from_path(path_to_rrd);
rec.log_file_from_path(path_to_rbl);

return 0;
}
19 changes: 19 additions & 0 deletions docs/snippets/all/reference/dataframe_view_query_external.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Query and display the first 10 rows of a recording in a dataframe view.
The blueprint is being loaded from an existing blueprint recording file.
"""

# python dataframe_view_query_external.py /tmp/dna.rrd /tmp/dna.rbl

import sys

import rerun as rr

path_to_rrd = sys.argv[1]
path_to_rbl = sys.argv[2]

rr.init("rerun_example_dataframe_view_query_external", spawn=True)

rr.log_file_from_path(path_to_rrd)
rr.log_file_from_path(path_to_rbl)
20 changes: 20 additions & 0 deletions docs/snippets/all/reference/dataframe_view_query_external.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Query and display the first 10 rows of a recording in a dataframe view.
//!
//! The blueprint is being loaded from an existing blueprint recording file.

// cargo r -p snippets -- dataframe_view_query_external /tmp/dna.rrd /tmp/dna.rbl

fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = std::env::args().collect::<Vec<_>>();

let path_to_rrd = &args[1];
let path_to_rbl = &args[2];

let rec = rerun::RecordingStreamBuilder::new("rerun_example_dataframe_view_query_external")
.spawn()?;

rec.log_file_from_path(path_to_rrd, None /* prefix */, false /* static */)?;
rec.log_file_from_path(path_to_rbl, None /* prefix */, false /* static */)?;

Ok(())
}
17 changes: 16 additions & 1 deletion docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,22 @@ views = [
"rust",
"py",
]
"reference/dataframe_query" = [ # Requires RRD files, which are unstable
"reference/dataframe_query" = [ # No output
"cpp",
"rust",
"py",
]
"reference/dataframe_save_blueprint" = [ # No output
"cpp",
"rust",
"py",
]
"reference/dataframe_view_query" = [ # No output
"cpp",
"rust",
"py",
]
"reference/dataframe_view_query_external" = [ # No output
"cpp",
"rust",
"py",
Expand Down

0 comments on commit 39df0a0

Please sign in to comment.