217 lines
9.2 KiB
Go
217 lines
9.2 KiB
Go
package domain
|
||
|
||
import "time"
|
||
|
||
type AnalyticsLabelCount struct {
|
||
Label string `json:"label"`
|
||
Count int64 `json:"count"`
|
||
}
|
||
|
||
type AnalyticsLabelAmount struct {
|
||
Label string `json:"label"`
|
||
Count int64 `json:"count"`
|
||
Amount float64 `json:"amount"`
|
||
}
|
||
|
||
type AnalyticsRevenueByPlan struct {
|
||
PlanName string `json:"plan_name"`
|
||
Currency string `json:"currency"`
|
||
Revenue float64 `json:"revenue"`
|
||
}
|
||
|
||
type AnalyticsTimePoint struct {
|
||
Date time.Time `json:"date"`
|
||
Count int64 `json:"count"`
|
||
}
|
||
|
||
type AnalyticsRevenueTimePoint struct {
|
||
Date time.Time `json:"date"`
|
||
Revenue float64 `json:"revenue"`
|
||
}
|
||
|
||
// AnalyticsMonthlyRevenuePoint is one calendar month bucket (UTC month start) within a dashboard year query.
|
||
type AnalyticsMonthlyRevenuePoint struct {
|
||
Month int `json:"month"` // 1–12
|
||
MonthStart time.Time `json:"month_start"` // UTC date of month start (for sorting / tooltips)
|
||
Label string `json:"label"` // Short English month label, e.g. Jan
|
||
Currency string `json:"currency"`
|
||
Revenue float64 `json:"revenue"` // SUCCESS payments aggregate for that bucket
|
||
}
|
||
|
||
type AnalyticsUsersSection struct {
|
||
TotalUsers int64 `json:"total_users"`
|
||
NewToday int64 `json:"new_today"`
|
||
NewWeek int64 `json:"new_week"`
|
||
NewMonth int64 `json:"new_month"`
|
||
|
||
ByRole []AnalyticsLabelCount `json:"by_role"`
|
||
ByStatus []AnalyticsLabelCount `json:"by_status"`
|
||
ByAgeGroup []AnalyticsLabelCount `json:"by_age_group"`
|
||
ByGender []AnalyticsLabelCount `json:"by_gender"`
|
||
ByEducationLevel []AnalyticsLabelCount `json:"by_education_level"`
|
||
ByOccupation []AnalyticsLabelCount `json:"by_occupation"`
|
||
ByLearningGoal []AnalyticsLabelCount `json:"by_learning_goal"`
|
||
ByLanguageChallange []AnalyticsLabelCount `json:"by_language_challange"`
|
||
ByKnowledgeLevel []AnalyticsLabelCount `json:"by_knowledge_level"`
|
||
ByCountry []AnalyticsLabelCount `json:"by_country"`
|
||
ByRegion []AnalyticsLabelCount `json:"by_region"`
|
||
|
||
RegistrationsLast30Days []AnalyticsTimePoint `json:"registrations_last_30_days"`
|
||
}
|
||
|
||
// AnalyticsSubscriptionSnapshot is a point-in-time view of learner subscription state
|
||
// (not filtered by the dashboard created_at date range).
|
||
type AnalyticsSubscriptionSnapshot struct {
|
||
ActiveNow int64 `json:"active_now"`
|
||
ActiveLearners int64 `json:"active_learners"`
|
||
PendingNow int64 `json:"pending_now"`
|
||
ExpiredNow int64 `json:"expired_now"`
|
||
CancelledNow int64 `json:"cancelled_now"`
|
||
ExpiringWithin7Days int64 `json:"expiring_within_7_days"`
|
||
ExpiringWithin30Days int64 `json:"expiring_within_30_days"`
|
||
AutoRenewEnabled int64 `json:"auto_renew_enabled"`
|
||
LifetimeActive int64 `json:"lifetime_active"`
|
||
TermActive int64 `json:"term_active"`
|
||
}
|
||
|
||
type AnalyticsSubscriptionsSection struct {
|
||
TotalSubscriptions int64 `json:"total_subscriptions"`
|
||
ActiveSubscriptions int64 `json:"active_subscriptions"`
|
||
NewToday int64 `json:"new_today"`
|
||
NewWeek int64 `json:"new_week"`
|
||
NewMonth int64 `json:"new_month"`
|
||
|
||
ByStatus []AnalyticsLabelCount `json:"by_status"`
|
||
RevenueByPlan []AnalyticsRevenueByPlan `json:"revenue_by_plan"`
|
||
|
||
NewSubscriptionsLast30Days []AnalyticsTimePoint `json:"new_subscriptions_last_30_days"`
|
||
|
||
// Learner subscription behaviour
|
||
Snapshot AnalyticsSubscriptionSnapshot `json:"snapshot"`
|
||
ActiveByCategory []AnalyticsLabelCount `json:"active_by_category"`
|
||
ActiveByPlan []AnalyticsLabelCount `json:"active_by_plan"`
|
||
ActiveByLifetime []AnalyticsLabelCount `json:"active_by_lifetime"`
|
||
AcquisitionBySource []AnalyticsLabelCount `json:"acquisition_by_source"`
|
||
RevenueByCategory []AnalyticsLabelAmount `json:"revenue_by_category"`
|
||
CancellationsLast30Days []AnalyticsTimePoint `json:"cancellations_last_30_days"`
|
||
ExpirationsLast30Days []AnalyticsTimePoint `json:"expirations_last_30_days"`
|
||
|
||
// Resubscribe / renewal behaviour
|
||
Renewal AnalyticsSubscriptionRenewal `json:"renewal"`
|
||
NewByCohort []AnalyticsLabelCount `json:"new_by_cohort"`
|
||
ResubscriptionsLast30Days []AnalyticsTimePoint `json:"resubscriptions_last_30_days"`
|
||
}
|
||
|
||
// AnalyticsSubscriptionRenewal summarizes first-time vs returning buys and post-expiry renewals.
|
||
type AnalyticsSubscriptionRenewal struct {
|
||
FirstTimeSubscriptions int64 `json:"first_time_subscriptions"`
|
||
ReturningSubscriptions int64 `json:"returning_subscriptions"`
|
||
ResubscribeAfterExpiry int64 `json:"resubscribe_after_expiry"`
|
||
ExpiredInPeriod int64 `json:"expired_in_period"`
|
||
RenewedAfterExpiry int64 `json:"renewed_after_expiry"`
|
||
RenewalRate float64 `json:"renewal_rate"` // 0–1; renewed_after_expiry / expired_in_period
|
||
AvgDaysToResubscribe float64 `json:"avg_days_to_resubscribe"`
|
||
MedianDaysToResubscribe float64 `json:"median_days_to_resubscribe"`
|
||
}
|
||
|
||
type AnalyticsPaymentsSection struct {
|
||
TotalRevenue float64 `json:"total_revenue"`
|
||
AvgTransactionValue float64 `json:"avg_transaction_value"`
|
||
TotalPayments int64 `json:"total_payments"`
|
||
SuccessfulPayments int64 `json:"successful_payments"`
|
||
|
||
ByStatus []AnalyticsLabelAmount `json:"by_status"`
|
||
ByMethod []AnalyticsLabelAmount `json:"by_method"`
|
||
|
||
RevenueLast30Days []AnalyticsRevenueTimePoint `json:"revenue_last_30_days"`
|
||
|
||
// RevenueMonthly is populated only when the request includes year=..., with 12 months (possibly multiple currencies per month).
|
||
RevenueMonthly []AnalyticsMonthlyRevenuePoint `json:"revenue_monthly,omitempty"`
|
||
// MonthlyRevenueYear is set when RevenueMonthly is non-empty (the calendar year of those buckets).
|
||
MonthlyRevenueYear *int `json:"monthly_revenue_year,omitempty"`
|
||
}
|
||
|
||
// AnalyticsExamPrepContentCounts reflects the exam_prep schema: catalog_courses → units → unit_modules → lessons → lesson_practices.
|
||
type AnalyticsExamPrepContentCounts struct {
|
||
CatalogCourses int64 `json:"catalog_courses"`
|
||
Units int64 `json:"units"`
|
||
UnitModules int64 `json:"unit_modules"`
|
||
Lessons int64 `json:"lessons"`
|
||
LessonsWithVideo int64 `json:"lessons_with_video"`
|
||
LessonPractices int64 `json:"lesson_practices"`
|
||
}
|
||
|
||
type AnalyticsCoursesSection struct {
|
||
// Top-level summary fields preserve the dashboard contract using the unified hierarchy.
|
||
TotalCategories int64 `json:"total_categories"`
|
||
TotalCourses int64 `json:"total_courses"`
|
||
TotalSubCourses int64 `json:"total_sub_courses"`
|
||
TotalVideos int64 `json:"total_videos"`
|
||
|
||
ExamPrep AnalyticsExamPrepContentCounts `json:"exam_prep"`
|
||
}
|
||
|
||
type AnalyticsContentSection struct {
|
||
TotalQuestions int64 `json:"total_questions"`
|
||
TotalQuestionSets int64 `json:"total_question_sets"`
|
||
|
||
QuestionsByType []AnalyticsLabelCount `json:"questions_by_type"`
|
||
QuestionSetsByType []AnalyticsLabelCount `json:"question_sets_by_type"`
|
||
}
|
||
|
||
type AnalyticsNotificationsSection struct {
|
||
TotalSent int64 `json:"total_sent"`
|
||
ReadCount int64 `json:"read_count"`
|
||
UnreadCount int64 `json:"unread_count"`
|
||
|
||
ByChannel []AnalyticsLabelCount `json:"by_channel"`
|
||
ByType []AnalyticsLabelCount `json:"by_type"`
|
||
}
|
||
|
||
type AnalyticsIssuesSection struct {
|
||
TotalIssues int64 `json:"total_issues"`
|
||
ResolvedIssues int64 `json:"resolved_issues"`
|
||
ResolutionRate float64 `json:"resolution_rate"`
|
||
|
||
ByStatus []AnalyticsLabelCount `json:"by_status"`
|
||
ByType []AnalyticsLabelCount `json:"by_type"`
|
||
}
|
||
|
||
type AnalyticsTeamSection struct {
|
||
TotalMembers int64 `json:"total_members"`
|
||
ByRole []AnalyticsLabelCount `json:"by_role"`
|
||
ByStatus []AnalyticsLabelCount `json:"by_status"`
|
||
}
|
||
|
||
type AnalyticsVideoDropOffPoint struct {
|
||
CheckpointPercent int `json:"checkpoint_percent"`
|
||
TotalSessions int64 `json:"total_sessions"`
|
||
ViewersReached int64 `json:"viewers_reached"`
|
||
DropOffRate float64 `json:"drop_off_rate"`
|
||
}
|
||
|
||
type AnalyticsVideosSection struct {
|
||
TotalWatchSessions int64 `json:"total_watch_sessions"`
|
||
CompletedSessions int64 `json:"completed_sessions"`
|
||
ReplaySessions int64 `json:"replay_sessions"`
|
||
UniqueVideoStarts int64 `json:"unique_video_starts"`
|
||
UsersWhoReplayed int64 `json:"users_who_replayed"`
|
||
CompletionRate float64 `json:"completion_rate"`
|
||
ReplayRate float64 `json:"replay_rate"`
|
||
DropOffByCheckpoint []AnalyticsVideoDropOffPoint `json:"drop_off_by_checkpoint"`
|
||
}
|
||
|
||
type AnalyticsDashboard struct {
|
||
GeneratedAt time.Time `json:"generated_at"`
|
||
DateFilter AnalyticsDateFilter `json:"date_filter"`
|
||
Users AnalyticsUsersSection `json:"users"`
|
||
Subscriptions AnalyticsSubscriptionsSection `json:"subscriptions"`
|
||
Payments AnalyticsPaymentsSection `json:"payments"`
|
||
Courses AnalyticsCoursesSection `json:"courses"`
|
||
Videos AnalyticsVideosSection `json:"videos"`
|
||
Content AnalyticsContentSection `json:"content"`
|
||
Notifications AnalyticsNotificationsSection `json:"notifications"`
|
||
Issues AnalyticsIssuesSection `json:"issues"`
|
||
Team AnalyticsTeamSection `json:"team"`
|
||
}
|