update: fix rotation

This commit is contained in:
Dustella 2025-02-08 21:34:53 +08:00
parent e1b44ed2f9
commit 9a4efca7c2
Signed by: Dustella
GPG Key ID: 35AA0AA3DC402D5C
4 changed files with 22 additions and 6 deletions

5
.gitignore vendored
View File

@ -4,4 +4,7 @@
__pycache__
result
staged
res.md
res.md
dist
*.spec
build

View File

@ -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)

View File

@ -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")

View File

@ -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()