diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 029b628..cc040cb 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -1,12 +1,7 @@ name: SonarQube analysis -on: - push: - branches: - - main - pull_request: - branches: - - main +on: + workflow_dispatch: {} permissions: pull-requests: read diff --git a/get-temp.py b/get-temp.py deleted file mode 100644 index d34e013..0000000 --- a/get-temp.py +++ /dev/null @@ -1,67 +0,0 @@ -from datetime import datetime, timezone, timedelta -import re -import requests - -_sensor_stats = {"total_sensors": 0, "null_count": 0} - -def classify_temperature(average): - '''Classify temperature based on ranges using dictionary approach''' - # Define temperature ranges and their classifications - temp_classifications = { - "cold": (float('-inf'), 10, "Warning: Too cold"), - "good": (10, 36, "Good"), - "hot": (36, float('inf'), "Warning: Too hot") - } - - # Find the appropriate classification - for _, (min_temp, max_temp, status) in temp_classifications.items(): - if min_temp < average <= max_temp: - return status - - return "Unknown" # Default case - -def get_temperature(): - '''Function to get the average temperature from OpenSenseMap API.''' - - print("Fetching new data from OpenSenseMap API...") - - # Ensuring that data is not older than 1 hour. - time_iso = (datetime.now(timezone.utc) - timedelta(hours=1)).isoformat().replace("+00:00", "Z") - - params = { - "date": time_iso, - "format": "json" - } - - print('Getting data from OpenSenseMap API...') - - response = requests.get("https://api.opensensemap.org/boxes", params=params, timeout=480) - print('Data retrieved successfully!') - - _sensor_stats["total_sensors"] = sum( - 1 for line in response.text.splitlines() if re.search(r'^\s*"sensors"\s*:\s*\[', line) - ) - - res = [d.get('sensors') for d in response.json() if 'sensors' in d] - - temp_list = [] - _sensor_stats["null_count"] = 0 # Initialize counter for null measurements - - for sensor_list in res: - for measure in sensor_list: - if measure.get('unit') == "°C" and 'lastMeasurement' in measure: - last_measurement = measure['lastMeasurement'] - if last_measurement is not None and 'value' in last_measurement: - last_measurement_int = float(last_measurement['value']) - temp_list.append(last_measurement_int) - else: - _sensor_stats["null_count"] += 1 - - average = sum(temp_list) / len(temp_list) if temp_list else 0 - - # Use the dictionary-based classification - status = classify_temperature(average) - result = f'Average temperature: {average:.2f} °C ({status})\n' - - - return result, _sensor_stats \ No newline at end of file