Skip to content

Commit

Permalink
Add Firestore data structures and conversion functions for discussion…
Browse files Browse the repository at this point in the history
…s, resources, sessions, and speech
  • Loading branch information
TakalaWang committed Nov 25, 2024
1 parent bb0c259 commit 87e1628
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 104 deletions.
47 changes: 47 additions & 0 deletions src/lib/types/IndividualDiscussion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { Timestamp } from 'firebase-admin/firestore';

// Firestore data structure
export interface FirestoreIndividualDiscussion {
userId: string;
sessionId: string;
groupId: string;
history: {
role: 'system' | 'assistant' | 'user';
content: string;
speechId: string | null;
timestamp: Timestamp;
}[];
summary: string;
}

// Client-side data structure (serializable)
export interface IndividualDiscussion {
userId: string;
sessionId: string;
groupId: string;
history: {
role: 'system' | 'assistant' | 'user';
content: string;
speechId: string | null;
timestamp: string;
}[];
summary: string;
}

// convert Firestore data to client-side data
export function convertFirestoreIndividualDiscussion(
data: FirestoreIndividualDiscussion
): IndividualDiscussion {
return {
userId: data.userId,
sessionId: data.sessionId,
groupId: data.groupId,
history: data.history.map((history) => ({
role: history.role,
content: history.content,
speechId: history.speechId,
timestamp: history.timestamp.toDate().toISOString()
})),
summary: data.summary
};
}
51 changes: 51 additions & 0 deletions src/lib/types/groupDiscussion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { Timestamp } from 'firebase-admin/firestore';

// Firestore data structure
export interface FirestoreGroupDiscussion {
sessionId: string;
groupId: string;
history: {
name: string;
content: string;
speechId: string | null;
timestamp: Timestamp;
}[];
analysis: {
summary: string;
keywords: string[];
};
}

// Client-side data structure (serializable)
export interface GroupDiscussion {
sessionId: string;
groupId: string;
history: {
name: string;
content: string;
speechId: string | null;
timestamp: string;
}[];
analysis: {
summary: string;
keywords: string[];
};
}

// convert Firestore data to client-side data
export function convertFirestoreGroupDiscussion(data: FirestoreGroupDiscussion): GroupDiscussion {
return {
sessionId: data.sessionId,
groupId: data.groupId,
history: data.history.map((history) => ({
name: history.name,
content: history.content,
speechId: history.speechId,
timestamp: history.timestamp.toDate().toISOString()
})),
analysis: {
summary: data.analysis.summary,
keywords: data.analysis.keywords
}
};
}
24 changes: 24 additions & 0 deletions src/lib/types/resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Timestamp } from 'firebase-admin/firestore';

export interface FirestoreResource {
name: string;
fileId: string;
text: string;
addedAt: Timestamp;
}

export interface Resource {
name: string;
fileId: string;
text: string;
addedAt: string;
}

export function convertFirestoreResources(data: FirestoreResource): Resource {
return {
name: data.name,
fileId: data.fileId,
text: data.text,
addedAt: data.addedAt.toDate().toISOString()
};
}
128 changes: 24 additions & 104 deletions src/lib/types/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,17 @@ export interface FirestoreSession {
createdAt: Timestamp;
status: 'draft' | 'waiting' | 'active' | 'ended';
tempIdExpiry: Timestamp | null;
resources: {
[id: string]: {
type: 'link' | 'text' | 'file';
content: string;
addedAt: Timestamp;
};
};
goal: string;
subQuestions: string[];
resourcesIds: string[];
participants: {
[userId: string]: {
name: string;
groupId: string | null;
joinedAt: Timestamp;
};
};
stage: 'grouping' | 'individual' | 'group' | 'ended';
groups: {
[groupId: string]: {
name: string;
leaderId: string;
members: {
[userId: string]: {
name: string;
joinedAt: Timestamp;
};
};
individualDiscussions?: {
[userId: string]: {
transcript: string;
analysis: {
keyPoints: string[];
sentiment: string;
};
};
};
groupDiscussion?: {
transcript: string;
analysis: {
keyPoints: string[];
commonThemes: string[];
disagreements: string[];
};
};
};
};
}

// Client-side data structure (serializable)
Expand All @@ -65,91 +33,43 @@ export interface Session {
createdAt: string;
status: 'draft' | 'waiting' | 'active' | 'ended';
tempIdExpiry: string | null;
resources: {
[id: string]: {
type: 'link' | 'text' | 'file';
content: string;
addedAt: string;
};
};
goal: string;
subQuestions: string[];
resourcesIds: string[];
participants: {
[userId: string]: {
name: string;
groupId: string | null;
joinedAt: string;
};
};
stage: 'grouping' | 'individual' | 'group' | 'ended';
groups: {
[groupId: string]: {
name: string;
leaderId: string;
members: {
[userId: string]: {
name: string;
joinedAt: string;
};
};
individualDiscussions?: {
[userId: string]: {
transcript: string;
analysis: {
keyPoints: string[];
sentiment: string;
};
};
};
groupDiscussion?: {
transcript: string;
analysis: {
keyPoints: string[];
commonThemes: string[];
disagreements: string[];
};
};
};
};
}

// Helper function to convert Firestore data to client data
// convert Firestore data to client-side data
export function convertFirestoreSession(data: FirestoreSession): Session {
return {
...data,
id: data.id,
tempId: data.tempId,
hostId: data.hostId,
hostName: data.hostName,
title: data.title,
createdAt: data.createdAt.toDate().toISOString(),
tempIdExpiry: data.tempIdExpiry?.toDate()?.toISOString() || null,
resources: Object.fromEntries(
Object.entries(data.resources || {}).map(([key, resource]) => [
key,
{
...resource,
addedAt: resource.addedAt.toDate().toISOString()
}
])
),
status: data.status,
tempIdExpiry: data.tempIdExpiry ? data.tempIdExpiry.toDate().toISOString() : null,
goal: data.goal,
subQuestions: data.subQuestions,
resourcesIds: data.resourcesIds,
participants: Object.fromEntries(
Object.entries(data.participants || {}).map(([key, participant]) => [
key,
Object.entries(data.participants).map(([userId, participant]) => [
userId,
{
...participant,
name: participant.name,
groupId: participant.groupId,
joinedAt: participant.joinedAt.toDate().toISOString()
}
])
),
groups: Object.fromEntries(
Object.entries(data.groups || {}).map(([groupId, group]) => [
groupId,
{
...group,
members: Object.fromEntries(
Object.entries(group.members).map(([userId, member]) => [
userId,
{
...member,
joinedAt: member.joinedAt.toDate().toISOString()
}
])
)
}
])
)
stage: data.stage
};
}
5 changes: 5 additions & 0 deletions src/lib/types/speech.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface SpeechFirestore {
speechId: string;
fileid: string;
transation: string;
}

0 comments on commit 87e1628

Please sign in to comment.