Skip to content

Commit

Permalink
Low-level recording creation instead of using re_sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Oct 12, 2023
1 parent c693673 commit c080994
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/re_data_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ re_smart_channel.workspace = true
re_tracing.workspace = true
re_types.workspace = true

anyhow.workspace = true
document-features.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
Expand Down
27 changes: 25 additions & 2 deletions crates/re_data_store/src/store_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use re_arrow_store::{DataStoreConfig, GarbageCollectionOptions};
use re_log_types::{
ApplicationId, ArrowMsg, ComponentPath, DataCell, DataRow, DataTable, EntityPath,
EntityPathHash, EntityPathOpMsg, LogMsg, PathOp, RowId, SetStoreInfo, StoreId, StoreInfo,
StoreKind, TimePoint, Timeline,
StoreKind, TableId, TimePoint, Timeline,
};
use re_types::{components::InstanceKey, Loggable as _};

Expand Down Expand Up @@ -225,7 +225,7 @@ impl EntityDb {

// ----------------------------------------------------------------------------

/// A in-memory database built from a stream of [`LogMsg`]es.
/// An in-memory database built from a stream of [`LogMsg`]es.
pub struct StoreDb {
/// The [`StoreId`] for this log.
store_id: StoreId,
Expand Down Expand Up @@ -254,6 +254,29 @@ impl StoreDb {
}
}

/// Helper function to create a recording from a [`StoreInfo`] and a some [`DataRow`]s.
///
/// This is useful to programmatically create recordings from within the viewer, which cannot
/// use the `re_sdk`, which is not Wasm-compatible.
pub fn from_info_and_rows(
store_info: StoreInfo,
rows: impl IntoIterator<Item = DataRow>,
) -> anyhow::Result<Self> {
let arrow_msg = DataTable::from_rows(TableId::random(), rows).to_arrow_msg()?;
let store_id = store_info.store_id.clone();
let mut store_db = StoreDb::new(store_id.clone());
store_db.add(
&SetStoreInfo {
row_id: RowId::random(),
info: store_info,
}
.into(),
)?;
store_db.add(&LogMsg::ArrowMsg(store_id, arrow_msg))?;

Ok(store_db)
}

pub fn recording_msg(&self) -> Option<&SetStoreInfo> {
self.recording_msg.as_ref()
}
Expand Down
4 changes: 4 additions & 0 deletions crates/re_log_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ pub enum StoreSource {
file_source: FileSource,
},

/// In-app guides.
InAppGuides,

/// Perhaps from some manual data ingestion?
Other(String),
}
Expand All @@ -365,6 +368,7 @@ impl std::fmt::Display for StoreSource {
FileSource::DragAndDrop => write!(f, "File via drag-and-drop"),
FileSource::FileDialog => write!(f, "File via file dialog"),
},
Self::InAppGuides => write!(f, "In-app guide"),
Self::Other(string) => format!("{string:?}").fmt(f), // put it in quotes
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ re_log_types.workspace = true
re_log.workspace = true
re_memory.workspace = true
re_renderer = { workspace = true, default-features = false }
re_sdk.workspace = true
re_smart_channel.workspace = true
re_space_view_bar_chart.workspace = true
re_space_view_spatial.workspace = true
Expand Down
9 changes: 4 additions & 5 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,10 @@ impl App {
}
}

