add logging

This commit is contained in:
Boaz Sender 2025-04-23 13:22:18 -07:00
parent 0eaa809a4f
commit 2f22dafa2b
6 changed files with 1505 additions and 1471 deletions

3
.gitignore vendored
View file

@ -1,2 +1 @@
node_modules node_modules
prisma/data.db

View file

@ -14,6 +14,7 @@ const getStanza = async (register) => {
register, register,
}, },
}); });
console.log(register, stanzaCount, skip, randomStanza);
return randomStanza[0].text; return randomStanza[0].text;
}; };
// Play portal wave PCM data and set bands // Play portal wave PCM data and set bands
@ -26,7 +27,8 @@ let register = "high";
let count = 0; let count = 0;
setInterval(() => { setInterval(() => {
const absSample = Math.abs(audioData.channelData[0][count]); const absSample = Math.abs(audioData.channelData[0][count]);
if (count == totalSamples - 1) { if (count == 100) {
//totalSamples - 1) {
count = 0; count = 0;
} }
else { else {
@ -40,7 +42,9 @@ setInterval(() => {
register = "low"; register = "low";
} }
sample = absSample; sample = absSample;
console.log(count);
}, 1); }, 1);
// Setup lcd screen
const lcd = new LCD(1, 0x27, 16, 2); const lcd = new LCD(1, 0x27, 16, 2);
lcd.beginSync(); lcd.beginSync();
lcd.clearSync(); lcd.clearSync();
@ -52,27 +56,32 @@ let tagCharacterLocation = 0;
setInterval(() => { setInterval(() => {
lcd.printLineSync(1, " "); lcd.printLineSync(1, " ");
setTimeout(() => { setTimeout(() => {
lcd.printLineSync(1, tag.substring(tagCharacterLocation, 16 + tagCharacterLocation)); lcd.printLineSync(1, tag);
}, WAIT); }, WAIT);
tagCharacterLocation++; tagCharacterLocation++;
if (tagCharacterLocation > tag.length) { if (tagCharacterLocation > tag.length) {
tagCharacterLocation = 0; tagCharacterLocation = 0;
} }
}, TICK); }, TICK);
let characterLocation = 0;
let stanzaText = "";
let endBuffer = "";
let totalTicks = 0;
// Play top line // Play top line
let stanzaCharacterLocation = 0;
let stanza = await getStanza(register);
while (true) { while (true) {
if (stanzaCharacterLocation == stanza.length) { if (characterLocation == totalTicks) {
stanzaCharacterLocation = 0; characterLocation = 0;
stanza = await getStanza(register); stanzaText = await getStanza(register);
endBuffer =
stanzaText.length > 16 ? "" : Array(16 - stanzaText.length).join(" ");
totalTicks = stanzaText.length + endBuffer.length;
} }
lcd.printLineSync(0, " "); lcd.printLineSync(0, " ");
setTimeout(() => { setTimeout(() => {
lcd.printLineSync(0, `${16 - stanzaCharacterLocation > 0 lcd.printLineSync(0, `${totalTicks - characterLocation > 0
? Array(16 - stanzaCharacterLocation).join(" ") ? Array(16 - characterLocation).join(" ")
: ""}${stanza}`.substring(stanzaCharacterLocation, stanza.length)); : ""}${stanzaText + endBuffer}`);
}, WAIT); }, WAIT);
await timer(TICK); await timer(TICK);
stanzaCharacterLocation++; characterLocation++;
} }

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -4,28 +4,28 @@ import { parse } from "csv";
const prisma = new PrismaClient(); const prisma = new PrismaClient();
// lyrics from https://docs.google.com/spreadsheets/d/1b8gANkghKpJKPzsPEigggxOydGgM8ntX0EAI4rPwbSU/edit?gid=0#gid=0 // lyrics from https://docs.google.com/spreadsheets/d/1b8gANkghKpJKPzsPEigggxOydGgM8ntX0EAI4rPwbSU/edit?gid=0#gid=0
// csv header: Artist,Album,Song,Stanza // csv header: Register,Artist,Album,Song,Stanza
const parser = fs.createReadStream(`prisma/lyrics.csv`).pipe(parse()); const parser = fs.createReadStream(`prisma/lyrics.csv`).pipe(parse());
for await (const record of parser) { for await (const record of parser) {
console.log(record[3]); console.log(record[4]);
await prisma.stanza.create({ await prisma.stanza.create({
data: { data: {
text: record[3], text: record[4],
register: record[4], register: record[0],
song: { song: {
connectOrCreate: { connectOrCreate: {
where: { where: {
name: record[2], name: record[3],
}, },
create: { create: {
name: record[2], name: record[3],
artist: { artist: {
connectOrCreate: { connectOrCreate: {
where: { where: {
name: record[0], name: record[1],
}, },
create: { create: {
name: record[0], name: record[1],
}, },
}, },
}, },

View file

@ -9,7 +9,6 @@ const prisma = new PrismaClient();
const getStanza = async (register: string) => { const getStanza = async (register: string) => {
const stanzaCount = await prisma.stanza.count({ where: { register } }); const stanzaCount = await prisma.stanza.count({ where: { register } });
const skip = Math.floor(Math.random() * stanzaCount); const skip = Math.floor(Math.random() * stanzaCount);
const randomStanza = await prisma.stanza.findMany({ const randomStanza = await prisma.stanza.findMany({
skip: skip, skip: skip,
take: 1, take: 1,
@ -18,10 +17,30 @@ const getStanza = async (register: string) => {
}, },
}); });
if (!randomStanza || !randomStanza[0].text) {
console.log(
register,
stanzaCount,
skip,
randomStanza,
"no stanza found in db"
);
// try one more time
const anotherStanzaTry = await prisma.stanza.findMany({
skip: skip,
take: 1,
where: {
register,
},
});
return anotherStanzaTry[0].text as string;
}
return randomStanza[0].text as string; return randomStanza[0].text as string;
}; };
// Play portal wave PCM data and set bands // Play portal wave PCM data and set bands
// This file has been downsampled to 1000hz (1,000 samples per second)
const fileData = fs.readFileSync("/home/grace/portal/blackportal1000.wav"); const fileData = fs.readFileSync("/home/grace/portal/blackportal1000.wav");
const wavFileInfo = WavFileDecoder.getWavFileInfo(fileData); const wavFileInfo = WavFileDecoder.getWavFileInfo(fileData);
const audioData = WavFileDecoder.decodeWavFile(fileData); const audioData = WavFileDecoder.decodeWavFile(fileData);
@ -37,6 +56,7 @@ setInterval(() => {
const absSample = Math.abs(audioData.channelData[0][count]); const absSample = Math.abs(audioData.channelData[0][count]);
if (count == totalSamples - 1) { if (count == totalSamples - 1) {
count = 0; count = 0;
console.log("total samples reached");
} else { } else {
count++; count++;
} }
@ -49,8 +69,10 @@ setInterval(() => {
} }
sample = absSample; sample = absSample;
console.log(count);
}, 1); }, 1);
// Setup lcd screen
const lcd = new LCD(1, 0x27, 16, 2); const lcd = new LCD(1, 0x27, 16, 2);
lcd.beginSync(); lcd.beginSync();
lcd.clearSync(); lcd.clearSync();
@ -66,10 +88,7 @@ let tagCharacterLocation = 0;
setInterval(() => { setInterval(() => {
lcd.printLineSync(1, " "); lcd.printLineSync(1, " ");
setTimeout(() => { setTimeout(() => {
lcd.printLineSync( lcd.printLineSync(1, tag);
1,
tag.substring(tagCharacterLocation, 16 + tagCharacterLocation)
);
}, WAIT); }, WAIT);
tagCharacterLocation++; tagCharacterLocation++;
@ -78,26 +97,33 @@ setInterval(() => {
} }
}, TICK); }, TICK);
let characterLocation = 0;
let stanzaText = "";
let endBuffer = "";
let totalTicks = 0;
// Play top line // Play top line
let stanzaCharacterLocation = 0;
let stanza = await getStanza(register);
while (true) { while (true) {
if (stanzaCharacterLocation == stanza.length) { if (characterLocation == totalTicks) {
stanzaCharacterLocation = 0; characterLocation = 0;
stanza = await getStanza(register); stanzaText = await getStanza(register);
endBuffer =
stanzaText.length > 16 ? "" : Array(16 - stanzaText.length).join(" ");
totalTicks = stanzaText.length + endBuffer.length;
}
if (!stanzaText) {
console.log("no stanza text in stanza scroller");
} }
lcd.printLineSync(0, " "); lcd.printLineSync(0, " ");
setTimeout(() => { setTimeout(() => {
lcd.printLineSync( lcd.printLineSync(
0, 0,
`${ `${
16 - stanzaCharacterLocation > 0 totalTicks - characterLocation > 0
? Array(16 - stanzaCharacterLocation).join(" ") ? Array(16 - characterLocation).join(" ")
: "" : ""
}${stanza}`.substring(stanzaCharacterLocation, stanza.length) }${stanzaText + endBuffer}`
); );
}, WAIT); }, WAIT);
await timer(TICK); await timer(TICK);
stanzaCharacterLocation++; characterLocation++;
} }