journalData = {
if(pastedBlockJournal){
var pastedDay = pastedBlockJournal
} else {
var pastedDay = `(B,L) May 27, 2023
🟦🟦 Quality Sleep 🛌 |Hlth| [ce]
🟪🟪 Eating Vegan 🌱 |Veg| [ce]
🟪🟪 Car Free🚶🏻♀️🚶🏻♂️|Eco| [ce]
🟪🟪 Minimalism 🪷|Simp| [ce]
🟩 Beach Medi (L) 🧘🏻♀️🏝 |Peac|:: Touched my inner self and found peace
🟩🟩 Morning Walk🚶🏻♀️🌹|Mov|:: Beautiful AM walk where we stopped and smelled the roses
🟨 Breakfast (L) 🍊🌮 |Hlth|
🟧🟧 Notes / Draw (B) 📘✍🏼 |+E|{EP1}
🟨 Online Groceries (L) 🛒🌭 |+L|
🟪 Beach Social (L) 🌊🌞|Scl|(Jl,Jy)
🟧 Roots of Old Game (B) 📝 |+E|{EP1}
🟧 Chat with GPT (B) 🔬🧫|+E|{EP1}
🟨 Dinner (L) 🍝 |Hlth|
🟩🟩 Streaming 📺 |Play|`
}
let blockRecords = pastedDay.split('\n').filter(line => line != "");
let lineOne = blockRecords.shift()
let lineOneLeftParIdx1 = lineOne.indexOf("(");
if(lineOneLeftParIdx1 == 0){
let lineOneRightParIdx1 = lineOne.indexOf(")");
var defaultCreators = lineOne.slice(lineOneLeftParIdx1 + 1, lineOneRightParIdx1).trim().split(",");
var date = lineOne.split(")")[1].trim()
var parsedDate = new Date(date)
} else {
var date = lineOne
var defaultCreators = null
}
var regex = /<a?:.+?:\d{18}>|\p{Extended_Pictographic}/gu; // /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
var blocksIndex = []
// blocks, text, creators, vibes, frame, who, group, type, details
let parsed = blockRecords.map((row, idx) => {
let blockEntry = row
let firstLeftParIdx = blockEntry.indexOf("("); // returns -1 if none found
let closingLeftParIdx = blockEntry.indexOf("(", firstLeftParIdx + 1)
let openFrameIdx1 = blockEntry.indexOf("|");
let closeFrameIdx1 = blockEntry.indexOf("|", openFrameIdx1 + 1)
let finalFrameIdx = blockEntry.lastIndexOf("|")
let debug = {} // add debug info as needed
// blocks
let parts = row.split(" ")
let raw = parts.shift().match(regex)
blocksIndex.push(raw)
let qty = raw.length
let blocks = {raw, qty}
// text
let textStartPos = qty*2
let afterBlocks = blockEntry.slice(textStartPos)
let fistEmojiIdx = afterBlocks.search(regex) - 1
debug.firstEmjoiIdx = fistEmojiIdx
let startFrameIdx = afterBlocks.indexOf("|")
let startGroupIdx = afterBlocks.indexOf("{")
let nextBreakIdx
if(startGroupIdx && startGroupIdx < startFrameIdx){
// group "{" comes before frame "|"
nextBreakIdx = startGroupIdx
} else {
// typical break is at frame "|"
nextBreakIdx = startFrameIdx
}
debug.nextBreakIdx = nextBreakIdx
let textEndPos
let beginVibes
if(firstLeftParIdx == -1 || firstLeftParIdx > openFrameIdx1){
// use "emoji" break or "|" break
if(fistEmojiIdx > 0){
textEndPos = fistEmojiIdx + 1
beginVibes = textEndPos - 1
} else {
textEndPos = startFrameIdx
}
} else {
// use "(" break
textEndPos = afterBlocks.indexOf("(");
beginVibes = afterBlocks.indexOf(")");
}
let text = afterBlocks.slice(0, textEndPos).trim();
// vibes
let vibes = beginVibes ? afterBlocks.slice(beginVibes + 1, startFrameIdx).trim() : '' // .match(regex);
// creators
let leftParIdx1 = blockEntry.indexOf("(");
let rightParIdx1 = blockEntry.indexOf(")");
let creators
if(firstLeftParIdx == -1 || firstLeftParIdx > openFrameIdx1){
// use defaultCreator
creators = defaultCreators
} else {
creators = blockEntry.slice(leftParIdx1 + 1, rightParIdx1).trim().split(",");
}
// frame
let frame = blockEntry.slice(openFrameIdx1 + 1, closeFrameIdx1).trim();
// who
let afterFrame = blockEntry.slice(finalFrameIdx)
let leftParIdx2 = afterFrame.lastIndexOf("(");
let who
if(leftParIdx2 == -1){
// use defaultCreator
if(defaultCreators){
who = null
} else {
who = creators
}
} else {
let rightParIdx2 = afterFrame.lastIndexOf(")");
who = afterFrame.slice(leftParIdx2 + 1, rightParIdx2).trim().split(",");
}
// group
let leftCurlIdx = blockEntry.indexOf("{");
if(leftCurlIdx != -1){
let rightCurlIdx = blockEntry.indexOf("}");
var group = blockEntry.slice(leftCurlIdx + 1, rightCurlIdx).trim() //.split(",");
} else {
var group = null
}
// type
let leftSqrIdx = blockEntry.indexOf("[");
if(leftSqrIdx != -1){
let rightSqrIdx = blockEntry.indexOf("]");
var type = blockEntry.slice(leftSqrIdx + 1, rightSqrIdx).trim() //.split(",");
} else {
var type = null
}
// details
let details = blockEntry.split("::")
if(details.length == 2){
details = details[1].trim()
} else {
details = null
}
return {blocks, text, debug, creators, vibes, frame, who, group, type, details}
})
let processed = parsed.map((row, idx) => {
// add "Date" and "ID"
let creatorSplit = row.creators.map(creator => {
let qtyCreators = row.creators.length
let qtyBlocks = row.blocks.qty
let counts = {qtyCreators, qtyBlocks} // only return during debugging
let id = nanoid()
let blocks = Math.ceil(qtyBlocks/qtyCreators) // round up on any partial block division
let text = row.text
let vibes = row.vibes
let frame = row.frame
let who = row.who
let group = row.group
let type = row.type
let details = row.details
return {id, blocks, text, creator, vibes, frame, who, group, type, details}
})
return creatorSplit
}).flat()
// Block Index for Colored 3D Cubes
let flatBlockIdx = blocksIndex.flat()
let blockIdx = flatBlockIdx.map((blc,idx) => {
let hexCode = blc.codePointAt(0).toString(16)
let emojiIdx = emojiBlocksIndex.findIndex(obj => obj.hexCode === hexCode)
let cubitX = cubitPositions[idx].x
let cubitY = cubitPositions[idx].y
return {blc, hexCode, emojiIdx, cubitX, cubitY}
})
// Emoji Day Story
let emojiStory = (parsed.map(e => e.vibes)).join('')
// Stats
let uniqueCreators = Array.from(new Set(processed.map(obj => obj.creator)));
// Calculate stats summary
let statsSummary = processed.reduce((summary, obj) => {
const { creator, group, color, frame, /*type,*/ blocks } = obj;
summary.totalBlocks += blocks;
summary.creators[creator] = (summary.creators[creator] || 0) + blocks;
summary.groups[group] = (summary.groups[group] || 0) + blocks;
// summary.colors[color] = (summary.colors[color] || 0) + blocks;
summary.frames[frame] = (summary.frames[frame] || 0) + blocks;
// summary.types[type] = (summary.types[type] || 0) + blocks;
return summary;
}, {
totalBlocks: 0,
creators: {},
groups: {},
// colors: {},
frames: {},
// types: {}
});
return {date, parsedDate, defaultCreators, blockRecords, blockIdx, parsed, processed, emojiStory, uniqueCreators, statsSummary}
}