Skip to content

Instantly share code, notes, and snippets.

@rmcauley
Created January 28, 2011 21:27
Show Gist options
  • Save rmcauley/800993 to your computer and use it in GitHub Desktop.
Save rmcauley/800993 to your computer and use it in GitHub Desktop.
for (vector<TimeReleaseOptions>::iterator i = offairoptions.begin(); i != offairoptions.end(); i++) {
if (i->maxexpiretime == -1) continue;
// get the song's category name (ie: get album if i->category is album)
if (!db.query("SELECT " + i->category + " FROM " + db.TBL_SONGS + " WHERE song_id = " + itoa(song_id))) {
log << Logger::WARN << "PlaylistControl implementOffAirTimes: Database error while attempting to select category " << i->category << " data." << endl;
break;
}
if (db.fetchRow()) {
long id = db.getLong(0);
if (id > 0) {
// get appropriate rating (ie: get rating of song's album)
double publicrating = getRating(id, i->category, mv_avg_amt);
double multiplier = 1.0;
double oaage = 1;
long override = -1;
long age = 0;
if (i->category == "album_id") age = album_age;
else if (i->category == "song_id") age = song_age;
//log << Logger::SPAM << "PlaylistControl implementOffAirTimes: Age: " << age << " / Enabled?" << i->age_enabled << endl;
if ((age > 0) && (i->age_enabled)) {
// turn the age from seconds to weeks
double agewk = age / 604800.0;
if (agewk <= i->age_s2_start) {
oaage = (agewk / i->age_s2_start) * (i->age_s2_minmulti - i->age_s1_minmulti) + i->age_s1_minmulti;
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: OAage Stage 1 in use. Age: " << agewk << " out of " << i->age_s2_start << " = " << oaage << " multiplier." << endl;
}
else if (agewk < i->age_s2_end) {
oaage = i->age_s2_minmulti + ((1.0 - i->age_s2_minmulti) * ((0.32436 - (i->age_s2_end / 288.0) + (pow(i->age_s2_end, 2.0) / 38170.0)) * loge(2.0 * agewk + 1.0)));
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: OAage Stage 2 in use. Age: " << agewk << " out of " << i->age_s2_end << " = " << oaage << " multiplier." << endl;
}
else {
oaage = 1.0;
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Age of item is too old, OAage = 1." << endl;
}
}
if (i->category == "album_id") {
double oasize = 1;
if ((album_songcount > 0) && (i->size_enabled)) {
oasize = i->size_minmulti + (i->size_maxmulti - i->size_minmulti) / (1 + pow(2.7183, (i->size_slope * (album_songcount - i->size_rampstart))) / 2);
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: OAsize calculated. Size: " << album_songcount << ", ramp start at " << i->size_rampstart << " = " << oasize << " multiplier." << endl;
}
if (album_absmulti > 0) {
multiplier = album_absmulti;
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Album absmulti " << album_absmulti << " override in use." << endl;
}
else if (oasize < oaage) {
multiplier = oasize * album_modmulti;
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Album OAsize in use: " << oasize << " * " << album_modmulti << " = " << multiplier << endl;
}
else {
multiplier = oaage * album_modmulti;
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Album OAage in use: " << oaage << " * " << album_modmulti << " = " << multiplier << endl;
}
override = album_override;
}
else if (i-> category == "song_id") {
multiplier = oaage * song_multiplier;
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Song OAage in use: " << oaage << " * " << song_multiplier << " = " << multiplier << endl;
override = song_override;
}
// calculate release time and update database
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Average rating is: " << publicrating << " for " << i->category << "." << endl;
long releasetime = calculateReleaseTime(*i, publicrating, multiplier, override);
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Off air multiplier: " << multiplier << ", override: " << override << ", final OA: " << releasetime << endl;
if (releasetime > 0) {
db.update("UPDATE " + db.TBL_SONGS + " SET song_releasetime = " + itoa(rwtime() + releasetime) + ", song_available = FALSE, song_rowupdated = " + itoa(rwtime()) + " WHERE " + i->category + " = " + itoa(id) + " AND song_releasetime <= " + itoa(rwtime() + releasetime));
}
else {
log << Logger::DEBUG << "PlaylistControl implementOffAirTimes: Release time <= 0, OA not applied." << endl;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment