diff --git a/nodemon.json b/nodemon.json deleted file mode 100644 index 7f04f27430d875fa6b8f186026a678d740b975f5..0000000000000000000000000000000000000000 --- a/nodemon.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "watch": ["src", "index.js"], - "ignore": ["*.spec.ts"], - "ext": "ts" -} diff --git a/src/core/server.spec.ts b/src/core/server.spec.ts deleted file mode 100644 index 5f11f800b6650b926920b4990d5575ddeebeb5c7..0000000000000000000000000000000000000000 --- a/src/core/server.spec.ts +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blendb. - * - * blendb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blendb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blendb. If not, see <http://www.gnu.org/licenses/>. - */ - -// import { expect } from "chai"; -// -// import { Server } from "./server"; - -/*describe("server class", () => { - it("should be able to create and retrieve sources", () => { - const server = new Server(); - - // create two sources - const source1 = server.source("source1"); - const source2 = server.source("source2"); - - // retrieve the first one - const retrieved = server.source("source1"); - - // check if sources were actually created/retrieved - expect(source1).to.be.an("object"); - expect(source2).to.be.an("object"); - expect(retrieved).to.be.an("object"); - - // check if the two created sources are different - expect(source1).to.not.be.equal(source2); - - // check if the retrieved source is the same as the created one - expect(source1).to.be.equal(retrieved); - }); - - it("should be able to create and retrieve aggregates", () => { - const server = new Server(); - - // create two aggregates - const aggr1 = server.aggregate(["met:one"], ["dim:one", "dim:two"]); - const aggr2 = server.aggregate(["met:two"], ["dim:one", "dim:two"]); - - // retrieve the first one - const retrieved = server.aggregate(["met:one"], ["dim:two", "dim:one"]); - - // check if aggregates were actually created/retrieved - expect(aggr1).to.be.an("object"); - expect(aggr2).to.be.an("object"); - expect(retrieved).to.be.an("object"); - - // check if the two created aggregates are different - expect(aggr1).to.not.be.equal(aggr2); - - // check if the retrieved aggregate is the same as the created one - expect(aggr1).to.be.equal(retrieved); - }); - - it("should be able to create and retrieve transformers", () => { - const server = new Server(); - - const source1 = server.source("source1"); - const aggr1 = server.aggregate(["met:one"], ["dim:one", "dim:two"]); - const aggr2 = server.aggregate(["met:one", "met:two"], ["dim:one"]); - - // create two transformers - const transformer1 = server.transformer("transformer1", { - source: source1, - destination: aggr1, - functions: { - map: (doc: any, emit: Function) => { return; }, - reduce: (dimensions: any, metrics: any) => { return {}; } - } - }); - const transformer2 = server.transformer("transformer2", { - source: source1, - destination: aggr2, - functions: { - map: (doc: any, emit: Function) => { return; }, - reduce: (dimensions: any, metrics: any) => { return {}; } - } - }); - - // retrieve the first one - const retrieved = server.transformer("transformer1"); - - // check if transformers were actually created/retrieved - expect(transformer1).to.be.an("object"); - expect(transformer2).to.be.an("object"); - expect(retrieved).to.be.an("object"); - - // check if the two created transformers are different - expect(transformer1).to.not.be.equal(transformer2); - - // check if the retrieved transformer is the same as the created one - expect(transformer1).to.be.equal(retrieved); - }); - - it("should fail to create two transformer with name collision", () => { - const server = new Server(); - - const source1 = server.source("source1"); - const aggr1 = server.aggregate(["met:one"], ["dim:one", "dim:two"]); - const aggr2 = server.aggregate(["met:one", "met:two"], ["dim:one"]); - - server.transformer("transformer1", { - source: source1, - destination: aggr1, - functions: { - map: (doc: any, emit: Function) => { return; }, - reduce: (dimensions: any, metrics: any) => { return {}; } - } - }); - - expect(() => { - server.transformer("transformer1", { - source: source1, - destination: aggr2, - functions: { - map: (doc: any, emit: Function) => { return; }, - reduce: (dimensions: any, metrics: any) => { return {}; } - } - }); - }).to.throw(Error); - }); - - it("should fail to retrieve a transformer that doesn't exist", () => { - const server = new Server(); - - expect(() => { - server.transformer("transformerX"); - }).to.throw(Error); - }); -});*/ diff --git a/src/core/server.ts b/src/core/server.ts deleted file mode 100644 index b973b4067f02a93181aa830ab7919e878868144d..0000000000000000000000000000000000000000 --- a/src/core/server.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blend. - * - * blend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blend. If not, see <http://www.gnu.org/licenses/>. - */ - -import { Hash } from "../util/hash"; - -import { Source } from "./source"; -import { Transformer, ITransformerOptions } from "./transformer"; -import { Aggregate } from "./aggregate"; - -export class Server { - private sources: Map<string, Source>; - private transformers: Map<string, Transformer>; - private aggregates: Map<string, Aggregate>; - - constructor() { - this.sources = new Map(); - this.transformers = new Map(); - this.aggregates = new Map(); - } - - /*public source(name: string, options?: any) { - if (this.sources.has(name)) { - return this.sources.get(name); - } - else { - const source = new Source(name, options); - this.sources.set(name, source); - return source; - } - }*/ - - public aggregate(metrics: string[], dimensions: string[], options?: any) { - const id = Hash.sha1(metrics.sort(), dimensions.sort()); - - if (this.aggregates.has(id)) { - return this.aggregates.get(id); - } - else { - const aggregate = new Aggregate(metrics, dimensions, options); - this.aggregates.set(id, aggregate); - return aggregate; - } - } - - public transformer(name: string, options?: ITransformerOptions) { - if (typeof options !== "undefined") { - if (this.transformers.has(name)) { - throw new Error("A transformer named '" + name + "' already exists"); - } - - const transformer = new Transformer(name, options); - this.transformers.set(name, transformer); - return transformer; - } - else { - if (!this.transformers.has(name)) { - throw new Error("A transformer named '" + name + "' does not exist"); - } - - return this.transformers.get(name); - } - } -} diff --git a/src/core/transformer.spec.ts b/src/core/transformer.spec.ts deleted file mode 100644 index ddf7ac222df0d43c5647692522aa97e66048011c..0000000000000000000000000000000000000000 --- a/src/core/transformer.spec.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blendb. - * - * blendb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blendb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blendb. If not, see <http://www.gnu.org/licenses/>. - */ - -// import { expect } from "chai"; -// -// import { Hash } from "../util/hash"; -// -// import { Transformer } from "./transformer"; -// import { Source } from "./source"; -// import { Aggregate } from "./aggregate"; - -/*describe("transformer class", () => { - const source = new Source("testSource"); - const aggregate = new Aggregate(["met:one"], ["dim:one", "dim:two"]); - - it("should be able to aggregate data", () => { - source.truncate(); - - for (let i = 0; i < 1000; i++) { - source.push({ - id: i % 10, - seed: Math.random() - }); - } - - source.push({ id: 10, seed: 5 }); - source.push({ id: 10, seed: 5 }); - source.push({ id: 10, seed: 5 }); - source.push({ id: 10, seed: 5 }); - source.push({ id: 10, seed: 5 }); - - const transformer = new Transformer("processTransformer", { - source: source, - destination: aggregate, - functions: { - map: ((doc: any, emit: Function) => { - emit({ - "dim:one": doc.id, - "dim:two": Hash.sha1(doc.seed) - }, { - "met:one": Math.floor(doc.seed * 100000) / 100 - }); - }), - reduce: ((dimensions: any, metrics: any) => { - let tmp = 0; - metrics.forEach((met: any) => { - tmp += met["met:one"]; - }); - return { - "met:one": tmp - }; - }) - } - }); - - transformer.apply(); - - let result = aggregate.find({ - "dim:one": 10, - "dim:two": Hash.sha1(5) - }); - - expect(result).to.have.length(1); - expect(result[0]).to.have.property("metrics"); - expect(result[0].metrics).to.have.property("met:one"); - expect(result[0].metrics["met:one"]).to.be.equal(25000); - }); -}); -*/ diff --git a/src/core/transformer.ts b/src/core/transformer.ts deleted file mode 100644 index e3c6734cde7b6939e72619d2e3f399dfa9613153..0000000000000000000000000000000000000000 --- a/src/core/transformer.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blendb. - * - * blendb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blendb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blendb. If not, see <http://www.gnu.org/licenses/>. - */ - -import { Hash } from "../util/hash"; - -import { Source } from "./source"; -import { Aggregate } from "./aggregate"; - -export interface ITransformerOptions { - source: Source; - destination: Aggregate; - functions: { - map: (doc: any, emit: Function) => void; - reduce: (dimensions: any, metrics: any) => any; - }; -} - -export class Transformer { - public name: string; - public source: Source; - public destination: Aggregate; - private functions: any; - - constructor(name: string, options: ITransformerOptions) { - this.name = name; - this.source = options.source; - this.destination = options.destination; - this.functions = { - map: options.functions.map, - reduce: options.functions.reduce - }; - } - - public apply() { - let temp = new Map(); - - this.destination.truncate(); - - this.source.forEach((doc: any) => { - let emit = (dimensions: any, metrics: any) => { - let key = Hash.sha1(dimensions); - let current = temp.get(key) || { dimensions, metrics: [] }; - temp.set(key, { - dimensions, - metrics: current.metrics.concat([metrics]) - }); - }; - - this.functions.map(doc, emit); - }); - - temp.forEach((value, key) => { - let dimensions = value.dimensions; - let metrics = value.metrics; - - if (metrics.length > 1) { - this.destination.push({ - dimensions: dimensions, - metrics: this.functions.reduce(dimensions, metrics) - }); - } - else { - this.destination.push({ - dimensions: dimensions, - metrics: metrics - }); - } - }); - } -}