FEATURE: Refinements to Emotion in dashboard (#947)

* FEATURE: Refinements to Emotion in dashboard

- Added descriptions to individual reports
- Made reports work with data older than 60 days
This commit is contained in:
Rafael dos Santos Silva 2024-11-25 11:31:51 -03:00 committed by GitHub
parent ea24328415
commit 5fb1177f7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 27 deletions

View File

@ -6,22 +6,14 @@
</div>
<div class="cell value today-count">
<a
href="{{this.filterURL}}activity-after%3A{{this.today}}%20order%3A{{this.model.type}}"
>
{{number this.model.todayCount}}
</a>
{{number this.model.todayCount}}
</div>
<div
class="cell value yesterday-count {{this.model.yesterdayTrend}}"
title={{this.model.yesterdayCountTitle}}
>
<a
href="{{this.filterURL}}activity-after%3A{{this.yesterday}}%20order%3A{{this.model.type}}"
>
{{number this.model.yesterdayCount}}
</a>
{{number this.model.yesterdayCount}}
{{d-icon this.model.yesterdayTrendIcon}}
</div>
@ -29,11 +21,7 @@
class="cell value sevendays-count {{this.model.sevenDaysTrend}}"
title={{this.model.sevenDaysCountTitle}}
>
<a
href="{{this.filterURL}}activity-after%3A{{this.lastWeek}}%20order%3A{{this.model.type}}"
>
{{number this.model.lastSevenDaysCount}}
</a>
{{number this.model.lastSevenDaysCount}}
{{d-icon this.model.sevenDaysTrendIcon}}
</div>
@ -41,12 +29,7 @@
class="cell value thirty-days-count {{this.model.thirtyDaysTrend}}"
title={{this.model.thirtyDaysCountTitle}}
>
<a
href="{{this.filterURL}}activity-after%3A{{this.lastMonth}}%20order%3A{{this.model.type}}"
>
{{number this.model.lastThirtyDaysCount}}
</a>
{{number this.model.lastThirtyDaysCount}}
{{#if this.model.canDisplayTrendIcon}}
{{d-icon this.model.thirtyDaysTrendIcon}}
{{/if}}

View File

@ -7,6 +7,13 @@ export default class AdminDashboardSentiment extends AdminDashboardTabController
return { startDate: this.startDate, endDate: this.endDate };
}
get emotionFilters() {
return {
startDate: moment().format("YYYY-MM-DD"),
endDate: moment().subtract(2, "month").format("YYYY-MM-DD"),
};
}
get emotions() {
const emotions = [
"admiration",

View File

@ -60,6 +60,7 @@
{{#each this.emotions as |metric|}}
<AdminReport
@showHeader={{false}}
@filters={{this.emotionFilters}}
@forcedModes="emotion"
@dataSourceName="emotion_{{metric}}"
/>

View File

@ -117,60 +117,88 @@ en:
yaxis: "Date"
emotion_admiration:
title: 🤩 Admiration
description: "Posts classified with the emotion admiration via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_amusement:
title: 😄 Amusement
description: "Posts classified with the emotion amusement via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_anger:
title: 😠 Anger
description: "Posts classified with the emotion anger via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_annoyance:
title: 😒 Annoyance
description: "Posts classified with the emotion annoyance via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_approval:
title: 👍 Approval
description: "Posts classified with the emotion approval via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_caring:
title: 🤗 Caring
description: "Posts classified with the emotion caring via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_confusion:
title: 😕 Confusion
description: "Posts classified with the emotion confusion via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_curiosity:
title: 🤔 Curiosity
description: "Posts classified with the emotion curiosity via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_desire:
title: 😍 Desire
description: "Posts classified with the emotion desire via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_disappointment:
title: 😞 Disappointment
description: "Posts classified with the emotion disappointment via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_disapproval:
title: 👎 Disapproval
description: "Posts classified with the emotion disapproval via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_disgust:
title: 🤢 Disgust
description: "Posts classified with the emotion disgust via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_embarrassment:
title: 😳 Embarrassment
description: "Posts classified with the emotion embarrassment via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_excitement:
title: 🤪 Excitement
description: "Posts classified with the emotion excitement via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_fear:
title: 😨 Fear
description: "Posts classified with the emotion fear via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_gratitude:
title: 🙏 Gratitude
description: "Posts classified with the emotion gratitude via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_grief:
title: 😢 Grief
description: "Posts classified with the emotion grief via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_joy:
title: 😊 Joy
description: "Posts classified with the emotion joy via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_love:
title: ❤️ Love
description: "Posts classified with the emotion love via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_nervousness:
title: 😰 Nervousness
description: "Posts classified with the emotion nervousness via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_neutral:
title: 😐 Neutral
description: "Posts classified with the emotion neutral via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_optimism:
title: 🌟 Optimism
description: "Posts classified with the emotion optimism via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_pride:
title: 🦁 Pride
description: "Posts classified with the emotion pride via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_realization:
title: 💡 Realization
description: "Posts classified with the emotion realization via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_relief:
title: 😌 Relief
description: "Posts classified with the emotion relief via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_remorse:
title: 😔 Remorse
description: "Posts classified with the emotion remorse via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_sadness:
title: 😭 Sadness
description: "Posts classified with the emotion sadness via AI, using the model 'SamLowe/roberta-base-go_emotions'."
emotion_surprise:
title: 😲 Surprise
description: "Posts classified with the emotion surprise via AI, using the model 'SamLowe/roberta-base-go_emotions'."
discourse_ai:
ai_artifact:

View File

@ -6,15 +6,16 @@ module DiscourseAi
def self.register!(plugin)
Emotions::LIST.each do |emotion|
plugin.add_report("emotion_#{emotion}") do |report|
query_results = DiscourseAi::Sentiment::EmotionDashboardReport.fetch_data
report.data = query_results.pop(30).map { |row| { x: row.day, y: row.send(emotion) } }
report.prev30Days =
query_results.take(30).reduce(0) { |sum, row| sum + row.send(emotion) }.to_i
query_results = DiscourseAi::Sentiment::EmotionDashboardReport.fetch_data(report)
report.data = query_results.map { |row| { x: row.day, y: row.send(emotion) } }
if report.facets.include?(:prev_period) && query_results.length > 30
report.prev30Days = query_results[31..60].sum { |row| row.send(emotion) }
end
end
end
def self.fetch_data
DB.query(<<~SQL, end: Time.now.tomorrow.midnight, start: 60.days.ago.midnight)
def self.fetch_data(report)
DB.query(<<~SQL, end: report.end_date, start: report.start_date)
SELECT
posts.created_at::DATE AS day,
#{