109 lines
3.2 KiB
Dart
109 lines
3.2 KiB
Dart
library analytics_model;
|
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
/// Modèle pour une métrique analytics — aligné avec AnalyticsDataDTO
|
|
class AnalyticsModel extends Equatable {
|
|
final String? id;
|
|
final String typeMetrique;
|
|
final String periodeAnalyse;
|
|
final double valeur;
|
|
final double? valeurPrecedente;
|
|
final double? pourcentageEvolution;
|
|
final DateTime? dateDebut;
|
|
final DateTime? dateFin;
|
|
final String? libelle;
|
|
final String? description;
|
|
final String? unite;
|
|
final String? couleur;
|
|
final String? icone;
|
|
|
|
const AnalyticsModel({
|
|
this.id,
|
|
required this.typeMetrique,
|
|
required this.periodeAnalyse,
|
|
required this.valeur,
|
|
this.valeurPrecedente,
|
|
this.pourcentageEvolution,
|
|
this.dateDebut,
|
|
this.dateFin,
|
|
this.libelle,
|
|
this.description,
|
|
this.unite,
|
|
this.couleur,
|
|
this.icone,
|
|
});
|
|
|
|
bool get hasPositiveTrend =>
|
|
pourcentageEvolution != null && pourcentageEvolution! > 0;
|
|
bool get hasNegativeTrend =>
|
|
pourcentageEvolution != null && pourcentageEvolution! < 0;
|
|
|
|
factory AnalyticsModel.fromJson(Map<String, dynamic> json) {
|
|
return AnalyticsModel(
|
|
id: json['id']?.toString(),
|
|
typeMetrique: json['typeMetrique']?.toString() ?? '',
|
|
periodeAnalyse: json['periodeAnalyse']?.toString() ?? '',
|
|
valeur: _parseDouble(json['valeur']),
|
|
valeurPrecedente: json['valeurPrecedente'] != null
|
|
? _parseDouble(json['valeurPrecedente'])
|
|
: null,
|
|
pourcentageEvolution: json['pourcentageEvolution'] != null
|
|
? _parseDouble(json['pourcentageEvolution'])
|
|
: null,
|
|
dateDebut: json['dateDebut'] != null
|
|
? DateTime.tryParse(json['dateDebut'].toString())
|
|
: null,
|
|
dateFin: json['dateFin'] != null
|
|
? DateTime.tryParse(json['dateFin'].toString())
|
|
: null,
|
|
libelle: json['libellePersonnalise']?.toString() ?? json['typeMetrique']?.toString(),
|
|
description: json['description']?.toString(),
|
|
unite: json['unite']?.toString(),
|
|
couleur: json['couleur']?.toString(),
|
|
icone: json['icone']?.toString(),
|
|
);
|
|
}
|
|
|
|
static double _parseDouble(dynamic val) {
|
|
if (val == null) return 0.0;
|
|
if (val is num) return val.toDouble();
|
|
return double.tryParse(val.toString()) ?? 0.0;
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [id, typeMetrique, valeur, periodeAnalyse];
|
|
}
|
|
|
|
/// KPI synthétique pour le tableau de bord des rapports
|
|
class KpiModel extends Equatable {
|
|
final String libelle;
|
|
final double valeur;
|
|
final String? unite;
|
|
final double? evolution;
|
|
final String? couleur;
|
|
|
|
const KpiModel({
|
|
required this.libelle,
|
|
required this.valeur,
|
|
this.unite,
|
|
this.evolution,
|
|
this.couleur,
|
|
});
|
|
|
|
factory KpiModel.fromJson(Map<String, dynamic> json) {
|
|
return KpiModel(
|
|
libelle: json['libelle']?.toString() ?? json['nom']?.toString() ?? '',
|
|
valeur: AnalyticsModel._parseDouble(json['valeur'] ?? json['value']),
|
|
unite: json['unite']?.toString(),
|
|
evolution: json['evolution'] != null
|
|
? AnalyticsModel._parseDouble(json['evolution'])
|
|
: null,
|
|
couleur: json['couleur']?.toString(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
List<Object?> get props => [libelle, valeur];
|
|
}
|