problem.dart 2.3 KB

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