Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACORDO OFICIAL #975

Open
felipeliliti opened this issue Jul 20, 2024 · 0 comments
Open

ACORDO OFICIAL #975

felipeliliti opened this issue Jul 20, 2024 · 0 comments

Comments

@felipeliliti
Copy link

import pandas as pd
import numpy as np
import requests

def collect_data(api_url):
response = requests.get(api_url)
data = response.json()
df = pd.DataFrame(data)
return df

Exemplo de URL de API para coleta de dados

api_url = "https://example.com/api/system_status"
data = collect_data(api_url)from sklearn.ensemble import IsolationForest

def detect_anomalies(data):
model = IsolationForest(contamination=0.01)
model.fit(data)
data['anomaly'] = model.predict(data)
anomalies = data[data['anomaly'] == -1]
return anomalies

anomalies = detect_anomalies(data)from twilio.rest import Client

def send_alert(anomalies):
if not anomalies.empty:
account_sid = 'your_account_sid'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
message = client.messages.create(
body=f"Anomalias detectadas: {anomalies}",
from_='+1234567890',
to='+0987654321'
)
print(message.sid)

send_alert(anomalies)
from flask import Flask, render_template
import pandas as pd

app = Flask(name)

@app.route('/')
def index():
data = collect_data(api_url)
anomalies = detect_anomalies(data)
return render_template('index.html', tables=[data.to_html(classes='data', header="true"), anomalies.to_html(classes='data', header="true")])

if name == 'main':
app.run(debug=True)from apscheduler.schedulers.blocking import BlockingScheduler

scheduler = BlockingScheduler()

@scheduler.scheduled_job('interval', minutes=5)
def scheduled_job():
data = collect_data(api_url)
anomalies = detect_anomalies(data)
send_alert(anomalies)

scheduler.start()

<title>TechGuardian Dashboard</title>

Status dos Sistemas

Dados Coletados

{{ tables[0]|safe }}

Anomalias Detectadas

{{ tables[1]|safe }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant