class 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 public  BeatLoopAltTimeseriesClassifier(IAnalyticsHorizontalDal analyticsHorizontalDal);

}