Пример #1
0
        public void QueryIsBuiltFromFileCorrectly()
        {
            const string PathToFile  = "path-to-file";
            QueryResult  dummyResult = new QueryResult {
                ResultEntries = new List <ResultEntry> {
                    new ResultEntry()
                }
            };
            List <HashedFingerprint> hashedFingerprints =
                new List <HashedFingerprint>(
                    new[]
            {
                new HashedFingerprint(GenericSignature, GenericHashBuckets, 0, 0),
                new HashedFingerprint(GenericSignature, GenericHashBuckets, 1, 0.928),
                new HashedFingerprint(GenericSignature, GenericHashBuckets, 2, 0.928 * 2)
            });

            fingerprintCommandBuilder.Setup(builder => builder.BuildFingerprintCommand()).Returns(fingerprintingSource.Object);
            fingerprintingSource.Setup(source => source.From(PathToFile)).Returns(withAlgorithConfiguration.Object);
            withAlgorithConfiguration.Setup(config => config.WithFingerprintConfig(It.IsAny <EfficientFingerprintConfigurationForQuerying>())).Returns(usingFingerprintServices.Object);
            usingFingerprintServices.Setup(u => u.UsingServices(audioService.Object)).Returns(fingerprintCommand.Object);
            fingerprintCommand.Setup(command => command.Hash()).Returns(Task.Factory.StartNew(() => hashedFingerprints));
            queryFingerprintService.Setup(service => service.Query(modelService.Object, hashedFingerprints, It.IsAny <DefaultQueryConfiguration>())).Returns(dummyResult);

            QueryResult queryResult = queryCommandBuilder.BuildQueryCommand()
                                      .From(PathToFile)
                                      .UsingServices(modelService.Object, audioService.Object)
                                      .Query()
                                      .Result;

            Assert.AreSame(dummyResult, queryResult);
        }
Пример #2
0
        public void QueryIsBuiltFromFileCorrectly()
        {
            const string PathToFile  = "path-to-file";
            QueryResult  dummyResult = new QueryResult {
                IsSuccessful = true, ResultEntries = It.IsAny <List <ResultEntry> >()
            };
            List <HashData> hashDatas = new List <HashData>(new[] { new HashData(GenericSignature, GenericHashBuckets), new HashData(GenericSignature, GenericHashBuckets), new HashData(GenericSignature, GenericHashBuckets) });

            fingerprintCommandBuilder.Setup(builder => builder.BuildFingerprintCommand()).Returns(fingerprintingSource.Object);
            fingerprintingSource.Setup(source => source.From(PathToFile)).Returns(withAlgorithConfiguration.Object);
            withAlgorithConfiguration.Setup(config => config.WithFingerprintConfig(It.IsAny <DefaultFingerprintConfiguration>())).Returns(fingerprintCommand.Object);
            fingerprintCommand.Setup(command => command.Hash()).Returns(Task.Factory.StartNew(() => hashDatas));
            queryFingerprintService.Setup(service => service.Query(hashDatas, It.IsAny <DefaultQueryConfiguration>())).Returns(dummyResult);

            QueryResult queryResult = queryCommandBuilder.BuildQueryCommand()
                                      .From(PathToFile)
                                      .WithDefaultConfigs()
                                      .Query()
                                      .Result;

            Assert.AreEqual(dummyResult, queryResult);
        }
Пример #3
0
        public async Task QueryIsBuiltFromFileCorrectly()
        {
            const string pathToFile         = "path-to-file";
            var          dummyResult        = new QueryResult(new List <ResultEntry>(), Hashes.GetEmpty(MediaType.Audio), new QueryStats(0, 0, 0, 0));
            var          hashedFingerprints = new Hashes(new List <HashedFingerprint>(
                                                             new[]
            {
                new HashedFingerprint(GenericHashBuckets(), 0, 0, Array.Empty <byte>()),
                new HashedFingerprint(GenericHashBuckets(), 1, 0.928f, Array.Empty <byte>()),
                new HashedFingerprint(GenericHashBuckets(), 2, 0.928f * 2, Array.Empty <byte>())
            }), 0.928 * 3, MediaType.Audio, DateTime.Now, Enumerable.Empty <string>());

            fingerprintCommandBuilder.Setup(builder => builder.BuildFingerprintCommand()).Returns(fingerprintingSource.Object);
            fingerprintingSource.Setup(source => source.From(pathToFile)).Returns(withAlgorithmConfiguration.Object);
            withAlgorithmConfiguration.Setup(config => config.WithFingerprintConfig(It.IsAny <DefaultFingerprintConfiguration>())).Returns(usingFingerprintServices.Object);
            usingFingerprintServices.Setup(u => u.UsingServices(audioService.Object)).Returns(fingerprintCommand.Object);
            fingerprintCommand.Setup(command => command.Hash()).Returns(Task.Factory.StartNew(() => hashedFingerprints));
            queryFingerprintService.Setup(service => service.Query(hashedFingerprints, It.IsAny <DefaultQueryConfiguration>(), modelService.Object)).Returns(dummyResult);

            _ = await queryCommandBuilder.BuildQueryCommand()
                .From(pathToFile)
                .UsingServices(modelService.Object, audioService.Object)
                .Query();
        }
        public void ShouldFingerprintAndQuerySuccessfully()
        {
            var modelService = new InMemoryModelService();

            for (int i = 0; i < 30; ++i)
            {
                var samples = new AudioSamples(GetRandomSamples(120), "${i}", 5512);
                var hashes  = fcb.BuildFingerprintCommand()
                              .From(samples)
                              .UsingServices(audioService)
                              .Hash()
                              .Result;
                var track          = new TrackData("${i}", "", "", "", 2017, 120);
                var trackReference = modelService.InsertTrack(track);
                modelService.InsertHashDataForTrack(hashes, trackReference);
            }

            Console.WriteLine("Fingerprinting Time, Query Time, Candidates Found");
            double avgFingerprinting = 0, avgQuery = 0;
            int    totalRuns = 10;

            for (int i = 0; i < totalRuns; ++i)
            {
                var samples     = new AudioSamples(GetRandomSamples(120), "${i}", 5512);
                var queryResult = qcb.BuildQueryCommand()
                                  .From(samples)
                                  .UsingServices(modelService, this.audioService)
                                  .Query()
                                  .Result;

                Console.WriteLine("{0,10}ms{1,15}ms{2,15}", queryResult.Stats.FingerprintingDuration, queryResult.Stats.QueryDuration, queryResult.Stats.TotalFingerprintsAnalyzed);
                avgFingerprinting += queryResult.Stats.FingerprintingDuration;
                avgQuery          += queryResult.Stats.QueryDuration;
            }

            Console.WriteLine("Avg. Fingerprinting: {0,0:000}ms, Avg. Query: {1, 0:000}ms", avgFingerprinting / totalRuns, avgQuery / totalRuns);
        }