problem.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /// 题目数据模型
  2. class Problem {
  3. final String id;
  4. final double difficulty;
  5. final String questionType;
  6. final String importType;
  7. final List<String> chapters;
  8. final List<String> knowledgeCodes;
  9. final String comment;
  10. final String source;
  11. final String createdAt;
  12. final String updatedAt;
  13. final String? renderHtml;
  14. Problem({
  15. required this.id,
  16. this.difficulty = 0.5,
  17. this.questionType = '',
  18. this.importType = '精选题',
  19. this.chapters = const [],
  20. this.knowledgeCodes = const [],
  21. this.comment = '',
  22. this.source = '',
  23. this.createdAt = '',
  24. this.updatedAt = '',
  25. this.renderHtml,
  26. });
  27. factory Problem.fromJson(Map<String, dynamic> json) {
  28. return Problem(
  29. id: json['id'] ?? '',
  30. difficulty: (json['difficulty'] ?? 0.5).toDouble(),
  31. questionType: json['question_type'] ?? '',
  32. importType: json['import_type'] ?? '精选题',
  33. chapters: List<String>.from(json['chapters'] ?? []),
  34. knowledgeCodes: List<String>.from(json['knowledge_codes'] ?? []),
  35. comment: json['comment'] ?? '',
  36. source: json['source'] ?? '',
  37. createdAt: json['created_at'] ?? '',
  38. updatedAt: json['updated_at'] ?? '',
  39. renderHtml: json['render_html'],
  40. );
  41. }
  42. String get difficultyLabel {
  43. if (difficulty >= 0.7) return '易';
  44. if (difficulty >= 0.4) return '中';
  45. return '难';
  46. }
  47. bool get isAnnotated => knowledgeCodes.isNotEmpty && knowledgeCodes.first.isNotEmpty;
  48. }
  49. /// 搜索命中结果
  50. class SearchResult {
  51. final String id;
  52. final String bodySnippet;
  53. final double difficulty;
  54. final String questionType;
  55. final String importType;
  56. final List<String> chapters;
  57. SearchResult({
  58. required this.id,
  59. this.bodySnippet = '',
  60. this.difficulty = 0.5,
  61. this.questionType = '',
  62. this.importType = '',
  63. this.chapters = const [],
  64. });
  65. factory SearchResult.fromJson(Map<String, dynamic> json) {
  66. return SearchResult(
  67. id: json['id'] ?? '',
  68. bodySnippet: json['body_snippet'] ?? '',
  69. difficulty: (json['difficulty'] ?? 0.5).toDouble(),
  70. questionType: json['question_type'] ?? '',
  71. importType: json['import_type'] ?? '',
  72. chapters: List<String>.from(json['chapters'] ?? []),
  73. );
  74. }
  75. }