From 02dd800c5718d3bddb6439e3e9ef724ed710bb89 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 31 Jan 2022 14:50:12 +0000 Subject: [PATCH 1/2] Inara: Change the way we determine if a credits delta is interesting Now based on the *minimum* of a fractional or absolute change. See for discussion. --- plugins/inara.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index be4f35ac..abc45d5e 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -33,7 +33,10 @@ if TYPE_CHECKING: _TIMEOUT = 20 FAKE = ('CQC', 'Training', 'Destination') # Fake systems that shouldn't be sent to Inara -CREDIT_RATIO = 1.05 # Update credits if they change by 5% over the course of a session +# We only update Credits to Inara if the delta from the last sent value is +# greater than certain thresholds +CREDITS_DELTA_MIN_FRACTION = 0.05 # Fractional difference threshold +CREDITS_DELTA_MIN_ABSOLUTE = 10_000_000 # Absolute difference threshold # These need to be defined above This @@ -1358,7 +1361,10 @@ def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001 this.station_link.update_idletasks() if config.get_int('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr): - if not (CREDIT_RATIO > this.last_credits / data['commander']['credits'] > 1 / CREDIT_RATIO): + if ( + abs(this.last_credits - data['commander']['credits']) >= + min(this.last_credits * CREDITS_DELTA_MIN_FRACTION, CREDITS_DELTA_MIN_ABSOLUTE) + ): this.filter_events( Credentials(this.cmdr, this.FID, str(credentials(this.cmdr))), lambda e: e.name != 'setCommanderCredits' From adb8055f0871b17eeec912e4f319f9288e8aae9b Mon Sep 17 00:00:00 2001 From: Athanasius Date: Mon, 31 Jan 2022 15:22:36 +0000 Subject: [PATCH 2/2] Inara: Be paranoid in case of -ve credits balance --- plugins/inara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inara.py b/plugins/inara.py index abc45d5e..08b3b86d 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -1363,7 +1363,7 @@ def cmdr_data(data: CAPIData, is_beta): # noqa: CCR001 if config.get_int('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr): if ( abs(this.last_credits - data['commander']['credits']) >= - min(this.last_credits * CREDITS_DELTA_MIN_FRACTION, CREDITS_DELTA_MIN_ABSOLUTE) + min(abs(this.last_credits * CREDITS_DELTA_MIN_FRACTION), CREDITS_DELTA_MIN_ABSOLUTE) ): this.filter_events( Credentials(this.cmdr, this.FID, str(credentials(this.cmdr))),