@@ -1181,6 +1181,175 @@ analytics.get("/agents/top", async (ctx: Context) => {
1181
1181
ctx . body = { data } ;
1182
1182
} ) ;
1183
1183
1184
+ analytics . get ( "/feedback/thumb/up" , async ( ctx : Context ) => {
1185
+ const { projectId } = ctx . state ;
1186
+ const { datesQuery, filteredRunsQuery, granularity } = parseQuery (
1187
+ projectId ,
1188
+ ctx . querystring ,
1189
+ ctx . query ,
1190
+ ) ;
1191
+
1192
+ if ( granularity === "weekly" ) {
1193
+ const res = await sql `
1194
+ with dates as (
1195
+ ${ datesQuery }
1196
+ ),
1197
+ filtered_runs as (
1198
+ ${ filteredRunsQuery }
1199
+ ),
1200
+ feedback_data as (
1201
+ select
1202
+ r.local_created_at,
1203
+ case when r.feedback->>'thumb' = 'up' then 1 else 0 end as thumbs_up,
1204
+ from
1205
+ filtered_runs r
1206
+ where
1207
+ r.feedback->>'thumb' is not null
1208
+ ),
1209
+ weekly_avg as (
1210
+ select
1211
+ d.date,
1212
+ case when fd.local_created_at is not null then fd.local_created_at else d.date end as local_created_at,
1213
+ coalesce(sum(fd.thumbs_up), 0) as total_thumbs_up
1214
+ from
1215
+ dates d
1216
+ left join feedback_data fd on fd.local_created_at >= d.date and fd.local_created_at < d.date + interval '7 days'
1217
+ group by
1218
+ d.date,
1219
+ case when fd.local_created_at is not null then fd.local_created_at else d.date end
1220
+ order by d.date
1221
+ )
1222
+ select
1223
+ date,
1224
+ coalesce(total_thumbs_up, 0) as value,
1225
+ 'Thumbs Up' as name
1226
+ from
1227
+ weekly_avg
1228
+ order by
1229
+ date;
1230
+ ` ;
1231
+ ctx . body = { data : res } ;
1232
+ return ;
1233
+ } else {
1234
+ const res = await sql `
1235
+ with dates as (
1236
+ ${ datesQuery }
1237
+ ),
1238
+ filtered_runs as (
1239
+ ${ filteredRunsQuery }
1240
+ ),
1241
+ feedback_data as (
1242
+ select
1243
+ r.local_created_at as date,
1244
+ case when r.feedback->>'thumb' = 'up' then 1 else 0 end as thumbs_up
1245
+ from
1246
+ filtered_runs r
1247
+ where
1248
+ feedback is not null
1249
+ )
1250
+ select
1251
+ date,
1252
+ total_thumbs_up as value,
1253
+ 'Thumbs Up' as name from
1254
+ (select d.date, coalesce(sum(fd.thumbs_up), 0)::int as total_thumbs_up
1255
+ from
1256
+ dates d
1257
+ left join feedback_data fd on d.date = fd.date
1258
+ group by
1259
+ d.date
1260
+ order by
1261
+ d.date ) r;
1262
+ ` ;
1263
+ console . log ( res ) ;
1264
+ ctx . body = { data : res } ;
1265
+ return ;
1266
+ }
1267
+ } ) ;
1268
+
1269
+ analytics . get ( "/feedback/thumb/down" , async ( ctx : Context ) => {
1270
+ const { projectId } = ctx . state ;
1271
+ const { datesQuery, filteredRunsQuery, granularity } = parseQuery (
1272
+ projectId ,
1273
+ ctx . querystring ,
1274
+ ctx . query ,
1275
+ ) ;
1276
+
1277
+ if ( granularity === "weekly" ) {
1278
+ const res = await sql `
1279
+ with dates as (
1280
+ ${ datesQuery }
1281
+ ),
1282
+ filtered_runs as (
1283
+ ${ filteredRunsQuery }
1284
+ ),
1285
+ feedback_data as (
1286
+ select
1287
+ r.local_created_at,
1288
+ case when r.feedback->>'down' = 'up' then 1 else 0 end as thumbs_down,
1289
+ from
1290
+ filtered_runs r
1291
+ where
1292
+ r.feedback->>'down' is not null
1293
+ ),
1294
+ weekly_avg as (
1295
+ select
1296
+ d.date,
1297
+ case when fd.local_created_at is not null then fd.local_created_at else d.date end as local_created_at,
1298
+ coalesce(sum(fd.thumbs_down), 0) as total_thumbs_down
1299
+ from
1300
+ dates d
1301
+ left join feedback_data fd on fd.local_created_at >= d.date and fd.local_created_at < d.date + interval '7 days'
1302
+ group by
1303
+ d.date,
1304
+ case when fd.local_created_at is not null then fd.local_created_at else d.date end
1305
+ order by d.date
1306
+ )
1307
+ select
1308
+ date,
1309
+ coalesce(total_thumbs_down, 0) as value,
1310
+ 'Thumbs Up' as name
1311
+ from
1312
+ weekly_avg
1313
+ order by
1314
+ date;
1315
+ ` ;
1316
+ ctx . body = { data : res } ;
1317
+ return ;
1318
+ } else {
1319
+ const res = await sql `
1320
+ with dates as (
1321
+ ${ datesQuery }
1322
+ ),
1323
+ filtered_runs as (
1324
+ ${ filteredRunsQuery }
1325
+ ),
1326
+ feedback_data as (
1327
+ select
1328
+ r.local_created_at as date,
1329
+ case when r.feedback->>'thumb' = 'down' then 1 else 0 end as thumbs_down
1330
+ from
1331
+ filtered_runs r
1332
+ where
1333
+ feedback is not null
1334
+ )
1335
+ select
1336
+ date,
1337
+ total_thumbs_down as value,
1338
+ 'Thumbs Down' as name from
1339
+ (select d.date, coalesce(sum(fd.thumbs_down), 0)::int as total_thumbs_down
1340
+ from
1341
+ dates d
1342
+ left join feedback_data fd on d.date = fd.date
1343
+ group by
1344
+ d.date
1345
+ order by
1346
+ d.date ) r;
1347
+ ` ;
1348
+ ctx . body = { data : res } ;
1349
+ return ;
1350
+ }
1351
+ } ) ;
1352
+
1184
1353
analytics . get ( "/feedback-ratio" , async ( ctx : Context ) => {
1185
1354
const { projectId } = ctx . state ;
1186
1355
const { datesQuery, filteredRunsQuery, granularity } = parseQuery (
0 commit comments