Exemplo n.º 1
0
        public static string GetClubForPlayer(long playerId, world world)
        {
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + smcSqlite;
            int    clubId = 0;

            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @"select club_id from players where player_id = " + playerId.ToString();

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        clubId = reader.GetInt32(0);
                    }
                }
            }
            if (clubId > 0)
            {
                return(world.clubs[clubId].name);
            }
            else
            {
                return("Unknown club");
            }
        }
Exemplo n.º 2
0
        // TEMPLATE
        public static string ReportTemplate(long clubId, world world)
        {
            Dictionary <int, int> result = new Dictionary <int, int>();
            StringBuilder         sb     = new StringBuilder();
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Utilities.smcSqlite;

            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @"select  
                    player_id, fitness, morale, wages, position, dob, foot, value, height, weight, country_id, club_id
                  from players as p
                    order by wages desc, club_id asc , value   ";


                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        //reader.GetInt32(0);
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 3
0
        // To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var getAgentsPlayers = GetAgentsPlayers.FromJson(jsonString);

        public static string AgentsPlayersReport(GetAgentsPlayers agentsPlayers, world world)
        {
            StringBuilder sb = new StringBuilder();

            // sb.AppendLine(agentsPlayers.Result.Data)
            bool didHeader = false;

            foreach (var player in agentsPlayers.Result.Data)
            {
                if (!didHeader)
                {
                    sb.AppendLine(player.AgentName);
                    sb.AppendLine(new String('=', player.AgentName.Length));
                    didHeader = true;
                }

                string playerName = Utilities.GetPlayerNameFromId(player.PlayerId, world);
                string clubName   = Utilities.GetClubNameFromId(player.ClubId, world);

                sb.AppendLine(string.Format(StringTemplates.AgentsPlayersReport,
                                            player.PlayerId.ToString(),
                                            playerName,
                                            player.ClubId.ToString(),
                                            clubName));
            }

            return(sb.ToString());
        }
Exemplo n.º 4
0
        public static string ClubOrderbookReport(long clubId, world world)
        {
            Dictionary <int, int> result = new Dictionary <int, int>();
            StringBuilder         sb     = new StringBuilder();
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Utilities.smcSqlite;

            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @"select * from share_orders where share_type = ""club"" order by share_id, share_type, price desc, num, name  ";

                int lastClubId = 0;

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        // result.Add(reader.GetInt32(0), reader.GetInt32(1));
                        if (lastClubId != reader.GetInt32(3))
                        {
                            // add header
                            sb.AppendLine("CLUB " + Utilities.GetClubNameFromId(reader.GetInt32(3), world));
                            sb.AppendLine("  TYPE       PRICE       SHARES NAME");
                        }
                        string type = string.Empty;
                        if (reader.GetInt32(1) == 1)
                        {
                            type = "ask";
                        }
                        else if (reader.GetInt32(1) == 0)
                        {
                            type = "bid";
                        }

                        string price = reader.GetInt32(6).ToString("N0");
                        string num   = reader.GetInt32(5).ToString("N0");
                        string name  = reader.GetString(4);

                        sb.AppendLine(
                            string.Format(
                                StringTemplates.ClubsOrderbooksRow,
                                type,
                                price,
                                num,
                                name
                                ));

                        lastClubId = reader.GetInt32(3);
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 5
0
        public static string GetPlayerNameFromId(long id, world world)
        {
            int i = Int32.Parse(id.ToString());

            try
            {
                return(world.players[i].firstname + " " + world.players[i].lastname);
            }
            catch
            {
                return("Unknown player id: " + i.ToString());
            }
        }
Exemplo n.º 6
0
        public static string GetClubNameFromId(long id, world world)
        {
            string result = string.Empty;
            int    i      = Int32.Parse(id.ToString());

            try
            {
                return(world.clubs[i].name);
            }
            catch
            {
                return("Unknown club id: " + i.ToString());
            }
        }
        // To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
        //
        //    using get_all_managers;
        //
        //    var getAllManagers = GetAllManagers.FromJson(jsonString);

        public static string ManagersListReport(GetAllManagers managers, world world)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("ALL MANAGERS");
            sb.AppendLine("============");

            foreach (var manager in managers.Result.Data)
            {
                sb.AppendLine(string.Format(StringTemplates.AllManagersReport, manager.ManagerName, manager.ClubId, Utilities.GetClubNameFromId(manager.ClubId, world)));
            }

            return(sb.ToString());
        }
        public static string UsersReport(GetAllUsers users, world world)
        {
            string result = string.Empty;

            StringBuilder sb = new StringBuilder();

            // Users is pretty boring unless we add some other information. Manager or agent would be good.

            foreach (var user in users.Result.Data)
            {
                // user.Name
            }

            return(result);
        }
        private static string GetPlayerNameFromId(long id, SMElite.world world)
        {
            int    id2    = Convert.ToInt32(id);
            string result = string.Empty;

            try
            {
                result = world.players[id2].firstname + " " + world.players[id2].lastname + " - " + id.ToString();
            }
            catch
            {
                result = "Uknown - encountered an error";
            }

            return(result);
        }
        public static string GetAllTransferHistoryReport(GetAllTransferHistory allTransferHistory, world world)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(StringTemplates.AllTransferHistoryHeader);

            foreach (var history in allTransferHistory.Result.Data)
            {
                // Set up nicely named vars to use
                string amount = Utilities.GetNiceAmount(history.Amount);
                string from   = Utilities.GetClubNameFromId(history.ClubIdFrom, world);
                string to     = Utilities.GetClubNameFromId(history.ClubIdTo, world);
                string sDate  = Utilities.GetNiceDateTime(Utilities.UnixTimeStampToDateTime((double)history.Date));
                string player = Utilities.GetPlayerNameFromId(history.PlayerId, world);

                // Add a line to the report with the string templates.
                sb.AppendLine(string.Format(StringTemplates.AllTransferHistoryRow, player, from, to, amount.ToString(), sDate));
            }

            return(sb.ToString());
        }
