why i get this error :
/root/Env/imdb/lib/python3.8/site-packages/scipy/stats/_continuous_distns.py:411: RuntimeWarning: Mean of empty slice.
loc = data.mean()
/root/Env/imdb/lib/python3.8/site-packages/numpy/core/_methods.py:192: RuntimeWarning: invalid value encountered in scalar divide
ret = ret.dtype.type(ret / rcount)
/root/Env/imdb/lib/python3.8/site-packages/scipy/stats/_continuous_distns.py:416: RuntimeWarning: Mean of empty slice.
scale = np.sqrt(((data - loc)**2).mean())
here is my code :
def calculate_3month_priority():
try:

Define the time periods in months
ini
Copy
movies = get_movies_within_3month()

ini
Copy
# Define the boxes for the priority scores
boxes = np.linspace(-3, 3, 7)[1:-1]

# Get the current date

# Iterate over the time periods

# Calculate the watch counts for the current time period
watch_counts = [movie.engagementStatistics for movie in movies]

# Check if there are no movies for the current time period


# Fit a normal distribution to the watch counts
mean, std_dev = norm.fit(watch_counts)

# Normalize the watch counts using the normal distribution
normalized_watch_counts = [(count - mean) / std_dev for count in watch_counts]

# Divide the normalized watch counts into boxes
box_indices = np.digitize(normalized_watch_counts, boxes, right=True)

# Sort the movies by priority score in descending order (highest to lowest)
sorted_movies = sorted(zip(movies, normalized_watch_counts, box_indices), key=lambda x: (x[2], x[1]), reverse=True)




# Iterate over the sorted movies and write them to the worksheet
for j, (movie, priority, box_index) in enumerate(sorted_movies, start=2):
    # Write the movie title, priority, and box index to the worksheet
    # my_json = json.loads(movie.periodPriority)
    # my_json[0]['3month'] = priority
    # movie.periodPriority = json.dumps(my_json)
    # movie.ThreeMonthPriority = priority
    # movie.save()
    logger.debug(f'title is {movie.title}--{priority}')
    logger.debug('movie saved')
except Exception as e :
logger.debug(f'error is : {e}')
and here is my mode :
class Film(models.Model):
id = models.AutoField(primary_key=True, verbose_name='id')
title = models.CharField(max_length=150, db_index=True, blank=True, verbose_name='title')
type = models.IntegerField(choices=((1, 'movies'), (2, 'series')), verbose_name='type')
ageClassification = models.CharField(max_length=150, db_index=True, verbose_name='ageClassification',null=True)
runtime = models.CharField(max_length=150, db_index=True, verbose_name='runtime')
featureYear = models.IntegerField(blank=True,null=True)
description = HTMLField(blank=True, verbose_name='description',null=True)
keyWordUrl = models.URLField(blank=True, verbose_name='keyWordLink',null=True)
storyLineUrl = models.URLField(blank=True, verbose_name='storyLineLink',null=True)
newsUrl = models.URLField(blank=True, verbose_name='newsLink',null=True)
criticUrl = models.URLField(blank=True, verbose_name='criticLink',null=True)
storyline= HTMLField(blank=True, verbose_name='storyline',null=True)
sysnopse= HTMLField(blank=True, verbose_name='synopse',null=True)
imdbScoreRate = models.FloatField(null=True, blank=True, verbose_name="imdbScore")
MetaScoreRate = models.FloatField(null=True, blank=True, verbose_name="metaScore")
imdbLink = models.URLField(verbose_name='ImdbLink',unique=True)
productionStatus = models.CharField(max_length=200, blank=True,null=True, verbose_name='productionStatus')
numVotes = models.FloatField(null=True, blank=True, verbose_name="numVotes")
stars = models.CharField(max_length=250, blank=True,null=True)
writers = models.CharField(max_length=250, blank=True,null=True)
directors = models.CharField(max_length=250, blank=True,null=True)
releaseDate = models.DateField(blank=True, null=True)
artists = models.ManyToManyField(Artist, related_name='artists', through='Role', blank=True, verbose_name='artists',null=True)
engagementStatistics = models.IntegerField(blank=True, verbose_name='engagementStatistics',null=True)
genre = models.JSONField(blank=True,null=True)
boxOffice = models.JSONField(blank=True,null=True)
company = models.JSONField(blank=True,null=True)
cast = models.JSONField(blank=True,null=True)
relatedReviews = models.ManyToManyField(Reviews,through='FilmReviews', related_name='reviews',blank=True,verbose_name='reviews')
relatedReviewsJson = models.JSONField(blank=True,null=True)
relatedNewsJson = models.JSONField(blank=True,null=True)
relatedNews = models.ManyToManyField(News,through='FilmNews',related_name='news',blank=True, verbose_name='news' )
pubDate = models.DateTimeField('date published', auto_now_add=True, db_index=True)
periodPriority = models.JSONField(blank=True,null=True)
ThreeMonthPriority = models.FloatField(null=True, blank=True)
SixMonthPriority = models.FloatField(null=True, blank=True)
FarMonthPriority = models.FloatField(null=True, blank=True)
priorityMaxEngCompany = models.FloatField(null=True, blank=True)
priorityMaxMovieActor = models.FloatField(null=True, blank=True)
priorityMaxMovieDirecotr = models.FloatField(null=True, blank=True)
priorityMeta = models.FloatField(null=True, blank=True)
priority_meta_group = models.CharField(max_length=20, blank=True, null=True)
modifyDate = models.DateTimeField(auto_now=True, db_index=True)
InYearPriority = models.FloatField(null=True, blank=True)