This repository was archived by the owner on Jul 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathserver.py
More file actions
63 lines (54 loc) · 1.9 KB
/
Copy pathserver.py
File metadata and controls
63 lines (54 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask
import requests
import flask
import pickle
import pandas as pd
import sys
import os
from dotenv import load_dotenv
from joblib import load
load_dotenv()
# app = Flask(__name__)
# @app.route('/')
# cookies only needed if behind realm auth
# get meter data
# maximo_domain = sys.argv[1] # IP Address + PORT
#max_token = sys.argv[2]
asset_id = sys.argv[1] # "2112"
realm_token = sys.argv[2]
cookies = dict(LtpaToken2=realm_token)
headers = {'Content-Type': 'application/json',
"maxauth": os.getenv("max_token")}
# Prereq
# Create meter for each sensor value / feature associated with model
q_endpoint = "/maximo/oslc/os/mxasset?oslc.select=assetmeter,expectedlife&oslc.where=assetnum=" + asset_id
res = requests.get(os.getenv("maximo_domain") + q_endpoint,
cookies=cookies, headers=headers)
meter_data = {}
print(res)
meters = res.json()["rdfs:member"][0]["spi:assetmeter"]
for m in meters:
meter_data[m['spi:metername']] = m['spi:lastreading']
# convert meter values to pandas dataframe
meter_df = pd.DataFrame.from_dict(meter_data, orient='index')
'''
clf = load("lin_reg.joblib")
clf.predict(meter_df)
predictions = clf.predict(meter_df)
print("RUL:" + predictions.join())
'''
threshold = 50
predictions = [62]
# update RUL in maximo DB
requests.post(maximo_domain + "/maximo/oslc/os/mxasset/" + restid,
data={"expectedlife": predictions[0]}, cookies=cookies, headers=headers)
# create work order if RUL below threshold
if predictions[0] < threshold:
asset_num = str(2112)
site_id = "DENVER"
wo_endpoint = "/maxrest/rest/mbo/workorder?_lid=" + username + "&_lpwd=" + password + \
"&_compact=true&_format=json&description=FixTurboFan&siteid=" + \
site_id + "&assetnum=" + asset_num
requests.put(maximo_domain + wo_endpoint,
data={"expectedlife": predictions[0]}, cookies=cookies, headers=headers)
# NOTES, remove below