Feat: generated network for classification problem of cat/dog

Feat: first version of dataGatherer client
This commit is contained in:
Lorenzo Iovino 2019-04-07 12:18:41 +02:00
parent 86dbfc120a
commit 6feb5af4d0
20 changed files with 425 additions and 162 deletions

View file

@ -0,0 +1,11 @@
export class Data {
private name: string;
private data: any;
private timestamp: number;
constructor(name: string, data: any) {
this.name = name;
this.data = data;
this.timestamp = Date.now();
}
}

View file

@ -0,0 +1,24 @@
import { Source } from "./../source/Source";
export class Gatherer {
private sources: Array<Source>;
constructor(sources: Array<Source>) {
this.sources = sources;
}
public start() {
for(const source of this.sources){
source.startCollect();
}
}
public getData(): any {
let allData = [];
for(const source of this.sources){
allData = allData.concat(source.getData());
}
return allData;
}
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<script src="../dist/bundle.js"></script>
</head>
<body>
</body>
</html>

23
DataGatherer/src/main.ts Normal file
View file

@ -0,0 +1,23 @@
import { Sender } from "./sender/Sender";
import { Mouse } from "./source/mouse/Mouse";
import { Gatherer } from "./gatherer/Gatherer";
import { Keyboard } from "./source/keyboard/Keyboard";
function main() {
const gatherer: Gatherer = new Gatherer([
new Keyboard('keyboard', ['keydown']),
new Mouse('mouse', ['click', 'mousemove'])
]);
gatherer.start();
const sender: Sender = new Sender(() => gatherer.getData(), '/predictor', 4000, 2000);
sender.start()
.subscribe(
val => {
console.log(val);
}
);
}
main();

View file

@ -0,0 +1,34 @@
import { interval, Observable, of } from 'rxjs';
import { filter, flatMap, delay } from 'rxjs/operators';
import { Rxios } from 'rxios';
export class Sender {
private url: string;
private port: number;
private interval: number;
private dataSourceFn: any;
constructor(dataSourceFn: any, url: string, port: number, interval: number) {
this.url = url;
this.port = port;
this.interval = interval;
this.dataSourceFn = dataSourceFn;
}
public start() {
return interval(this.interval)
.pipe(
flatMap(() => this.send(this.dataSourceFn()))
)
}
private send(data: any) {
const http: Rxios = new Rxios();
//return http.post(this.url, data);
function generateFakeResponse() {
return Array.from({length: 20}, () => Math.random().toPrecision(2));
}
return of(generateFakeResponse()).pipe(delay(200));
}
}

View file

@ -0,0 +1,30 @@
import { Data } from "./../data/Data";
export class Source {
private name: string;
public data: Array<any> = [];
public events: Array<string>;
constructor(name: string, events: Array<string>) {
this.name = name;
this.events = events;
}
public startCollect() {
for(const event of this.events){
document.addEventListener(event, (e) => {
this.data.push(new Data(event, e));
});
}
}
public getData() {
const data = JSON.parse(JSON.stringify(this.data));
this.deleteAllData();
return data;
}
public deleteAllData() {
this.data = [];
}
}

View file

@ -0,0 +1,8 @@
import { Source } from '../Source';
export class Keyboard extends Source {
constructor(name: string, events: Array<string>) {
super(name, events);
}
}

View file

@ -0,0 +1,9 @@
import { Source } from '../Source';
export class Mouse extends Source {
constructor(name: string, events: Array<string>) {
super(name, events);
}
}