mirror of
				https://github.com/ivanch/tcc.git
				synced 2025-10-31 09:27:36 +00:00 
			
		
		
		
	adding nginx page & simulation endpoint
This commit is contained in:
		
							
								
								
									
										26
									
								
								ASP.NET/Controllers/SimulationController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								ASP.NET/Controllers/SimulationController.cs
									
									
									
									
									
										Normal 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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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/81Bkht5C/big-image.png && \ | ||||
|     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 && \ | ||||
|     mkdir -p ./static && \ | ||||
|     mv small-image.png ./static && \ | ||||
|     mv big-image.png ./static && \ | ||||
|     mv video.mp4 ./static | ||||
|     mv video.mp4 ./static && \ | ||||
|     mv nginx.html ./static | ||||
|  | ||||
| # Build runtime image | ||||
| FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim | ||||
|   | ||||
| @@ -18,7 +18,8 @@ WORKDIR /app | ||||
|  | ||||
| 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/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 . . | ||||
|  | ||||
| @@ -27,6 +28,7 @@ RUN cargo build --release && \ | ||||
|     mv small-image.png ./static && \ | ||||
|     mv big-image.png ./static && \ | ||||
|     mv video.mp4 ./static && \ | ||||
|     mv nginx.html ./static && \ | ||||
|     ldconfig /usr/local/lib | ||||
|  | ||||
| ENV LD_LIBRARY_PATH=/usr/local/lib | ||||
|   | ||||
| @@ -15,6 +15,20 @@ async fn static_serve(req: HttpRequest) -> Result<NamedFile> { | ||||
|     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")] | ||||
| async fn load_small_image() -> Result<NamedFile> { | ||||
|     let real_path = "static/small-image.png"; | ||||
| @@ -74,6 +88,7 @@ async fn main() -> std::io::Result<()> { | ||||
|             .service(load_big_image) | ||||
|             .service(save_big_image) | ||||
|             .service(blur_image) | ||||
|             .service(simulation_harmonic_progression) | ||||
|             .app_data(web::PayloadConfig::new(1024 * 1024 * 1024)) | ||||
|     }) | ||||
|     .bind(("0.0.0.0", 5000))? | ||||
|   | ||||
| @@ -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 && \ | ||||
|     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/RzXwJG7o/nginx.html && \ | ||||
|     rm -rf runtimes && \ | ||||
|     mkdir -p ./static && \ | ||||
|     mv small-image.png ./static && \ | ||||
|     mv big-image.png ./static && \ | ||||
|     mv video.mp4 ./static | ||||
|     mv video.mp4 ./static && \ | ||||
|     mv nginx.html ./static | ||||
|  | ||||
| COPY . . | ||||
|  | ||||
|   | ||||
| @@ -1,11 +1,13 @@ | ||||
| from flask import Flask | ||||
| from controllers.status import status_blueprint | ||||
| from controllers.simulation import simulation_blueprint | ||||
| from controllers.image import image_blueprint | ||||
|  | ||||
| app = Flask(__name__) | ||||
|  | ||||
| # | ||||
| app.register_blueprint(status_blueprint) | ||||
| app.register_blueprint(simulation_blueprint) | ||||
| app.register_blueprint(image_blueprint) | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|   | ||||
							
								
								
									
										23
									
								
								FlaskAPI/controllers/simulation.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								FlaskAPI/controllers/simulation.py
									
									
									
									
									
										Normal 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 | ||||
| @@ -126,7 +126,9 @@ if __name__ == '__main__': | ||||
|         endpoint_file = endpoint_name.replace('/', '') | ||||
|  | ||||
|         filename = f'data/resource_ASP.NET_{endpoint_file}.csv' | ||||
|         filename = filename.replace("?", "_") | ||||
|         generate_resource_graph(filename, framework_name, endpoint_name) | ||||
|  | ||||
|         filename = f'data/req_ASP.NET_{endpoint_file}.csv' | ||||
|         filename = filename.replace("?", "_") | ||||
|         generate_req_graph(filename, framework_name, endpoint_name) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user