Commit d5720591 authored by Matteo's avatar Matteo
Browse files

update server endpoints

parent 2d316e30
PerformanceResults.xlsx
README.md
.DS_Store
\ No newline at end of file
.DS_Store
server/venv
server/pycache
\ No newline at end of file
{"WorkingPath": "/data", "FilesName": "sad", "Brands": true, "Speed": 7.5, "TapeThresholdPercentual": 80, "CapstanThresholdPercentual": 50, "MinDist": 10, "AngleThresh": 10000, "ScaleThresh": 200, "PosThresh": 40, "MinDistCapstan": 1, "AngleThreshCapstan": 1000, "ScaleThreshCapstan": 30, "PosThreshCapstan": 10}
\ No newline at end of file
{"WorkingPath": "./", "FilesName": "prova", "Brands": true, "Speed": 7.5, "TapeThresholdPercentual": 80, "CapstanThresholdPercentual": 50, "MinDist": 10, "AngleThresh": 10000, "ScaleThresh": 200, "PosThresh": 40, "MinDistCapstan": 1, "AngleThreshCapstan": 1000, "ScaleThreshCapstan": 30, "PosThreshCapstan": 10}
\ No newline at end of file
......@@ -2,4 +2,11 @@ title: Video Analyser
description: >
This is the API for the Video Analyser.
It is used to upload videos and get the results of the analysis.
The analysis is done by the Video Analyser
\ No newline at end of file
The analysis is done by the Video Analyser
license_info:
name: GPL-3.0
url: https://www.gnu.org/licenses/gpl-3.0.en.html
contact:
name: Matteo Spanio
email: dev2@audioinnova.com
version: 1.0.0
\ No newline at end of file
import os
import subprocess
import json
import yaml
def analyze(files_name: str, working_path: str | None = None) -> subprocess.CompletedProcess:
executable = os.path.abspath("frame_extraction/bin/frame_extraction")
config = get_file_content("config/config.json", "json")
# Update configuration file with query parameters
config["FilesName"] = files_name
if working_path is not None:
config["WorkingPath"] = working_path
with open("config/config.json", "w") as json_file:
json.dump(config, json_file)
process = subprocess.run([executable], capture_output=True)
return process
def get_file_content(file_name: str, format: str) -> dict:
with open(file_name) as fd:
if format == "yaml":
content = yaml.safe_load(fd)
return content
elif format == "json":
content = json.load(fd)
return content
import os
import subprocess
import json
import yaml
from fastapi import FastAPI, Response, status
with open("VideoAnalyser.json") as json_file:
info = json.load(json_file)
import server.functions as functions
app = FastAPI(
title="Video Analyser",
description=info["Description"],
version=info["Identifier"]["Specification"]["Version"],
contact={
"name": "Matteo Spanio",
"email": "dev2@audioinnova.com",
},
license_info={
"name": "GPL-3.0 License",
"url": "http://www.gnu.org/licenses/gpl-3.0.html"
}
)
info = functions.get_file_content('server/documentation.yaml', 'yaml')
app = FastAPI(**info)
@app.get("/")
def index():
return {"endpoints": ["analyze", "docs"]}
return {"endpoints": ["irregularityFile1", "irregularityFile2", "description", "docs"]}
@app.get("/description")
async def get_description():
with open('server/documentation.yaml') as yaml_file:
documentation = yaml.safe_load(yaml_file)
return documentation
return info
@app.get("/analyze", status_code=200)
async def analyze(files_name: str, response: Response, working_path: str | None = None ):
@app.get("/irregularityFile/{id}", status_code=200)
def get_irregularity_file(files_name: str, id: int, response: Response, working_path: str | None = None):
executable = os.path.abspath("frame_extraction/bin/frame_extraction")
required_file = f'VideoAnalyser_IrregularityFileOutput{id}.json'
try:
return functions.get_file_content(required_file, 'json')
# Read configuration file
with open("config/config.json") as json_file:
config = json.load(json_file)
except:
process = functions.analyze(files_name, working_path)
# Update configuration file with query parameters
config["FilesName"] = files_name
if working_path is not None:
config["WorkingPath"] = working_path
with open("config/config.json", "w") as json_file:
json.dump(config, json_file)
if process.returncode == 0:
return functions.get_file_content(required_file, 'json')
process = [
executable,
]
cprocess = subprocess.run(process, capture_output=True)
if cprocess.returncode == 0:
with open('AudioAnalyser_IrregularityFileOutput1.json') as json_file:
editing_list = json.load(json_file)
return editing_list
else:
response.status_code = status.HTTP_412_PRECONDITION_FAILED
return {"error": {
"returncode": cprocess.returncode,
"stdout": cprocess.stdout.decode("utf-8"),
"stderr": cprocess.stderr.decode("utf-8"),
}}
else:
response.status_code = status.HTTP_412_PRECONDITION_FAILED
return {"error": {
"returncode": process.returncode,
"stdout": process.stdout.decode("utf-8"),
"stderr": process.stderr.decode("utf-8"),
}}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment