Hi, e.g we have this schema:

now we have the query

```
{
# M1 -- Star Wars by its unique ID
var(func: uid(0x30d72)) {
g as genre
}
# Calculate the average rating for every movie
var(func: has(rated)) {
allmovies as rated @facets(a as rating) {
c as count(~rated)
avg as math(a / c)
}
}
# Give every movie a score
var(func: uid(allmovies)) {
x as count(genre @filter(uid(g)))
score as math(avg + x)
}
# Return the top 10 movies
fin(func: uid(score), orderdesc: val(score), first: 10) {
name
val(score)
}
}
```

can someone explain to me,

what exactly this block is doing:

```
# Calculate the average rating for every movie
var(func: has(rated)) {
allmovies as rated @facets(a as rating) {
c as count(~rated)
avg as math(a / c)
}
}
```

I of course know it calcs the average rating for every movie, but I donâ€™t understand that block exactly happens inside there

my assumption:

with `has(rated)`

we get all users that ever rated something.

then we save all movie uid within `allmovies`

for later. Question: duplicates are just overwritten, right? since some users of course rate the same movies.

Then we traverse the edge & get the facet and save the rating in the variable `a`

then we count how often the movie was rated, and save it to the variable `c`

. is that correct?

then we calc the rating of that user, e.g he rated 4 of the 5 stars and the movie has 200 ratings; then we calc 4 / 200 which is 0.002 and store that into `avg`

.

So, where exactly is the average rating for every movie calced now?

I know it has something to do with the value variables, since they get sum up in nested queries. But i dunno how that happens now. Maybe `avg`

is a sum of 0.02 + 0.02 + 0.015 + 0.01 and so on; which does not make any sense. So I have a knowledge gap in my understanding of value variables. can someone explain it to me?