Skip to content

Commit 970d1af

Browse files
author
Robbie
committed
Move website files back to website directory for GitHub Pages
1 parent c09d55b commit 970d1af

236 files changed

Lines changed: 18468 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Byte-compiled Python files
2+
*.pyc
3+
*.pyo
4+
__pycache__/
5+
6+
# Virtual environment
7+
.venv/
8+
env/
9+
venv/
10+
11+
# Logs and output files
12+
13+
# Cache and temporary files
14+
*.cache/
15+
*.bak/
16+
*.swp
17+
*.tmp
18+
*.~*
19+
.DS_Store
20+
thumbs.db
21+
22+
# Documentation and reports
23+
24+
25+
# Data and checkpoints
26+
27+
28+
# Config and explanation files
29+
30+
31+
# Templates and testing
32+
templates/
33+
tests/
34+
posts/
35+
versions/
36+
wiki/
37+
38+
# Image files and assets

ExampleExperiment_experiment.log

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2025-04-28 10:14:41,638 - INFO - Starting experiment: ExampleExperiment
2+
2025-04-28 10:14:41,638 - INFO - Metadata: {'author': 'OpenSourceContributor'}
3+
2025-04-28 10:14:41,638 - INFO - Running trial 1 out of 5
4+
2025-04-28 10:14:41,638 - INFO - Trial 1 result: 43
5+
2025-04-28 10:14:41,638 - INFO - Running trial 2 out of 5
6+
2025-04-28 10:14:41,638 - INFO - Trial 2 result: 38
7+
2025-04-28 10:14:41,638 - INFO - Running trial 3 out of 5
8+
2025-04-28 10:14:41,638 - INFO - Trial 3 result: 43
9+
2025-04-28 10:14:41,638 - INFO - Running trial 4 out of 5
10+
2025-04-28 10:14:41,638 - INFO - Trial 4 result: 73
11+
2025-04-28 10:14:41,638 - INFO - Running trial 5 out of 5
12+
2025-04-28 10:14:41,638 - INFO - Trial 5 result: 71
13+
2025-04-28 10:14:41,638 - INFO - Experiment ExampleExperiment completed in 0:00:00.000474

advanced_pipeline_report.pdf

1.16 KB
Binary file not shown.

ai_advanced_monitoring.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import logging
2+
import time
3+
import psutil
4+
5+
6+
class AdvancedMonitoring:
7+
"""
8+
Provides advanced monitoring functionality for system performance, including
9+
real-time metrics collection, periodic logging, and logging configuration.
10+
11+
The class contains static methods to monitor system performance with details
12+
such as CPU usage, memory usage, and latency. It supports periodic logging
13+
of these metrics and allows configuring the logging behavior for customization.
14+
15+
:ivar attribute1: No attributes are defined in this class as it contains
16+
only static methods.
17+
"""
18+
19+
@staticmethod
20+
def monitor_performance():
21+
"""
22+
Monitors real-time system performance and returns a performance report.
23+
24+
:return: dict containing performance metrics such as CPU usage, memory usage, and latency.
25+
"""
26+
logging.info("Starting advanced performance monitoring...")
27+
28+
# Collecting system metrics using psutil
29+
cpu_usage = psutil.cpu_percent(interval=1) # CPU usage as percentage
30+
memory_info = psutil.virtual_memory() # Memory usage information
31+
latency = AdvancedMonitoring.simulated_latency() # Simulated latency for demonstration
32+
33+
# Creating a performance report
34+
performance_report = {
35+
"cpu_usage": f"{cpu_usage}%",
36+
"memory_usage": f"{memory_info.used / (1024 ** 2):.2f} MB", # Convert to MB
37+
"latency": f"{latency} ms"
38+
}
39+
40+
# Logging the report
41+
logging.info("Performance Monitoring Report Generated.")
42+
logging.debug(f"Performance Details: {performance_report}")
43+
return performance_report
44+
45+
@staticmethod
46+
def simulated_latency():
47+
"""
48+
Simulates latency measurement for demonstration purposes.
49+
Replace this with actual model or process latency in real implementations.
50+
51+
:return: Simulated latency in milliseconds.
52+
"""
53+
# Simulating latency measurement
54+
return round(200 + (time.time() % 10)) # Example: fluctuates slightly for a realistic demo
55+
56+
@staticmethod
57+
def log_periodic_metrics(interval=60):
58+
"""
59+
Logs system performance metrics at regular intervals.
60+
61+
:param interval: Time interval in seconds for periodic logging.
62+
"""
63+
logging.info("Starting periodic performance logging...")
64+
try:
65+
while True:
66+
metrics = AdvancedMonitoring.monitor_performance()
67+
logging.info(f"Periodic Metrics: {metrics}")
68+
time.sleep(interval)
69+
except KeyboardInterrupt:
70+
logging.info("Advanced Monitoring terminated by user.")
71+
72+
@staticmethod
73+
def setup_logging(level=logging.INFO, log_file=None):
74+
"""
75+
Configures the logging setup for monitoring.
76+
77+
:param level: Logging level (default: logging.INFO).
78+
:param log_file: Optional file path to save logs, logs to console by default.
79+
"""
80+
handlers = [logging.StreamHandler()]
81+
if log_file:
82+
handlers.append(logging.FileHandler(log_file))
83+
84+
logging.basicConfig(
85+
level=level,
86+
format="%(asctime)s - %(levelname)s - %(message)s",
87+
handlers=handlers,
88+
)
89+
90+
91+
if __name__ == "__main__":
92+
# Example execution of the script
93+
AdvancedMonitoring.setup_logging(level=logging.DEBUG) # Setting up logging
94+
logging.info("Starting AI Advanced Monitoring script...")
95+
AdvancedMonitoring.log_periodic_metrics(interval=30) # Start periodic monitoring every 30 seconds