Exemplo n.º 11
0
        public static string ClubEconomicsReport(world world)
        {
            Dictionary <int, int> result = new Dictionary <int, int>();
            StringBuilder         sb     = new StringBuilder();
            string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Utilities.smcSqlite;

            sb.AppendLine("CLUB SHARE INFO REPORT");
            sb.AppendLine("  This report is to help you decide on what clubs you wish to purchase shares in.");
            sb.AppendLine("  50% of clubs in this report are playing 'away', so they don't have much revenue.");
            sb.AppendLine("  Those are marked with '**' in the total revenue column.");
            sb.AppendLine("  What you should pay attention to is the'HOUSE MONEY WEEKS' column.");
            sb.AppendLine("  That tells you how many weeks it takes to earn back your initial investment in weeks. ");
            sb.AppendLine("  That number is a rough estimate based on the current market. It could change radically and quickly. ");
            sb.AppendLine("");

            sb.AppendLine(
                string.Format(
                    StringTemplates.ClubEconomicsRow,
                    "CLUB",
                    "COUNTRY",
                    "BALANCE",
                    "PRICE",
                    "TV REVENUE",
                    "MANAGER SALARY",
                    "TOTAL REVENUE",
                    "DIVIDENDS",
                    "DIV PER SHARE",
                    "HOUSE MONEY WEEKS"
                    ));


            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @" select 
c.club_id, c.balance, c.value, c.manager_name, country_id, 
min(s.price) as price,  
b.tv_revenue as tv, 
(b.tv_revenue * 0.002) as manager_money,
(b.gate_receipts + b.tv_revenue + b.sponsor + merchandise) as revenue, 
(b.gate_receipts + b.tv_revenue + b.sponsor + merchandise) * 0.01 as dividend, 
(b.gate_receipts + b.tv_revenue + b.sponsor + merchandise) * 0.01 / 10000 as dividend_per_share,  
( min(s.price) / ( (b.gate_receipts + b.tv_revenue + b.sponsor + merchandise) * 0.01) * 10000  ) as housemoney

from 
clubs as c,
share_orders as s,
balance_sheets as b

where c.club_id = s.share_id and
      s.share_type = ""club"" and
      c.club_id = b.club_id and 
      s.is_ask = 1 
      -- and c.club_id = 45

group by c.club_id
order by housemoney asc , 
         manager_money desc,
         c.club_id
 ";


                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string club           = Utilities.GetClubNameFromId(reader.GetInt32(0), world);
                        string country        = reader.GetString(4);
                        int    balance        = reader.GetInt32(1);
                        int    price          = reader.GetInt32(5);
                        int    tv_revenue     = reader.GetInt32(6);
                        double manager_salary = reader.GetDouble(7);
                        int    total_revenue  = reader.GetInt32(8);
                        double dividends      = reader.GetDouble(9);
                        double div_per_share  = reader.GetDouble(10);
                        double housemoney     = reader.IsDBNull(11) ? 0 : reader.GetDouble(11);

                        string revenue_flag = tv_revenue == total_revenue ? "** " : "";

                        sb.AppendLine(
                            string.Format(
                                StringTemplates.ClubEconomicsRow,
                                club,
                                country,
                                balance.ToString("N0"),
                                price.ToString("N0"),
                                tv_revenue.ToString("N0"),
                                manager_salary.ToString("#,##0.00"),
                                revenue_flag + total_revenue.ToString("N0"),
                                dividends.ToString("#,##0.00"),
                                div_per_share.ToString("0.00"),
                                housemoney.ToString("0.00")
                                ));
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 12
0
        // find financial advice for buying players/clubs
        // sme code POPULATEtACTICS.CS =- line 1433 or so for positions


        public static string PlayerEconomicsReport(world world)
        {
            StringBuilder sb     = new StringBuilder();
            string        folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Utilities.smcSqlite;

            sb.AppendLine(
                string.Format(
                    StringTemplates.PlayerEconomicsRow,
                    "NAME",
                    "CLUB",
                    "COUNTRY",
                    "DOB",
                    "HEIGHT",
                    "WEIGHT",
                    "FOOT",
                    "POSITION",
                    "FITNESS",
                    "MORALE",
                    "WAGES",
                    "VALUE",
                    "DIVIDENDS",
                    "COMMISSIONS",
                    "PRICE",
                    "HOUSE MONEY WEEKS"
                    ));

            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @"select  
	p.player_id, p.fitness, p.morale, p.wages, p.position, p.dob, p.foot, p.value, p.height, p.weight, p.country_id, p.club_id, 
	min(s.price) as price, (price / ((p.wages * 0.02 * 2) / 10000)) as housemoney
from players as p, 
     share_orders as s
where p.player_id = s.share_id and 
	  s.share_type = ""player"" and

      s.is_ask = 1
group by p.player_id
order by housemoney asc, 
         p.wages desc,
         p.club_id asc,
         value ";


                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string pname      = Utilities.GetPlayerNameFromId(reader.GetInt32(0), world);
                        string cname      = Utilities.GetClubNameFromId(reader.GetInt32(11), world);
                        string country    = reader.GetString(10);
                        string dob        = Utilities.UnixTimeStampToDateTime(reader.GetInt32(5)).ToLongDateString();
                        int    height     = reader.GetInt32(8);
                        int    weight     = reader.GetInt32(9);
                        int    foot       = reader.GetInt32(6);
                        int    value      = reader.GetInt32(7) * 1000;
                        int    wages      = reader.GetInt32(3);
                        int    fitness    = reader.GetInt32(1);
                        int    position   = reader.GetInt32(4);
                        int    morale     = reader.GetInt32(2);
                        int    price      = reader.GetInt32(12);
                        double housemoney = reader.GetDouble(13);


                        double weeklyShareDividends   = wages * 0.02 * 2;  // paid 2x per week
                        double weeklyAgentCommissions = wages * 0.001 * 2; // paid 2x per week

                        // weeks to earn back investment - House Money Weeks
                        double weeksToEarnBackInvestment = weeklyShareDividends / (price * 100);
                        double onesharedividend          = weeklyShareDividends / 10000;
                        double priceBy1share             = price / onesharedividend;


                        sb.AppendLine(
                            string.Format(
                                StringTemplates.PlayerEconomicsRow,
                                pname,
                                cname,
                                country,
                                dob,
                                height.ToString(),
                                weight.ToString(),
                                Utilities.FootString(foot),
                                Utilities.PositionString(position),
                                fitness.ToString(),
                                Utilities.MoraleString(morale),
                                wages.ToString("N0"),
                                value.ToString("N0"),
                                weeklyShareDividends.ToString("N0"),
                                weeklyAgentCommissions.ToString("N0"),
                                price.ToString("N0"),
                                housemoney.ToString("#.00")
                                ));
                    }
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 13
0
        public static string PlayerOrderbookReport(long clubId, world world)
        {
            StringBuilder report             = new StringBuilder();
            string        folder             = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Utilities.smcSqlite;
            int           name_length        = 0;
            bool          is_bid_header_done = false;

            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @"select  
	s.order_id, s.is_ask, s.share_id, s.name, s.num, s.price, 
	p.player_id, p.club_id, p.wages, p.fitness, p.morale, 
	p.injured, p.injury_id, p.form, p.rating, p.banned, 
	p.cup_tied, p.yellow_cards, p.red_cards, 
	p.dob, p.foot, p.value, p.height, 
	p.weight, p.country_id, p.agent_name

from 
	share_orders as s, 
	players as p
where share_type = ""player"" and s.share_id = p.player_id 
order by
    s.is_ask desc,
    p.rating desc,
    s.share_id,
	s.price desc,
    s.num, 
	s.name, 
	s.share_type"    ;

                int lastPlayerId = 0;

                //0   order_id
                //1   is_ask
                //2   share_id
                //3   name
                //4   num
                //5   price
                //6   player_id
                //7   club_id
                //8   wages
                //9   fitness
                //10  morale
                //11  injured
                //12  injury_id
                //13  form
                //14  rating
                //15  banned
                //16  cup_tied
                //17  yellow_cards
                //18  red_cards
                //19  dob
                //20  foot
                //21  value
                //22  height
                //23  weight
                //24  country_id
                //25  agent_name

                int    order_id     = 0;
                string is_ask       = string.Empty;
                int    share_id     = 0;
                string name         = string.Empty;
                int    num          = 0;
                int    price        = 0;
                int    player_id    = 0;
                int    club_id      = 0;
                int    wages        = 0; //************
                int    fitness      = 0;
                int    morale       = 0;
                int    injured      = 0;
                int    injury_id    = 0;
                string form         = string.Empty;
                int    rating       = 0;
                int    banned       = 0;
                int    cup_tied     = 0;
                int    yellow_cards = 0;
                int    red_cards    = 0;
                int    dob          = 0;
                int    foot         = -1;
                int    value        = 0;//************
                int    height       = 0;
                int    weight       = 0;
                string country_id   = string.Empty;
                string agent_name   = string.Empty;

                report.AppendLine("  A/B                              NAME         PRICE    QTY RATING         VALUE     WAGES      V/W SELLER/BIDDER");
                report.AppendLine("  ASKS");
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        order_id     = reader.GetInt32(0);
                        is_ask       = reader.GetInt32(1) == 1 ? "ask" : "bid";
                        share_id     = reader.GetInt32(2);
                        name         = reader.GetString(3);
                        num          = reader.GetInt32(4);
                        price        = reader.GetInt32(5);
                        player_id    = reader.GetInt32(6);
                        club_id      = reader.GetInt32(7);
                        wages        = reader.GetInt32(8);
                        fitness      = reader.GetInt32(9);
                        morale       = reader.GetInt32(10);
                        injured      = reader.GetInt32(11);
                        injury_id    = reader.GetInt32(12);
                        form         = reader.GetString(13);
                        rating       = reader.GetInt32(14);
                        banned       = reader.GetInt32(15);
                        cup_tied     = reader.GetInt32(16);
                        yellow_cards = reader.GetInt32(17);
                        red_cards    = reader.GetInt32(18);
                        dob          = reader.GetInt32(19);
                        foot         = reader.GetInt32(20);
                        value        = reader.GetInt32(21);
                        height       = reader.GetInt32(22);
                        weight       = reader.GetInt32(23);
                        country_id   = reader.GetString(24);
                        agent_name   = reader.IsDBNull(25) ? string.Empty : reader.GetString(25);

                        string player_name = Utilities.GetPlayerNameFromId(player_id, world);

                        if (player_name.Length > name_length)
                        {
                            name_length = player_name.Length;
                        }

                        // bid header
                        if (!is_bid_header_done && is_ask == "bid")
                        {
                            is_bid_header_done = true;
                            // add bid header
                            report.AppendLine("  BIDS");
                        }

                        if (lastPlayerId != player_id)
                        {
                            // add header for each player
                            report.Append(string.Format(StringTemplates.PlayerOrderbookHeader, is_ask, /* player name */ player_name + " (" + player_id + ")"));
                        }
                        else
                        {
                            // append appropriate padding
                            report.Append(StringTemplates.PlayerOrderbookHeaderDummy);
                        }
                        //string type = string.Empty;
                        //if (reader.GetInt32(1) == 1)
                        //    type = "ask";
                        //else if (reader.GetInt32(1) == 0)
                        //    type = "bid";

                        //price = reader.GetInt32(6).ToString("N0");
                        //num = reader.GetInt32(5).ToString("N0");
                        //name = reader.GetString(4);

                        report.Append(
                            string.Format(
                                StringTemplates.PlayerOrderbookRow,
                                price.ToString("N0"),
                                num.ToString("N0"),
                                rating,
                                (value * 1000).ToString("N0"),
                                wages.ToString("N0"),
                                ((float)(value * 1000) / (float)wages).ToString("0.0"),
                                name
                                ) + Environment.NewLine);

                        lastPlayerId = player_id;
                    }
                }
            }

            return(report.ToString()); // name_length.ToString() + Environment.NewLine +
        }
