Calculating rating based on multiple counts

61 Views Asked by At

May be it is easy to calculate but I am stuck in this from last two days. I have web application which generates number of top brands and number of low brands. Now I want to calculate the overall rating by considering these two counts. I tried using Bayesian algorithm but it didn't fit. If I find only one top brand it gives high rating. Most of the time I end up getting either one high brand or low brand alone, which wont justify overall rating. When I get both in good number it works fine. Here is what I tried in my angular 2 code ,

        var TBS = 4;
        var LBS = 2;

        var totalTopBrands = this.totalHighBrandCount ;
        var totalLowBrands = this.totalLowBrandCount;



        // var rating = 0;
         var totalBrandCount =totalTopBrands + totalLowBrands;
        // if(totalBrandCount !== 0){
        //     rating = ((TBS * totalTopBrands) + ( LBS * totalLowBrands )) /(totalBrandCount) ;
        // }

        this.topBrandsRating = 0;
        this.lowBrandsRating = 0;
        this.overalRating = 0;
        const avg_num_votes = totalBrandCount/2;
        const avg_rating =  (TBS+LBS)/2;
        if(avg_num_votes !==0) {
            if(totalTopBrands!=0 ) {
                 this.topBrandsRating = ((avg_rating * avg_num_votes) + (totalTopBrands * TBS) ) / ((totalBrandCount/2) + totalTopBrands);
            }
            if(totalLowBrands!=0 ) {
                 this.lowBrandsRating = ((avg_rating * avg_num_votes) + (totalLowBrands * LBS) ) / ((totalBrandCount/2) + totalLowBrands);
            }
            this.overalRating = ((TBS * this.topBrandsRating) + ( LBS * this.lowBrandsRating )) /(this.lowBrandsRating+this.topBrandsRating) ;
        }

I understand my question is not that clear , please comment on this so that I can explain more about this.