How star ratings system works? - javascript

What I want is to know how star ratings works. I don't get the logic of it.
Example:
5 star - 300 people
4 star - 45 people
3 star - 100 people
2 star - 99 people
1 star - 10 people
Total of 554 people
I want to convert these number of votes to percentage and compute all of it to get its average
5 star - 40% (300 people)
4 star - 10% (45 people)
3 star - 21% (100 people)
2 star - 20 % (99 people)
1 star - 9% (10 people)
a total of 100%
It's just a random percentage. It's not the correct answer.
How can I achieve that ? I don't think if that's the correct process of ratings.

I am confused s to what the question is?
But first some math:
5 star - 300 people
4 star - 45 people
3 star - 100 people
2 star - 99 people
1 star - 10 people
Total of 554 people
We can easily calculate the vote distribution in percent for stars, lets check units:
[count of people]/[total of people] => ratio of people
ratio of x * 100 => % of x
i.e:
(300/554) * 100 = 54.1516245487 % of people
and compute for all
5 star - 300 people - 54.15 % of votes
4 star - 45 people - 8.12 % of votes
3 star - 100 people - 18.05 % of votes
2 star - 99 people - 17.87 % of votes
1 star - 10 people - 1.80 % of votes
error due to round off: 100 - (sum(%) = 99.99) = 0.01 so its ok to round of
however this is not what the figures you came with looks like.
This is probably because the code you are using, is not showing the percent of people who voted for something, but instead it shows an estimate of how the votes should be distributed, and not how they are.
Many rating systems actually count votes with different weights, depending on either the existing distribution, or to equate votes across cultures.
I am Danish, so I'll use that culture of reference, for the example.
Take for instance Rural Denmark.
In this culture, no one actually uses rates 5 or 1, unless the thing thats being rated is very extremely extraordinary bad or good.
In fact it is also more likely to get a 1 than a 5.
- but if you get a 2 or 4, it is not "close to 3" it is in fact really bad or really good..
In the Urban Denmark you get more exited, and easily vote 5 for something that is basivly a mediocre performance. Also 1 for something just because you had a bad day.
So for an ordinary but good show, (should rate mean 4) this would be the two distributions:
Rural:
5 stars - 1 people
4 stars - 3 people
3 stars - 10 people
2 stars - 5 people
1 stars - 1 people.
Urban:
5 stars - 4 people
4 stars - 5 people
3 stars - 5 people
2 stars - 3 people
1 stars - 3 people.
notice the cultural difference clearly shown in these made up results..
I am not making this up its called response styles, you may want to read this:
http://www.harzing.com/download/respstyles.pdf
So the developer needs to consider which response style the ratings should compensate for.
I could easily weigh the Rural votes, and let the 1 person who dared to press 5 stars, get extra weight in the votes, and also give the people that voted 3 stars, get less wieght. This would make the two results look more alike, and make it easier for an urban dweller to compare the results.
But is that actually correct. ? (to choose urban votes as the norm, and modify the others to fit) would the opposite argument be just as good?
weigh 5 and 1 less in the urban votes, and 3 more, to make it look more comparable for the rural population?
--
in your case it seems that the results carry weights
we cannot see how the weights have been found, but we can deduct something from them.
weights:
5 star - 40% / 54.15% ~= 0.74
4 star - 10% / 8.12% ~= 1.21
3 star - 21% / 18.05% ~= 1.16
2 star - 20% / 17.87% ~= 1.18
1 star - 9% / 1.8% ~= 5
so in this case a negative vote is valued with a high weight, and a positive vote, is given less wight.
I would have expected that the sum of the weights would equal 1, but they are not, so this could be the result of manually fine tuning the results of ratings, to some desired distribution (commercial interests), or perhaps a miscalculation on your part.

Just some basic math.
Sum: 300 + 45 + 100 + 99 + 10 = 554 Votes
Percentage by rating:
5 Star: (300/554) * 100 = 54,15162455%
4 Star: (45/554) * 100 = 8,122743682%
3 Star: (100/554) * 100 = 18,05054152%
2 Star: (99/554) * 100 = 17,8700361%
1 Star: (10/554) * 100 = 1,805054152%
Average:
(5*300) + (4*45) + (3*100) + (2*99) + (1*10) = 2188
2118 / 554 = 3,949458484 stars

