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
| 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 |
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
| [$setWindowFields: { | |
| partitionBy: "$location", | |
| sortBy: { | |
| date: 1 | |
| }, | |
| output: { | |
| average: { | |
| $avg: "$temp", | |
| window: { | |
| range: [-60, 60], |
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
| [{ | |
| $match: { | |
| $expr: { | |
| $gt: ["$date", { | |
| $dateSubtract: { | |
| startDate: "$$NOW", | |
| unit: "day", | |
| amount: 7 | |
| } | |
| }] |
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); |
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
| [{ | |
| $sort: { | |
| date: -1 | |
| } | |
| }, { | |
| $group: { | |
| _id: "$location", | |
| currentTemp: { | |
| $first: "$temp" | |
| } |
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
| { | |
| _id: ObjectId("6218cae28a77eb66ed8b372b"), | |
| room: 'GamesRoom', | |
| to: 900, | |
| target: 17 | |
| } |
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
| { | |
| $concat: ["Until ", { | |
| $cond: [{ | |
| $lt: ["$to", 1000] | |
| }, "0", ""] | |
| }, { | |
| $toString: "$to" | |
| }] | |
| } |
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
| { | |
| $set: { | |
| miltime: { | |
| $add: [{ | |
| $minute: "$date" | |
| }, { | |
| $multiply: [{ | |
| $hour: "$date" | |
| }, 100] | |
| }] |
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
| { | |
| $let: { | |
| vars: { | |
| targetdoc: { | |
| $max: { | |
| $filter: { | |
| input: "$location_lookup_targettemps", | |
| cond: { | |
| $gte: ["$$this.to", "$miltime"] | |
| } |
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
| [ | |
| {$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"}}}}}}, |