Feat: generated network for classification problem of cat/dog
Feat: first version of dataGatherer client
This commit is contained in:
parent
86dbfc120a
commit
6feb5af4d0
20 changed files with 425 additions and 162 deletions
11
DataGatherer/src/data/Data.ts
Normal file
11
DataGatherer/src/data/Data.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
24
DataGatherer/src/gatherer/Gatherer.ts
Normal file
24
DataGatherer/src/gatherer/Gatherer.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
8
DataGatherer/src/index.html
Normal file
8
DataGatherer/src/index.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="../dist/bundle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
23
DataGatherer/src/main.ts
Normal file
23
DataGatherer/src/main.ts
Normal 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();
|
||||
34
DataGatherer/src/sender/Sender.ts
Normal file
34
DataGatherer/src/sender/Sender.ts
Normal 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));
|
||||
}
|
||||
}
|
||||
30
DataGatherer/src/source/Source.ts
Normal file
30
DataGatherer/src/source/Source.ts
Normal 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 = [];
|
||||
}
|
||||
}
|
||||
8
DataGatherer/src/source/keyboard/Keyboard.ts
Normal file
8
DataGatherer/src/source/keyboard/Keyboard.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Source } from '../Source';
|
||||
|
||||
export class Keyboard extends Source {
|
||||
|
||||
constructor(name: string, events: Array<string>) {
|
||||
super(name, events);
|
||||
}
|
||||
}
|
||||
9
DataGatherer/src/source/mouse/Mouse.ts
Normal file
9
DataGatherer/src/source/mouse/Mouse.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { Source } from '../Source';
|
||||
|
||||
export class Mouse extends Source {
|
||||
|
||||
constructor(name: string, events: Array<string>) {
|
||||
super(name, events);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue