<commit_before>```R
library(RANN)  # nn
library(reshape2)  # dcast



# Custom Parser for Date.Time column
parser <- function(fmt)
{
    function(x)
    {
        # Define Return Object
        data.frame(
            # x[1] is an empty split from leading whitespace
            day  = as.Date(x[2], fmt), 
            hour = as.numeric(substr(x[3], 1, 2))
        )
    }
}



# Import Today's Data
infile <- file.choose()  # Locate your save file
x <- read.csv(infile, as.is = TRUE)[1:2]  # Only using Electricity
names(x) <- c("datetime", "kwh")
dt <- do.call(rbind, lapply(strsplit(x$datetime, ' +'), parser('%m/%d')))

x <- data.frame(x, dt)  # Hourly Grain
y <- reshape2::dcast(x, day ~ hour, value.var = 'kwh')  # Daily Grain



# kd-tree search model
kd <- nn2(y[-1], k=6)  # k=5 with 1 for matching self



# Every Day vs Top 5 (blue) vs This Day (red)
# What happened with Sep 28?? That's really the nearest 5?
set.seed(600)
for (i in 1:5)  # Try 5 Random Days; Review Plots Afterwards
{
    p <- sample(1:365, 1)  # Choose a random day
    idx <- kd$nn.idx[p, -1]  # top5 similar days to p
    
    matplot(t(y[-1]), type = 'l', col = 'gray80', lty = 2, main = y$day[p],
            las = 1, xlab = "Hour of Day (24 hours)", ylab = "kWh")<commit_msg>Added link to data source for day 2<commit_after>```R
library(RANN)  # nn
library(reshape2)  # dcast



# Custom Parser for Date.Time column
parser <- function(fmt)
{
    function(x)
    {
        # Define Return Object
        data.frame(
            # x[1] is an empty split from leading whitespace
            day  = as.Date(x[2], fmt), 
            hour = as.numeric(substr(x[3], 1, 2))
        )
    }
}



# Import Today's Data
# See http://en.openei.org/datasets/files/961/pub/
# Specifically using RESIDENTIAL_LOAD_DATA_E_PLUS_OUTPUT/BASE/USA_CA_Sacramento.Exec.AP.724830_TMY3_BASE.csv
infile <- file.choose()  # Locate your save file
x <- read.csv(infile, as.is = TRUE)[1:2]  # Only using Electricity
names(x) <- c("datetime", "kwh")
dt <- do.call(rbind, lapply(strsplit(x$datetime, ' +'), parser('%m/%d')))

x <- data.frame(x, dt)  # Hourly Grain
y <- reshape2::dcast(x, day ~ hour, value.var = 'kwh')  # Daily Grain



# kd-tree search model
kd <- nn2(y[-1], k=6)  # k=5 with 1 for matching self



# Every Day vs Top 5 (blue) vs This Day (red)
# What happened with Sep 28?? That's really the nearest 5?
set.seed(600)
for (i in 1:5)  # Try 5 Random Days; Review Plots Afterwards
{
    p <- sample(1:365, 1)  # Choose a random day
    idx <- kd$nn.idx[p, -1]  # top5 similar days to p
    
    matplot(t(y[-1]), type = 'l', col = 'gray80', lty = 2, main = y$day[p],
            las = 1, xlab = "Hour of Day (24 hours)", ylab = "kWh")
{'fraction_non_alphanumeric': 0.15902366863905326, 'fraction_numerical': 0.03217455621301775, 'mean_word_length': 2.7569444444444446, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, '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': '4162230', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1008, 'n_words': 303}