Exemplo n.º 14
0
        public static List <AdgvRow> GetPlayerOrderbookAdgvRows(List <AdgvColumn> cols, world world)
        {
            string         folder       = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Utilities.smcSqlite;
            List <AdgvRow> rows         = new List <AdgvRow>();
            int            shortcircuit = 0;


            // stop if the player doesn't exist
            List <int> existing_players = Utilities.GetAllPlayerIds();

            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @"select  
	s.order_id, s.is_ask, s.share_id, s.name, s.num, s.price, 
	p.player_id, p.club_id, p.wages, p.fitness, p.morale, 
	p.injured, p.injury_id, p.form, p.rating, p.banned, 
	p.cup_tied, p.yellow_cards, p.red_cards, 
	p.dob, p.foot, p.value, p.height, 
	p.weight, p.country_id, p.agent_name, p.position

from 
	share_orders as s, 
	players as p
where share_type = ""player"" and s.share_id = p.player_id 
order by
    s.is_ask desc,
    p.rating desc,
    s.share_id,
	s.price desc,
    s.num, 
	s.name, 
	s.share_type"    ;

                //0   order_id
                //1   is_ask
                //2   share_id
                //3   name
                //4   num
                //5   price
                //6   player_id
                //7   club_id
                //8   wages
                //9   fitness
                //10  morale
                //11  injured
                //12  injury_id
                //13  form
                //14  rating
                //15  banned
                //16  cup_tied
                //17  yellow_cards
                //18  red_cards
                //19  dob
                //20  foot
                //21  value
                //22  height
                //23  weight
                //24  country_id
                //25  agent_name
                //26  position

                int      order_id     = 0;
                string   is_ask       = string.Empty;
                int      share_id     = 0;
                string   name         = string.Empty;
                int      num          = 0;
                int      price        = 0;
                int      player_id    = 0;
                int      club_id      = 0;
                int      wages        = 0; //************
                int      fitness      = 0;
                string   morale       = string.Empty;
                int      injured      = 0;
                int      injury_id    = 0;
                string   form         = string.Empty;
                int      rating       = 0;
                int      banned       = 0;
                int      cup_tied     = 0;
                int      yellow_cards = 0;
                int      red_cards    = 0;
                DateTime dob          = DateTime.Now;
                string   foot         = string.Empty;
                int      value        = 0;//************
                int      height       = 0;
                int      weight       = 0;
                string   country_id   = string.Empty;
                string   agent_name   = string.Empty;
                string   position     = string.Empty;
                decimal  value_wages  = 0;

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        order_id  = reader.GetInt32(0);
                        is_ask    = reader.GetInt32(1) == 1 ? "ask" : "bid";
                        share_id  = reader.GetInt32(2);
                        name      = reader.GetString(3);
                        num       = reader.GetInt32(4);
                        price     = reader.GetInt32(5);
                        player_id = reader.GetInt32(6);

                        // Stop if player doesn't exist
                        if (!existing_players.Contains(player_id))
                        {
                            continue;
                        }

                        club_id      = reader.GetInt32(7);
                        wages        = reader.GetInt32(8);
                        fitness      = reader.GetInt32(9);
                        morale       = Utilities.MoraleString(reader.GetInt32(10));
                        injured      = reader.GetInt32(11);
                        injury_id    = reader.GetInt32(12);
                        form         = reader.GetString(13);
                        rating       = reader.GetInt32(14);
                        banned       = reader.GetInt32(15);
                        cup_tied     = reader.GetInt32(16);
                        yellow_cards = reader.GetInt32(17);
                        red_cards    = reader.GetInt32(18);
                        dob          = Utilities.UnixTimeStampToDateTime(reader.GetInt32(19));
                        foot         = Utilities.FootString(reader.GetInt32(20));
                        value        = reader.GetInt32(21) * 1000;
                        height       = reader.GetInt32(22);
                        weight       = reader.GetInt32(23);
                        country_id   = reader.GetString(24);
                        agent_name   = reader.IsDBNull(25) ? string.Empty : reader.GetString(25);
                        position     = Utilities.PositionString(reader.GetInt32(26));

                        value_wages = decimal.Round((decimal)value / (decimal)wages, 2);

                        string player_name = Utilities.GetPlayerNameFromId(player_id, world);

                        string club_name = Utilities.GetClubNameFromId(club_id, world);

                        List <object> list = new List <object>();
                        list.Add(order_id);
                        list.Add(is_ask);
                        list.Add(share_id);
                        list.Add(name);
                        list.Add(num);
                        list.Add(price);
                        list.Add(player_id);
                        list.Add(player_name);
                        list.Add(club_id);
                        list.Add(club_name);
                        list.Add(position);
                        list.Add(wages);



                        list.Add(value);
                        // add in ((float)(value * 1000) / (float)wages).ToString("0.0")
                        list.Add(value_wages);
                        list.Add(fitness);
                        list.Add(morale);
                        list.Add(injured);
                        list.Add(injury_id);
                        list.Add(form);
                        list.Add(rating);
                        list.Add(banned);
                        list.Add(cup_tied);
                        list.Add(yellow_cards);
                        list.Add(red_cards);
                        list.Add(dob);
                        list.Add(foot);
                        list.Add(height);
                        list.Add(weight);
                        list.Add(country_id);
                        list.Add(agent_name);

                        AdgvRow row = new AdgvRow(cols, list);
                        rows.Add(row);
                        //shortcircuit++;
                        //if (shortcircuit >= 100)
                        //    break;
                    }
                }
            }

            return(rows);
        }
