add popularity lists to stats.html

This commit is contained in:
Chris Danford
2003-12-09 07:12:28 +00:00
parent 3dc08e5efe
commit d4397d4644
8 changed files with 378 additions and 246 deletions
+112 -3
View File
@@ -1468,17 +1468,126 @@ void SortSongPointerArrayByGroupAndTitle( vector<Song*> &arraySongPointers )
* it. (This could be generalized with a template.) */
map<const Song*, CString> song_sort_val;
bool CompareSongPointersBySortVal(const Song *pSong1, const Song *pSong2)
bool CompareSongPointersBySortValueAscending(const Song *pSong1, const Song *pSong2)
{
return song_sort_val[pSong1] < song_sort_val[pSong2];
}
bool CompareSongPointersBySortValueDescending(const Song *pSong1, const Song *pSong2)
{
return song_sort_val[pSong1] > song_sort_val[pSong2];
}
void SortSongPointerArrayByMostPlayed( vector<Song*> &arraySongPointers, MemoryCard card )
{
for(unsigned i = 0; i < arraySongPointers.size(); ++i)
song_sort_val[arraySongPointers[i]] = ssprintf("%9i", arraySongPointers[i]->GetNumTimesPlayed(card));
stable_sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongPointersBySortVal );
reverse( arraySongPointers.begin(), arraySongPointers.end() );
stable_sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongPointersBySortValueDescending );
song_sort_val.clear();
}
CString GetSectionNameFromSongAndSort( const Song* pSong, SongSortOrder so )
{
if( pSong == NULL )
return "";
switch( so )
{
case SORT_PREFERRED:
return "";
case SORT_GROUP:
return pSong->m_sGroupName;
case SORT_TITLE:
case SORT_ARTIST:
{
CString s;
switch( so )
{
case SORT_TITLE: s = pSong->GetTranslitMainTitle(); break;
case SORT_ARTIST: s = pSong->GetTranslitArtist(); break;
default: ASSERT(0);
}
s = MakeSortString(s); // resulting string will be uppercase
if( s.empty() )
return "";
else if( s[0] >= '0' && s[0] <= '9' )
return "NUM";
else if( s[0] < 'A' || s[0] > 'Z')
return "OTHER";
else
return s.Left(1);
}
case SORT_BPM:
{
const int iBPMGroupSize = 20;
float fMinBPM, fMaxBPM;
pSong->GetDisplayBPM( fMinBPM, fMaxBPM );
int iMaxBPM = (int)fMaxBPM;
iMaxBPM += iBPMGroupSize - (iMaxBPM%iBPMGroupSize) - 1;
return ssprintf("%03d-%03d",iMaxBPM-(iBPMGroupSize-1), iMaxBPM);
}
case SORT_MOST_PLAYED:
return "";
case SORT_GRADE:
{
for( int i=NUM_GRADES; i>GRADE_NO_DATA; i-- )
{
Grade g = (Grade)i;
int iCount = pSong->GetNumNotesWithGrade( g );
if( iCount > 0 )
return ssprintf( "%4s x %d", GradeToString(g).c_str(), iCount );
}
return "NO DATA";
}
case SORT_EASY_METER:
{
Steps* pNotes = pSong->GetStepsByDifficulty(GAMESTATE->GetCurrentStyleDef()->m_StepsType,DIFFICULTY_EASY);
if( pNotes )
return ssprintf("%02d", pNotes->GetMeter() );
return "N/A";
}
case SORT_MEDIUM_METER:
{
Steps* pNotes = pSong->GetStepsByDifficulty(GAMESTATE->GetCurrentStyleDef()->m_StepsType,DIFFICULTY_MEDIUM);
if( pNotes )
return ssprintf("%02d", pNotes->GetMeter() );
return "N/A";
}
case SORT_HARD_METER:
{
Steps* pNotes = pSong->GetStepsByDifficulty(GAMESTATE->GetCurrentStyleDef()->m_StepsType,DIFFICULTY_HARD);
if( pNotes )
return ssprintf("%02d", pNotes->GetMeter() );
return "N/A";
}
case SORT_MENU:
return "";
case SORT_ALL_COURSES:
case SORT_NONSTOP_COURSES:
case SORT_ONI_COURSES:
case SORT_ENDLESS_COURSES:
default:
ASSERT(0);
return "";
}
}
void SortSongPointerArrayBySectionName( vector<Song*> &arraySongPointers, SongSortOrder so )
{
for(unsigned i = 0; i < arraySongPointers.size(); ++i)
{
CString val = GetSectionNameFromSongAndSort( arraySongPointers[i], so );
/* Make sure NUM comes first and OTHER comes last. */
if( val == "NUM" ) val = "0";
else if( val == "OTHER" ) val = "2";
else val = "1" + val;
song_sort_val[arraySongPointers[i]] = val;
}
stable_sort( arraySongPointers.begin(), arraySongPointers.end(), CompareSongPointersBySortValueAscending );
song_sort_val.clear();
}