Skip to content
Snippets Groups Projects
Commit 38d07a36 authored by Mostafa Hadizadeh's avatar Mostafa Hadizadeh
Browse files

added function to produce html and zip file in result

parent c0d3b43e
No related branches found
No related tags found
2 merge requests!4Add HTML and ZIP file to make the result section better,!2Plugin template
Pipeline #92741 passed
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
...@@ -14,6 +14,7 @@ PET plugin API wrapper. ...@@ -14,6 +14,7 @@ PET plugin API wrapper.
import os import os
import json import json
from pathlib import Path from pathlib import Path
import subprocess
# from evaluation_system.api.exceptions import PluginError # from evaluation_system.api.exceptions import PluginError
from typing import List, Optional from typing import List, Optional
...@@ -192,6 +193,128 @@ class PET(plugin.PluginAbstract): ...@@ -192,6 +193,128 @@ class PET(plugin.PluginAbstract):
return file_dict 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): 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"]) 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): ...@@ -223,5 +346,6 @@ class PET(plugin.PluginAbstract):
f"{tool_path} {json_file}", f"{tool_path} {json_file}",
stderr=error_f, stderr=error_f,
) )
self.prepare_html_output(config_dict["output_dir"])
return self.prepare_output(config_dict["output_dir"]) return self.prepare_output(config_dict["output_dir"])
...@@ -294,5 +294,5 @@ for ((YEAR=$START_YEAR;YEAR<END_YEAR+1;YEAR+=1)); do ...@@ -294,5 +294,5 @@ for ((YEAR=$START_YEAR;YEAR<END_YEAR+1;YEAR+=1)); do
} }
done done
wait wait
cd ${OUTPUT_DIR_VAR} && zip -r ${OUTPUT_DIR_VAR}/01_produced_data.zip . && cd -
echo '*** Calculation done ***' echo '*** Calculation done ***'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment