Skip to content
Snippets Groups Projects
Commit 632699b8 authored by Lorenz Boguhn's avatar Lorenz Boguhn
Browse files

Fixed old python scripts

parent d1bef630
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!96Handle shutdown,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
from fastapi import FastAPI from fastapi import FastAPI,Request
import trend_slope_computer as trend_slope_computer import trend_slope_computer as trend_slope_computer
import logging import logging
import os import os
import pandas as pd import pandas as pd
import json
import numpy as np
from fastapi.encoders import jsonable_encoder
app = FastAPI() app = FastAPI()
def execute(results, threshold):
@app.get("/evaluate-slope") d = []
def evaluate_slope(total_lag): for result in results:
print("request received") #print(results)
print(total_lag) group = result['metric']['group']
execute(total_lag, 1000) for value in result['values']:
return {"suitable" : "false"} # print(value)
d.append({'group': group, 'timestamp': int(
value[0]), 'value': int(value[1]) if value[1] != 'NaN' else 0})
df = pd.DataFrame(d)
def execute(total_lag, threshold): print(df)
df = pd.DataFrame(total_lag)
try: try:
trend_slope = trend_slope_computer.compute(df, 60) trend_slope = trend_slope_computer.compute(df, 0)
except Exception as e: except Exception as e:
err_msg = 'Computing trend slope failed' err_msg = 'Computing trend slope failed'
print(err_msg) print(err_msg)
...@@ -30,3 +35,12 @@ def execute(total_lag, threshold): ...@@ -30,3 +35,12 @@ def execute(total_lag, threshold):
print(f"Trend Slope: {trend_slope}") print(f"Trend Slope: {trend_slope}")
return trend_slope < threshold return trend_slope < threshold
@app.post("/evaluate-slope",response_model=bool)
async def evaluate_slope(request: Request):
print("request received")
x = json.loads(await request.body())
#x = np.array(x['total_lag'])
y = execute(x['total_lag'], 1000)
print(print(y))
return y
...@@ -2,7 +2,8 @@ from sklearn.linear_model import LinearRegression ...@@ -2,7 +2,8 @@ from sklearn.linear_model import LinearRegression
import pandas as pd import pandas as pd
import os import os
def compute(input, warmup_sec): def compute(x, warmup_sec):
input = x
input['sec_start'] = input.loc[0:, 'timestamp'] - input.iloc[0]['timestamp'] input['sec_start'] = input.loc[0:, 'timestamp'] - input.iloc[0]['timestamp']
regress = input.loc[input['sec_start'] >= warmup_sec] # Warm-Up regress = input.loc[input['sec_start'] >= warmup_sec] # Warm-Up
......
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