First of all get total no of people vote.
and use this function to show percentage.
star percentage = star total people vote * 100 / total no of people vote.
for example if you want to get 5 star rate percentage then
5 star percentage = 300 * 100 / 554

Related

Getting original value back after percentage increase?

I am a store owner.
The bank deducts 10%
How can I set my prices to be 10% extra.
e.g
Product costs $34
Add 10% and send $37.40 to the bank, then bank deducts 10% of $37.40, leaving the store with only $33.70, while 10% deduction should leave the store with $34
How much additional to add to the $34 so that the deduction leaves $34.
The best I can do is
34 + 10% = result
result + 1% = value to send to bank
value send to bank - 10% and roundup = 34
Needing commonly used formula.
Thanks in advance
Take the current price and divide it by (100 - bank percent) then multiple all by 100.
so you have $34.00 and you say this is reduced by 10%, but you want the final dollar value you get to be $34.00. So what is the starting price if you know the bank takes 10%.
origPrice = (34.00/(100-10)) * 100 = 37.78
So if you set the price at $37.78 and the bank takes 10%, you should have $34.00 deposited to the good.
Another good example on how to think of it, is this youtube video:
https://www.youtube.com/watch?v=SUxPEApSJ7U&t=1s
Use this:
bank price = intial price * 1.12
Example
37.74 = 34 * 1.12
I suggest adding 12% to the price

Why does this code run into an infinite loop in JS?

