@Test public void calculateRatingUnigramShouldBe1() { mockDal = Mockito.mock(IAnalyticsHorizontalDal.class); AnalyticsHorizontal analyticsHorizontal = new AnalyticsHorizontal(); analyticsHorizontal.setId(1); analyticsHorizontal.setRating(2); CompositionTimeSlot TS1 = new CompositionTimeSlot(){{setBeatLoopAltId(2);}}; TS1.setId(1); CompositionTimeSlot TS2 = new CompositionTimeSlot(){{setBeatLoopAltId(3);}}; TS2.setId(2); CompositionTimeSlot TS3 = new CompositionTimeSlot(){{setBeatLoopAltId(4);}}; TS3.setId(3); CompositionTimeSlot TS4 = new CompositionTimeSlot(){{setBeatLoopAltId(4);}}; TS4.setId(4); List<CompositionTimeSlot> timeSlots = new ArrayList<>(); timeSlots.add(TS1); timeSlots.add(TS2); timeSlots.add(TS3); timeSlots.add(TS4); analyticsHorizontal.setComposition_time_slots(timeSlots); List<AnalyticsHorizontal> mockList = new ArrayList<>(); mockList.add(analyticsHorizontal); Iterable<AnalyticsHorizontal> mockIterable = mockList; Mockito.when(mockDal.findAll()).thenReturn(mockIterable); beatLoopAltTimeseriesClassifier = new BeatLoopAltTimeseriesClassifier(mockDal); BeatLoop pbWeightable = new BeatLoop(); pbWeightable.setId(3); ProgressionUnitBar pbCurrent = new ProgressionUnitBar(); pbCurrent.setBeatLoopAlt(new BeatLoop(){{setId(3);}}); ProgressionUnitBar pbPrior = new ProgressionUnitBar(); pbPrior.setBeatLoopAlt(new BeatLoop(){{setId(2);}}); ProgressionUnitBar pbTwoPrior = null; int rating = beatLoopAltTimeseriesClassifier.calculateRating(pbWeightable, pbCurrent, pbPrior, pbTwoPrior, mockIterable); Assert.assertEquals(1, rating); }
@Override public int calculateRating(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals) { int rating = 0; for(AnalyticsHorizontal analyticsHorizontal : analyticsHorizontals){ boolean hasBigram = false; for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 1 && bigramIsNotNull(oneBarPrior, secondBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId()) && secondBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-2).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementBigramRating(analyticsHorizontal.getRating(), rating); hasBigram = true; } } } if(!hasBigram){ for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 0 && unigramIsNotNull(oneBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementUnigramRating(analyticsHorizontal.getRating(), rating); } } } } } return rating; }
BeatLoopAltTimeseriesClassifier implements IBeatSequenceClassifier { @Override public int calculateRating(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals) { int rating = 0; for(AnalyticsHorizontal analyticsHorizontal : analyticsHorizontals){ boolean hasBigram = false; for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 1 && bigramIsNotNull(oneBarPrior, secondBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId()) && secondBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-2).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementBigramRating(analyticsHorizontal.getRating(), rating); hasBigram = true; } } } if(!hasBigram){ for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 0 && unigramIsNotNull(oneBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementUnigramRating(analyticsHorizontal.getRating(), rating); } } } } } return rating; } }
BeatLoopAltTimeseriesClassifier implements IBeatSequenceClassifier { @Override public int calculateRating(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals) { int rating = 0; for(AnalyticsHorizontal analyticsHorizontal : analyticsHorizontals){ boolean hasBigram = false; for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 1 && bigramIsNotNull(oneBarPrior, secondBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId()) && secondBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-2).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementBigramRating(analyticsHorizontal.getRating(), rating); hasBigram = true; } } } if(!hasBigram){ for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 0 && unigramIsNotNull(oneBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementUnigramRating(analyticsHorizontal.getRating(), rating); } } } } } return rating; } @Autowired  BeatLoopAltTimeseriesClassifier(IAnalyticsHorizontalDal analyticsHorizontalDal); }
BeatLoopAltTimeseriesClassifier implements IBeatSequenceClassifier { @Override public int calculateRating(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals) { int rating = 0; for(AnalyticsHorizontal analyticsHorizontal : analyticsHorizontals){ boolean hasBigram = false; for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 1 && bigramIsNotNull(oneBarPrior, secondBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId()) && secondBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-2).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementBigramRating(analyticsHorizontal.getRating(), rating); hasBigram = true; } } } if(!hasBigram){ for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 0 && unigramIsNotNull(oneBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementUnigramRating(analyticsHorizontal.getRating(), rating); } } } } } return rating; } @Autowired  BeatLoopAltTimeseriesClassifier(IAnalyticsHorizontalDal analyticsHorizontalDal); @Override WeightClass classify(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals); @Override int calculateRating(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals); }
BeatLoopAltTimeseriesClassifier implements IBeatSequenceClassifier { @Override public int calculateRating(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals) { int rating = 0; for(AnalyticsHorizontal analyticsHorizontal : analyticsHorizontals){ boolean hasBigram = false; for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 1 && bigramIsNotNull(oneBarPrior, secondBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId()) && secondBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-2).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementBigramRating(analyticsHorizontal.getRating(), rating); hasBigram = true; } } } if(!hasBigram){ for(Integer i=0; i<analyticsHorizontal.getComposition_time_slots().size(); i++){ if(i > 0 && unigramIsNotNull(oneBarPrior, analyticsHorizontal, i)){ if(weightable.getId().equals(analyticsHorizontal.getComposition_time_slots().get(i).getBeatLoopAltId()) && oneBarPrior.getBeatLoopAlt().getId().equals(analyticsHorizontal.getComposition_time_slots().get(i-1).getBeatLoopAltId())){ rating = SequenceClassiferUtils.incrementUnigramRating(analyticsHorizontal.getRating(), rating); } } } } } return rating; } @Autowired  BeatLoopAltTimeseriesClassifier(IAnalyticsHorizontalDal analyticsHorizontalDal); @Override WeightClass classify(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals); @Override int calculateRating(IWeightable weightable, ProgressionUnitBar currentBar, ProgressionUnitBar oneBarPrior, ProgressionUnitBar secondBarPrior, Iterable<AnalyticsHorizontal> analyticsHorizontals);  }