Skip to content

Instantly share code, notes, and snippets.

View johnlpage's full-sized avatar

John Page johnlpage

  • MongoDB Inc.
  • Glasgow
View GitHub Profile
exports = async function(arg) {
const axios = require('axios');
const APIKEY = "XXXXXXXXXXXXXXXXXXXf";
const endpoint = `https://api.openweathermap.org/data/2.5/weather?lat=55.7384&lon=-4.216&appid=${APIKEY}`;
try {
weather = await axios.get(endpoint);
if (weather.status == 200) {
console.log(JSON.stringify(weather.data));
const roomtemps = context.services.get("mongodb-atlas").db("energy").collection("roomtemps");
// add this to the roomtemps too for simplicity
[$setWindowFields: {
partitionBy: "$location",
sortBy: {
date: 1
},
output: {
average: {
$avg: "$temp",
window: {
range: [-60, 60],
[{
$match: {
$expr: {
$gt: ["$date", {
$dateSubtract: {
startDate: "$$NOW",
unit: "day",
amount: 7
}
}]
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);
[{
$sort: {
date: -1
}
}, {
$group: {
_id: "$location",
currentTemp: {
$first: "$temp"
}
{
_id: ObjectId("6218cae28a77eb66ed8b372b"),
room: 'GamesRoom',
to: 900,
target: 17
}
{
$concat: ["Until ", {
$cond: [{
$lt: ["$to", 1000]
}, "0", ""]
}, {
$toString: "$to"
}]
}
{
$set: {
miltime: {
$add: [{
$minute: "$date"
}, {
$multiply: [{
$hour: "$date"
}, 100]
}]
{
$let: {
vars: {
targetdoc: {
$max: {
$filter: {
input: "$location_lookup_targettemps",
cond: {
$gte: ["$$this.to", "$miltime"]
}
[
{$limit:1},
{$set: { x : {$range:[-144,0]}, y : {$range:[-120,0]} }},
{$unwind :"$x"},
{$unwind: "$y"},
{$set : { r: {$add: [{$divide:["$x",8000]},-0.73]}, i: {$add:[{$divide:["$y",8000]},0.15]}}},
{$set : { c : { $reduce : { input: {$range:[0,300]}, initialValue : { r:0,i:0,it:0 }, in :
{ $cond : { if: { $lt:["$$value.r",4]}, then: { it:{$add:["$$value.it",1]},
r: {$add:[{$subtract:[{$pow:["$$value.r",2]}, {$pow:["$$value.i",2]} ]},"$r"]},
i: {$add: [{$multiply:[2,"$$value.r","$$value.i"]},"$i"]} } ,else: "$$value"}}}}}},