Skip to content

Instantly share code, notes, and snippets.

View TobyEalden's full-sized avatar

Toby Ealden TobyEalden

View GitHub Profile
@TobyEalden
TobyEalden / databot-subscription.js
Created March 29, 2019 15:14
Databot subscription
module.exports = (function() {
"use strict";
/**
* Databot input requirements:
* {
* queueId: "<dataset id to be monitored>",
* tdxServer: "e.g. http://tdx.nqm-1.com",
* ddpServer: "e.g. http://ddp.nqm-1.com"
* }
import React from "react";
const useDataSubscription = (tdx, datasetId, selector, options) => {
const [data, setData] = React.useState([]);
React.useEffect(
() => {
let subscription;
let observer;
if (tdx) {
curl -X POST https://tdx.nqminds.com/token -H 'authorization: Basic <app-id>:<app-secret>' -H 'cache-control: no-cache' -H 'content-type: application/json' -d '{"grant_type":"client_credentials", "ttl": 31536000}'
module.exports = (function() {
"use strict";
const Promise = require("bluebird");
function databot(input, output, context) {
const tdxApi = context.tdxApi;
const mappingId = input.mappingId;
// filter boundary dataset with a list of all ccgs
const filter = {
mappingType: "ons-mapping",
parentType: "CCG15CD",
const databot = function(input, output, context) {
const api = context.tdxApi;
let x = 0;
const readStream = api.getNDDatasetData(
"HygXQFrwx-", // This contains nearly 6 million documents
null,
null,
{limit: 0}
);
const writeStream = split(JSON.parse, null, {trailing: true});
function mapData(populationData, ratioData, serviceArray, areaServiceId, deststream) {
// re-format the ratioData from an array to a dictionary lookup object
// in order to do the multiplications with poplet data
const ratioObject = dicLookup(ratioData, serviceArray);
const writePromises = [];
_.forEach(populationData, (populationObj) => {
const key = `${populationObj.area_id}${populationObj.gender}${populationObj.age_band}`;
if (ratioObject[key]) {
const rObj = {
areaServiceId: areaServiceId,
@TobyEalden
TobyEalden / overkill?.js
Last active May 2, 2017 09:34 — forked from iendjinn/overkill?.js
this is overkill :)
function blob(xIn, yIn) {
const x = xIn;
const y = yIn;
this.setY = (yIn) => {
y = y;
};
this.getY = () => {
return y;
};
import {dataLoader, optionsWithError} from "../../../configs/app-data-loader";
import Home from "../components/home";
import {Meteor} from "meteor/meteor";
function dataMapper({
connectionManager,
setRegionId,
setUserName,
setGeoCentre,
setProjectionListId,
let total = 0;
const processChunk = function(chunkList, chunkIndex) {
const chunk = chunkList[chunkIndex];
// do stuff with chunk asynchronously
return doStuff(chunk)
.then((result) => {
if (chunkIndex < chunkList.length) {
total += result;
@TobyEalden
TobyEalden / Bluebird.js
Last active February 17, 2017 12:44 — forked from iendjinn/Bluebird.js
// estimator.js
module.exports = (function() {
var getData = function(id, cb) {
return api.getDataAsync(id, this.state.filter);
}
function estimator(initial) {
this.state = initial;