{ "HIGHLIGHTSTROKECOLORS": [ [ "cloud", "#000000" ] ], "ARGPLUGINS": [ [ "fetch", "var block = logo.blocks.blockList[blk];var conns = block.connections;var field = logo.parseArg(logo, turtle, conns[2]);var uid = logo.parseArg(logo, turtle, conns[1]);var hoursAgo = logo.parseArg(logo, turtle, conns[3]);var d = new Date();var now = d.getTime() / 1000;var deltaSeconds = now - impactLastFetchTime;var haveData = false;if (deltaSeconds > 3600 || uid != impactUID) { var apiURL = 'https://sensor-station.appspot.com/sensor_station'; console.log('using server data'); try { var request = new XMLHttpRequest(); request.open('GET', apiURL, false); request.send(null); var response = request.responseText; console.log(response); } catch (e) { logo.errorMsg(_('Impact data not available.'), blk); } try { impactData = JSON.parse(response); haveData = true; } catch (e) { logo.errorMsg(_('Cannot parse Impact data.'), blk); }} else { haveData = true; console.log('using cached data');}var output = 0;if (haveData) { impactLastFetchTime = now; impactUID = uid; var foundUID = false; var foundTime = false; if (hoursAgo < 0) { var minTime = 0; var maxTime = now; } else { var minTime = now - hoursAgo * 3600 - 1800; var maxTime = now - hoursAgo * 3600 + 1800; } try { for (var i = impactData.length - 1; i > -1; i--) { if ('uid' in impactData[i] && impactData[i]['uid'] == uid) { foundUID = true; if ('tstamp' in impactData[i]) { var tstamp = impactData[i]['tstamp'] / 1000; \t\t if (tstamp > minTime && tstamp < maxTime) { foundTime = true; if (field in impactData[i]) { output = impactData[i][field]; } else { logo.errorMsg(_('Impact field not found.'), blk); } break; } } } else if ('id' in impactData[i] && impactData[i]['id'] == uid) { foundUID = true; if ('tstamp' in impactData[i]) { var tstamp = impactData[i]['tstamp'] / 1000; \t\t if (tstamp > minTime && tstamp < maxTime) { foundTime = true; if (field in impactData[i]) { output = impactData[i][field]; } else { logo.errorMsg(_('Impact field not found.'), blk); } break; } } } } if (!foundUID) { logo.errorMsg(_('Impact UID not found.'), blk); } else if (!foundTime) { logo.errorMsg(_('Impact Time not found.'), blk); } } catch (e) { logo.errorMsg(_('Impact data not available.'), blk); }}block.value = Number(output);" ] ], "GLOBALS": "impactLastFetchTime = 0;impactUID = '';impactHoursAgo = 0;impactData = null;", "PALETTEHIGHLIGHTCOLORS": [ [ "cloud", "#ffb1b3" ] ], "PALETTEPLUGINS": [ [ "cloud", " " ] ], "BLOCKPLUGINS": [ [ "fetchdata", "var fetchBlk = new ProtoBlock('fetch');fetchBlk.palette = palettes.dict['cloud'];blocks.protoBlockDict['fetch'] = fetchBlk;fetchBlk.staticLabels.push(_('fetch'), _('UID'), _('field'), _('hours ago'));fetchBlk.adjustWidthToLabel();fetchBlk.threeArgMathBlock();fetchBlk.dockTypes[1] = 'anyin';fetchBlk.dockTypes[2] = 'anyin';fetchBlk.dockTypes[3] = 'numberin';fetchBlk.defaults.push(\"UID\");fetchBlk.defaults.push(\"temp\");fetchBlk.defaults.push(0);" ] ], "PALETTEFILLCOLORS": [ [ "cloud", "#ff0066" ] ], "PALETTESTROKECOLORS": [ [ "cloud", "#ef003e" ] ] }