2025-03-05 11:40:19 +08:00

84 lines
2.3 KiB
Python

# 探空气球只有重力波
import base64
from urllib import response
from quart import Blueprint
from CONSTANT import DATA_BASEPATH
import modules.balloon as balloon
from quart import jsonify, request, send_file
from modules.balloon.gravityw_plot_perday import render_by_mode_single
from modules.balloon.gravityw_plot_year import get_all_modes, render_based_on_mode
from modules.balloon.utils import *
from quart.utils import run_sync
BASE_PATH_BALLOON = DATA_BASEPATH.balloon
all_year_data = pd.read_parquet(f"{BASE_PATH_BALLOON}/ballon_data_lin.parquet")
balloon_module = Blueprint("Balloon", __name__)
@balloon_module.route("/metadata/modes")
def supermeta():
return jsonify({
"combos": comboType,
"comboMode": comboMode,
"date": comboDate
})
@balloon_module.route("/metadata")
def list_ballon():
all_ballon_files = glob.glob(
f"{BASE_PATH_BALLOON}/**/**.nc", recursive=True)
return all_ballon_files
@balloon_module.route("/metadata/year")
def list_ballon_year_modes():
return get_all_modes()
@balloon_module.route("/metadata/stations")
def list_stations():
return []
@balloon_module.route("/render/year")
async def render_full_year():
# get start_year and end_year from query
start_year = request.args.get('start_year')
end_year = request.args.get('end_year')
mode = request.args.get('mode')
season = request.args.get('season')
station = request.args.get('station')
print(start_year, end_year)
df = await run_sync(get_ballon_full_df_by_year)(int(start_year), int(end_year), station, False)
buff = render_based_on_mode(df, mode, season)
return await send_file(buff, mimetype='image/png')
@balloon_module.route("/render/single")
async def render_single_path():
path = request.args.get('path')
mode = request.args.get('mode')
data = balloon.read_data(path)
result = render_by_mode_single(data, mode)
if result.has_data is False:
# give a 204 response if no data is found
return '', 204
img_str = base64.b64encode(result.image.getvalue()).decode("utf-8")
response_data = {
"image": img_str,
"metadata": {
"是否是地形波": "" if result.is_terrain_wave else "",
}
}
return response_data