goatfahad commited on
Commit
fc0cb89
·
verified ·
1 Parent(s): fa4fde3

Upload dbt\models\marts\m_corpus_summary.sql with huggingface_hub

Browse files
dbt//models//marts//m_corpus_summary.sql ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -- Marts: source-level summary statistics
2
+ -- Combines corpus and emotion data for dashboard metrics
3
+
4
+ WITH corpus_stats AS (
5
+ SELECT
6
+ source,
7
+ COUNT(*) AS document_count,
8
+ ROUND(AVG(word_count), 1) AS avg_words,
9
+ SUM(word_count) AS total_words,
10
+ ROUND(AVG(char_length), 1) AS avg_chars
11
+ FROM {{ ref('staging_corpus') }}
12
+ GROUP BY source
13
+ ),
14
+ emotion_stats AS (
15
+ SELECT
16
+ source,
17
+ dominant_emotion AS top_emotion,
18
+ document_count AS emotion_docs,
19
+ avg_word_count,
20
+ avg_char_count
21
+ FROM {{ ref('int_emotion_profiles') }}
22
+ QUALIFY ROW_NUMBER() OVER (PARTITION BY source ORDER BY document_count DESC) = 1
23
+ )
24
+
25
+ SELECT
26
+ c.source,
27
+ c.document_count,
28
+ c.avg_words,
29
+ c.total_words,
30
+ e.top_emotion,
31
+ e.emotion_docs
32
+ FROM corpus_stats c
33
+ LEFT JOIN emotion_stats e ON c.source = e.source