adding nginx page & simulation endpoint

This commit is contained in:
José Henrique 2023-10-26 22:33:28 -03:00
parent bba35341fb
commit 2e71c4e8ed
8 changed files with 77 additions and 3 deletions

View File

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using TCC.Services;
namespace TCC.Controllers
{
[ApiController]
[Route("simulation")]
public class SimulationController : ControllerBase
{
public SimulationController()
{
}
[HttpGet("harmonic-progression")]
public async Task<IActionResult> GetHarmonicProgression([FromQuery] int n)
{
float sum = 0;
for (int i = 1; i <= n; i++)
{
sum += 1.0f / i;
}
return Ok(sum);
}
}
}

View File

@ -15,11 +15,13 @@ RUN cd out && \
wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \ wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \ wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html && \
rm -rf runtimes && \ rm -rf runtimes && \
mkdir -p ./static && \ mkdir -p ./static && \
mv small-image.png ./static && \ mv small-image.png ./static && \
mv big-image.png ./static && \ mv big-image.png ./static && \
mv video.mp4 ./static mv video.mp4 ./static && \
mv nginx.html ./static
# Build runtime image # Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim

View File

@ -18,7 +18,8 @@ WORKDIR /app
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \ wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html
COPY . . COPY . .
@ -27,6 +28,7 @@ RUN cargo build --release && \
mv small-image.png ./static && \ mv small-image.png ./static && \
mv big-image.png ./static && \ mv big-image.png ./static && \
mv video.mp4 ./static && \ mv video.mp4 ./static && \
mv nginx.html ./static && \
ldconfig /usr/local/lib ldconfig /usr/local/lib
ENV LD_LIBRARY_PATH=/usr/local/lib ENV LD_LIBRARY_PATH=/usr/local/lib

View File

@ -15,6 +15,20 @@ async fn static_serve(req: HttpRequest) -> Result<NamedFile> {
Ok(NamedFile::open(real_path)?) Ok(NamedFile::open(real_path)?)
} }
#[get("/simulation/harmonic-progression")]
async fn simulation_harmonic_progression(req: HttpRequest) -> impl Responder {
let query_str = req.query_string();
let qs = QString::from(query_str);
let radius = qs.get("n").unwrap_or("1").parse::<f64>().unwrap_or(1.0);
let mut sum = 0.0;
for i in 1..=radius as i32 {
sum += 1.0 / i as f64;
}
HttpResponse::Ok().body(format!("{}", sum))
}
#[get("/image/load-small-image")] #[get("/image/load-small-image")]
async fn load_small_image() -> Result<NamedFile> { async fn load_small_image() -> Result<NamedFile> {
let real_path = "static/small-image.png"; let real_path = "static/small-image.png";
@ -74,6 +88,7 @@ async fn main() -> std::io::Result<()> {
.service(load_big_image) .service(load_big_image)
.service(save_big_image) .service(save_big_image)
.service(blur_image) .service(blur_image)
.service(simulation_harmonic_progression)
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024)) .app_data(web::PayloadConfig::new(1024 * 1024 * 1024))
}) })
.bind(("0.0.0.0", 5000))? .bind(("0.0.0.0", 5000))?

View File

@ -11,11 +11,13 @@ RUN apt-get update && apt-get install -y imagemagick && apt-get install -y wget
RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \
wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \ wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \
wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \ wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \
wget https://files.ivanch.me/api/public/dl/RzXwJG7o/nginx.html && \
rm -rf runtimes && \ rm -rf runtimes && \
mkdir -p ./static && \ mkdir -p ./static && \
mv small-image.png ./static && \ mv small-image.png ./static && \
mv big-image.png ./static && \ mv big-image.png ./static && \
mv video.mp4 ./static mv video.mp4 ./static && \
mv nginx.html ./static
COPY . . COPY . .

View File

@ -1,11 +1,13 @@
from flask import Flask from flask import Flask
from controllers.status import status_blueprint from controllers.status import status_blueprint
from controllers.simulation import simulation_blueprint
from controllers.image import image_blueprint from controllers.image import image_blueprint
app = Flask(__name__) app = Flask(__name__)
# #
app.register_blueprint(status_blueprint) app.register_blueprint(status_blueprint)
app.register_blueprint(simulation_blueprint)
app.register_blueprint(image_blueprint) app.register_blueprint(image_blueprint)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -0,0 +1,23 @@
from flask import request, Blueprint
simulation_blueprint = Blueprint('simulation_blueprint', __name__)
class SimulationController:
def __init__(self):
pass
def harmonic_progression(self, n):
sum = 0
for i in range(1, n):
sum += 1/i
return sum
simulation_controller = SimulationController()
@simulation_blueprint.route('/simulation/harmonic-progression', methods=['GET'])
def return_ok():
n = int(request.args.get('n'))
sum = simulation_controller.harmonic_progression(n)
return str(sum), 200

View File

@ -126,7 +126,9 @@ if __name__ == '__main__':
endpoint_file = endpoint_name.replace('/', '') endpoint_file = endpoint_name.replace('/', '')
filename = f'data/resource_ASP.NET_{endpoint_file}.csv' filename = f'data/resource_ASP.NET_{endpoint_file}.csv'
filename = filename.replace("?", "_")
generate_resource_graph(filename, framework_name, endpoint_name) generate_resource_graph(filename, framework_name, endpoint_name)
filename = f'data/req_ASP.NET_{endpoint_file}.csv' filename = f'data/req_ASP.NET_{endpoint_file}.csv'
filename = filename.replace("?", "_")
generate_req_graph(filename, framework_name, endpoint_name) generate_req_graph(filename, framework_name, endpoint_name)