Created
March 4, 2022 13:07
-
-
Save johnlpage/2193194e252a3623c6f1c8a476573566 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numfont = [24, 36, 44, 36, 52, 36, 24, 0, 8, 24, 8, 8, 8, 8, 8, 0, 24, 36, | |
36, 8, 16, 32, 60, 0, 60, 4, 24, 4, 36, 36, 24, 0, 8, 24, 24, 40, 40, 60, 8, 0, | |
60, 32, 56, 4, 36, 36, 24, 0, 8, 16, 24, 36, 36, 36, 24, 0, 60, 4, 8, 8, 8, 16, 16, | |
0, 24, 36, 36, 24, 36, 36, 24, 0, 24, 36, 36, 36, 24, 8, 16 | |
] | |
async function write_text_num(image, x, y, txt) { | |
for (let d = 0; d < txt.length; d++) { | |
let charcode = txt[d].charCodeAt(0); | |
if (charcode >= 48 && charcode <= 57) { | |
let font_offset = (charcode - 48) * 8; | |
for (let row = 0; row < 8; row++) { | |
let fontline = numfont[font_offset + row]; | |
for (let col = 0; col < 8; col++) { | |
if (fontline & (128 >> col)) { | |
await image.updateOne({ | |
x: x + (d * 6) + col, | |
y: y + row | |
}, { | |
$set: { | |
c: 1 | |
} | |
})}}}}}} | |
async function fillrect(image, x, y, x2, y2, c) { | |
await image.updateMany({ | |
x: { $gte: x, $lte: x2 }, | |
y: { $gte: y, $lte: y2 }} | |
}, { $set: { c } }); | |
} | |
async function rect(image, x, y, x2, y2, c) { | |
await image.updateMany({ | |
x: x, | |
y: { $gte: y, $lte: y2 } | |
}, { $set: { c } }); | |
await image.updateMany({ | |
x: x2, | |
y: { $gte: y, $lte: y2 } | |
}, { $set: { c } }); | |
await image.updateMany({ | |
x: { $gte: x, $lte: x2 }, | |
y: y | |
}, { $set: { c } }); | |
await image.updateMany({ | |
x: { $gte: x, $lte: x2 }, | |
y: y2 | |
}, { $set: { c } }); | |
} | |
exports = async function(arg) { | |
const image = context.services.get("mongodb-atlas").db("energy").collection("image"); | |
const tempcol = context.services.get("mongodb-atlas").db("energy").collection("roomtemps"); | |
let recs = []; | |
const iw = 160; | |
const ih = 120; | |
for (x = 0; x < iw; x++) { | |
for (y = 0; y < ih; y++) { | |
recs.push({ x, y, c: null }); | |
} | |
} | |
await image.deleteMany({}) | |
await image.insertMany(recs) | |
//Sizes as percent | |
const rooms = { | |
GamesRoom: [80, 20, 100, 100], | |
Study: [60, 60, 80, 100], | |
Hallway: [60, 20, 80, 60], | |
LivingRoom: [1, 40, 60, 100], | |
cloakroom: [75, 20, 80, 40], | |
office2: [40, 1, 60, 40], | |
Utility: [20, 1, 40, 40] | |
}; | |
const vmul = ih / 100; | |
const hmul = iw / 100; | |
await image.updateOne({ x: iw - 1, y: ih - 1 }, { | |
$set: { c: 32 } | |
}); //Upper Bound Colour and Size | |
for (var room in rooms) { | |
dimensions = rooms[room]; | |
const scaled = dimensions.map((d, ix) => Math.floor(d * ([hmul, vmul][ix % 2])) - 1); | |
const curtemp = tempcol.find({ location: room }).sort({ _id: -1 }).limit(1).toArray(); | |
let temp = null; | |
if (curtemp.length == 1) { | |
temp = curtemp[0].temp; | |
} | |
console.log(`${room} ${temp}`); | |
await fillrect(image, ...scaled, temp); | |
await rect(image, ...scaled, 1); | |
await write_text_num(image, scaled[0] + 4, scaled[1] + 4, `${temp}`); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment