Skip to content

Commit 3bdb702

Browse files
cdxkerskeptrunedev
authored andcommitted
feature: refactor status to be a list of all important events
1 parent cbfe506 commit 3bdb702

9 files changed

Lines changed: 87 additions & 80 deletions

File tree

clients/trieve-shopify-extension/app/components/analytics/AdvancedTableComponent.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ export interface Filter {
2929
pinned?: boolean;
3030
}
3131

32+
// Either component or content is required
3233
export interface AdvancedTableCell {
33-
content: string;
34+
component?: React.ReactNode;
35+
content?: string;
3436
url?: string;
3537
}
3638

@@ -105,7 +107,7 @@ export const AdvancedTableComponent = ({
105107
}))}
106108
queryValue={query}
107109
cancelAction={{
108-
onAction: () => {},
110+
onAction: () => { },
109111
disabled: false,
110112
loading: false,
111113
}}
@@ -152,7 +154,7 @@ export const AdvancedTableComponent = ({
152154
{heading.sortCol && (
153155
<span className="ml-1">
154156
{sortSelected[0].split(" ")[0] ===
155-
heading.sortCol ? (
157+
heading.sortCol ? (
156158
sortSelected[0].split(" ")[1] === "asc" ? (
157159
<Icon source={ChevronUpIcon} tone="base" />
158160
) : (
@@ -188,25 +190,26 @@ export const AdvancedTableComponent = ({
188190
id={index.toString()}
189191
position={index}
190192
>
191-
{row.map((cell, innerIndex) => (
192-
<IndexTable.Cell
193-
key={innerIndex}
194-
className="max-w-[200px] truncate"
195-
>
196-
{cell.url ? (
197-
<Link to={cell.url}>
198-
<InlineStack wrap={false}>
199-
<ViewIcon width={20} />
200-
<Text as="span" variant="bodyMd" truncate={true}>
201-
{cell.content}
202-
</Text>
203-
</InlineStack>
204-
</Link>
205-
) : (
206-
cell.content
207-
)}
208-
</IndexTable.Cell>
209-
))}
193+
{row.map((cell, innerIndex) => {
194+
const innerCell = cell.component ? cell.component : <Text as="span" variant="bodyMd" truncate={true}>{cell.content}</Text>;
195+
return (
196+
<IndexTable.Cell
197+
key={innerIndex}
198+
className="max-w-[250px] truncate"
199+
>
200+
{cell.url ? (
201+
<Link to={cell.url}>
202+
<InlineStack wrap={false}>
203+
<ViewIcon width={20} />
204+
{innerCell}
205+
</InlineStack>
206+
</Link>
207+
) : (
208+
innerCell
209+
)}
210+
</IndexTable.Cell>
211+
);
212+
})}
210213
</IndexTable.Row>
211214
);
212215
})}

clients/trieve-shopify-extension/app/components/analytics/chat/ChatEventsFilter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface EventFiltersProps {
77
setEventsFilter: Dispatch<SetStateAction<TopicEventFilter>>;
88
}
99

10-
const AVAILABLE_EVENT_TYPES: { label: string; value: EventNamesFilter }[] = [
10+
export const AVAILABLE_EVENT_TYPES: { label: string; value: EventNamesFilter }[] = [
1111
{ label: "Followup Clicked", value: "site-followup_query" },
1212
{ label: "Click", value: "Click" },
1313
{ label: "Add to Cart", value: "site-add_to_cart" },

clients/trieve-shopify-extension/app/routes/app._dashboard.chats.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import {
1919
AdvancedTableComponent,
2020
Filter,
2121
} from "../components/analytics/AdvancedTableComponent";
22-
import { ChoiceList, IndexFiltersProps, RangeSlider } from "@shopify/polaris";
22+
import { Text, Badge, ChoiceList, IndexFiltersProps, RangeSlider } from "@shopify/polaris";
2323
import { DateRangePicker } from "../components/analytics/DateRangePicker";
2424
import { ComponentNameSelect } from "../components/analytics/ComponentNameSelect";
2525
import { allChatsQuery } from "app/queries/analytics/chat";
26-
import { EventFilters } from "app/components/analytics/chat/ChatEventsFilter";
26+
import { AVAILABLE_EVENT_TYPES, EventFilters } from "app/components/analytics/chat/ChatEventsFilter";
2727

2828
export default function ChatsPage() {
2929
const { trieve } = useTrieve();
@@ -69,17 +69,44 @@ export default function ChatsPage() {
6969
return previousData;
7070
}
7171

72-
console.log("getting data", data)
7372
if (!data?.topics) {
7473
return [];
7574
}
7675

7776
// TODO: Create badge with "highest ranking event"
7877
let newData: AdvancedTableCell[][] =
7978
data?.topics.map((topic) => {
79+
let event_names_counts: Record<string, number> = {
80+
"site-add_to_cart": 0,
81+
"site-checkout": 0,
82+
"Click": 0,
83+
};
84+
for (const event of topic.event_names) {
85+
if (event == "View") continue;
86+
87+
event_names_counts[event] =
88+
(event_names_counts[event] ?? 0) + 1;
89+
}
8090
return [
8191
{ content: topic.name, url: `/app/chatview/${topic.topic_id}` },
82-
{ content: topic.status },
92+
// Make a badge with count and name
93+
{
94+
component: (
95+
<div className="flex gap-2">
96+
{Object.entries(event_names_counts).map(([event_name, count]) => {
97+
const eventLabel = AVAILABLE_EVENT_TYPES.find((e) => e.value === event_name)?.label ?? event_name
98+
99+
if (count == 0) return null
100+
101+
return (
102+
<div className="flex items-center gap-1">
103+
<Badge>{`${count.toLocaleString()} ${eventLabel}(s)`}</Badge>
104+
</div>
105+
);
106+
})}
107+
</div>
108+
)
109+
},
83110
{ content: topic.message_count.toLocaleString() },
84111
{
85112
content: topic.avg_top_score?.toLocaleString("en-US", {
@@ -436,8 +463,6 @@ export default function ChatsPage() {
436463
}
437464
}, [query]);
438465

439-
console.log("I am here data", mappedData);
440-
441466
return (
442467
<AdvancedTableComponent
443468
additionalControls={

clients/trieve-shopify-extension/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
"react-dom": "^18.2.0",
5353
"tailwind-merge": "^3.1.0",
5454
"tailwindcss": "^3.4.17",
55-
"trieve-search-component": "0.4.55",
56-
"trieve-ts-sdk": "*",
57-
"vite-tsconfig-paths": "^5.0.1"
55+
"trieve-ts-sdk": "0.0.83",
56+
"vite-tsconfig-paths": "^5.0.1",
57+
"trieve-search-component": "0.4.55"
5858
},
5959
"devDependencies": {
6060
"@remix-run/eslint-config": "^2.7.1",

clients/trieve-shopify-extension/yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9352,16 +9352,16 @@ trieve-search-component@0.4.55:
93529352
tailwind-merge "^3.0.2"
93539353
trieve-ts-sdk "0.0.73"
93549354

9355-
trieve-ts-sdk@*:
9356-
version "0.0.83"
9357-
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.83.tgz#a9bd0bbd71e09f3f9017844d91894fde95c5edb9"
9358-
integrity sha512-EPDy342dDTNVmzzALMtk9JExCn5yt1oyp9moiS4VLyN52hFaKY4MxoSsEp9/Bp7PRNXS2Z8u1H+PTn+joovhbw==
9359-
93609355
trieve-ts-sdk@0.0.73:
93619356
version "0.0.73"
93629357
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.73.tgz#9de17428ddb4b1f6d68709695f371d185c4bda79"
93639358
integrity sha512-68iG/OlmKSGmnmI/J33S6VKleEAfq4txzARhvKv1g+CYSaG7HOH76n0cFDMtUUEEKn1PD4nV82uh5ZFtfIxD0A==
93649359

9360+
trieve-ts-sdk@0.0.83:
9361+
version "0.0.83"
9362+
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.83.tgz#a9bd0bbd71e09f3f9017844d91894fde95c5edb9"
9363+
integrity sha512-EPDy342dDTNVmzzALMtk9JExCn5yt1oyp9moiS4VLyN52hFaKY4MxoSsEp9/Bp7PRNXS2Z8u1H+PTn+joovhbw==
9364+
93659365
trim-lines@^3.0.0:
93669366
version "3.0.1"
93679367
resolved "https://registry.yarnpkg.com/trim-lines/-/trim-lines-3.0.1.tgz#d802e332a07df861c48802c04321017b1bd87338"

clients/ts-sdk/openapi.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9093,7 +9093,7 @@
90939093
"message_count",
90949094
"avg_top_score",
90959095
"avg_hallucination_score",
9096-
"status"
9096+
"event_names"
90979097
],
90989098
"properties": {
90999099
"avg_hallucination_score": {
@@ -9112,6 +9112,13 @@
91129112
"created_at": {
91139113
"type": "string"
91149114
},
9115+
"event_names": {
9116+
"type": "array",
9117+
"items": {
9118+
"type": "string"
9119+
},
9120+
"description": "All event_names that are associated with the topic, may contain duplicate names"
9121+
},
91159122
"id": {
91169123
"type": "string",
91179124
"format": "uuid"
@@ -9127,9 +9134,6 @@
91279134
"owner_id": {
91289135
"type": "string"
91299136
},
9130-
"status": {
9131-
"type": "string"
9132-
},
91339137
"topic_id": {
91349138
"type": "string",
91359139
"format": "uuid"

clients/ts-sdk/src/types.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,14 @@ export type ClickhouseTopicAnalyticsSummary = {
557557
avg_query_rating?: (number) | null;
558558
avg_top_score: number;
559559
created_at: string;
560+
/**
561+
* All event_names that are associated with the topic, may contain duplicate names
562+
*/
563+
event_names: Array<(string)>;
560564
id: string;
561565
message_count: number;
562566
name: string;
563567
owner_id: string;
564-
status: string;
565568
topic_id: string;
566569
updated_at: string;
567570
};

server/src/data/models.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8125,7 +8125,8 @@ pub struct TopicAnalyticsSummaryClickhouse {
81258125
pub avg_top_score: f64,
81268126
pub avg_hallucination_score: f64,
81278127
pub avg_query_rating: Option<f64>,
8128-
pub status: String,
8128+
/// All event_names that are associated with the topic, may contain duplicate names
8129+
pub event_names: Vec<String>,
81298130
}
81308131

81318132
#[derive(Debug, Serialize, Deserialize, ToSchema)]
@@ -8140,7 +8141,8 @@ pub struct ClickhouseTopicAnalyticsSummary {
81408141
pub avg_top_score: f64,
81418142
pub avg_hallucination_score: f64,
81428143
pub avg_query_rating: Option<f64>,
8143-
pub status: String,
8144+
/// All event_names that are associated with the topic, may contain duplicate names
8145+
pub event_names: Vec<String>,
81448146
}
81458147

81468148
impl From<TopicAnalyticsSummaryClickhouse> for ClickhouseTopicAnalyticsSummary {
@@ -8156,7 +8158,7 @@ impl From<TopicAnalyticsSummaryClickhouse> for ClickhouseTopicAnalyticsSummary {
81568158
avg_top_score: value.avg_top_score,
81578159
avg_hallucination_score: value.avg_hallucination_score,
81588160
avg_query_rating: value.avg_query_rating,
8159-
status: value.status,
8161+
event_names: value.event_names,
81608162
}
81618163
}
81628164
}

server/src/operators/analytics_operator.rs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{
44
ChatRevenueResponse, ClusterAnalyticsFilter, ClusterTopicsClickhouse,
55
ComponentAnalyticsFilter, ComponentInteractionTimeResponse, ComponentNamesResponse,
66
DatasetAnalytics, EventAnalyticsFilter, EventData, EventDataClickhouse, EventNameAndCounts,
7-
EventNamesFilter, FloatTimePoint, FloatTimePointClickhouse, FollowupQueriesResponse,
8-
FollowupQuery, GetEventsResponseBody, Granularity, HeadQueries, IntegerTimePoint,
7+
FloatTimePoint, FloatTimePointClickhouse, FollowupQueriesResponse, FollowupQuery,
8+
GetEventsResponseBody, Granularity, HeadQueries, IntegerTimePoint,
99
IntegerTimePointClickhouse, MessagesPerUserResponse, Pool, PopularChat,
1010
PopularChatsResponse, PopularFilters, PopularFiltersClickhouse, RAGAnalyticsFilter,
1111
RAGSortBy, RAGUsageGraphResponse, RAGUsageResponse, RagQueryEvent, RagQueryEventClickhouse,
@@ -1858,9 +1858,10 @@ pub async fn get_topic_queries_query(
18581858
AVG(rag_queries.top_score) as top_score,
18591859
AVG(rag_queries.hallucination_score) as hallucination_score,
18601860
AVG(JSONExtract(query_rating, 'rating', 'Nullable(Float64)')) as query_rating,
1861-
'View' as status
1861+
groupArray(topic_events.event_name) as event_names
18621862
FROM topics
18631863
JOIN rag_queries ON topics.topic_id = rag_queries.topic_id
1864+
JOIN events as topic_events ON rag_queries.id = toUUID(topic_events.request_id)
18641865
",
18651866
);
18661867

@@ -1924,7 +1925,7 @@ pub async fn get_topic_queries_query(
19241925
(page.unwrap_or(1) - 1) * 10
19251926
));
19261927

1927-
let mut topics = clickhouse_client
1928+
let topics = clickhouse_client
19281929
.query(query_string.as_str())
19291930
.bind(dataset_id)
19301931
.fetch_all::<TopicAnalyticsSummaryClickhouse>()
@@ -1934,37 +1935,6 @@ pub async fn get_topic_queries_query(
19341935
ServiceError::InternalServerError("Error fetching topics".to_string())
19351936
})?;
19361937

1937-
let topic_ids: Vec<uuid::Uuid> = topics.iter().map(|topic| topic.topic_id).collect();
1938-
1939-
let topic_events: Vec<TopicIdEventTypePair> = clickhouse_client
1940-
.query(
1941-
"SELECT rag_queries.topic_id as topic_id, events.event_name as event_name
1942-
FROM events
1943-
JOIN rag_queries ON rag_queries.id = toUUIDOrNull(events.request_id)
1944-
WHERE rag_queries.dataset_id = ? AND rag_queries.topic_id in ?",
1945-
)
1946-
.bind(dataset_id)
1947-
.bind(topic_ids)
1948-
.fetch_all::<TopicIdEventTypePair>()
1949-
.await
1950-
.map_err(|e| {
1951-
log::error!("Error fetching query: {:?}", e);
1952-
ServiceError::InternalServerError("Error fetching query".to_string())
1953-
})?;
1954-
1955-
for topic_pair in topic_events {
1956-
if let Some(topic) = topics
1957-
.iter_mut()
1958-
.find(|t| t.topic_id == topic_pair.topic_id)
1959-
{
1960-
let current_status = EventNamesFilter::from_string(&topic.status);
1961-
let topic_status = EventNamesFilter::from_string(&topic_pair.event_name);
1962-
1963-
if topic_status > current_status {
1964-
topic.status = topic_pair.event_name.clone();
1965-
}
1966-
}
1967-
}
19681938
Ok(TopicQueriesResponse {
19691939
topics: topics.into_iter().map(|t| t.into()).collect(),
19701940
})

0 commit comments

Comments
 (0)