110 lines
3.7 KiB
Dart
110 lines
3.7 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import 'finbert_result_model.dart';
|
|
import 'matched_asset_model.dart';
|
|
|
|
class NewsArticleModel extends Equatable {
|
|
final String id;
|
|
final String title;
|
|
final String author;
|
|
final String summary;
|
|
final String contentRaw;
|
|
final String sourceUrl;
|
|
final DateTime scrapedAt;
|
|
final DateTime publishedAt;
|
|
final String status;
|
|
|
|
// Flatted sentiment properties
|
|
final String sentiment;
|
|
final double sentimentScore;
|
|
final double confidence;
|
|
final FinbertResultModel? finbertResult;
|
|
final List<MatchedAssetModel> matchedAssets;
|
|
|
|
const NewsArticleModel({
|
|
required this.id,
|
|
required this.title,
|
|
required this.author,
|
|
required this.summary,
|
|
required this.contentRaw,
|
|
required this.sourceUrl,
|
|
required this.scrapedAt,
|
|
required this.publishedAt,
|
|
required this.status,
|
|
required this.sentiment,
|
|
required this.sentimentScore,
|
|
required this.confidence,
|
|
this.finbertResult,
|
|
this.matchedAssets = const [],
|
|
});
|
|
|
|
factory NewsArticleModel.fromJson(Map<String, dynamic> json) {
|
|
List<MatchedAssetModel> assets = [];
|
|
final mList = json['matchedAssets'] ?? json['MatchedAssets'];
|
|
if (mList != null && mList is List) {
|
|
assets = mList.map((e) => MatchedAssetModel.fromJson(e as Map<String, dynamic>)).toList();
|
|
}
|
|
|
|
return NewsArticleModel(
|
|
id: json['id']?.toString() ?? json['Id']?.toString() ?? '',
|
|
title: json['title']?.toString() ?? json['Title']?.toString() ?? 'No Title',
|
|
author: json['author']?.toString() ?? json['Author']?.toString() ?? 'Unknown',
|
|
summary: json['summary']?.toString() ?? json['Summary']?.toString() ?? '',
|
|
contentRaw: json['contentRaw']?.toString() ?? json['ContentRaw']?.toString() ?? '',
|
|
sourceUrl: json['sourceUrl']?.toString() ?? json['SourceUrl']?.toString() ?? '',
|
|
scrapedAt: DateTime.tryParse(json['scrapedAt']?.toString() ?? json['ScrapedAt']?.toString() ?? '') ?? DateTime.now(),
|
|
publishedAt: DateTime.tryParse(json['publishedAt']?.toString() ?? json['PublishedAt']?.toString() ?? '') ?? DateTime.now(),
|
|
status: json['status']?.toString() ?? json['Status']?.toString() ?? 'Completed',
|
|
sentiment: json['sentiment']?.toString() ?? json['Sentiment']?.toString() ?? '',
|
|
|
|
sentimentScore: (json['sentimentScore'] ?? json['SentimentScore'] ?? 0.0).toDouble(),
|
|
confidence: (json['confidence'] ?? json['Confidence'] ?? 0.0).toDouble(),
|
|
finbertResult: (json['finbertResult'] != null || json['FinbertResult'] != null)
|
|
? FinbertResultModel.fromJson(json['finbertResult'] ?? json['FinbertResult'])
|
|
: null,
|
|
matchedAssets: assets,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'author': author,
|
|
'summary': summary,
|
|
'contentRaw': contentRaw,
|
|
'sourceUrl': sourceUrl,
|
|
'scrapedAt': scrapedAt.toIso8601String(),
|
|
'publishedAt': publishedAt.toIso8601String(),
|
|
'status': status,
|
|
'sentiment': sentiment,
|
|
'sentimentScore': sentimentScore,
|
|
'confidence': confidence,
|
|
'finbertResult': finbertResult != null ? {
|
|
'label': finbertResult!.label,
|
|
'score': finbertResult!.score,
|
|
'positiveProbability': finbertResult!.positiveProbability,
|
|
'negativeProbability': finbertResult!.negativeProbability,
|
|
'neutralProbability': finbertResult!.neutralProbability,
|
|
'processingTimeMs': finbertResult!.processingTimeMs,
|
|
} : null,
|
|
};
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
id,
|
|
title,
|
|
author,
|
|
summary,
|
|
contentRaw,
|
|
sourceUrl,
|
|
scrapedAt,
|
|
publishedAt,
|
|
status,
|
|
sentiment,
|
|
sentimentScore,
|
|
confidence,
|
|
finbertResult,
|
|
];
|
|
}
|