Add al files from local folder
This commit is contained in:
77
Influxdataframe.py
Normal file
77
Influxdataframe.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Dec 2 07:46:09 2022
|
||||
|
||||
@author: Daniel Häfliger
|
||||
"""
|
||||
import pandas as pd
|
||||
import Influxclient as I
|
||||
import influxdb_client
|
||||
|
||||
|
||||
# Returns values of an influxDB as they where specified in the config.xml
|
||||
# as a Pandas Dataframe
|
||||
def Get_Df():
|
||||
|
||||
|
||||
xfile = pd.read_xml('config.xml')
|
||||
org = (xfile.loc[xfile['category'] == 'influx'].organisation[0])
|
||||
token = (xfile.loc[xfile['category'] == 'influx'].influxtoken[0])
|
||||
url = (xfile.loc[xfile['category'] == 'influx'].url[0])
|
||||
|
||||
client = influxdb_client.InfluxDBClient(
|
||||
url=url,
|
||||
token=token,
|
||||
org=org
|
||||
)
|
||||
|
||||
bucket = (xfile.loc[xfile['category'] == 'influx'].bucket[0])
|
||||
measurement = (xfile.loc[xfile['category'] == 'influx'].measurement[0])
|
||||
|
||||
interval = (xfile.loc[xfile['category'] == 'influx'].interval[0])
|
||||
valuessince = (xfile.loc[xfile['category'] == 'influx'].time[0])
|
||||
|
||||
Input = xfile.loc[xfile['category'] == 'feature'].f[1]
|
||||
#numberofFeature=(xfile.loc[xfile['category']=='feature'].features[1])
|
||||
|
||||
feature = Input.split()
|
||||
pred = xfile.loc[xfile['category'] == 'pred'].p1[2]
|
||||
|
||||
|
||||
data = {
|
||||
|
||||
"y_r": I.Get_Time(client, bucket, valuessince, measurement, feature[0])[0],
|
||||
"y_i": I.Get_Time(client, bucket, valuessince, measurement, feature[0])[1],
|
||||
"d_r": I.Get_Time(client, bucket, valuessince, measurement, feature[0])[2],
|
||||
"d_i": I.Get_Time(client, bucket, valuessince, measurement, feature[0])[3],
|
||||
|
||||
}
|
||||
|
||||
for i in range(len(feature)):
|
||||
newd = {(feature[i]): I.Get_Value(client, bucket,
|
||||
valuessince, measurement, feature[i])}
|
||||
data.update(newd)
|
||||
|
||||
newd = {(pred): I.Get_Value(client, bucket,
|
||||
valuessince, measurement, pred)}
|
||||
data.update(newd)
|
||||
|
||||
return pd.DataFrame(data)
|
||||
|
||||
|
||||
|
||||
# Shifts the target variable and adds [shift_number] colums with the shiftet
|
||||
# values, then return the new Dataframe
|
||||
def ShiftTarget(df, shift_number, targetvariable):
|
||||
dfziel = df[[targetvariable]].copy()
|
||||
df = df.rename(columns={targetvariable:(targetvariable+str(0))})
|
||||
dfziel = dfziel.rename(columns={targetvariable:(targetvariable+str(0))})
|
||||
|
||||
|
||||
|
||||
for i in range(shift_number):
|
||||
dfziel = dfziel.rename(columns={(targetvariable+str(i)):targetvariable+str(i+1)})
|
||||
dfziel = dfziel.shift(1)
|
||||
df = pd.concat([df, dfziel], axis=1)
|
||||
|
||||
return df
|
||||
Reference in New Issue
Block a user