fta
This commit is contained in:
parent
a033a53a32
commit
73eb9647a2
@ -55,9 +55,9 @@ from .datasets import (
|
|||||||
datasets_document,
|
datasets_document,
|
||||||
datasets_segments,
|
datasets_segments,
|
||||||
external,
|
external,
|
||||||
|
fta_test,
|
||||||
hit_testing,
|
hit_testing,
|
||||||
website,
|
website,
|
||||||
fta_test,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Import explore controllers
|
# Import explore controllers
|
||||||
|
@ -1,30 +1,20 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from flask import Response
|
|
||||||
import requests
|
import requests
|
||||||
|
from flask import Response
|
||||||
|
from flask_restful import Resource, reqparse
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
|
||||||
from controllers.console import api
|
from controllers.console import api
|
||||||
|
|
||||||
from flask_restful import Resource, reqparse
|
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
|
|
||||||
from models.fta import ComponentFailure, ComponentFailureStats
|
|
||||||
|
|
||||||
from extensions.ext_storage import storage
|
from extensions.ext_storage import storage
|
||||||
|
from models.fta import ComponentFailure, ComponentFailureStats
|
||||||
|
|
||||||
|
|
||||||
class FATTestApi(Resource):
|
class FATTestApi(Resource):
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument(
|
parser.add_argument("log_process_data", nullable=False, required=True, type=str, location="args")
|
||||||
"log_process_data",
|
|
||||||
nullable=False,
|
|
||||||
required=True,
|
|
||||||
type=str,
|
|
||||||
location="args"
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print(args["log_process_data"])
|
print(args["log_process_data"])
|
||||||
# Extract the JSON string from the text field
|
# Extract the JSON string from the text field
|
||||||
@ -47,7 +37,7 @@ class FATTestApi(Resource):
|
|||||||
FailureMode=data["FailureMode"],
|
FailureMode=data["FailureMode"],
|
||||||
Cause=data["Cause"],
|
Cause=data["Cause"],
|
||||||
RepairAction=data["RepairAction"],
|
RepairAction=data["RepairAction"],
|
||||||
Technician=data["Technician"]
|
Technician=data["Technician"],
|
||||||
)
|
)
|
||||||
db.session.add(component_failure)
|
db.session.add(component_failure)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@ -98,41 +88,31 @@ class FATTestApi(Resource):
|
|||||||
# Convert stats to list of tuples format
|
# Convert stats to list of tuples format
|
||||||
stats_list = []
|
stats_list = []
|
||||||
for stat in component_failure_stats:
|
for stat in component_failure_stats:
|
||||||
stats_list.append((
|
stats_list.append(
|
||||||
stat.StatID,
|
(
|
||||||
stat.Component,
|
stat.StatID,
|
||||||
stat.FailureMode,
|
stat.Component,
|
||||||
stat.Cause,
|
stat.FailureMode,
|
||||||
stat.PossibleAction,
|
stat.Cause,
|
||||||
stat.Probability,
|
stat.PossibleAction,
|
||||||
stat.MTBF
|
stat.Probability,
|
||||||
))
|
stat.MTBF,
|
||||||
|
)
|
||||||
|
)
|
||||||
return {"data": stats_list}, 200
|
return {"data": stats_list}, 200
|
||||||
|
|
||||||
|
|
||||||
# generate-fault-tree
|
# generate-fault-tree
|
||||||
class GenerateFaultTreeApi(Resource):
|
class GenerateFaultTreeApi(Resource):
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument(
|
parser.add_argument("llm_text", nullable=False, required=True, type=str, location="args")
|
||||||
"llm_text",
|
|
||||||
nullable=False,
|
|
||||||
required=True,
|
|
||||||
type=str,
|
|
||||||
location="args"
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
entities = args["llm_text"].replace("```", "").replace("\\n", "\n")
|
entities = args["llm_text"].replace("```", "").replace("\\n", "\n")
|
||||||
print(entities)
|
print(entities)
|
||||||
request_data = {
|
request_data = {"fault_tree_text": entities}
|
||||||
"fault_tree_text": entities
|
|
||||||
}
|
|
||||||
url = "https://fta.cognitech-dev.live/generate-fault-tree"
|
url = "https://fta.cognitech-dev.live/generate-fault-tree"
|
||||||
headers = {
|
headers = {"accept": "application/json", "Content-Type": "application/json"}
|
||||||
"accept": "application/json",
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
}
|
|
||||||
|
|
||||||
response = requests.post(url, json=request_data, headers=headers)
|
response = requests.post(url, json=request_data, headers=headers)
|
||||||
print(response.json())
|
print(response.json())
|
||||||
@ -140,24 +120,17 @@ class GenerateFaultTreeApi(Resource):
|
|||||||
|
|
||||||
|
|
||||||
class ExtractSVGApi(Resource):
|
class ExtractSVGApi(Resource):
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument(
|
parser.add_argument("svg_text", nullable=False, required=True, type=str, location="args")
|
||||||
"svg_text",
|
|
||||||
nullable=False,
|
|
||||||
required=True,
|
|
||||||
type=str,
|
|
||||||
location="args"
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
# svg_text = ''.join(args["svg_text"].splitlines())
|
# svg_text = ''.join(args["svg_text"].splitlines())
|
||||||
svg_text = args["svg_text"].replace('\n', '')
|
svg_text = args["svg_text"].replace("\n", "")
|
||||||
svg_text = svg_text.replace('\"', '"')
|
svg_text = svg_text.replace('"', '"')
|
||||||
print(svg_text)
|
print(svg_text)
|
||||||
svg_text_json = json.loads(svg_text)
|
svg_text_json = json.loads(svg_text)
|
||||||
svg_content = svg_text_json.get("data").get("svg_content")[0]
|
svg_content = svg_text_json.get("data").get("svg_content")[0]
|
||||||
svg_content = svg_content.replace('\n', '').replace('\"', '"')
|
svg_content = svg_content.replace("\n", "").replace('"', '"')
|
||||||
file_key = "fta_svg/" + "fat.svg"
|
file_key = "fta_svg/" + "fat.svg"
|
||||||
if storage.exists(file_key):
|
if storage.exists(file_key):
|
||||||
storage.delete(file_key)
|
storage.delete(file_key)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import base64
|
import base64
|
||||||
from pathlib import Path
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from configs import dify_config
|
from configs import dify_config
|
||||||
from core.file import file_repository
|
from core.file import file_repository
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from core.tools.errors import ToolProviderCredentialValidationError
|
|
||||||
from core.tools.provider.builtin.dalle.tools.dalle2 import DallE2Tool
|
|
||||||
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
|
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
from base64 import b64decode
|
|
||||||
import json
|
|
||||||
import tempfile
|
import tempfile
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
from openai import OpenAI
|
|
||||||
from yarl import URL
|
|
||||||
from core.file.enums import FileType
|
from core.file.enums import FileType
|
||||||
|
|
||||||
from core.file.file_manager import download_to_target_path
|
from core.file.file_manager import download_to_target_path
|
||||||
from core.rag.extractor.text_extractor import TextExtractor
|
from core.rag.extractor.text_extractor import TextExtractor
|
||||||
from core.rag.splitter.fixed_text_splitter import FixedRecursiveCharacterTextSplitter
|
from core.rag.splitter.fixed_text_splitter import FixedRecursiveCharacterTextSplitter
|
||||||
|
@ -1,32 +1,10 @@
|
|||||||
import base64
|
|
||||||
import enum
|
|
||||||
import hashlib
|
|
||||||
import hmac
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import pickle
|
|
||||||
import re
|
|
||||||
import time
|
|
||||||
from json import JSONDecodeError
|
|
||||||
|
|
||||||
from sqlalchemy import func
|
|
||||||
from sqlalchemy.dialects.postgresql import JSONB
|
|
||||||
|
|
||||||
from configs import dify_config
|
|
||||||
from core.rag.retrieval.retrieval_methods import RetrievalMethod
|
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from extensions.ext_storage import storage
|
|
||||||
|
|
||||||
from .account import Account
|
|
||||||
from .model import App, Tag, TagBinding, UploadFile
|
|
||||||
from .types import StringUUID
|
|
||||||
|
|
||||||
|
|
||||||
class ComponentFailure(db.Model):
|
class ComponentFailure(db.Model):
|
||||||
__tablename__ = "component_failure"
|
__tablename__ = "component_failure"
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
db.UniqueConstraint('Date', 'Component', 'FailureMode', 'Cause', 'Technician', name='unique_failure_entry'),
|
db.UniqueConstraint("Date", "Component", "FailureMode", "Cause", "Technician", name="unique_failure_entry"),
|
||||||
)
|
)
|
||||||
|
|
||||||
FailureID = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
FailureID = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user