Exemplo n.º 15
0
        // To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
        //
        //    using QuickType;
        //
        //    var getBestShareOrders = GetBestShareOrders.FromJson(jsonString);

        public static string GetShareOrdersReport(get_best_share_orders.GetBestShareOrders shareOrders, world world)
        {
            StringBuilder sbClubs   = new StringBuilder();
            StringBuilder sbPlayers = new StringBuilder();

            // var sortedDict = from entry in Players orderby entry.Value.Minted descending, entry.Value.Inventory.Count descending select entry;

            List <Datum> clubAskOrders   = new List <Datum>();
            List <Datum> clubBidOrders   = new List <Datum>();
            List <Datum> playerAskOrders = new List <Datum>();
            List <Datum> playerBidOrders = new List <Datum>();

            foreach (var order in shareOrders.Result.Data)
            {
                if (order.Share.Club.HasValue)
                {
                    string clubName = Utilities.GetClubNameFromId(order.Share.Club.Value, world);
                    if (order.BestAsk.HasValue)
                    {
                        clubAskOrders.Add(order);
                    }
                    if (order.BestBid.HasValue)
                    {
                        clubBidOrders.Add(order);
                    }
                }
                else
                {
                    string playerName = Utilities.GetPlayerNameFromId(order.Share.Player.Value, world);
                    //playerOrders.Add(order);
                    if (order.BestAsk.HasValue)
                    {
                        playerAskOrders.Add(order);
                    }
                    if (order.BestBid.HasValue)
                    {
                        playerBidOrders.Add(order);
                    }
                }
            }

            // Bug fix - GSP is returning players that don't exist in orders - need to remove them
            // 2020-10-22 - This bug may be fixed - remove this after verifying
            List <int> existingPlayers = new List <int>();     // A list to contain all players that exist - their player_ids

            existingPlayers = Utilities.GetAllPlayerIds();     // Just returns select player_id from players
            List <Datum> playersToRemove = new List <Datum>(); // Create a list of players to remove, i.e. the ones that don't exist

            foreach (var player in playerBidOrders)
            {
                if (!existingPlayers.Contains(Convert.ToInt32(player.Share.Player)))
                {
                    // If the player_id isn't in the list of existing players, add it to the remove list
                    playersToRemove.Add(player);
                }
            }

            // It only affects bids, but might as well do asks as well
            foreach (var player in playerAskOrders)
            {
                if (!existingPlayers.Contains(Convert.ToInt32(player.Share.Player)))
                {
                    //playerAskOrders.Remove(player);
                    playersToRemove.Add(player);
                }
            }

            // Go over our list of players to remove, and remove them from the bid and ask lists
            foreach (var player in playersToRemove)
            {
                playerBidOrders.Remove(player);
                playerAskOrders.Remove(player);
            }
            // Done - lists are now cleaned of players that don't exist

            var sortedClubAsks   = from entry in clubAskOrders orderby entry.BestAsk.Value descending select entry;
            var sortedClubBids   = from entry in clubBidOrders orderby entry.BestBid.Value descending select entry;
            var sortedPlayerAsks = from entry in playerAskOrders orderby entry.BestAsk.Value descending select entry;
            var sortedPlayerBids = from entry in playerBidOrders orderby entry.BestBid.Value descending select entry;

            sbClubs.AppendLine("CLUB ASKS");

            foreach (var club in sortedClubAsks)
            {
                sbClubs.AppendLine(string.Format(StringTemplates.OrdersReportClubRow, Utilities.GetClubNameFromId(club.Share.Club.Value, world).ToString(), "ask", club.BestAsk.Value.ToString("N0")));
            }

            sbClubs.AppendLine("CLUB BIDS");
            foreach (var club in sortedClubBids)
            {
                sbClubs.AppendLine(string.Format(StringTemplates.OrdersReportClubRow,
                                                 Utilities.GetClubNameFromId(club.Share.Club.Value, world).ToString(),
                                                 "bid",
                                                 club.BestBid.Value.ToString("N0")));
            }

            Dictionary <int, int> playerClubIds = Utilities.GetClubsForPlayers();

            sbPlayers.AppendLine("PLAYER ASKS");
            foreach (var player in sortedPlayerAsks)
            {
                try
                {
                    sbPlayers.AppendLine(string.Format(StringTemplates.OrdersReportPlayerRow,
                                                       Utilities.GetPlayerNameFromId(player.Share.Player.Value, world),
                                                       "ask",
                                                       player.BestAsk.Value.ToString("N0"),
                                                       Utilities.GetClubNameFromId(playerClubIds[Convert.ToInt32(player.Share.Player.Value)], world)
                                                       //Utilities.GetClubForPlayer(player.Share.Player.Value, world)
                                                       ));
                }
                catch { }
            }

            sbPlayers.AppendLine("PLAYER BIDS");
            foreach (var player in sortedPlayerBids)
            {
                try
                {
                    //int? cId = playerClubIds[Convert.ToInt32(player.Share.Player.Value)];

                    sbPlayers.AppendLine(string.Format(StringTemplates.OrdersReportPlayerRow,
                                                       Utilities.GetPlayerNameFromId(player.Share.Player.Value, world),
                                                       "bid",
                                                       player.BestBid.Value.ToString("N0"),

                                                       Utilities.GetClubNameFromId(playerClubIds[Convert.ToInt32(player.Share.Player.Value)], world)
                                                       //Utilities.GetClubForPlayer(player.Share.Player.Value, world
                                                       ));
                }
                catch { }
            }


            return(sbClubs.ToString() + Environment.NewLine + Environment.NewLine + sbPlayers.ToString());
        }
        // To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
        //
        //    using QuickType;
        //
        //    var getUserShareOrders = GetUserShareOrders.FromJson(jsonString);
        public static string GetUserShareOrdersReport(GetUserShareOrders userShareOrders, world world, string name)
        {
            if (userShareOrders.Result.Data.Length == 0)
            {
                return(string.Empty);
            }

            StringBuilder sb = new StringBuilder();

            var sortedOrders = from entry in userShareOrders.Result.Data orderby entry.Type ascending, entry.Price descending select entry;

            sb.AppendLine(name + " ASKS & BIDS");

            foreach (var order in sortedOrders)
            {
                // "  {0, 16} {1, 4} {2,-8} SMC for {3, 6} shares of {4, 16} totaling {5, -15}";
                string type  = order.Type.ToString();
                string price = order.Price.ToString("N0");
                string total = (order.Price * order.Num).ToString("N0");

                // club or player?
                string asset = "Unknown club or player";
                string PorC  = "???";
                if (order.Share.Club.HasValue)
                {
                    asset = Utilities.GetClubNameFromId(order.Share.Club.Value, world);
                    PorC  = "CLUB";
                }
                else if (order.Share.Player.HasValue)
                {
                    asset = Utilities.GetPlayerNameFromId(order.Share.Player.Value, world);
                    PorC  = "PLAYER";
                }

                sb.AppendLine(string.Format(StringTemplates.UserShareOrderRow,
                                            name,
                                            type,
                                            price,
                                            order.Num.ToString("N0"),
                                            PorC,
                                            asset,
                                            total));
            }
            sb.AppendLine("  ===============");

            return(sb.ToString());
        }
