chore(data-ana): merge data-ana full implementation into main

Merge feat/data-ana-ai11 with complete data analytics service
This commit is contained in:
SpecialX
2026-07-10 19:13:39 +08:00
29 changed files with 5308 additions and 401 deletions

View File

@@ -6,18 +6,15 @@ package next_edu_cloud.events.v1;
// outbox pattern and consumed by downstream services (notifications, analytics,
// audit, etc.).
//
// Topic naming follows the arbitration in coord-cross-review §3.1:
// edu.teaching.<aggregate>.<action>
//
// Event routing (TOPIC_MAP in outbox.publisher.ts):
// edu.exam.events <- exam.created / exam.updated / exam.deleted
// edu.homework.events <- homework.assigned / homework.submitted / homework.graded
// edu.grade.events <- grade.recorded / grade.updated
// edu.class.events <- class.transferred
// edu.content.textbook.events <- textbook.created / textbook.updated / textbook.published / textbook.archived
// edu.content.chapter.events <- chapter.created / chapter.updated / chapter.deleted
// edu.content.knowledge_point.events <- knowledge_point.created / knowledge_point.updated / knowledge_point.prerequisite_added / knowledge_point.prerequisite_removed
// edu.content.question.events <- question.created / question.updated / question.published / question.deleted
// edu.teaching.exam.published <- exam.published
// edu.teaching.homework.assigned <- homework.assigned / homework.submitted / homework.graded
// edu.teaching.grade.recorded <- grade.recorded / grade.updated
// edu.teaching.class.transferred <- class.transferred
//
// Derived data events (Outbox exempt, see 004 §12.2):
// edu.insight.mastery.updated <- mastery.updated / warning.triggered (action field distinguishes)
// edu.insight.ai.usage <- ai.usage.recorded
message ClassEvent {
string event_id = 1;
@@ -185,3 +182,40 @@ message QuestionEvent {
string action = 12;
map<string, string> metadata = 13;
}
// MasteryEvent 掌握度/预警派生数据事件Outbox 豁免,直接 Kafka producer 发布).
// action 字段区分mastery.updated掌握度更新/ warning.triggered预警触发.
// 两者复用同一 topic edu.insight.mastery.updated总裁裁决 §2.11.
message MasteryEvent {
string event_id = 1;
string action = 2; // mastery.updated / warning.triggered
int64 occurred_at = 3;
string student_id = 4;
string knowledge_point_id = 5;
double mastery_level = 6; // 0.0-1.0mastery.updated 时有效)
double previous_level = 7; // 上一次掌握度mastery.updated 时有效)
// warning.triggered 时以下字段有效
string warning_type = 8; // LOW_MASTERY / CRITICAL_LOW / SCORE_DROP / ABSENT_FREQUENT / TREND_DECLINE
string target_id = 9; // 预警目标(学生 ID
double threshold = 10; // 预警阈值
double current_value = 11; // 当前值
string severity = 12; // INFO / WARN / CRITICAL
map<string, string> metadata = 13;
}
// AIUsageEvent AI 用量计费事件ai 服务发布data-ana 消费落 ai_usage_log.
message AIUsageEvent {
string event_id = 1;
string request_id = 2;
string user_id = 3;
string provider = 4; // openai / anthropic / baichuan / local
string model = 5;
uint32 prompt_tokens = 6;
uint32 completion_tokens = 7;
uint32 total_tokens = 8;
uint32 latency_ms = 9;
bool success = 10;
uint32 cost_cents = 11; // 计费(分)
int64 occurred_at = 12;
map<string, string> metadata = 13;
}