< Summary

Line coverage
86%
Covered lines: 26
Uncovered lines: 4
Coverable lines: 30
Total lines: 841
Line coverage: 86.6%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: .cctor()100%11100%
File 2: Of(...)100%4471.42%
File 2: OfVideoLocation(...)87.5%88100%
File 2: Degrees(...)100%11100%

File(s)

/home/runner/work/anichron/anichron/src/.artifacts/obj/Anichron.Worker/debug/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs

File '/home/runner/work/anichron/anichron/src/.artifacts/obj/Anichron.Worker/debug/Microsoft.Extensions.Logging.Generators/Microsoft.Extensions.Logging.Generators.LoggerMessageGenerator/LoggerMessage.g.cs' does not exist (any more).

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Extraction/Positions.cs

#LineLine coverage
 1using MetadataExtractor;
 2using MetadataExtractor.Formats.Exif;
 3using MetadataExtractor.Formats.QuickTime;
 4using System.Globalization;
 5using System.Text.RegularExpressions;
 6using Directory = MetadataExtractor.Directory;
 7
 8namespace Anichron.Worker.Ingestion.Extraction;
 9
 10internal static partial class Positions
 11{
 12    public static (double? Latitude, double? Longitude) Of(IReadOnlyList<Directory> directories, ILogger logger)
 18613    {
 18614        var gps = directories.OfType<GpsDirectory>().FirstOrDefault();
 18615        if (gps is null)
 18116            return OfVideoLocation(directories, logger);
 17        try
 518        {
 19            // GetGeoLocation() returns Nullable<GeoLocation>; the pattern unwraps it.
 520            var location = gps.GetGeoLocation();
 521            return location is { } coordinates
 522                ? (coordinates.Latitude, coordinates.Longitude)
 523                : (null, null);
 24        }
 25        // Stryker disable once Block
 026        catch (Exception ex)
 027        {
 028            Log.GpsCoordinatesParseFailed(logger, ex);
 029            return (null, null);
 30        }
 18631    }
 32
 33    private static (double? Latitude, double? Longitude) OfVideoLocation(IReadOnlyList<Directory> directories, ILogger l
 18134    {
 18135        var raw = directories.OfType<QuickTimeMetadataHeaderDirectory>().FirstOrDefault()
 18136            ?.GetString(QuickTimeMetadataHeaderDirectory.TagGpsLocation);
 18137        if (raw is null)
 16538            return (null, null);
 1639        if (Iso6709().Match(raw) is not { Success: true } match)
 1140        {
 1141            Log.Iso6709ParseFailed(logger, raw);
 1142            return (null, null);
 43        }
 44
 545        return (Degrees(match.Groups["latitude"].Value), Degrees(match.Groups["longitude"].Value));
 18146    }
 47
 1048    private static double Degrees(string value) => double.Parse(value, NumberStyles.AllowLeadingSign | NumberStyles.Allo
 49
 50    [GeneratedRegex(@"^(?<latitude>[+-]\d{2}(\.\d+)?)(?<longitude>[+-]\d{3}(\.\d+)?)([+-]\d+(\.\d+)?)?/$", RegexOptions.
 51    private static partial Regex Iso6709();
 52
 53    private static partial class Log
 54    {
 55        [LoggerMessage(Level = LogLevel.Debug, Message = "Failed to parse GPS coordinates from EXIF data.")]
 56        public static partial void GpsCoordinatesParseFailed(ILogger logger, Exception exception);
 57
 58        [LoggerMessage(Level = LogLevel.Debug, Message = "No position: malformed ISO 6709 location '{Raw}'.")]
 59        public static partial void Iso6709ParseFailed(ILogger logger, string raw);
 60    }
 61}