pydfs-lineup-optimizer
pydfs-lineup-optimizer copied to clipboard
Add Team Next to Player in Printout of CS Lineups
Good Morning,
Thank you again for including CSGO, I really appreciate all the hard work. I was wondering if it would be an easy fix for to me include the Team name of the players when I go to print out the lineups. It currently only includes the CPT/Flex, Name, Projected Points and price. Please let me know if there is some code I can enter in to display the team name of each player as well. Thank you so much!
You just have to modify this code in lineup_printer.py
class IndividualSportLineupPrinter(LineupPrinter): OUTPUT_FORMAT = '{index:>2}. {lineup_position:<5} {name:<30}{fppg:<15}{salary:<10}\n'
The other option is to subclass LineupPrinter and create a custom printer. Then you would have to create new settings and use them when you instantiate the optimizer optimizer = LineupOptimizer(settings=CustomSettings, **kwargs)
You just have to modify this code in lineup_printer.py
class IndividualSportLineupPrinter(LineupPrinter): OUTPUT_FORMAT = '{index:>2}. {lineup_position:<5} {name:<30}{fppg:<15}{salary:<10}\n'
Thank you for your response. I tried making these changes to the code but it is still not printing out correctly:
class IndividualSportLineupPrinter(LineupPrinter): def _print_player(self, index, player): return '{0:>2}. {1:<5} {2:<30}{3:<8}{4:<8}{5:<10}\n'.format( index, player.lineup_position, player.full_name, player.team, round(player.fppg, 3), str(player.salary) + '$', )
Please let me know if you can find the error. Thanks again for your help!
You don't need to overload _print_player. You just need to change OUTPUT_FORMAT to reflect your desired output.
class IndividualSportLineupPrinter(LineupPrinter):
OUTPUT_FORMAT = '{index:>2}. {lineup_position:<5} {name:<30}{positions:<6}{team:<15}{game:<9} {fppg:<15}{salary:<10}\n'
If you don't want to alter the code directly (it would get overwritten when the library updates and it affects other individual sports), then just create a separate function to print a CSGO lineup. You may need to adjust the function below a little bit, but it gives you an idea of how it would look.
def print_csgo_lineup(lineup, fields=None, sep=', '):
"""Prints a CSGO lineup with team
Args:
lineup (Lineup): the lineup object
fields (iterable): the fields you want to print
sep (str): the separator for the fields, default ', '
"""
if not fields:
fields = ('name', 'team', 'game', 'salary', 'fppg')
for player in lineup.lineup:
vals = [player._player.__dict__.get(k) for k in fields]
vals.insert(1, player.lineup_position)
print sep.join(vals)
Thank you for the assistance, I am still fairly new to Python and don't think I am at the level to make these changes. But once I have some more time to learn, I will see if I can make these happen. I appreciate your help with this though!