Kun je de nachtwacht borduren in 10 jaar?

Mijn vrouw werkt aan een borduurproject om De Nachtwacht van Rembrandt na te maken. Ze wil het binnen 10 jaar af hebben. Omdat ik dit soort dingen leuk vind, bood ik aan om te helpen berekenen of ze nog op schema ligt.

import os
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from nachtwacht import date_from_filename, get_finished_parts, TOTAL_PARTS
from sklearn import linear_model
import numpy as np
from datetime import datetime

haal de bestanden van de bestaande blogposts.

image_folder = "../content/nachtwacht/"
files = [os.path.abspath(os.path.join(image_folder, f)) for f in os.listdir(image_folder) if f.startswith("nachtwacht")]
posts = [(f, date_from_filename(f), get_finished_parts(f)) for f in sorted(files)]

dates = [d for (_,d,_) in posts]

def to_timestamp(date):
    return datetime.combine(date, datetime.min.time()).timestamp()

def dates_to_timestamps(dates):
    timestamps = [to_timestamp(d) for d in dates]
    timestamps = np.array(timestamps).reshape(-1, 1)
    return timestamps
timestamps = dates_to_timestamps(dates)
finished_parts = [fp for (_,_,fp) in posts]

Gebruik een standaard lineair model

lm = linear_model.LinearRegression()
model = lm.fit(timestamps,finished_parts)
def plot_graph(model, dates, finished_parts):
    timestamps = dates_to_timestamps(dates)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(dates, finished_parts)
    ax.plot(dates, model.predict(timestamps), color='red')
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))

    plt.xticks(rotation=45)

Fit het lineaire model op alle datums / afgewerkte delen

plot_graph(model, dates, finished_parts)

png

Valt het gat op tussen de zomer van 2024 en 2025? Op haar blog kun je lezen wat er gebeurde.

def calculate_end_date(model):
    m = model.coef_[0]     # The coefficient (slope)
    b = model.intercept_   # The intercept
    required_x = (TOTAL_PARTS - b) / m
    required_x
    end_date = datetime.fromtimestamp(required_x)
    print("Predicted end date:", end_date.date())
    return end_date
end_date = calculate_end_date(model)
Predicted end date: 2034-12-16
plot_graph(dates + [end_date], finished_parts + [TOTAL_PARTS])

png

neem alleen de meest recente 5 posts

model = lm.fit(dates_to_timestamps(dates[-5:]),finished_parts[-5:])
end_date = calculate_end_date(model)
plot_graph(dates + [end_date], finished_parts + [TOTAL_PARTS])
Predicted end date: 2030-10-31

Hopen dat het lukt om in 2030 klaar te zijn!

png