feat(App): update Finlytic Flutter app UI and blocs
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
class FinbertResultModel extends Equatable {
|
||||
final String label;
|
||||
final double score;
|
||||
final double positiveProbability;
|
||||
final double negativeProbability;
|
||||
final double neutralProbability;
|
||||
final String processingTimeMs;
|
||||
final String? summarySnippet;
|
||||
|
||||
const FinbertResultModel({
|
||||
required this.label,
|
||||
required this.score,
|
||||
required this.positiveProbability,
|
||||
required this.negativeProbability,
|
||||
required this.neutralProbability,
|
||||
required this.processingTimeMs,
|
||||
this.summarySnippet,
|
||||
});
|
||||
|
||||
factory FinbertResultModel.fromJson(Map<String, dynamic> json) {
|
||||
Map<String, dynamic>? probs = json['probabilities'] ?? json['Probabilities'];
|
||||
|
||||
return FinbertResultModel(
|
||||
label: json['label'] ?? json['Label'] ?? 'NEUTRAL',
|
||||
score: (json['compound_score'] ?? json['compoundScore'] ?? json['score'] ?? json['Score'] ?? 0.0).toDouble(),
|
||||
positiveProbability: (probs != null ? (probs['positive'] ?? probs['Positive'] ?? 0.0) : (json['positiveProbability'] ?? json['PositiveProbability'] ?? 0.0)).toDouble(),
|
||||
negativeProbability: (probs != null ? (probs['negative'] ?? probs['Negative'] ?? 0.0) : (json['negativeProbability'] ?? json['NegativeProbability'] ?? 0.0)).toDouble(),
|
||||
neutralProbability: (probs != null ? (probs['neutral'] ?? probs['Neutral'] ?? 0.0) : (json['neutralProbability'] ?? json['NeutralProbability'] ?? 0.0)).toDouble(),
|
||||
processingTimeMs: json['processingTimeMs']?.toString() ?? json['ProcessingTimeMs']?.toString() ?? '0ms',
|
||||
summarySnippet: json['summary_snippet']?.toString() ?? json['summarySnippet']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'label': label,
|
||||
'score': score,
|
||||
'positiveProbability': positiveProbability,
|
||||
'negativeProbability': negativeProbability,
|
||||
'neutralProbability': neutralProbability,
|
||||
'processingTimeMs': processingTimeMs,
|
||||
'summarySnippet': summarySnippet,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
label,
|
||||
score,
|
||||
positiveProbability,
|
||||
negativeProbability,
|
||||
neutralProbability,
|
||||
processingTimeMs,
|
||||
summarySnippet,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'finbert_result_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;
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
factory NewsArticleModel.fromJson(Map<String, dynamic> json) {
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user