| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /// 题目数据模型
- class Problem {
- final String id;
- final double difficulty;
- final String questionType;
- final String importType;
- final List<String> chapters;
- final List<String> knowledgeCodes;
- final String comment;
- final String source;
- final String createdAt;
- final String updatedAt;
- final String? renderHtml;
- final String bodyPreview;
- Problem({
- required this.id,
- this.difficulty = 0.5,
- this.questionType = '',
- this.importType = '精选题',
- this.chapters = const [],
- this.knowledgeCodes = const [],
- this.comment = '',
- this.source = '',
- this.createdAt = '',
- this.updatedAt = '',
- this.renderHtml,
- this.bodyPreview = '',
- });
- factory Problem.fromJson(Map<String, dynamic> json) {
- return Problem(
- id: json['id'] ?? '',
- difficulty: (json['difficulty'] ?? 0.5).toDouble(),
- questionType: json['question_type'] ?? '',
- importType: json['import_type'] ?? '精选题',
- chapters: List<String>.from(json['chapters'] ?? []),
- knowledgeCodes: List<String>.from(json['knowledge_codes'] ?? []),
- comment: json['comment'] ?? '',
- source: json['source'] ?? '',
- createdAt: json['created_at'] ?? '',
- updatedAt: json['updated_at'] ?? '',
- renderHtml: json['render_html'],
- bodyPreview: json['body_preview'] ?? '',
- );
- }
- String get difficultyLabel {
- if (difficulty >= 0.7) return '易';
- if (difficulty >= 0.4) return '中';
- return '难';
- }
- bool get isAnnotated => knowledgeCodes.isNotEmpty && knowledgeCodes.first.isNotEmpty;
- }
- /// 搜索命中结果
- class SearchResult {
- final String id;
- final String bodySnippet;
- final double difficulty;
- final String questionType;
- final String importType;
- final List<String> chapters;
- SearchResult({
- required this.id,
- this.bodySnippet = '',
- this.difficulty = 0.5,
- this.questionType = '',
- this.importType = '',
- this.chapters = const [],
- });
- factory SearchResult.fromJson(Map<String, dynamic> json) {
- return SearchResult(
- id: json['id'] ?? '',
- bodySnippet: json['body_snippet'] ?? '',
- difficulty: (json['difficulty'] ?? 0.5).toDouble(),
- questionType: json['question_type'] ?? '',
- importType: json['import_type'] ?? '',
- chapters: List<String>.from(json['chapters'] ?? []),
- );
- }
- }
|