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

[Как] bool MySQLCalculateScores ()

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

  1. DhL Ньюфаг

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

    ghostdbmysql.cpp
    Код:
    bool MySQLCalculateScores( void *conn, string *error, uint32_t botid, string formula, string mingames )
    {
    
         //
    
    }
    
    Как можно реализовать в данной ф-и подсчет статистики? (Формулу сделал)
    НО, как сделать чтобы отнималось\прибавлялось определенное кол-во очков за лив\дисконнект\луз\вин?

    Ну или в дота_ело реализовать формулу как в ghostdbmysql :]
    Код:
    (((wins-losses)/totgames)+(kills-deaths+assists/2)+(creepkills/100+creepdenies/10+neutralkills/50)+(raxkills/6)+(towerkills/11))
    з.ы. думаю первое будет проще :)
  2. Synth (LM) Пантограф!

    Сообщения:
    2.762
    Спасибы:
    172
    Сборка бота GHost:
    My own version of GhostOne
    Дата начала использования бота:
    15.06.2008
    Skype:
    Мой статус
    Формулу смени:

    wins*10-losess*15-disc*15

    Измени код:

    sum(dp.neutralkills) as neutralkillstotal, sum(gp.leftreason LIKE CONVERT( _utf8 '%drop%' USING latin1) and gp.leftreason LIKE CONVERT( _utf8 '%lagged%' USING latin1)) as disc, sum(dp.deaths) as deathstotal,
  3. DhL Ньюфаг

    Сообщения:
    36
    Спасибы:
    0
    Код:
    (((wins*10-losses*15-disc*15)/totgames)+(kills-deaths+assists/2)+(creepkills/100+creepdenies/10+neutralkills/50)+(raxkills/6)+(towerkills/11))
    Так что-ли ?))
  4. Synth (LM) Пантограф!

    Сообщения:
    2.762
    Спасибы:
    172
    Сборка бота GHost:
    My own version of GhostOne
    Дата начала использования бота:
    15.06.2008
    Skype:
    Мой статус
    Ну это ололо конечно будет, ибо уже стата не будет верной. Лучше просто
    Код:
    (wins*10-losses*15-disc*20)/totgames)
  5. DhL Ньюфаг

    Сообщения:
    36
    Спасибы:
    0
    Не хотелось бы менять формулу :)

    Может можно как-то по другому сделать?

    ghostdbmysql.cpp
    Код:
    Query5 = "SELECT gp.team as team, dg.winner as winner FROM gameplayers as gp, dotagames as dg WHERE gp.name = '" + names[i] + "' and gp.gameid = dg.gameid";
    		
    		if( mysql_real_query( (MYSQL *)conn, Query5.c_str( ), Query5.size( ) ) != 0 )
    			*error = mysql_error( (MYSQL *)conn );
    
    		MYSQL_RES *Result2 = mysql_store_result( (MYSQL *)conn );
    
    		vector<string> Row2 = MySQLFetchRow( Result2 );
    
    		uint32_t player_team = UTIL_ToUInt32( Row2[0] );
    		winner_team = MySQLEscapeString( conn, Row2[1] );
    
    		if( player_team == 0 )
    		{
    			player_team_won = 1;
    		}
    		else
    		{
    			player_team_won = 2;
    		}
    
    		if( player_team_won == winner_team )
    		{
    			scores[i] += 5;
    		}
    		else
    		{
    			scores[i] -= 3;
    		}
    
    Это я пытался сделать на вин\луз. Кстати, верный код?:)
  6. Synth (LM) Пантограф!

    Сообщения:
    2.762
    Спасибы:
    172
    Сборка бота GHost:
    My own version of GhostOne
    Дата начала использования бота:
    15.06.2008
    Skype:
    Мой статус
    Весь код дай.
  7. DhL Ньюфаг

    Сообщения:
    36
    Спасибы:
    0
    Код:
    bool MySQLCalculateScores( void *conn, string *error, uint32_t botid, string formula, string mingames )
    {
    	bool Success = false;
    	
    	string Query = "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 = gp.gameid and dg.gameid = dp.gameid and dp.gameid = ga.id and gp.gameid = dg.gameid and gp.colour = dp.colour";
    	Query+=" group by gp.name having totgames >= " + mingames + ") as h) as i ORDER BY totalscore desc, name asc";
    	string Query2;
    	string Query4;
    	string Query5;
    	string Query3 = "DELETE from scores";
    	string name;
    	string server;
    	double Score = -100000.0;
    	double end_scores = 0.0;
    
    	vector<string> names;
    	vector<double> scores;
    	vector<string> servers;
    
    	if( mysql_real_query( (MYSQL *)conn, Query3.c_str( ), Query3.size( ) ) != 0 )
    		*error = mysql_error( (MYSQL *)conn );
    
    	if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.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( ) == 3 )
    			{
    				names.push_back(MySQLEscapeString( conn, Row[0] ));
    				servers.push_back(MySQLEscapeString( conn, Row[1]));
    				scores.push_back(UTIL_ToDouble( Row[2] ));
    
    				Row = MySQLFetchRow( Result );
    			}
    			mysql_free_result( Result );
    		}
    		else
    			*error = mysql_error( (MYSQL *)conn );
    	}
    	if (Success)
    	for (uint32_t i = 0; i<names.size();i++)
    	{
    
    		Query5 = "SELECT gp.team as team, dg.winner as winner FROM gameplayers as gp, dotagames as dg WHERE gp.name = '" + names[i] + "' and gp.gameid = dg.gameid";
    		
    		if( mysql_real_query( (MYSQL *)conn, Query5.c_str( ), Query5.size( ) ) != 0 )
    			*error = mysql_error( (MYSQL *)conn );
    
    		MYSQL_RES *Result2 = mysql_store_result( (MYSQL *)conn );
    
    		vector<string> Row2 = MySQLFetchRow( Result2 );
    
    		uint32_t player_team = UTIL_ToUInt32( Row2[0] );
    		uint32_t winner_team = UTIL_ToUInt32( Row2[1] );
    
    		int player_team_won = 0;
    
    		if( player_team == 0 )
    		{
    			player_team_won = 1;
    		}
    		else
    		{
    			player_team_won = 2;
    		}
    
    		if( player_team_won == winner_team )
    		{
    			end_scores = scores[i] + 5.0;
    		}
    		else
    		{
    			end_scores = scores[i] - 3.0;
    		}
    
    
    	
    		if( mysql_real_query( (MYSQL *)conn, Query.c_str( ), Query.size( ) ) != 0 )
    			*error = mysql_error( (MYSQL *)conn );
    
    		MYSQL_RES *Result3 = mysql_store_result( (MYSQL *)conn );
    
    		vector<string> Row3 = MySQLFetchRow( Result3 );
    
    		Row3 = MySQLFetchRow( Result3 );
    
    		double scores_p = UTIL_ToDouble( Row3[2] );
    
    		if( Row3[2].empty( ) )
    		{
    			double scores_p = 500.0 + end_scores;
    		}
    		else
    		{
    			double scores_p = end_scores;
    		}
    	
    
    		Query2 = "INSERT into scores (category,name,server,score) VALUES ('dota_elo','"+names[i]+"','"+servers[i]+"',"+UTIL_ToString(scores_p,6)+")";
    		if( mysql_real_query( (MYSQL *)conn, Query2.c_str( ), Query2.size( ) ) != 0 )
    			*error = mysql_error( (MYSQL *)conn );
    
    	}
    	names.clear();
    	servers.clear();
    	scores.clear();
    	return Success;
    }
  8. DhL Ньюфаг

    Сообщения:
    36
    Спасибы:
    0
    Спасибо, разобрался сам.
    Код:
    Query5 = "SELECT gp.team as team, dg.winner as winner FROM gameplayers as gp, dotagames as dg WHERE gp.name = '" + names[i] + "' and gp.gameid = dg.gameid";
    		
    		if( mysql_real_query( (MYSQL *)conn, Query5.c_str( ), Query5.size( ) ) != 0 )
    			*error = mysql_error( (MYSQL *)conn );
    
    		MYSQL_RES *Result2 = mysql_store_result( (MYSQL *)conn );
    
    		vector<string> Row2 = MySQLFetchRow( Result2 );
    
    		uint32_t player_team = UTIL_ToUInt32( Row2[0] );
    		uint32_t winner_team = UTIL_ToUInt32( Row2[1] );
    
    		int player_team_won = 0;
    
    		if( player_team == 0 )
    		{
    			player_team_won = 1;
    		}
    		else
    		{
    			player_team_won = 2;
    		}
    
    		if( player_team_won == winner_team )
    		{
    			end_scores = scores[i] + 5.0;
    		}
    		else
    		{
    			end_scores = scores[i] - 3.0;
    		}
    
    		Query6 = "SELECT dg.min, dg.sec, gp.left FROM gameplayers as gp, dotagames as dp WHERE gp.name = '" + name + "' AND gp.gameid = dg.gameid";
    		
    		if( mysql_real_query( (MYSQL *)conn, Query6.c_str( ), Query6.size( ) ) != 0 )
    			*error = mysql_error( (MYSQL *)conn );
    
    		MYSQL_RES *Result4 = mysql_store_result( (MYSQL *)conn );
    
    		vector<string> Row4 = MySQLFetchRow( Result4 );
    
    		Row4 = MySQLFetchRow( Result4 );
    
    		int left_at = UTIL_ToUInt32( Row4[2] );
    		int duration_min = UTIL_ToUInt32( Row4[0] );
    		int duration_sec = UTIL_ToUInt32( Row4[1] );
    
    		int duration_is = (duration_min * 60) + duration_sec;
    
    		int check_leave = left_at / duration_is;
    
    		if( check_leave < 0.8 )
    		{
    			end_scores = end_scores - 10.0;
    		}
    
    Может не совсем "красивый" код, но работает :)

    Актуально: customization/kak-uznatx-skolxko-na-skolxko-nachalasx-igra-t1850.html