How to use the dc.http function in dc

To help you get started, we’ve selected a few dc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github signicode / scramjet / samples / fantasies / live-streaming-voting.js View on Github external
serialize() {
        return JSON.stringify({
            contestant: this.contestant,
            phoneNumber: this.phoneNumber
        });
    }

    static deserialize(data) {
        return new Vote(data);
    }

}
Vote.invalid = new Vote();

dc.init()
    .readData(dc.http.readPostData(handler, "/api/vote"))
        .map(
            (data) => new Vote(data)
        )
        .filter(
            (vote) => vote !== Vote.invalid
        )
        .group(
            (vote) => vote.phoneNumber
        )
        .nagle()
        .reduce(
            (cache, votes) => votes.forEach((vote) => cache.replace(vote)),
            dc.hashCache((vote) => vote.phoneNumber)
        )

        .use((cache) => cache.changeStream())
github signicode / scramjet / samples / fantasies / live-streaming-voting.js View on Github external
/**
 * In a TV show people may vote on one of contestants.
 *
 * The server above allows to create a distributed and fault-tolerant service
 * with extreme ease.
 *
 * At the start the service exposes an url to post data to.
 * In the middle it does streamed calculations grouped by phone number and contestants.
 * At the end it exposes data over a websocket and http get urls.
 */

const dc = require("dc");
const http = require("http");

let handler = dc.http.requestHandler();
http.createServer(handler).listen(8080);

class Vote extends dc.http.PostData {

    constructor(data) {
        super();

        if (!data)
            return this;

        try {
            const voteData = data instanceof Object && data;
            if (voteData && voteData.contestant && voteData.phoneNumber && Object.keys(voteData).length === 2) {
                this.contestant = voteData.contestant;
                this.phoneNumber = voteData.phoneNumber;
                return this;
github signicode / scramjet / samples / fantasies / weather-service.js View on Github external
const dc = require("dc");
const http = require("http");

let handler = dc.http.requestHandler();
http.createServer(handler).listen(8080);


class WeatherData extends dc.http.PostData {

    constructor(data) {
        super();
        this.iana = data.iana;
        this.windDirection = data.windDirection;
        this.windSpeed = data.windSpeed;
    }

    validate() {
        return (
            typeof this.windSpeed === "number" && this.windSpeed >= 0 && this.windSpeed < 150 &&
            typeof this.windDirection === "number" && this.windDirection >= 0 && this.windDirection < 360
github signicode / scramjet / samples / fantasies / weather-service.js View on Github external
(stream) => stream.map(
                        (sampleList) => sampleList.latest
                    ).join().reduce(
                        (acc, weather) => (acc[weather.iana] = weather, acc)
                    ).expose(
                        dc.http.exposeData("/weather/{iana}", (input, iana) => input[iana])
                    )
            ).reduce(

dc

A multi-dimensional charting library built to work natively with crossfilter and rendered using d3.js

Apache-2.0
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis