Skip to content

Custom stats do not update visuals if string or numeric value is falsy but not None #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
uyrussell21 opened this issue Jan 9, 2024 · 1 comment · Fixed by #444
Closed
Labels
bug Something isn't working

Comments

@uyrussell21
Copy link

Describe the bug
Custom stats do not update visuals if string or numeric value is falsy (e.g. zero or empty string) but not None

To Reproduce

  1. Create a custom stats class that can return empty string or zero; in this case the numeric value returns 0
class ExampleProgressData(CustomDataSource):
    def as_numeric(self) -> float:
        return 0

    def as_string(self) -> str:
        return "0"
  1. Put class in theme.yaml
STATS:
  CUSTOM:
    INTERVAL: 1
    ExampleProgressData:
      RADIAL:
        SHOW: True
        X: 141
        Y: 275
        RADIUS: 28
        WIDTH: 8
        MIN_VALUE: 0
        MAX_VALUE: 100
        ANGLE_START: 110
        ANGLE_END: 70
        ANGLE_STEPS: 1
        ANGLE_SEP: 25
        CLOCKWISE: True
        BAR_COLOR: 255, 0, 0
        SHOW_TEXT: True
        SHOW_UNIT: True
        FONT: roboto/Roboto-Bold.ttf
        FONT_SIZE: 13
        FONT_COLOR: 200, 200, 200
        # BACKGROUND_COLOR: 0, 0, 0
        BACKGROUND_IMAGE: background.png
  1. Run the program or theme editor
  2. No graph is displayed.

Expected behavior
It should display the string "0" representation as defined in as_string() despite the radial graph being 0 as well

Screenshots / photos of the Turing screen
Current:
image

It should have been like this:
image

Environment:

  • Smart screen model: Turing 3.5”
  • Revision of this project: main branch
  • OS with version: Windows 10
  • Python version: Python 3.11
  • Hardware: AMD Ryzen 7 CPU, Nvidia GPU

Additional context
The problem lies in the Context class using truthy / falsy checks instead of checking if string or numeric value is None

# library/stats.py

class Custom:
    @staticmethod
    def stats():
    ...
-               if not string_value:
+               if string_value is None:
                    string_value = str(numeric_value)

                # Display text
                theme_data = config.THEME_DATA["STATS"]["CUSTOM"][custom_stat].get(
                    "TEXT", None
                )
-               if theme_data and string_value:
+               if theme_data and string_value is not None:
                    display_themed_value(theme_data=theme_data, value=string_value)

                # Display graph from numeric value
                theme_data = config.THEME_DATA["STATS"]["CUSTOM"][custom_stat].get(
                    "GRAPH", None
                )
-               if theme_data and numeric_value:
+               if theme_data and numeric_value is not None:
                    display_themed_progress_bar(
                        theme_data=theme_data, value=numeric_value
                    )

                # Display radial from numeric and text value
                theme_data = config.THEME_DATA["STATS"]["CUSTOM"][custom_stat].get(
                    "RADIAL", None
                )
-               if theme_data and numeric_value and string_value:
+               if theme_data and numeric_value is not None and string_value is not None:
                    display_themed_radial_bar(
                        theme_data=theme_data,
                        value=numeric_value,
                        custom_text=string_value,
                    )
@mathoudebine
Copy link
Owner

Hi! Thanks for raising this issue, I've made a PR that should fix it in the next version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants