<commit_before><?php

$benchmarkStart = microtime(true);

// redirect if this file is accessed directly
if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
    header("Location: ../index.php?state=stats");
    exit;
}

require_once __DIR__ . "/../config.php";
require_once __DIR__ . "/DB.class.php";
require_once __DIR__ . "/Helper.class.php";
require_once __DIR__ . "/Read.class.php";
require_once __DIR__ . "/Statistics.class.php";
require_once __DIR__ . "/TimeUnit.class.php";

// define colors
$gridColor      = "rgba(128, 128, 128, 0.10)";
$fillcolor      = "rgba(128, 128, 128, 0.45)";
$linecolor      = "rgba(128, 128, 128, 0.65)";
$fillcolorRed   = "rgba(170,   0,   0, 0.45)";
$linecolorRed   = "rgba(170,   0,   0, 0.55)";
$fillcolorGreen = "rgba(  0, 160,   0, 0.35)";
$linecolorGreen = "rgba(  0, 160,   0, 0.45)";
$fillcolorBlue  = "rgba(  0,   0, 192, 0.45)";
$linecolorBlue  = "rgba(  0,   0, 192, 0.60)";
$punchcardcolor = "rgba(128, 128, 128, 0.60)";

$gray  = array("fillcolor" => $fillcolor, "linecolor" => $linecolor);
$red   = array("fillcolor" => $fillcolorRed, "linecolor" => $linecolorRed);
$green = array("fillcolor" => $fillcolorGreen, "linecolor" => $linecolorGreen);
$blue  = array("fillcolor" => $fillcolorBlue, "linecolor" => $linecolorBlue);

// articles per day
// also part of: added vs. archived per day
$days = Statistics::articlesPerTime("days", "archived", false, $start, $end);
$daysX = array_map(
    function($ts) {
        return TimeUnit::sFormatTime("day", $ts);
    },
    array_keys($days)
);
$daysY = $days;
$daysText = array_map(
    function($n, $ts) {
        $s = ($n == 1) ? "" : "s";
        return "$n article$s on " . TimeUnit::sFormatTimeVerbose("day", $ts);
    },
    $daysY,
    array_keys($days)
);

// longest and current streak
$longestStreak = Statistics::longestStreak($start, $end);
$longestStreakStart = TimeUnit::sFormatTimeVerbose("day", $longestStreak["start"]);
$longestStreakEnd = TimeUnit::sFormatTimeVerbose("day", $longestStreak["end"]);
$longestStreakLength = $longestStreak["length"] . "-day";
$longestStreakCount = $longestStreak["count"] . " articles";
$longestStreakText = "The $longestStreakLength period from $longestStreakStart to $longestStreakEnd, with a total of $longestStreakCount.";
if ($longestStreakEnd == TimeUnit::sFormatTimeVerbose("day", $time)) {
    $streakText = "Longest (and current) streak: $longestStreakText";
} else {
    $streakText = "Longest streak: $longestStreakText";
    if ($start <= $time && $time <= $end) {
        $currentStreak = Statistics::currentStreak($start, $time);
        if ($currentStreak["length"] > 0) {
            $currentStreakLength = $currentStreak["length"] . " days";
            $currentStreakCount = $currentStreak["count"] . " articles";
            $streakText .= "<br>Current streak: The last $currentStreakLength, with a total of $currentStreakCount.";
        }
    }
}

// cumulative artices per day (based on articles per day)
$cumulativeDaysX = $daysX;
$cumulativeDaysY = array();
$accum = 0;<commit_msg>If the current streak is just today, display it accordingly<commit_after><?php

$benchmarkStart = microtime(true);

// redirect if this file is accessed directly
if (basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])) {
    header("Location: ../index.php?state=stats");
    exit;
}

require_once __DIR__ . "/../config.php";
require_once __DIR__ . "/DB.class.php";
require_once __DIR__ . "/Helper.class.php";
require_once __DIR__ . "/Read.class.php";
require_once __DIR__ . "/Statistics.class.php";
require_once __DIR__ . "/TimeUnit.class.php";

// define colors
$gridColor      = "rgba(128, 128, 128, 0.10)";
$fillcolor      = "rgba(128, 128, 128, 0.45)";
$linecolor      = "rgba(128, 128, 128, 0.65)";
$fillcolorRed   = "rgba(170,   0,   0, 0.45)";
$linecolorRed   = "rgba(170,   0,   0, 0.55)";
$fillcolorGreen = "rgba(  0, 160,   0, 0.35)";
$linecolorGreen = "rgba(  0, 160,   0, 0.45)";
$fillcolorBlue  = "rgba(  0,   0, 192, 0.45)";
$linecolorBlue  = "rgba(  0,   0, 192, 0.60)";
$punchcardcolor = "rgba(128, 128, 128, 0.60)";

$gray  = array("fillcolor" => $fillcolor, "linecolor" => $linecolor);
$red   = array("fillcolor" => $fillcolorRed, "linecolor" => $linecolorRed);
$green = array("fillcolor" => $fillcolorGreen, "linecolor" => $linecolorGreen);
$blue  = array("fillcolor" => $fillcolorBlue, "linecolor" => $linecolorBlue);

// articles per day
// also part of: added vs. archived per day
$days = Statistics::articlesPerTime("days", "archived", false, $start, $end);
$daysX = array_map(
    function($ts) {
        return TimeUnit::sFormatTime("day", $ts);
    },
    array_keys($days)
);
$daysY = $days;
$daysText = array_map(
    function($n, $ts) {
        $s = ($n == 1) ? "" : "s";
        return "$n article$s on " . TimeUnit::sFormatTimeVerbose("day", $ts);
    },
    $daysY,
    array_keys($days)
);

// longest and current streak
$longestStreak = Statistics::longestStreak($start, $end);
$longestStreakStart = TimeUnit::sFormatTimeVerbose("day", $longestStreak["start"]);
$longestStreakEnd = TimeUnit::sFormatTimeVerbose("day", $longestStreak["end"]);
$longestStreakLength = $longestStreak["length"] . "-day";
$longestStreakCount = $longestStreak["count"] . " articles";
$longestStreakText = "The $longestStreakLength period from $longestStreakStart to $longestStreakEnd, with a total of $longestStreakCount.";
if ($longestStreakEnd == TimeUnit::sFormatTimeVerbose("day", $time)) {
    $streakText = "Longest (and current) streak: $longestStreakText";
} else {
    $streakText = "Longest streak: $longestStreakText";
    if ($start <= $time && $time <= $end) {
        $currentStreak = Statistics::currentStreak($start, $time);
        if ($currentStreak["length"] > 0) {
            $currentStreakLength = ($currentStreak["length"] == 1) ? "Just today" : "The last " . $currentStreak["length"] . " days";
            $currentStreakCount = $currentStreak["count"] . " articles";
            $streakText .= "<br>Current streak: $currentStreakLength, with a total of $currentStreakCount.";
        }
    }
}

// cumulative artices per day (based on articles per day)
$cumulativeDaysX = $daysX;
$cumulativeDaysY = array();
$accum = 0;
{'fraction_non_alphanumeric': 0.17940893029232252, 'fraction_numerical': 0.03196273690973338, 'mean_word_length': 4.25929054054054, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1299765', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2241, 'n_words': 496}