diff --git a/pet-wrapper-api.py b/pet-wrapper-api.py index d8a6c72e448e84fc24a39d823dd515a43ea2e713..c43fe458cd95958f11221e0c88354d9c3e3acb1e 100644 --- a/pet-wrapper-api.py +++ b/pet-wrapper-api.py @@ -14,6 +14,7 @@ PET plugin API wrapper. import os import json from pathlib import Path +import subprocess # from evaluation_system.api.exceptions import PluginError from typing import List, Optional @@ -192,6 +193,128 @@ class PET(plugin.PluginAbstract): return file_dict + def prepare_html_output(self, path_output): + result = subprocess.run( + ["ls", "-la", path_output], capture_output=True, text=True + ) + ls_output = result.stdout + current_user = User() + + html_content = f"""<!DOCTYPE html> + <html> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <style> + body {{ + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; + margin: 0; + padding: 20px; + line-height: 1.6; + background-color: #1a1a1a; + display: flex; + flex-direction: column; + align-items: center; + min-height: 100vh; + }} + .info-text {{ + font-size: 16px; + max-width: 800px; + margin: 0 auto 20px auto; + background-color: white; + padding: 20px; + border-radius: 8px; + width: 100%; + box-sizing: border-box; + }} + .terminal {{ + background-color: #2d2d2d; + border-radius: 8px; + box-shadow: 0 10px 20px rgba(0,0,0,0.3); + width: 100%; + max-width: 800px; + overflow: hidden; + }} + .terminal-header {{ + background-color: #3d3d3d; + padding: 10px; + display: flex; + align-items: center; + }} + .terminal-buttons {{ + display: flex; + gap: 8px; + }} + .terminal-button {{ + width: 12px; + height: 12px; + border-radius: 50%; + }} + .terminal-button.close {{background-color: #ff5f56;}} + .terminal-button.minimize {{background-color: #ffbd2e;}} + .terminal-button.maximize {{background-color: #27c93f;}} + .terminal-title {{ + color: #ababab; + font-size: 14px; + margin-left: 20px; + }} + .terminal-body {{ + padding: 20px; + font-family: "Menlo", "Monaco", "Consolas", monospace; + font-size: 14px; + line-height: 1.5; + color: #fff; + overflow-x: auto; + }} + .prompt {{ + color: #98c379; + margin-bottom: 10px; + }} + .command {{ + color: #61afef; + margin-left: 8px; + }} + .output {{ + color: #abb2bf; + white-space: pre; + margin: 10px 0 20px 0; + }} + </style> + </head> + <body> + <div class="info-text"> + You can directly download the produced data from the link above or login to levante and and proceed with the exploration of the data. + </div> + <div class="terminal"> + <div class="terminal-header"> + <div class="terminal-buttons"> + <div class="terminal-button close"></div> + <div class="terminal-button minimize"></div> + <div class="terminal-button maximize"></div> + </div> + <span class="terminal-title">Terminal</span> + </div> + <div class="terminal-body"> + <div class="prompt"> + local:~$ <span class="command">ssh {current_user.getName()}@levante.dkrz.de</span> + </div> + <div class="prompt"> + {current_user.getName()}@levante.dkrz.de:~$ <span class="command">cd {path_output}</span> + </div> + <div class="prompt"> + {current_user.getName()}@levante.dkrz.de:{path_output}$ <span class="command">ls -la {path_output}</span> + </div> + <div class="output">{ls_output}</div> + </div> + </div> + </body> + </html>""" + + html_output_path = os.path.join(path_output, "02_view.html") + with open(html_output_path, "w") as f: + f.write(html_content) + + def run_tool(self, config_dict=None): config_dict["files"] = self.find_files(config_dict, ["tasmax", "tasmin", "sfcWind", "pvap", "rsds"], "day", config_dict["start_date"] + " to " + config_dict["end_date"]) @@ -223,5 +346,6 @@ class PET(plugin.PluginAbstract): f"{tool_path} {json_file}", stderr=error_f, ) + self.prepare_html_output(config_dict["output_dir"]) return self.prepare_output(config_dict["output_dir"]) diff --git a/src/pet/calculate_pet.sh b/src/pet/calculate_pet.sh index 6a7add285af29e148246fcb67cd1e4923c92e01f..a9b5b66696462878a1b5d6fd8ed9d9e624d9c7d1 100755 --- a/src/pet/calculate_pet.sh +++ b/src/pet/calculate_pet.sh @@ -294,5 +294,5 @@ for ((YEAR=$START_YEAR;YEAR<END_YEAR+1;YEAR+=1)); do } done wait - +cd ${OUTPUT_DIR_VAR} && zip -r ${OUTPUT_DIR_VAR}/01_produced_data.zip . && cd - echo '*** Calculation done ***'