SystemCommand::LoadLogMessage(mut log_messages) => {
for log_msg in log_messages.drain(..) {
let store_db = store_hub.store_db_mut(log_msg.store_id());
store_db.add(&log_msg).unwrap();
}
SystemCommand::LoadStoreDb(store_db) => {
let store_id = store_db.store_id().clone();
store_hub.insert_recording(store_db);
store_hub.set_recording_id(store_id);
}

SystemCommand::ResetViewer => self.reset(store_hub, egui_ctx),
Expand Down
5 changes: 4 additions & 1 deletion crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ impl AppEnvironment {
llvm_version: llvm_version.clone(),
},

StoreSource::File { .. } | StoreSource::Unknown | StoreSource::Other(_) => {
StoreSource::File { .. }
| StoreSource::Unknown
| StoreSource::InAppGuides
| StoreSource::Other(_) => {
// We should not really get here

#[cfg(debug_assertions)]
Expand Down
8 changes: 8 additions & 0 deletions crates/re_viewer/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ impl StoreHub {
}
}

/// Insert a new recording into the [`StoreHub`].
///
/// Note that the recording is not automatically made active. Use [`StoreHub::set_recording_id`]
/// if needed.
pub fn insert_recording(&mut self, store_db: StoreDb) {
self.store_dbs.insert_recording(store_db);
}

/// Mutable access to a [`StoreDb`] by id
pub fn store_db_mut(&mut self, store_id: &StoreId) -> &mut StoreDb {
self.store_dbs.store_db_entry(store_id)
Expand Down
40 changes: 27 additions & 13 deletions crates/re_viewer/src/ui/welcome_screen/python_quick_start.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use re_data_store::StoreDb;
use re_log_types::{
ApplicationId, DataRow, EntityPath, RowId, StoreId, StoreInfo, StoreKind, StoreSource, Time,
TimePoint,
};
use re_viewer_context::{SystemCommand, SystemCommandSender};

pub(super) fn python_quick_start(
command_sender: &re_viewer_context::CommandSender,
) -> re_sdk::RecordingStreamResult<()> {
let (rec, storage) = re_sdk::RecordingStreamBuilder::new("Python Getting Started").memory()?;

rec.log(
"markdown",
&re_sdk::TextDocument::new(
) -> anyhow::Result<()> {
let text_doc =
re_types::archetypes::TextDocument::new(
r#"
## Python Quick Start
Expand Down Expand Up @@ -75,15 +77,27 @@ TBC
"#
.trim(),
)
.with_media_type(re_sdk::MediaType::markdown()),
.with_media_type(re_types::components::MediaType::markdown());

let row = DataRow::from_archetype(
RowId::random(),
TimePoint::timeless(),
EntityPath::from("quick_start"),
&text_doc,
)?;

let log_msgs = storage.take();
let store_id = rec.store_info().map(|info| info.store_id.clone());
command_sender.send_system(SystemCommand::LoadLogMessage(log_msgs));
if let Some(store_id) = store_id {
command_sender.send_system(SystemCommand::SetRecordingId(store_id));
}
let store_info = StoreInfo {
application_id: ApplicationId::from("Python Quick Start"),
store_id: StoreId::random(StoreKind::Recording),
is_official_example: true,
started: Time::now(),
store_source: StoreSource::InAppGuides,
store_kind: StoreKind::Recording,
};

let store_db = StoreDb::from_info_and_rows(store_info, [row])?;

command_sender.send_system(SystemCommand::LoadStoreDb(store_db));

Ok(())
}
3 changes: 2 additions & 1 deletion crates/re_viewer/src/viewer_analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl ViewerAnalytics {
re_log_types::FileSource::DragAndDrop => "file_drag_and_drop".to_owned(),
re_log_types::FileSource::FileDialog => "file_dialog".to_owned(),
},
StoreSource::InAppGuides => "in_app_guides".to_owned(),
StoreSource::Other(other) => other.clone(),
};

Expand Down Expand Up @@ -210,7 +211,7 @@ impl ViewerAnalytics {
self.deregister("llvm_version"); // can't be both!
}
StoreSource::CSdk => {} // TODO(andreas): Send version and set it.
StoreSource::Unknown | StoreSource::Other(_) => {}
StoreSource::Unknown | StoreSource::InAppGuides | StoreSource::Other(_) => {}
}

self.register("store_source", store_source);
Expand Down
5 changes: 3 additions & 2 deletions crates/re_viewer_context/src/command_sender.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use re_data_source::DataSource;
use re_log_types::{DataRow, LogMsg, StoreId};
use re_data_store::StoreDb;
use re_log_types::{DataRow, StoreId};
use re_ui::{UICommand, UICommandSender};

// ----------------------------------------------------------------------------
Expand All @@ -11,7 +12,7 @@ pub enum SystemCommand {
LoadDataSource(DataSource),

/// Load some log messages.
LoadLogMessage(Vec<LogMsg>),
LoadStoreDb(StoreDb),

/// Reset the `Viewer` to the default state
ResetViewer,
Expand Down

0 comments on commit c080994

Please sign in to comment.