def calculate_rating(rating):
    """Calculates overall rating from rating array."""
    #Uses a simple averaging formula. A refinement could be to replace this with
    #a weighted formula. For instance giving greater weight for more popular options.
    cumulative = 0
    weight = 0
    for i in range(1,6):
        cumulative += rating[i] * i
        weight += rating[i]

    if weight > 0 and cumulative > 0:
        return cumulative / weight

    return 0