Exemplo n.º 17
0
        public static List <AdgvRow> GetClubOrderbookAdgvRows(List <AdgvColumn> cols, world world)
        {
            string         folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Utilities.smcSqlite;
            List <AdgvRow> rows   = new List <AdgvRow>();

            //Stop if club doesn't exist
            // List<int> existing_clubs = Utilities.Get

            #region get rows


            using (var connection = new SqliteConnection("Data Source=" + folder))
            {
                connection.Open();

                var command = connection.CreateCommand();
                command.CommandText =
                    @"select so.order_id, 
	so.is_ask, 
	so.share_type, 
	so.share_id, 
	so.name, 
	so.num, 
	so.price, 
	(so.price * so.num) as total, 
	c.club_id, 
	c.balance, 
	c.form, 
	c.fans_start, 
	c.fans_current, 
	c.stadium_size_start, 
	c.stadium_size_current, 
	c.stadium_id, 
	c.manager_name, 
	c.chairman_name, 
	c.home_colour, 
	c.away_colour, 
	c.value, 
	c.default_formation, 
	c.rating, 
	c.country_id, 
	-- c.committed_tactics, 
	c.game_world_id, 
	c.proposed_manager
from share_orders as so,
    clubs as c

where share_type = ""club""
    and c.club_id = so.share_id
    -- and c.club_id = 45

order by so.price desc, c.value desc, c.club_id asc
--c.committed_tactics, 
";

                //0   order_id
                //1   is_ask
                //2   share_type
                //3   share_id
                //4   name
                //5   num
                //6   price
                //7   total
                //8   club_id
                //9   balance
                //10  form
                //11  fans_start
                //12  fans_current
                //13  stadium_size_start
                //14  stadium_size_current
                //15  stadium_id
                //16  manager_name
                //17  chairman_name
                //18  home_colour
                //19  away_colour
                //20  value
                //21  default_formation
                //22  rating
                //23  country_id
                //24  committed_tactics -- commented out...
                //24  game_world_id
                //25  proposed_manager


                int    order_id             = 0;
                string is_ask               = "???";
                string share_type           = string.Empty;
                int    share_id             = 0;
                string name                 = string.Empty;
                int    num                  = 0;
                int    price                = 0;
                int    total                = 0;
                int    club_id              = 0;
                int    balance              = 0;
                string form                 = string.Empty;
                int    fans_start           = 0;
                int    fans_current         = 0;
                int    stadium_size_start   = 0;
                int    stadium_size_current = 0;
                int    stadium_id           = 0;
                string manager_name         = string.Empty;
                string chairman_name        = string.Empty;
                string home_colour          = string.Empty;
                string away_colour          = string.Empty;
                int    value                = 0;
                int    default_formation    = 0;
                int    rating               = 0;
                string country_id           = string.Empty;
                //Byte[] committed_tactics;
                int    game_world_id    = 0;
                string proposed_manager = string.Empty;


                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        order_id = reader.GetInt32(0);
                        is_ask   = reader.GetInt32(1) == 1 ? "ask" : "bid";
                        share_id = reader.GetInt32(3);
                        name     = reader.GetString(4);
                        num      = reader.GetInt32(5);
                        price    = reader.GetInt32(6);
                        total    = reader.GetInt32(7);
                        club_id  = reader.GetInt32(8);

                        // Stop if club doesn't exist
                        //if (!existing_clubs.Contains(player_id)) // Still need to create method for this
                        //    continue;

                        balance              = reader.GetInt32(9);
                        form                 = reader.GetString(10);
                        fans_start           = reader.GetInt32(11);
                        fans_current         = reader.GetInt32(12);
                        stadium_size_start   = reader.GetInt32(13);
                        stadium_size_current = reader.GetInt32(14);
                        stadium_id           = reader.GetInt32(15);
                        manager_name         = reader.IsDBNull(16) ? string.Empty : reader.GetString(16);
                        chairman_name        = reader.IsDBNull(17) ? string.Empty : reader.GetString(17);
                        home_colour          = reader.GetString(18);
                        away_colour          = reader.GetString(19);
                        value                = reader.GetInt32(20);
                        default_formation    = reader.IsDBNull(21) ? -1 : reader.GetInt32(21);
                        rating               = reader.GetInt32(22);
                        country_id           = reader.GetString(23);
                        // committed_tactics = reader.GetBytes .GetString(24);
                        game_world_id    = reader.GetInt32(24);
                        proposed_manager = reader.IsDBNull(25) ? string.Empty : reader.GetString(25);

                        string club_name = Utilities.GetClubNameFromId(club_id, world);

                        List <object> list = new List <object>();
                        list.Add(order_id);
                        list.Add(is_ask);
                        //list.Add(share_type);
                        list.Add(share_id);
                        list.Add(club_name);
                        list.Add(name);
                        list.Add(num);
                        list.Add(price);
                        list.Add(total);
                        //list.Add(club_id);
                        //list.Add(club_name);
                        list.Add(balance);
                        list.Add(form);
                        list.Add(fans_start);
                        list.Add(fans_current);
                        list.Add(stadium_size_start);
                        list.Add(stadium_size_current);
                        list.Add(stadium_id);
                        list.Add(manager_name);
                        list.Add(chairman_name);
                        list.Add(home_colour);
                        list.Add(away_colour);
                        list.Add(value);
                        list.Add(default_formation);
                        list.Add(rating);
                        list.Add(country_id);
                        // list.Add(committed_tactics);
                        list.Add(game_world_id);
                        list.Add(proposed_manager);

                        AdgvRow row = new AdgvRow(cols, list);
                        rows.Add(row);
                        //shortcircuit++;
                        //if (shortcircuit >= 100)
                        //    break;
                    }
                }
            }

            #endregion



            return(rows);
        }
        public static string Get_club_tactics(SMElite.get_club_tactics.GetClubTactics getClubTactics, SMElite.world world)
        {
            StringBuilder result = new StringBuilder();

            // result.AppendLine("Team Instructions");

            //result.AppendLine("Tackling Style: " + getClubTactics.Result.Data.t)

            foreach (var v in getClubTactics.Result.Data.TacticActions)
            {
                result.AppendLine("TEAM INSTRUCTIONS @ Time: " + v.Time.ToString());
                result.AppendLine(string.Format(StringTemplates.Tactics, "Goal Margin ", tactics.GetGoalMargin(Convert.ToInt32(v.GoalMargin))));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Tackling Style ", tactics.tacklingstyle[v.TacklingStyle]));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Passing Style ", tactics.passingstyle[v.PassingStyle]));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Tempo ", tactics.tempo[v.Tempo]));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Mentality ", tactics.mentality[v.Mentality]));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Attacking ", tactics.attackingstyle[v.Attacking]));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Pressing ", tactics.pressing[v.Pressing]));
                result.AppendLine("  ----");
                result.AppendLine("");

                result.AppendLine("PLAY STYLE");
                result.AppendLine(string.Format(StringTemplates.Tactics, "Counter Attack ", YesOrNo(v.CounterAttack)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Tight Marking ", YesOrNo(v.TightMarking)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Use Playmaker ", YesOrNo(v.UsePlaymaker)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Men Behind Ball ", YesOrNo(v.MenBehindBall)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Play Offside Trap ", YesOrNo(v.PlayOffside)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Use Target Man ", YesOrNo(v.UseTargetMan)));
                result.AppendLine("  ----");
                result.AppendLine("");

                result.AppendLine("PLAYER INSTRUCTIONS");
                result.AppendLine(string.Format(StringTemplates.Tactics, "Captain ", GetPlayerNameFromId(getClubTactics.Result.Data.TeamSheet[Convert.ToInt32(v.Captain)], world)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Freekicks ", GetPlayerNameFromId(getClubTactics.Result.Data.TeamSheet[Convert.ToInt32(v.FreeKicks)], world)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Playmaker ", GetPlayerNameFromId(getClubTactics.Result.Data.TeamSheet[Convert.ToInt32(v.Playmaker)], world)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Penalty Taker ", GetPlayerNameFromId(getClubTactics.Result.Data.TeamSheet[Convert.ToInt32(v.PenaltyTaker)], world)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Corner Taker ", GetPlayerNameFromId(getClubTactics.Result.Data.TeamSheet[Convert.ToInt32(v.CornerTaker)], world)));
                result.AppendLine(string.Format(StringTemplates.Tactics, "Target Man ", GetPlayerNameFromId(getClubTactics.Result.Data.TeamSheet[Convert.ToInt32(v.TargetMan)], world)));
                result.AppendLine("  ----");
                result.AppendLine("");

                result.AppendLine("LINE UP");

                foreach (var p in v.Lineup)
                {
                    result.AppendLine("  " + GetPlayerNameFromId(getClubTactics.Result.Data.TeamSheet[Convert.ToInt32(p)], world));
                }
                result.AppendLine("  ----");
                result.AppendLine("");
            }


            // And the team
            result.AppendLine("TEAM SHEET");
            foreach (var v in getClubTactics.Result.Data.TeamSheet)
            {
                result.AppendLine("  " + GetPlayerNameFromId(v, world));
            }

            return(result.ToString());
        }