Skip to content
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

indexticker: fix rendering of 0.0x% #2913

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions apps/indexticker/index_ticker.star
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ v1.3 - Added NIKKEI, Europe 350, Global 100, Global 1200, NZX50 indices; support
load("animation.star", "animation")
load("encoding/json.star", "json")
load("http.star", "http")
load("math.star", "math")
load("humanize.star", "humanize")
load("render.star", "render")
load("schema.star", "schema")

Expand Down Expand Up @@ -60,27 +60,9 @@ def main(config):
Current = INDEX_JSON["chart"]["result"][0]["meta"]["regularMarketPrice"]

PointsDiff = Current - LastClose
PercentDiff = PointsDiff / LastClose
StrPercentDiff = str(int(math.round(PercentDiff * 10000)))

# if % greater than 0
# elif % between 0 and -1
# elif % less than 0

if PercentDiff > 0:
StrPercentDiff = (StrPercentDiff[0:-2] + "." + StrPercentDiff[-2:])
elif PercentDiff > -0.01:
StrPercentDiff = StrPercentDiff.replace("-", "-0")
StrPercentDiff = (StrPercentDiff[0:-2] + "." + StrPercentDiff[-2:])
elif PercentDiff < 0:
StrPercentDiff = (StrPercentDiff[0:-2] + "." + StrPercentDiff[-2:])

if StrPercentDiff.startswith("."):
StrPercentDiff = "0" + StrPercentDiff
DiffColor = "#00ff00"
elif StrPercentDiff.startswith("-"):
StrPercentDiff = StrPercentDiff[1:]
StrPercentDiff = "-" + StrPercentDiff
PercentDiff = PointsDiff / LastClose * 100.0

if PercentDiff < 0:
DiffColor = "#f00"

if RangeSelection == "5m&range=1d":
Expand All @@ -97,8 +79,7 @@ def main(config):
Interval = "YTD"

if DisplaySelection == "true":
StrPercentDiff = StrPercentDiff + "%"
DisplayDiff = StrPercentDiff
DisplayDiff = humanize.float("#.##", PercentDiff) + "%"
else:
DisplayDiff = str(PointsDiff)[:6]

Expand Down
Loading