Udpate default script to a random svg line graph generator

This commit is contained in:
Peter Stockings
2024-03-24 21:49:05 +11:00
parent e21a575726
commit 6dcd46fee0

32
app.py
View File

@@ -41,16 +41,34 @@ API_URL = 'https://isolator.peterstockings.com/execute' #'http://127.0.0.1:5000/
DEFAULT_FUNCTION_NAME = 'foo'
DEFAULT_SCRIPT = """async (req) => {
console.log(`Hello ${environment.name}`)
return HtmlResponse(
`<div>
<h1>Method:${req.method}</h1>
<h3>Hello ${environment.name}</h3>
</div>`)
console.log(`Method:${req.method}`)
console.log(`Generating ${environment.lines} random lines...`)
let svgContent = "";
for (let i = 0; i < environment.lines; i++) {
console.log(i)
let pathD = "M2 " + Math.random() * 79;
let circles = "";
for (let x = 12; x <= 202; x += 10) {
let y = Math.random() * 79
pathD += ` L${x} ${y}`;
circles += `<circle cx="${x}" cy="${y}" r="1"></circle>`;
}
let pathColor = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
svgContent += `
<g style="fill: ${pathColor}; stroke: ${pathColor};">
<path d="${pathD}" fill="none" stroke="${pathColor}"></path>
${circles}
</g>`;
}
return HtmlResponse(`<svg viewBox="0 0 204 79" preserveAspectRatio="none">${svgContent}</svg>`);
}"""
DEFAULT_ENVIRONMENT = """{
"name": "Peter"
"lines": 3
}"""
def map_isolator_response_to_flask_response(response):