dashboard mejorado
This commit is contained in:
@@ -755,6 +755,46 @@ class VideosProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get top 5 videos by views using Supabase function
|
||||
/// Returns list of maps with: media_file_id, title, file_url, storage_path, reproducciones, poster_url
|
||||
Future<List<Map<String, dynamic>>> getTop5VideosByViews() async {
|
||||
try {
|
||||
final response = await supabaseML.rpc('get_top_5_videos_by_views');
|
||||
|
||||
if (response == null) return [];
|
||||
|
||||
return (response as List<dynamic>)
|
||||
.map((item) => Map<String, dynamic>.from(item as Map))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print('Error en getTop5VideosByViews: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// Get video metrics using Supabase function
|
||||
/// Returns: total_videos, total_reproducciones, promedio_reproducciones_por_dia
|
||||
Future<Map<String, dynamic>?> getVideoMetrics() async {
|
||||
try {
|
||||
final response = await supabaseML.rpc('get_video_metrics');
|
||||
|
||||
if (response == null || (response as List).isEmpty) return null;
|
||||
|
||||
// La función retorna un array con un solo objeto
|
||||
final data = (response as List).first as Map<String, dynamic>;
|
||||
|
||||
return {
|
||||
'total_videos': data['total_videos'] ?? 0,
|
||||
'total_reproducciones': data['total_reproducciones'] ?? 0,
|
||||
'promedio_reproducciones_por_dia':
|
||||
data['promedio_reproducciones_por_dia'] ?? 0.0,
|
||||
};
|
||||
} catch (e) {
|
||||
print('Error en getVideoMetrics: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Update missing video durations (batch process)
|
||||
Future<Map<String, dynamic>> updateMissingDurations(
|
||||
Function(int current, int total) onProgress,
|
||||
|
||||
Reference in New Issue
Block a user