ai_advanced_reporting.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import logging
2+
from fpdf import FPDF
3+
4+
5+
class AdvancedReporting:
6+
"""
7+
Provides methods to generate PDF reports summarizing pipeline metrics and insights,
8+
and to configure logging for the report generation process.
9+
10+
This class is designed to handle the creation of professional-quality PDF reports
11+
based on given pipeline data. Additionally, it offers a utility to setup logging
12+
for monitoring and debugging purposes.
13+
14+
:ivar default_font: Default font used for the PDF reports.
15+
:type default_font: str
16+
:ivar default_font_size: Default size of the font used in PDF reports.
17+
:type default_font_size: int
18+
:ivar log_level: Default logging level for report generation process.
19+
:type log_level: int
20+
"""
21+
22+
@staticmethod
23+
def generate_pdf_report(report_data, output_path):
24+
"""
25+
Generates a PDF report summarizing pipeline metrics and insights.
26+
27+
:param report_data: Dictionary containing metrics, charts, or summaries.
28+
:param output_path: String, the path where the PDF report will be saved.
29+
"""
30+
logging.info("Starting PDF report generation...")
31+
try:
32+
# Initialize the PDF object
33+
pdf = FPDF()
34+
pdf.add_page()
35+
pdf.set_font("Arial", size=12)
36+
37+
# Add title
38+
pdf.cell(200, 10, txt="Pipeline Report", ln=True, align="C")
39+
pdf.ln(10) # Add a line break
40+
41+
# Fill the report data into PDF
42+
for key, value in report_data.items():
43+
if isinstance(value, dict):
44+
# Handle nested dictionaries by flattening them
45+
pdf.cell(200, 10, txt=f"{key}:", ln=True, align="L")
46+
for sub_key, sub_value in value.items():
47+
pdf.cell(200, 10, txt=f" {sub_key}: {sub_value}", ln=True, align="L")
48+
else:
49+
pdf.cell(200, 10, txt=f"{key}: {value}", ln=True, align="L")
50+
51+
# Save the PDF to the specified output path
52+
pdf.output(output_path)
53+
logging.info(f"PDF report successfully saved at: {output_path}")
54+
except Exception as e:
55+
logging.error(f"Failed to generate PDF report: {e}")
56+
raise
57+
58+
@staticmethod
59+
def setup_logging(level=logging.INFO, log_file=None):
60+
"""
61+
Configures logging for the report generation process.
62+
63+
:param level: Logging level (default: logging.INFO).
64+
:param log_file: Optional, file path to store logs. Logs to console if not specified.
65+
"""
66+
handlers = [logging.StreamHandler()]
67+
if log_file:
68+
handlers.append(logging.FileHandler(log_file))
69+
70+
logging.basicConfig(
71+
level=level,
72+
format="%(asctime)s - %(levelname)s - %(message)s",
73+
handlers=handlers,
74+
)
75+
76+
77+
if __name__ == "__main__":
78+
# Setup logging for the script
79+
AdvancedReporting.setup_logging(level=logging.DEBUG)
80+
81+
logging.info("Advanced Reporting Script Started...")
82+
83+
# Example Usage: Sample report data
84+
example_report_data = {
85+
"Model": "Random Forest",
86+
"Accuracy": "87%",
87+
"Precision": "85%",
88+
"Recall": "81%",
89+
"Training Summary": {
90+
"Training Time": "15 minutes",
91+
"Training Data": "Dataset-X",
92+
},
93+
"Final Comments": "The performance is satisfactory, with opportunities for improvement in recall."
94+
}
95+
96+
# Generating the report
97+
output_report_path = "advanced_pipeline_report.pdf"
98+
AdvancedReporting.generate_pdf_report(example_report_data, output_report_path)

