Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: C/C++ CI
name: Multi-Language Portfolio CI

on:
push:
Expand All @@ -7,17 +7,39 @@ on:
branches: [ "main" ]

jobs:
build:

validate-project:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: configure
run: ./configure
- name: make
run: make
- name: make check
run: make check
- name: make distcheck
run: make distcheck

# 1. Setup Python & Check for Syntax Errors
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Python Lint
run: |
python -m pip install --upgrade pip
pip install flake8
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

# 2. Setup Java & Build Check
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build Java
run: |
# This will look for any .java files and try to compile them to ensure no syntax errors
find . -name "*.java" > java_files.txt
if [ -s java_files.txt ]; then xargs javac < java_files.txt; fi

# 3. Setup C++ & Compile Check
- name: Build C++
run: |
# This checks for .cpp files and compiles them with g++
find . -name "*.cpp" > cpp_files.txt
if [ -s cpp_files.txt ]; then g++ -std=c++17 $(cat cpp_files.txt) -o check_output || echo "No main function found"; fi
if [ -s check_output ]; then ./check_output; fi

68 changes: 53 additions & 15 deletions python-backend-api/weather_microservices/app.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,66 @@
from fastapi import FastAPI
from worker import data_ingestion_pipeline
from database import db
from database import Sessionlocal as SessionLocal,redis_client
from fastapi import Depends
from sqlalchemy.orm import Session
from sqlalchemy import func
app = FastAPI(title="Weather Microservice")
from sqlalchemy import func
from models import Weather
import json
app = FastAPI(title="Weather Microservice")

def get_db():
session = db
session = SessionLocal()
try:
yield session
finally:
session.close()

@app.get("/analytics")
def get_analytics(session : Session = Depends(get_db)):
max_temp,min_temp,avg_temp = session.query(func.max(Weather.temperature),func.min(Weather.temperature),func.avg(Weather.temperature)).first()
if max_temp is None:
return {"status": "pending", "message": "No data points gathered by worker engine yet."}
return {
"status": "success",
"metrics": {
"maximum_temperature": round(max_temp),
"minimum_temperature": round(min_temp),
"average_temperature": round(avg_temp)}
}
try:
cache_key = "weather_stats"

# 1. Check Redis first
cached_data = redis_client.get(cache_key)
if cached_data is not None:
print("🚀 CACHE HIT: Serving directly from Redis memory!")
return json.loads(cached_data) # Turn string back into JSON dictionary

print("🐢 CACHE MISS: Fetching calculations from MySQL...")

# 2. Run the heavy MySQL aggregation query
stats = session.query(
func.max(Weather.temperature),
func.min(Weather.temperature),
func.avg(Weather.temperature)
).first()

max_temp, min_temp, avg_temp = stats
if max_temp is None:
return {"status": "pending", "message": "Database empty."}

# 3. Format the final output response
response_payload = {
"status": "success",
"metrics": {
"maximum_temperature": round(max_temp, 2),
"minimum_temperature": round(min_temp, 2),
"average_temperature": round(avg_temp, 2)
}
}

# 4. Save a copy in Redis with a Time-To-Live (TTL) of 60 seconds
redis_client.setex(
name=cache_key,
time=60, # Expires automatically in 60 seconds
value=json.dumps(response_payload) # Convert dict to string
)

return response_payload
except Exception as e:
return {"status": "error", "message": str(e)}

if __name__ == "__main__":
import uvicorn



Loading