File size: 4,844 Bytes
80bfc09 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | import { Fetcher, apiRequest } from "./apiClient";
import { ImageFeatures } from "./checkpointsApi";
export interface EpisodeSummary {
episode_index: number;
length: number;
duration_s: number | null;
tasks: string[];
}
export interface EpisodeListResponse {
success: boolean;
message?: string;
repo_id: string;
fps: number | null;
robot_type: string | null;
total_episodes: number;
total_frames: number | null;
image_features: ImageFeatures;
episodes: EpisodeSummary[];
}
export interface EpisodeCamera {
name: string;
/**
* Where this episode starts inside the camera's mp4. Several episodes share
* one file, so this is almost never 0 — and each camera carries its own
* offset, which is why syncing secondaries means mapping through this value
* rather than copying the driver's currentTime.
*/
from_timestamp: number | null;
to_timestamp: number | null;
chunk: number;
file_index: number;
}
export interface EpisodeDetail {
success: boolean;
message?: string;
repo_id: string;
episode_index: number;
length: number;
duration_s: number | null;
tasks: string[];
fps: number | null;
robot_type: string | null;
cameras: EpisodeCamera[];
prev_episode: number | null;
next_episode: number | null;
total_episodes: number;
}
export interface MotionResponse {
success: boolean;
message?: string;
episode_index: number;
/** One aggregate value per frame: the sum of absolute joint deltas. */
motion: number[];
max_motion: number;
}
export interface Thumbnail {
frame_index: number;
data_uri: string;
}
export interface ThumbnailsResponse {
success: boolean;
message?: string;
episode_index: number;
camera: string;
thumbnails: Thumbnail[];
}
export async function listEpisodes(
baseUrl: string,
fetcher: Fetcher,
repoId: string,
signal?: AbortSignal,
): Promise<EpisodeListResponse> {
const qs = new URLSearchParams({ repo_id: repoId });
return apiRequest<EpisodeListResponse>(baseUrl, fetcher, `/dataset-episodes?${qs}`, {
signal,
action: "List episodes",
});
}
export async function getEpisode(
baseUrl: string,
fetcher: Fetcher,
repoId: string,
episodeIndex: number,
signal?: AbortSignal,
): Promise<EpisodeDetail> {
const qs = new URLSearchParams({
repo_id: repoId,
episode_index: String(episodeIndex),
});
return apiRequest<EpisodeDetail>(baseUrl, fetcher, `/dataset-episode?${qs}`, {
signal,
action: "Load episode",
});
}
export async function getMotion(
baseUrl: string,
fetcher: Fetcher,
repoId: string,
episodeIndex: number,
signal?: AbortSignal,
): Promise<MotionResponse> {
const qs = new URLSearchParams({
repo_id: repoId,
episode_index: String(episodeIndex),
});
return apiRequest<MotionResponse>(baseUrl, fetcher, `/dataset-motion?${qs}`, {
signal,
action: "Load motion trace",
});
}
export async function getThumbnails(
baseUrl: string,
fetcher: Fetcher,
repoId: string,
episodeIndex: number,
camera: string,
count: number,
signal?: AbortSignal,
): Promise<ThumbnailsResponse> {
const qs = new URLSearchParams({
repo_id: repoId,
episode_index: String(episodeIndex),
camera,
count: String(count),
});
return apiRequest<ThumbnailsResponse>(baseUrl, fetcher, `/dataset-thumbnails?${qs}`, {
signal,
action: "Load thumbnails",
});
}
/**
* URL for one camera's mp4. Goes straight into <video src>, so it can't ride
* apiRequest — the browser fetches it itself and does its own Range seeking.
*
* Addressed by chunk/file, not by episode: episodes share a file, so this URL
* stays identical as you page between them and the element never reloads.
*/
export function videoUrl(
baseUrl: string,
repoId: string,
camera: string,
chunk: number,
fileIndex: number,
): string {
const qs = new URLSearchParams({
repo_id: repoId,
camera,
chunk: String(chunk),
file: String(fileIndex),
});
return `${baseUrl}/dataset-video?${qs}`;
}
/** URL for a single decoded frame as a PNG. Goes into <video poster> (or <img src>). */
export function frameUrl(
baseUrl: string,
repoId: string,
episodeIndex: number,
camera: string,
frameIndex: number,
maxWidth?: number,
): string {
const qs = new URLSearchParams({
repo_id: repoId,
episode_index: String(episodeIndex),
camera,
frame_index: String(frameIndex),
});
if (maxWidth) qs.set("max_width", String(maxWidth));
return `${baseUrl}/dataset-frame?${qs}`;
}
export function formatDuration(seconds: number | null | undefined): string {
if (seconds === null || seconds === undefined) return "—";
if (seconds < 60) return `${seconds.toFixed(1)}s`;
const m = Math.floor(seconds / 60);
const s = Math.round(seconds % 60);
return `${m}m ${String(s).padStart(2, "0")}s`;
}
|