def start_cooldown(self, sid, cool_time = False): if sid == 0: return if cool_time: pass elif self.data['cool_override']: cool_time = self.data['cool_override'] else: cool_rating = self.rating_precise if not cool_rating or cool_rating == 0: cool_rating = 3 # AlbumCD = minAlbumCD + ((maxAlbumR - albumR)/(maxAlbumR - minAlbumR)*(maxAlbumCD - minAlbumCD)) # old: auto_cool = cooldown.cooldown_config[sid]['min_album_cool'] + (((4 - (cool_rating - 1)) / 4.0) * (cooldown.cooldown_config[sid]['max_album_cool'] - cooldown.cooldown_config[sid]['min_album_cool'])) auto_cool = cooldown.cooldown_config[sid]['min_album_cool'] + (((5 - cool_rating) / 4.0) * (cooldown.cooldown_config[sid]['max_album_cool'] - cooldown.cooldown_config[sid]['min_album_cool'])) album_song_count = self.get_num_songs(sid) log.debug("cooldown", "min_album_cool: %s .. max_album_cool: %s .. auto_cool: %s .. album_song_count: %s .. rating: %s" % (cooldown.cooldown_config[sid]['min_album_cool'], cooldown.cooldown_config[sid]['max_album_cool'], auto_cool, album_song_count, cool_rating)) cool_size_multiplier = config.get_station(sid, "cooldown_size_min_multiplier") + (config.get_station(sid, "cooldown_size_max_multiplier") - config.get_station(sid, "cooldown_size_min_multiplier")) / (1 + math.pow(2.7183, (config.get_station(sid, "cooldown_size_slope") * (album_song_count - config.get_station(sid, "cooldown_size_slope_start")))) / 2) cool_age_multiplier = cooldown.get_age_cooldown_multiplier(self.data['added_on']) cool_time = int(auto_cool * cool_size_multiplier * cool_age_multiplier * self.data['cool_multiply']) log.debug("cooldown", "auto_cool: %s .. cool_size_multiplier: %s .. cool_age_multiplier: %s .. cool_multiply: %s .. cool_time: %s" % (auto_cool, cool_size_multiplier, cool_age_multiplier, self.data['cool_multiply'], cool_time)) updated_album_ids[sid][self.id] = True log.debug("cooldown", "Album ID %s Station ID %s cool_time period: %s" % (self.id, sid, cool_time)) return self._start_cooldown_db(sid, cool_time)
def start_cooldown(self, sid): """ Calculates cooldown based on jfinalfunk's crazy algorithms. Cooldown may be overriden by song_cool_* rules found in database. Cooldown is only applied if the song exists on the given station """ if (self.sid != sid) or (not self.sid in self.data["sids"]) or sid == 0: return for metadata in self.groups: log.debug("song_cooldown", "Starting group cooldown on group %s" % metadata.id) metadata.start_cooldown(sid) # Albums always have to go last since album records in the DB store cached cooldown values for metadata in self.albums: log.debug("song_cooldown", "Starting album cooldown on album %s" % metadata.id) metadata.start_cooldown(sid) cool_time = cooldown.cooldown_config[sid]["max_song_cool"] if self.data["cool_override"]: cool_time = self.data["cool_override"] else: cool_rating = self.data["rating"] # If no rating exists, give it a middle rating if not self.data["rating"] or self.data["rating"] == 0: cool_rating = cooldown.cooldown_config[sid]["base_rating"] auto_cool = cooldown.cooldown_config[sid]["min_song_cool"] + ( ((4 - (cool_rating - 1)) / 4.0) * (cooldown.cooldown_config[sid]["max_song_cool"] - cooldown.cooldown_config[sid]["min_song_cool"])) cool_time = (auto_cool * cooldown.get_age_cooldown_multiplier( self.data["added_on"]) * self.data["cool_multiply"]) log.debug( "cooldown", "Song ID %s Station ID %s cool_time period: %s" % (self.id, sid, cool_time), ) cool_time = int(cool_time + timestamp()) db.c.update( "UPDATE r4_song_sid SET song_cool = TRUE, song_cool_end = %s WHERE song_id = %s AND sid = %s AND song_cool_end < %s", (cool_time, self.id, sid, cool_time), ) self.data["cool"] = True self.data["cool_end"] = cool_time # if 'request_only_end' in self.data and self.data['request_only_end'] != None: self.data[ "request_only_end"] = self.data["cool_end"] + config.get_station( sid, "cooldown_request_only_period") self.data["request_only"] = True db.c.update( "UPDATE r4_song_sid SET song_request_only = TRUE, song_request_only_end = %s WHERE song_id = %s AND sid = %s AND song_request_only_end IS NOT NULL", (self.data["request_only_end"], self.id, sid), )
def start_cooldown(self, sid): """ Calculates cooldown based on jfinalfunk's crazy algorithms. Cooldown may be overriden by song_cool_* rules found in database. Cooldown is only applied if the song exists on the given station """ if (self.sid != sid) or (not self.sid in self.data['sids']) or sid == 0: return for metadata in self.groups: log.debug("song_cooldown", "Starting group cooldown on group %s" % metadata.id) metadata.start_cooldown(sid) # Albums always have to go last since album records in the DB store cached cooldown values for metadata in self.albums: log.debug("song_cooldown", "Starting album cooldown on album %s" % metadata.id) metadata.start_cooldown(sid) cool_time = cooldown.cooldown_config[sid]['max_song_cool'] if self.data['cool_override']: cool_time = self.data['cool_override'] else: cool_rating = self.data['rating'] # If no rating exists, give it a middle rating if not self.data['rating'] or self.data['rating'] == 0: cool_rating = cooldown.cooldown_config[sid]['base_rating'] auto_cool = cooldown.cooldown_config[sid]['min_song_cool'] + (((4 - (cool_rating - 1)) / 4.0) * (cooldown.cooldown_config[sid]['max_song_cool'] - cooldown.cooldown_config[sid]['min_song_cool'])) cool_time = auto_cool * cooldown.get_age_cooldown_multiplier(self.data['added_on']) * self.data['cool_multiply'] log.debug("cooldown", "Song ID %s Station ID %s cool_time period: %s" % (self.id, sid, cool_time)) cool_time = int(cool_time + timestamp()) db.c.update("UPDATE r4_song_sid SET song_cool = TRUE, song_cool_end = %s WHERE song_id = %s AND sid = %s AND song_cool_end < %s", (cool_time, self.id, sid, cool_time)) self.data['cool'] = True self.data['cool_end'] = cool_time if 'request_only_end' in self.data and self.data['request_only_end'] != None: self.data['request_only_end'] = self.data['cool_end'] + config.get_station(sid, "cooldown_request_only_period") self.data['request_only'] = True db.c.update("UPDATE r4_song_sid SET song_request_only = TRUE, song_request_only_end = %s WHERE song_id = %s AND sid = %s AND song_request_only_end IS NOT NULL", (self.data['request_only_end'], self.id, sid))