From 9a4efca7c250be734517c2b630b5cb03e3d1a70b Mon Sep 17 00:00:00 2001 From: Dustella Date: Sat, 8 Feb 2025 21:34:53 +0800 Subject: [PATCH] update: fix rotation --- .gitignore | 5 ++++- backend.py | 8 ++++++-- src/__init__.py | 2 +- src/plot.py | 13 +++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index c0d0230..f1538dd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ __pycache__ result staged -res.md \ No newline at end of file +res.md +dist +*.spec +build \ No newline at end of file diff --git a/backend.py b/backend.py index dfa4b1d..0dbdf33 100644 --- a/backend.py +++ b/backend.py @@ -1,11 +1,15 @@ from flask import Flask - +from flask_cors import CORS import src +import os app = Flask(__name__) +CORS(app) app.register_blueprint(src.tc_module, url_prefix='/tc') if __name__ == '__main__': - app.run(debug=True, port=35000) + # get port from env 'VERTEX_PORT' + port = os.getenv('VERTEX_PORT', 35000) + app.run(debug=True, host='0.0.0.0', port=port) diff --git a/src/__init__.py b/src/__init__.py index 022f973..ce67d09 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -22,7 +22,7 @@ def render(): data_this_day = data["data"][:, :, int(day)] map = create_heatmap(data_this_day, shift=( - 0, 180), colormap='hot', rotate_90=1) + 0, -180), colormap='hot', rotate_90=3) buff = BytesIO() map.save(buff, format="PNG") diff --git a/src/plot.py b/src/plot.py index 0d3106c..9722c1b 100644 --- a/src/plot.py +++ b/src/plot.py @@ -80,12 +80,21 @@ def create_heatmap(data, # 创建颜色映射 if colormap == 'hot': # 红色到黄色的渐变 + # 非线性变换,使得低值更容易区分。 使用 sqrt(x) 作为映射函数 def get_color(value): + # 首先把原value从0~0.1映射到0~1。如果value大于0.1,就直接取1 + value = min(value / 0.4, 1) if np.isnan(value): return (0, 0, 0, 0) - r = int(min(255, value * 510)) - g = int(max(0, min(255, value * 510 - 255))) + r = int(min(255, np.sqrt(value) * 256)) + g = int(max(0, min(255, np.sqrt(value) * 256 - 256))) return (r, g, 0, int(value * 255)) + # def get_color(value): + # if np.isnan(value): + # return (0, 0, 0, 0) + # r = int(min(255, value * 510)) + # g = int(max(0, min(255, value * 510 - 255))) + # return (r, g, 0, int(value * 255)) # 填充像素 pixels = image.load()