Skip to content

Commit 5ce0479

Browse files
committed
add long transcript seed data
1 parent 52bc01c commit 5ce0479

File tree

5 files changed

+128
-37
lines changed

5 files changed

+128
-37
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { SeedDefinition } from "./shared";
2-
import { curatedSeed, emptySeed, randomSeed } from "./versions";
2+
import { curatedSeed, emptySeed, longSeed, randomSeed } from "./versions";
33

44
export { type SeedDefinition } from "./shared";
55

6-
export const seeds: SeedDefinition[] = [emptySeed, randomSeed, curatedSeed];
6+
export const seeds: SeedDefinition[] = [
7+
emptySeed,
8+
randomSeed,
9+
longSeed,
10+
curatedSeed,
11+
];

apps/desktop/src/components/devtool/seed/shared/builders.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {
1919
WordStorage,
2020
} from "@hypr/store";
2121

22-
import { DEFAULT_USER_ID, id } from "../../../../utils";
2322
import { createCalendar } from "./calendar";
2423
import { createChatGroup, createChatMessage } from "./chat";
2524
import { createChatShortcut } from "./chat-shortcut";
@@ -274,36 +273,19 @@ export const buildTranscriptsForSessions = (
274273
const words: Record<string, WordStorage> = {};
275274

276275
sessionIds.forEach((sessionId) => {
277-
const transcriptId = id();
278-
const createdAt = faker.date.recent({ days: 30 });
279-
const startedAt = createdAt.getTime();
280-
281-
const transcript = generateTranscript();
282-
let maxEndMs = 0;
283-
284-
transcript.words.forEach((word) => {
285-
if (word.end_ms !== undefined && word.end_ms > maxEndMs) {
286-
maxEndMs = word.end_ms;
287-
}
288-
const wordId = id();
289-
words[wordId] = {
290-
user_id: DEFAULT_USER_ID,
291-
transcript_id: transcriptId,
292-
text: word.text,
293-
start_ms: word.start_ms,
294-
end_ms: word.end_ms,
295-
channel: word.channel,
296-
created_at: faker.date.recent({ days: 30 }).toISOString(),
297-
};
276+
const result = generateTranscript({ sessionId });
277+
278+
if (!("transcript" in result)) {
279+
throw new Error("Expected transcript metadata");
280+
}
281+
282+
const { transcriptId, transcript, words: transcriptWords } = result;
283+
284+
Object.entries(transcriptWords).forEach(([wordId, word]) => {
285+
words[wordId] = word;
298286
});
299287

300-
transcripts[transcriptId] = {
301-
user_id: DEFAULT_USER_ID,
302-
session_id: sessionId,
303-
created_at: createdAt.toISOString(),
304-
started_at: startedAt,
305-
ended_at: maxEndMs > 0 ? startedAt + maxEndMs : undefined,
306-
};
288+
transcripts[transcriptId] = transcript;
307289
});
308290

309291
return { transcripts, words };

apps/desktop/src/components/devtool/seed/shared/transcript.ts

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { faker } from "@faker-js/faker";
22

3-
import type { WordStorage } from "@hypr/store";
3+
import type { Transcript, WordStorage } from "@hypr/store";
44

55
import { DEFAULT_USER_ID, id } from "../../../../utils";
66

7+
type TranscriptWithMetadata = {
8+
transcriptId: string;
9+
transcript: Transcript;
10+
words: Record<string, WordStorage>;
11+
};
12+
13+
type TranscriptWordsOnly = {
14+
words: Array<WordStorage>;
15+
};
16+
717
const selectWeighted = <T,>(choices: Array<{ weight: number; value: T }>): T =>
818
faker.helpers.weightedArrayElement(choices);
919

@@ -80,15 +90,37 @@ const generateSentence = () => {
8090
return sentenceWords;
8191
};
8292

83-
export const generateTranscript = () => {
93+
export function generateTranscript(options: {
94+
turnCount?: { min: number; max: number };
95+
days?: number;
96+
sessionId: string;
97+
}): TranscriptWithMetadata;
98+
export function generateTranscript(options?: {
99+
turnCount?: { min: number; max: number };
100+
days?: number;
101+
sessionId?: undefined;
102+
}): TranscriptWordsOnly;
103+
export function generateTranscript(options?: {
104+
turnCount?: { min: number; max: number };
105+
days?: number;
106+
sessionId?: string;
107+
}): TranscriptWithMetadata | TranscriptWordsOnly {
108+
const {
109+
turnCount: turnCountRange = { min: 200, max: 500 },
110+
days = 30,
111+
sessionId,
112+
} = options ?? {};
113+
84114
const channelCount = 2;
85-
const turnCount = faker.number.int({ min: 10, max: 20 });
115+
const turnCount = faker.number.int(turnCountRange);
86116

87117
const transcriptId = id();
88118
const words: Array<WordStorage> = [];
89119
let currentTimeMs = 0;
90120
let currentChannel = 0;
91-
const createdAt = faker.date.recent({ days: 30 }).toISOString();
121+
const createdAt = faker.date.recent({ days });
122+
const createdAtStr = createdAt.toISOString();
123+
const startedAt = createdAt.getTime();
92124

93125
for (let turnIndex = 0; turnIndex < turnCount; turnIndex++) {
94126
const sentenceCount = selectWeighted([
@@ -119,7 +151,7 @@ export const generateTranscript = () => {
119151

120152
words.push({
121153
user_id: DEFAULT_USER_ID,
122-
created_at: createdAt,
154+
created_at: createdAtStr,
123155
transcript_id: transcriptId,
124156
channel: currentChannel,
125157
text: ` ${text}`,
@@ -159,5 +191,25 @@ export const generateTranscript = () => {
159191
currentChannel = (currentChannel + 1) % channelCount;
160192
}
161193

194+
if (sessionId) {
195+
const wordsRecord: Record<string, WordStorage> = {};
196+
words.forEach((word) => {
197+
const wordId = id();
198+
wordsRecord[wordId] = word;
199+
});
200+
201+
return {
202+
transcriptId,
203+
transcript: {
204+
user_id: DEFAULT_USER_ID,
205+
session_id: sessionId,
206+
created_at: createdAtStr,
207+
started_at: startedAt,
208+
ended_at: startedAt + currentTimeMs,
209+
},
210+
words: wordsRecord,
211+
};
212+
}
213+
162214
return { words };
163-
};
215+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { curatedSeed } from "./curated";
22
export { emptySeed } from "./empty";
3+
export { longSeed } from "./long";
34
export { randomSeed } from "./random";
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { faker } from "@faker-js/faker";
2+
import type { Tables } from "tinybase/with-schemas";
3+
4+
import type { Schemas } from "../../../../store/tinybase/main";
5+
import type { Store as PersistedStore } from "../../../../store/tinybase/main";
6+
import type { SeedDefinition } from "../shared";
7+
import {
8+
createHuman,
9+
createOrganization,
10+
createSession,
11+
generateTranscript,
12+
} from "../shared";
13+
14+
faker.seed(789);
15+
16+
const LONG_DATA = (() => {
17+
const organization = createOrganization();
18+
const human = createHuman(organization.id, true);
19+
const session = createSession();
20+
21+
const result = generateTranscript({
22+
turnCount: { min: 800, max: 1200 },
23+
days: 7,
24+
sessionId: session.id,
25+
});
26+
27+
if (!("transcript" in result)) {
28+
throw new Error("Expected transcript metadata");
29+
}
30+
31+
const { transcriptId, transcript, words } = result;
32+
33+
return {
34+
organizations: { [organization.id]: organization.data },
35+
humans: { [human.id]: human.data },
36+
sessions: { [session.id]: session.data },
37+
transcripts: { [transcriptId]: transcript },
38+
words,
39+
} satisfies Tables<Schemas[0]>;
40+
})();
41+
42+
export const longSeed: SeedDefinition = {
43+
id: "long",
44+
label: "Long",
45+
run: (store: PersistedStore) => {
46+
store.transaction(() => {
47+
store.delTables();
48+
store.setTables(LONG_DATA);
49+
});
50+
},
51+
};

0 commit comments

Comments
 (0)