from datetime import datetime
print(f"Date of last update: {datetime.now().strftime('%d.%m.%Y, %H:%M')}")
Date of last update: 28.07.2025, 03:50
Utility functionsΒΆ
%load_ext autoreload
%autoreload 2
from IPython.display import display, Markdown
from mfnf import MFNF
def md(text):
display(Markdown(text))
df = MFNF().aggregate_pageviews()
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime
from statsmodels.tsa.seasonal import seasonal_decompose
def show_trend_analysis(df):
# Assuming `df` is your DataFrame
# Ensure 'timestamp' is of datetime dtype
df["timestamp"] = pd.to_datetime(df["timestamp"])
# Filter out the current month
current_date = datetime.now()
df_filtered = df[
(df["timestamp"].dt.year < current_date.year)
| (
(df["timestamp"].dt.year == current_date.year)
& (df["timestamp"].dt.month < current_date.month)
)
]
# Set the 'timestamp' as the index
df_filtered.set_index("timestamp", inplace=True)
# Resample to get monthly view data
monthly_views = df_filtered["views"].resample("ME").sum()
# Decompose the series
decomposition = seasonal_decompose(
monthly_views.dropna(), model="additive", period=12
)
# Set style for seaborn
sns.set_style("whitegrid")
# Plot the monthly views using Seaborn
plt.figure(figsize=(12, 6))
sns.lineplot(x=monthly_views.index, y=monthly_views.values, marker="o", linewidth=2)
plt.title("Total Views by Month (Excluding Current Month)")
plt.xlabel("Month")
plt.ylabel("Views")
plt.xticks(rotation=45)
plt.show()
# Plot the decomposition
fig, axs = plt.subplots(4, 1, figsize=(14, 12), sharex=True)
decomposition.observed.plot(ax=axs[0], color="blue")
axs[0].set_ylabel("Observed")
axs[0].set_title("Observed Component")
decomposition.trend.plot(ax=axs[1], color="orange")
axs[1].set_ylabel("Trend")
axs[1].set_title("Trend Component")
decomposition.seasonal.plot(ax=axs[2], color="green")
axs[2].set_ylabel("Seasonal")
axs[2].set_title("Seasonal Component")
decomposition.resid.plot(ax=axs[3], color="red")
axs[3].set_ylabel("Residual")
axs[3].set_title("Residual Component")
plt.tight_layout()
plt.show()
md("## <span id='total-views'>Trend analysis of total views per month</span>")
show_trend_analysis(df.copy())
Trend analysis per bookΒΆ
from mfnf import books
for book in books:
md(f"### {book}")
show_trend_analysis(df[df["book_name"] == book].copy())
License of this reportΒΆ
Copyright YEAR Stephan Kulla ("Kulla")
Licensed under the Apache License, Version 2.0 (the "Apache License") and Creative Commons Attribution 4.0 International (the "CC-BY License"). You may choose either of these licenses to govern your use of this project.
You may obtain a copy of the Apache License at: http://www.apache.org/licenses/LICENSE-2.0
You may obtain a copy of the CC-BY License at: https://creativecommons.org/licenses/by/4.0/
Unless required by applicable law or agreed to in writing, software and content distributed under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for the specific language governing permissions and limitations under the License.
Under the CC-BY License, you are free to share and adapt the material provided you give appropriate credit, provide a link to the license, and indicate if changes were made. See the CC-BY License for full details.
Third-Party Components and Licenses: This product also includes third-party components which are distributed under their respective licenses. Please refer to the NOTICE file for details.