getLoadingStats static method

Future<DataLoadingStats> getLoadingStats()

Get data loading statistics

Implementation

static Future<DataLoadingStats> getLoadingStats() async {
  final stopwatch = Stopwatch()..start();

  try {
    final data = await loadQuranData();
    stopwatch.stop();

    // Calculate statistics
    final totalSurahs = data.surahs.length;
    final totalAyat =
        data.surahs.fold<int>(0, (sum, surah) => sum + surah.numberOfAyahs);
    final totalCharacters = data.surahs.fold<int>(
        0,
        (sum, surah) =>
            sum +
            surah.ayat
                .fold<int>(0, (ayahSum, ayah) => ayahSum + ayah.text.length));

    final meccanSurahs = data.surahs.where((s) => s.isMeccan).length;
    final medinanSurahs = data.surahs.where((s) => s.isMedianan).length;
    final sajdahAyat = data.surahs.fold<int>(0,
        (sum, surah) => sum + surah.ayat.where((ayah) => ayah.sajdah).length);

    return DataLoadingStats(
      loadingTimeMs: stopwatch.elapsedMilliseconds,
      totalSurahs: totalSurahs,
      totalAyat: totalAyat,
      totalCharacters: totalCharacters,
      meccanSurahs: meccanSurahs,
      medinanSurahs: medinanSurahs,
      sajdahAyat: sajdahAyat,
      isValid: validateQuranData(data),
      dataSize: totalCharacters * 2, // Approximate size in bytes (UTF-16)
    );
  } catch (e) {
    stopwatch.stop();
    throw Exception('Failed to get loading stats: $e');
  }
}