Human Signals Service¶
Human signals processing, signal flattening, and metrics aggregation.
Functions¶
safe_literal_eval(s)
¶
Safely evaluate a Python literal string.
Source code in backend/app/services/human_signals_service.py
safe_json_or_literal(s)
¶
Try JSON first, fall back to Python literal eval.
Source code in backend/app/services/human_signals_service.py
extract_case_label(content)
¶
Extract a short label from the first conversation message.
Looks for a New ... case: <label> pattern first, then falls back
to the first non-empty line of text (truncated to 80 chars).
Source code in backend/app/services/human_signals_service.py
detect_signals_format(df)
¶
Detect if DataFrame has the required signals format (metric_name, dataset_id, signals).
Source code in backend/app/services/human_signals_service.py
detect_source_fields(df)
¶
Detect if data has source fields (source_name, source_component, environment).
build_metric_schema(df)
¶
Auto-discover metric schema from data.
For each unique metric_name, inspects signals JSON across all rows to discover: - Signal keys and their types (boolean, string, number, array) - Unique values for string signals (for filter options and chart labels) - metric_category (classification vs score)
Source code in backend/app/services/human_signals_service.py
aggregate_cases(df)
¶
Generic per-case aggregation.
Groups by dataset_id, extracts shared columns (source_name, source_component, environment, timestamp, conversation, message_count), then for each metric row flattens all signals as {metric_name}__{signal_key}.
Source code in backend/app/services/human_signals_service.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |