Skip to content
Snippets Groups Projects
Commit 6b21d1a5 authored by Lorenz Boguhn's avatar Lorenz Boguhn Committed by Lorenz Boguhn
Browse files

Fixed old python scripts

parent c172480b
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!92Introduce experiment evaluation,!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 logging
import os
import pandas as pd
import json
import numpy as np
from fastapi.encoders import jsonable_encoder
app = FastAPI()
def execute(results, threshold):
@app.get("/evaluate-slope")
def evaluate_slope(total_lag):
print("request received")
print(total_lag)
execute(total_lag, 1000)
return {"suitable" : "false"}
d = []
for result in results:
#print(results)
group = result['metric']['group']
for value in result['values']:
# 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):
df = pd.DataFrame(total_lag)
print(df)
try:
trend_slope = trend_slope_computer.compute(df, 60)
trend_slope = trend_slope_computer.compute(df, 0)
except Exception as e:
err_msg = 'Computing trend slope failed'
print(err_msg)
......@@ -30,3 +35,12 @@ def execute(total_lag, threshold):
print(f"Trend Slope: {trend_slope}")
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
import pandas as pd
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']
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