Commit 2a74f913 authored by Jeremy Pallats's avatar Jeremy Pallats 💬
Browse files

FIX #125: UM sheet improvement

- Changes made based on feedback.
parent a964af29
Loading
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -1133,11 +1133,14 @@ class Hold(Action):
                      self.duser.display_name, hold, system)

        response = hold.system.display()
        if hold.system.is_skipped:
            response += '\n\nThis system should be left for now. Type `!um` for more targets.'
        if hold.system.is_undermined:
            response += '\n\nSystem is finished with held merits. Type `!um` for more targets.'
            response += '\n\n**{}** Have a :skull: for completing {}. Don\'t forget to redeem.'.format(
                self.duser.display_name, system.name)


        return ([hold], response)

    @check_mentions
@@ -1746,6 +1749,9 @@ class UM(Action):

            if self.args.offset:
                system.map_offset = self.args.offset
            if self.args.priority:
                system.priority = " ".join(self.args.priority)
                self.payloads += cogdb.scanners.UMScanner.update_systemum_priority_dict(system.sheet_col, system.priority)
            if self.args.set:
                system.set_status(self.args.set)
            if self.args.set or self.args.offset:
@@ -1793,7 +1799,7 @@ class UM(Action):
            return

        else:
            systems = cogdb.query.um_get_systems(self.session, sheet_src=self.args.sheet_src)
            systems = cogdb.query.um_get_systems(self.session, sheet_src=self.args.sheet_src, exclude_finished=True)
            response = '__Current Combat / Undermining Targets__\n\n' + '\n'.join(
                [system.display() for system in systems])

+4 −0
Original line number Diff line number Diff line
@@ -679,6 +679,9 @@ def subs_um(subs, prefix):
**{prefix}um burr --offset 4000**
**{prefix}um burr -o 4000**
        Set the offset difference of cmdr merits and galmap.
**{prefix}um burr --priority Medium**
**{prefix}um burr -p Medium**
        Set the priority for the undermining system.
**{prefix}um --list**
        Show all outstanding merits by users and system.
**{prefix}um --npcs**
@@ -691,6 +694,7 @@ def subs_um(subs, prefix):
    sub.add_argument('-s', '--set',
                     help='Set the status of the system, us:them. Example-> --set 3500:200')
    sub.add_argument('-o', '--offset', type=int, help='Set the system galmap offset.')
    sub.add_argument('-p', '--priority', nargs='+', help='The priority to set for the system.')
    sub.add_argument('-l', '--list', action='store_true', help='Show all outstanding merits on sheet.')
    sub.add_argument('--npcs', action='store_true', help='List powerplay NPC ships by alligence.')

+24 −11
Original line number Diff line number Diff line
@@ -498,17 +498,21 @@ def um_find_system(session, system_name, *, sheet_src=EUMSheet.main):
        return systems[0]


def um_get_systems(session, *, exclude_finished=True, sheet_src=EUMSheet.main):
def um_get_systems(session, *, exclude_finished=True, sheet_src=EUMSheet.main, ignore_leave=True):
    """
    Return a list of all current undermining targets.

    kwargs:
        exclude_finished: Return only active UM targets.
        sheet_src: Select UM targets from sheet_src, default main.
        ignore_leave: Ignore the systems with like "leave for now" in notes.
    """
    systems = session.query(UMSystem).\
        filter(UMSystem.sheet_src == sheet_src).\
        all()
        filter(UMSystem.sheet_src == sheet_src)

    if ignore_leave:
        systems = systems.filter(sqla.not_(UMSystem.is_skipped))
    systems = systems.all()

    if exclude_finished:
        # Force in memory check, due to differing implementation of is_undermined
@@ -656,6 +660,10 @@ def um_all_held_merits(session, *, sheet_src=EUMSheet.main):
    """
    Return a list of lists that show all users with merits still held.

    Systems excluded if:
        - System set to "Leave for now"
        - No held merits & system is undermined.

    List of the form:
    [
        [CMDR, system_name_1, system_name_2, ...],
@@ -663,24 +671,30 @@ def um_all_held_merits(session, *, sheet_src=EUMSheet.main):
        [cmdrname, merits_system_1, merits_system_2, ...],
    ]
    """
    c_dict = {}
    systems = session.query(UMSystem).\
        filter(UMSystem.sheet_src == EUMSheet.main,
               sqla.not_(UMSystem.is_skipped),
               sqla.or_(UMSystem.cmdr_merits > 0,
                        sqla.not_(UMSystem.is_undermined))).\
        order_by(UMSystem.id).\
        all()
    system_ids = [x.id for x in systems]
    held_merits = session.query(UMHold).\
        filter(UMHold.held > 0,
               UMHold.sheet_src == sheet_src).\
               UMHold.sheet_src == sheet_src,
               UMHold.system_id.in_(system_ids)).\
        order_by(UMHold.system_id).\
        all()

    c_dict = {}
    for merit in held_merits:
        try:
            c_dict[merit.user.name][merit.system.name] = merit
        except KeyError:
            c_dict[merit.user.name] = {merit.system.name: merit}

    systems = session.query(UMSystem).\
        filter(UMSystem.sheet_src == EUMSheet.main).\
        order_by(UMSystem.id).\
        all()
    system_names = [sys.name for sys in systems]
    rows = []
    system_names = [sys.name for sys in systems]
    for cmdr in c_dict:
        row = [cmdr]
        for system_name in system_names:
@@ -688,7 +702,6 @@ def um_all_held_merits(session, *, sheet_src=EUMSheet.main):
                row += [c_dict[cmdr][system_name].held]
            except KeyError:
                row += [0]

        rows += [row]

    return [['CMDR'] + system_names] + rows
+15 −0
Original line number Diff line number Diff line
@@ -455,6 +455,21 @@ class UMScanner(FortScanner):
        values = [[progress_us], [progress_them], ['Hold Merits'], [map_offset]]
        return [{'range': cell_range, 'values': values}]

    @staticmethod
    def update_systemum_priority_dict(col, priority):
        """
        Create an update system dict. See AsyncGSheet.batch_update

        Args:
            col: The main (left most) column of the system in sheet.
            priority: The new priority to set.

        Returns: A list of update dicts to pass to batch_update.
        """
        column = cog.sheets.Column(col)
        cell_range = '{col}8:{col}8'.format(col=column.fwd())
        return [{'range': cell_range, 'values': [[priority]]}]

    @staticmethod
    def update_hold_dict(system_col, user_row, held, redeemed):
        """
+11 −0
Original line number Diff line number Diff line
@@ -746,6 +746,17 @@ class UMSystem(Base):
        """ The remaining merites targetted to undermine. """
        return cls.goal - sqla.func.greatest(cls.cmdr_merits + cls.map_offset, cls.progress_us)

    @hybrid_property
    def is_skipped(self):
        """ The system should be skipped. """
        priority = self.priority.lower()
        return 'leave' in priority or 'skip' in priority

    @is_skipped.expression
    def is_skipped(cls):
        """ The system should be skipped. """
        return or_(cls.priority.ilike("%leave%"), cls.priority.ilike("%skip%"))

    @property
    def descriptor(self):
        """ Descriptive prefix for string. """
Loading