I am trying out Advent Of Code 2021, A bunch of challenges in coding basically.
On Day 3 2021 Part 2, I run into a problem with recursion and loop-based code.
Here is the JS code:
let input = `00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010`
let numbers = input.split("\n")
let onBits = []
let offBits = []
for (let i = 0; i < numbers[0].length; i++) {
if (numbers.length == 1) {
console.log(numbers[0])
break;
}
for (let j = 0; j < numbers.length; j++) {
let bit = parseInt(numbers[j].split("")[i])
if (bit == 1) {
onBits.push(numbers[j])
} else if (bit == 0) {
offBits.push(numbers[j])
}
}
if (onBits.length > offBits.length) {
numbers = onBits
console.log(`${onBits.length} > ${offBits.length}`)
} else if (onBits.length == offBits.length) {
numbers = onBits
console.log(`${onBits.length} == ${offBits.length} so OnBits.`)
} else if (onBits.length < offBits.length) {
numbers = offBits
console.log(`${onBits.length} < ${offBits.length}`)
}
}
I am basically getting the input and splitting it, Then I get the most common first bit and get every number that has that as their first bit.
So, for example,
The first common bit is 1, that means the numbers array will become an array that has every number that has 1 as their first bit.
And then I loop this with the resulted array until I get one specified number.
But, for some reason this goes into an infinite loop?
The offBits apparently increase rapidly with no reason into an infinite loop.
Any help is appreciated.
In this case, I am trying to find the oxygen generator rating.
Sorry for making this complicated.
Full problem (part 1, part 2)
--- Day 3: Binary Diagnostic ---
The submarine has been making some odd creaking noises, so you ask it to produce a diagnostic report just in case.
The diagnostic report (your puzzle input) consists of a list of binary numbers which, when decoded properly, can tell you many useful things about the conditions of the submarine. The first parameter to check is the power consumption.
You need to use the binary numbers in the diagnostic report to generate two new binary numbers (called the gamma rate and the epsilon rate). The power consumption can then be found by multiplying the gamma rate by the epsilon rate.
Each bit in the gamma rate can be determined by finding the most common bit in the corresponding position of all numbers in the diagnostic report. For example, given the following diagnostic report:
00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010
Considering only the first bit of each number, there are five 0 bits and seven 1 bits. Since the most common bit is 1, the first bit of the gamma rate is 1.
The most common second bit of the numbers in the diagnostic report is 0, so the second bit of the gamma rate is 0.
The most common value of the third, fourth, and fifth bits are 1, 1, and 0, respectively, and so the final three bits of the gamma rate are 110.
So, the gamma rate is the binary number 10110, or 22 in decimal.
The epsilon rate is calculated in a similar way; rather than use the most common bit, the least common bit from each position is used. So, the epsilon rate is 01001, or 9 in decimal. Multiplying the gamma rate (22) by the epsilon rate (9) produces the power consumption, 198.
Use the binary numbers in your diagnostic report to calculate the gamma rate and epsilon rate, then multiply them together. What is the power consumption of the submarine? (Be sure to represent your answer in decimal, not binary.)
--- Part Two ---
Next, you should verify the life support rating, which can be determined by multiplying the oxygen generator rating by the CO2 scrubber rating.
Both the oxygen generator rating and the CO2 scrubber rating are values that can be found in your diagnostic report - finding them is the tricky part. Both values are located using a similar process that involves filtering out values until only one remains. Before searching for either rating value, start with the full list of binary numbers from your diagnostic report and consider just the first bit of those numbers. Then:
Keep only numbers selected by the bit criteria for the type of rating value for which you are searching. Discard numbers which do not match the bit criteria.
If you only have one number left, stop; this is the rating value for which you are searching.
Otherwise, repeat the process, considering the next bit to the right.
The bit criteria depends on which type of rating value you want to find:
To find oxygen generator rating, determine the most common value (0 or 1) in the current bit position, and keep only numbers with that bit in that position. If 0 and 1 are equally common, keep values with a 1 in the position being considered.
To find CO2 scrubber rating, determine the least common value (0 or 1) in the current bit position, and keep only numbers with that bit in that position. If 0 and 1 are equally common, keep values with a 0 in the position being considered.
For example, to determine the oxygen generator rating value using the same example diagnostic report from above:
Start with all 12 numbers and consider only the first bit of each number. There are more 1 bits (7) than 0 bits (5), so keep only the 7 numbers with a 1 in the first position: 11110, 10110, 10111, 10101, 11100, 10000, and 11001.
Then, consider the second bit of the 7 remaining numbers: there are more 0 bits (4) than 1 bits (3), so keep only the 4 numbers with a 0 in the second position: 10110, 10111, 10101, and 10000.
In the third position, three of the four numbers have a 1, so keep those three: 10110, 10111, and 10101.
In the fourth position, two of the three numbers have a 1, so keep those two: 10110 and 10111.
In the fifth position, there are an equal number of 0 bits and 1 bits (one each). So, to find the oxygen generator rating, keep the number with a 1 in that position: 10111.
As there is only one number left, stop; the oxygen generator rating is 10111, or 23 in decimal.
Then, to determine the CO2 scrubber rating value from the same example above:
Start again with all 12 numbers and consider only the first bit of each number. There are fewer 0 bits (5) than 1 bits (7), so keep only the 5 numbers with a 0 in the first position: 00100, 01111, 00111, 00010, and 01010.
Then, consider the second bit of the 5 remaining numbers: there are fewer 1 bits (2) than 0 bits (3), so keep only the 2 numbers with a 1 in the second position: 01111 and 01010.
In the third position, there are an equal number of 0 bits and 1 bits (one each). So, to find the CO2 scrubber rating, keep the number with a 0 in that position: 01010.
As there is only one number left, stop; the CO2 scrubber rating is 01010, or 10 in decimal.
Finally, to find the life support rating, multiply the oxygen generator rating (23) by the CO2 scrubber rating (10) to get 230.
Use the binary numbers in your diagnostic report to calculate the oxygen generator rating and CO2 scrubber rating, then multiply them together. What is the life support rating of the submarine? (Be sure to represent your answer in decimal, not binary.)

How to make optimal decision in poker like single player card game?

