File size: 2,884 Bytes
2cbfbf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59b5c7b
2cbfbf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * String formatting utilities for path construction
 * Consolidates repeated padding and path building logic
 */

import { PADDING } from "./constants";

/**
 * Pad number to specified length with leading zeros
 *
 * @param num - Number to pad
 * @param length - Desired string length
 * @returns Zero-padded string
 */
export function padNumber(num: number, length: number): string {
  return num.toString().padStart(length, "0");
}

/**
 * Format episode chunk index with standard padding
 *
 * @param chunkIndex - Chunk index number
 * @returns Padded chunk index string (e.g., "001")
 */
export function formatEpisodeChunk(chunkIndex: number): string {
  return padNumber(chunkIndex, PADDING.EPISODE_CHUNK);
}

/**
 * Format episode index with standard padding
 *
 * @param episodeIndex - Episode index number
 * @returns Padded episode index string (e.g., "000042")
 */
export function formatEpisodeIndex(episodeIndex: number): string {
  return padNumber(episodeIndex, PADDING.EPISODE_INDEX);
}

/**
 * Format file index with standard padding
 *
 * @param fileIndex - File index number
 * @returns Padded file index string (e.g., "001")
 */
export function formatFileIndex(fileIndex: number): string {
  return padNumber(fileIndex, PADDING.FILE_INDEX);
}

/**
 * Format chunk index with standard padding
 *
 * @param chunkIndex - Chunk index number
 * @returns Padded chunk index string (e.g., "001")
 */
export function formatChunkIndex(chunkIndex: number): string {
  return padNumber(chunkIndex, PADDING.CHUNK_INDEX);
}

/**
 * Build video path for v3 datasets
 *
 * @param videoKey - Video key/name (e.g., "observation.image")
 * @param chunkIndex - Data chunk index
 * @param fileIndex - File index within chunk
 * @returns Formatted video path (e.g., "videos/observation.image/chunk-001/file-000.mp4")
 */
export function buildV3VideoPath(
  videoKey: string,
  chunkIndex: number,
  fileIndex: number,
): string {
  return `videos/${videoKey}/chunk-${formatChunkIndex(chunkIndex)}/file-${formatFileIndex(fileIndex)}.mp4`;
}

/**
 * Build data path for v3 datasets
 *
 * @param chunkIndex - Data chunk index
 * @param fileIndex - File index within chunk
 * @returns Formatted data path (e.g., "data/chunk-001/file-000.parquet")
 */
export function buildV3DataPath(chunkIndex: number, fileIndex: number): string {
  return `data/chunk-${formatChunkIndex(chunkIndex)}/file-${formatFileIndex(fileIndex)}.parquet`;
}

/**
 * Build episodes metadata path for v3 datasets
 *
 * @param chunkIndex - Episode chunk index
 * @param fileIndex - File index within chunk
 * @returns Formatted episodes metadata path (e.g., "meta/episodes/chunk-001/file-000.parquet")
 */
export function buildV3EpisodesMetadataPath(
  chunkIndex: number,
  fileIndex: number,
): string {
  return `meta/episodes/chunk-${formatChunkIndex(chunkIndex)}/file-${formatFileIndex(fileIndex)}.parquet`;
}