1. Соблюдайте Правила форума и проявляйте уважение к другим участникам беседы.

Не работает статистика :(

Тема в разделе 'Кодинг/Собственные решения', создана пользователем DhL, 18 янв 2011.

  1. DhL Ньюфаг

    Сообщения:
    36
    Спасибы:
    0
    Привет ;)

    Переписал функцию MySQLCalculateScores() (ghostdbmysql.cpp)

    Суть кода:
    Считать score последней игры, прибавлять старый score и заносить в базу.

    Но теперь он в базу ничего не заносит, не знаю даже в чем проблема... подскажите плз :)

    Код:
    bool MySQLCalculateScores( void *conn, string *error, uint32_t botid, string formula, string mingames )
    {
    	bool Success = false;
    	
    	string SelectGames = "SELECT gameid, winner FROM dotagames WHERE winner <> 0 ORDER BY id";
    	
    	uint32_t gameid;
    	uint32_t winner;
    	string name;
    	double player_score = 0.0;
    	double old_player_score = 0.0;
    	uint32_t player_team;
    	uint32_t winner_team;
    	string server;
    	
    	if( mysql_real_query( (MYSQL *)conn, SelectGames.c_str( ), SelectGames.size( ) ) != 0 )
    		*error = mysql_error( (MYSQL *)conn );
    	else
    	{
    		Success = true;
    		MYSQL_RES *Result = mysql_store_result( (MYSQL *)conn );
    
    		if( Result )
    		{
    			vector<string> Row = MySQLFetchRow( Result );
    
    			while( Row.size( ) == 2 )
    			{
    				gameid = UTIL_ToUInt32( MySQLEscapeString( conn, Row[0] ) );
    				winner = UTIL_ToUInt32( MySQLEscapeString( conn, Row[1] ) );
    				Row = MySQLFetchRow( Result );
    				
    				string SelectByFormule = "select name,server, ((((wins-losses)/totgames)+(kills-deaths+assists/2)+(creepkills/100+creepdenies/10+neutralkills/50)+(raxkills/6)+(towerkills/11))) as totalscore from(select *, (kills/deaths) as killdeathratio, (totgames-wins) as losses from (select gp.name as name,ga.server as server,gp.gameid as gameid, gp.colour as colour, avg(dp.courierkills) as courierkills, sum(dp.raxkills) as raxkillstotal, sum(dp.towerkills) as towerkillstotal, sum(dp.assists) as assiststotal, sum(dp.courierkills) as courierkillstotal, sum(dp.creepdenies) as creepdeniestotal, sum(dp.creepkills) as creepkillstotal, sum(dp.neutralkills) as neutralkillstotal, sum(dp.deaths) as deathstotal, sum(dp.kills) as killstotal, avg(dp.raxkills) as raxkills,avg(dp.towerkills) as towerkills, avg(dp.assists) as assists, avg(dp.creepdenies) as creepdenies, avg(dp.creepkills) as creepkills,avg(dp.neutralkills) as neutralkills, avg(dp.deaths) as deaths, avg(dp.kills) as kills,count(*) as totgames, SUM(case when((dg.winner = 1 and dp.newcolour < 6) or (dg.winner = 2 and dp.newcolour > 6)) then 1 else 0 end) as wins from gameplayers as gp, dotagames as dg, games as ga,dotaplayers as dp where dg.winner <> 0 and dp.gameid = '" + UTIL_ToString( gameid ) + "' and dp.gameid = gp.gameid and dg.gameid = dp.gameid and dp.gameid = ga.id and gp.gameid = dg.gameid and gp.colour = dp.colour";
    					   SelectByFormule +=" group by gp.name having totgames >= 0) as h) as i ORDER BY totalscore desc, name asc";
    					   
    				if( mysql_real_query( (MYSQL *)conn, SelectByFormule.c_str( ), SelectByFormule.size( ) ) != 0 )
    					*error = mysql_error( (MYSQL *)conn );
    				else
    				{
    					MYSQL_RES *Result2 = mysql_store_result( (MYSQL *)conn );
    					
    					if( Result2 )
    					{
    						vector<string> Row2 = MySQLFetchRow( Result2 );
    						
    						while( Row2.size( ) == 3 )
    						{
    							name = MySQLEscapeString( conn, Row2[0] );
    							server = MySQLEscapeString( conn, Row2[1] );
    							player_score = UTIL_ToDouble( MySQLEscapeString( conn, Row2[2] ) );
    							
    							string SelectOldScore = "SELECT ss.score, gp.team FROM scores as ss, gameplayers as gp WHERE gp.name = '" + name + "'";
    							
    							if( mysql_real_query( (MYSQL *)conn, SelectOldScore.c_str( ), SelectOldScore.size( ) ) != 0 )
    								*error = mysql_error( (MYSQL *)conn );
    							else
    							{
    								MYSQL_RES *Result3 = mysql_store_result( (MYSQL *)conn );
    								
    								//if( Result3 )
    								//{
    									vector<string> Row3 = MySQLFetchRow( Result3 );
    									
    									while( Row3.size( ) == 2 )
    									{
    										old_player_score = UTIL_ToDouble( MySQLEscapeString( conn, Row3[0] ) );
    										player_team = UTIL_ToUInt32( MySQLEscapeString( conn, Row3[1] ) );
    										
    										if( winner == 1 )
    											winner_team = 0;
    										else if( winner = 2 )
    											winner_team = 1;
    										else
    											winner_team = 0;
    											
    										if( winner_team == player_team )
    										{
    											player_score += 5.0;
    										}
    										else
    										{
    											player_score += -3.0;
    										}
    										
    										if( Row3[0].empty( ) )
    										{
    											string InsertScores = "INSERT INTO scores (category, name, server, score) VALUES ('dota_elo', '" + name + "', '" + server + "', '" + UTIL_ToString( player_score ) + "')";
    											
    											if( mysql_real_query( (MYSQL *)conn, InsertScores.c_str( ), InsertScores.size ( ) ) != 0 )
    												*error = mysql_error( (MYSQL *)conn );
    										}
    										else
    										{
    											double upd_score = 0.0;
    											upd_score = player_score + old_player_score;
    											
    											string UpdateScores = "UPDATE scores SET score = '" + UTIL_ToString( upd_score ) + "' WHERE name = '" + name + "'";
    										}
    									}
    									mysql_free_result( Result3 );
    								//}
    							}
    						}
    						mysql_free_result( Result2 );
    					}
    					else
    						*error = mysql_error( (MYSQL *)conn );
    				}
    			}
    			mysql_free_result( Result );
    		}
    		else
    			*error = mysql_error( (MYSQL *)conn );
    	}
    	
    	return Success;
    }
  2. fake Старожила

    Сообщения:
    1.624
    Спасибы:
    19
    Дата начала использования бота:
    11.11.11
    почему бы тебе не изменить update_dota_elo
    можеш вообще выкинуть всю ело часть и оставить тупо прогу которая будет делать запросы в мускл...
    исходник в папке с ботом
  3. DhL Ньюфаг

    Сообщения:
    36
    Спасибы:
    0
    А что скажешь по этому коду?
    Он не работает ;(

    Да, я хотел в update_dota_elo.exe сделать.