ai_alerting.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import smtplib
2+
from email.mime.text import MIMEText
3+
import logging
4+
import os
5+
6+
7+
class AlertingSystem:
8+
"""
9+
A system for sending email alerts using SMTP settings.
10+
11+
This class facilitates the sending of alert emails. It requires SMTP
12+
configuration details including server address, port number, sender's and
13+
receiver's email addresses, and the sender’s email password. This system
14+
ensures secure communication using TLS encryption before sending emails.
15+
16+
:ivar smtp_settings: Dictionary containing the following SMTP credentials and settings:
17+
- smtp_server: SMTP server address
18+
- port: SMTP server port
19+
- sender_email: The sender's email address
20+
- receiver_email: The recipient's email address
21+
- password: The sender's email password
22+
:type smtp_settings: dict
23+
"""
24+
25+
def __init__(self, smtp_settings):
26+
"""
27+
Initialize the AlertingSystem with specified SMTP settings.
28+
29+
:param smtp_settings: Dictionary containing SMTP credentials and settings:
30+
- smtp_server: SMTP server address
31+
- port: SMTP server port
32+
- sender_email: The sender's email address
33+
- receiver_email: The recipient's email address
34+
- password: The sender's email password
35+
"""
36+
self.smtp_settings = smtp_settings
37+
38+
def send_email_alert(self, subject, body):
39+
"""
40+
Sends an alert email to the specified recipient.
41+
42+
:param subject: Subject of the email
43+
:param body: Content of the email
44+
"""
45+
try:
46+
# Create the email message
47+
msg = MIMEText(body)
48+
msg["Subject"] = subject
49+
msg["From"] = self.smtp_settings["sender_email"]
50+
msg["To"] = self.smtp_settings["receiver_email"]
51+
52+
# Connect to the SMTP server and send the email
53+
with smtplib.SMTP(self.smtp_settings["smtp_server"], self.smtp_settings["port"]) as server:
54+
server.starttls() # Upgrade the connection to secure
55+
server.login(self.smtp_settings["sender_email"], self.smtp_settings["password"])
56+
server.sendmail(
57+
self.smtp_settings["sender_email"],
58+
self.smtp_settings["receiver_email"],
59+
msg.as_string()
60+
)
61+
logging.info("Alert email sent successfully.")
62+
63+
except Exception as e:
64+
logging.error(f"Failed to send email alert: {e}")
65+
66+
67+
def setup_logging(level=logging.INFO, log_file=None):
68+
"""
69+
Sets up logging for the application by configuring the log level,
70+
log format, and output handlers. The function allows the logs
71+
to be displayed in the console and optionally saved to a file.
72+
73+
:param level: The logging level (e.g., logging.INFO, logging.DEBUG).
74+
:type level: int
75+
:param log_file: The path to a file where logs should be written. If not
76+
provided, logs will only appear in the console.
77+
:type log_file: str or None
78+
:return: None
79+
"""
80+
handlers = [logging.StreamHandler()]
81+
if log_file:
82+
handlers.append(logging.FileHandler(log_file))
83+
84+
logging.basicConfig(
85+
level=level,
86+
format="%(asctime)s - %(levelname)s - %(message)s",
87+
handlers=handlers
88+
)
89+
90+
91+
if __name__ == "__main__":
92+
# Configure logging
93+
setup_logging(log_file="alerting.log")
94+
95+
# SMTP configuration: Use environment variables or secure storage for sensitive data
96+
smtp_settings = {
97+
"smtp_server": os.getenv("SMTP_SERVER", "smtp.mailtrap.io"),
98+
"port": int(os.getenv("SMTP_PORT", 587)),
99+
"sender_email": os.getenv("SMTP_SENDER_EMAIL", "sender@example.com"),
100+
"receiver_email": os.getenv("SMTP_RECEIVER_EMAIL", "receiver@example.com"),
101+
"password": os.getenv("SMTP_PASSWORD", "your_password"),
102+
}
103+
104+
# Initialize the alerting system
105+
alert = AlertingSystem(smtp_settings)
106+
107+
# Example: Simulating pipeline execution and error alerting
108+
try:
109+
logging.info("Starting pipeline execution...")
110+
# Simulated function: execute_pipeline()
111+
raise RuntimeError("Simulated pipeline failure for testing alert email.")
112+
except Exception as e:
113+
logging.error(f"Pipeline error detected: {e}")
114+
alert.send_email_alert(
115+
subject="Pipeline Execution Failure!",
116+
body=f"The pipeline encountered an error: {e}"
117+
)

0 commit comments

Comments
 (0)