I need some help to finish my app that helps to make optimal decision in card game.
Short game description:
Single player game - 1 player one deck only for himself
24 card deck, card values from 1 to 8, 3 colors of each (Red,Yellow, Blue).
At start of the game deck gets randomly shuffled then player pulls 5 cards (19 left in deck) to his hand and from this point he's allowed to:
Put away one card (this card is not in game anylonger) and take one card from top of shuffled deck for its place.
or
Can put away 3 cards that form a one of possible point granting combinations, then takes 3 cards to his hand.
Game ends when cards in deck ends and player have no more possible scoring combinations.
Goal of the game is to obtain as much points as possible.
List of variants: (called later combinations)
Three of a kind (8 possible in total):
111 - 20 points
222 - 30 points
333 - 40 points
444 - 50 points
555 - 60 points
666 - 70 points
777 - 80 points
888 - 90 points
Straight (card can have any color, 144 possible in total):
123 - 10 points
234 - 20 points
345 - 30 points
456 - 40 points
567 - 50 points
678 - 60 points
Straight flush (cards have to be in the same color, RRR/YYY/BBB, 18 possible in total):
123 - 50 points
234 - 60 points
345 - 70 points
456 - 80 points
567 - 90 points
678 - 100 points
I created the whole game logic in JS but suffer to make algoritm that will help me:
which card to put away from hand? - to get highest chance for combination
or:
which card to put away from hand?- to lose least amount of possible combinations
I don't really know which approach i should take. Or should i combine them somehow and let the formula decide? Currently I'm reading about risk reward ratio maybe thats the way to go?
I have to remember that with each card less i have less and less possible combinations (starting with 170), but sometimes its worth in later stage of the game to sacrifice cheaper combination for higher point score.
My past ways of thinking:
Calculate the probability of each possible remaining combination when putting away each card from hand.(i.e. 5 times) and decide which one is the worst.
Calculate the probability of each possible remaining combination for every 2 card subset of 5 card set in hand (so 10 times looking for 1 card to fill the combination) and decide which card from hand is the worst.
Calculate the probability of each possible remaining combination left in deck (not counting cards in hand there). 3+ moves in advance
And somehow add those three together to get optimal/close to optimal solution?
Should i add potential loss to my calculations and how to form them? If i take weak combination and later in the game i can not obtain higher ones since they are mutually exclusive.

How to find the amount of each review based on the average and total number of reviews

So I have this problem that I need to work out for work, but I can't figure out a good algorithm. I am given the average for the reviews and the number of total reviews. From those two pieces of information, I need to randomly generate how many 5 star, 4 star, 3 star, 2 star, and 1 star reviews were made. Here are two formulas that might better explain what exactly the problem is.
Given Review Average (x)
Given Total Number of Reviews (y)
Find:
a = # of 5 star reviews
b = # of 4 star reviews
c = # of 3 star reviews
d = # of 2 star reviews
e = # of 1 star reviews
a + b + c + d + e = total # of reviews (KNOWN: y)
(5*a + 4*b + 3*c + 2*d + 1*e) = total number of stars = average(x) * total reviews(y)
This is more of a type of math problem than programming, but I need to be able to write some type of algorithm to get a,b,c,d, and e programatically in JavaScript. Does anyone know of any good algorithms for something like this? Thanks!
You can get the maximum possible points total by making everything a 5-star review. You can reduce this total by one by making one of the 5-star reviews a 4-star review. You could continue reducing this by one until everything is a 4-star review. Again, reduce by one by making a 4-star review a 3-star review...
So there is a way to get every possible points total from all 5-stars to all 1-stars, and you can get some sort of answer for every possible total.
Of course, you don't need to compute this point by point. You can start your search by comparing the points total with all 5-stars, all 4-stars.. all 1-stars and find the smallest total bigger than your target. Then change just enough of whatever star you have settled on to the next smallest value to reach your exact target.
(Of course this will look a bit artificial but you couldn't be creating fake review numbers to push products on a sight because this would be false advertising and sooner or later you would get caught).

Rounding glitch in javascript, returning 4000%

I am trying to measure the percentage of the amount of enemies in a javascript game I am developing.
Math.round(10000000 / V.S * 100) / 100
This code works fine when V.S is over 1 million, however returns observed values such as 3400% when V.S is around the thousands, but this should be about 0.01%.
V.S is the amount of enemies
10 million is the amount of enemies needed to make you lose the game
I want to show the percentage between the amount currently and the amount needed to lose the game.
How can I make it show that?
V.S is the amount of enemies
10 million is the amount of enemies needed to make you lose the game
Your current code yields how many times V.S goes into 10 million
I want to show the percentage between the amount currently and the
amount needed to lose the game.
If you want to know what percentage of the 10 million has shown up:
var pctShown = V.S/100000; //or Math.round(V.S/100000) if you want only whole pcts
(note: reduction of dividing by 10,000,000 then * 100 to get a pct representation)
If you want the percent remaining, simply find the inverse:
var pctRemaining = 100 - V.S/100000; //or again Math.round(100 - V.S/100000)

Categories

Resources