Concatenated OpenAI code for Adafruit's expected 1000 certification date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.linear_model import LinearRegression | |
import numpy as np | |
import json | |
# Load the JSON data from the provided file | |
with open("/mnt/data/oshwa_data.json", "r") as file: | |
oshwa_data = json.load(file) | |
# Display the type of the root object and a brief summary of its content | |
root_type = type(oshwa_data) | |
summary = {} | |
if isinstance(oshwa_data, dict): | |
for key, value in oshwa_data.items(): | |
summary[key] = type(value) | |
root_type, summary | |
# Extract the certification dates for Adafruit | |
adafruit_dates = [datetime.datetime.fromisoformat(entry['certificationDate'].split('T')[0]) | |
for entry in oshwa_data | |
if entry['responsibleParty'] == 'Adafruit Industries, LLC' and 'certificationDate' in entry] | |
# Sort the dates and calculate the cumulative count | |
adafruit_dates.sort() | |
adafruit_cumulative_counts = np.arange(1, len(adafruit_dates) + 1) | |
# Convert dates to ordinal values for regression | |
adafruit_dates_ordinal = [date.toordinal() for date in adafruit_dates] | |
# Plot | |
plt.figure(figsize=(14, 8)) | |
plt.plot(adafruit_dates, adafruit_cumulative_counts, label="Adafruit", marker='o') | |
plt.axhline(y=1000, color='r', linestyle='--', label="1,000 Certifications Target") | |
plt.xlabel("Date") | |
plt.ylabel("Cumulative Certifications") | |
plt.title("Cumulative Certifications Over Time (Adafruit)") | |
plt.legend() | |
plt.grid(True, which='both', linestyle='--', linewidth=0.5) | |
plt.tight_layout() | |
plt.show() | |
# Predict certification counts for future dates | |
future_dates = pd.date_range(start=adafruit_dates[-1], periods=365*5, freq='D') # Predicting for the next 5 years | |
future_dates_ordinal = [date.toordinal() for date in future_dates] | |
predicted_counts = model.predict(np.array(future_dates_ordinal).reshape(-1, 1)) | |
# Find the date when the predicted count reaches or exceeds 1,000 | |
predicted_date_index = np.where(predicted_counts >= 1000)[0][0] | |
predicted_date = future_dates[predicted_date_index] | |
predicted_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment