Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOne #191

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

DOne #191

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions 0001-task-3-done.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
From abd3e4c0a7af80a80390f8c9edca6a26440f4f30 Mon Sep 17 00:00:00 2001
From: Mrpradhanji <[email protected]>
Date: Mon, 12 Aug 2024 14:43:31 +0530
Subject: [PATCH] task 3 done

---
src/DataManipulator.ts | 38 +++++++++++++++++++++++++++-----------
src/Graph.tsx | 30 ++++++++++++++++++------------
2 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts
index 7f62295..1d2facc 100644
--- a/src/DataManipulator.ts
+++ b/src/DataManipulator.ts
@@ -1,20 +1,36 @@
import { ServerRespond } from './DataStreamer';

export interface Row {
- stock: string,
- top_ask_price: number,
- timestamp: Date,
+ price_abc: number,
+ price_def: number,
+ ratio: number,
+ timestamp: Date,
+ upper_bound: number,
+ lower_bound: number,
+ trigger_alert: number | undefined,
}


export class DataManipulator {
- static generateRow(serverResponds: ServerRespond[]) {
- return serverResponds.map((el: any) => {
- return {
- stock: el.stock,
- top_ask_price: el.top_ask && el.top_ask.price || 0,
- timestamp: el.timestamp,
- };
- })
+
+ static generateRow(serverResponds: ServerRespond[]) : Row {
+ const priceABC = (serverResponds[0].top_ask.price + serverResponds[0].top_bid.price) /2;
+ const priceDEF = (serverResponds[1].top_ask.price + serverResponds[1].top_bid.price) /2;
+ const ratio = priceABC / priceDEF;
+ const upperBound = 1 + 0.05;
+ const lowerBound = 1 - 0.05;
+
+ return{
+ price_abc: priceABC,
+ price_def: priceDEF,
+ ratio,
+ timestamp : serverResponds[0].timestamp > serverResponds[1].timestamp ?
+ serverResponds[0].timestamp : serverResponds[1].timestamp ,
+ upper_bound: upperBound,
+ lower_bound: lowerBound,
+ trigger_alert: (ratio > upperBound || ratio < lowerBound) ? ratio : undefined,
+
+ }
+
}
}
diff --git a/src/Graph.tsx b/src/Graph.tsx
index 277797d..43f8083 100644
--- a/src/Graph.tsx
+++ b/src/Graph.tsx
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
-import { Table } from '@finos/perspective';
+import { Table, TableData } from '@finos/perspective';
import { ServerRespond } from './DataStreamer';
import { DataManipulator } from './DataManipulator';
import './Graph.css';
@@ -23,10 +23,13 @@ class Graph extends Component<IProps, {}> {
const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;

const schema = {
- stock: 'string',
- top_ask_price: 'float',
- top_bid_price: 'float',
+ price_abc: 'float',
+ price_def: 'float',
+ ratio: 'float',
timestamp: 'date',
+ upper_bound:'float',
+ lower_bound:'float',
+ trigger_alert: 'float',
};

if (window.perspective && window.perspective.worker()) {
@@ -36,23 +39,26 @@ class Graph extends Component<IProps, {}> {
// Load the `table` in the `<perspective-viewer>` DOM reference.
elem.load(this.table);
elem.setAttribute('view', 'y_line');
- elem.setAttribute('column-pivots', '["stock"]');
elem.setAttribute('row-pivots', '["timestamp"]');
- elem.setAttribute('columns', '["top_ask_price"]');
+ elem.setAttribute('columns', '["ratio", "lower_bound", "upper_bound","trigger_alert"]');
elem.setAttribute('aggregates', JSON.stringify({
- stock: 'distinctcount',
- top_ask_price: 'avg',
- top_bid_price: 'avg',
- timestamp: 'distinct count',
+ price_abc: 'avg',
+ price_def: 'avg',
+ ratio: 'avg',
+ timestamp: 'distinct count',
+ upper_bound:'avg',
+ lower_bound:'avg',
+ trigger_alert: 'avg',
}));
}
}

componentDidUpdate() {
if (this.table) {
- this.table.update(
+ this.table.update([
DataManipulator.generateRow(this.props.data),
- );
+ ] as unknown as TableData);
+
}
}
}
--
2.43.0.windows.1

38 changes: 27 additions & 11 deletions src/DataManipulator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import { ServerRespond } from './DataStreamer';

export interface Row {
stock: string,
top_ask_price: number,
timestamp: Date,
price_abc: number,
price_def: number,
ratio: number,
timestamp: Date,
upper_bound: number,
lower_bound: number,
trigger_alert: number | undefined,
}


export class DataManipulator {
static generateRow(serverResponds: ServerRespond[]) {
return serverResponds.map((el: any) => {
return {
stock: el.stock,
top_ask_price: el.top_ask && el.top_ask.price || 0,
timestamp: el.timestamp,
};
})

static generateRow(serverResponds: ServerRespond[]) : Row {
const priceABC = (serverResponds[0].top_ask.price + serverResponds[0].top_bid.price) /2;
const priceDEF = (serverResponds[1].top_ask.price + serverResponds[1].top_bid.price) /2;
const ratio = priceABC / priceDEF;
const upperBound = 1 + 0.05;
const lowerBound = 1 - 0.05;

return{
price_abc: priceABC,
price_def: priceDEF,
ratio,
timestamp : serverResponds[0].timestamp > serverResponds[1].timestamp ?
serverResponds[0].timestamp : serverResponds[1].timestamp ,
upper_bound: upperBound,
lower_bound: lowerBound,
trigger_alert: (ratio > upperBound || ratio < lowerBound) ? ratio : undefined,

}

}
}
30 changes: 18 additions & 12 deletions src/Graph.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Table } from '@finos/perspective';
import { Table, TableData } from '@finos/perspective';
import { ServerRespond } from './DataStreamer';
import { DataManipulator } from './DataManipulator';
import './Graph.css';
Expand All @@ -23,10 +23,13 @@ class Graph extends Component<IProps, {}> {
const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;

const schema = {
stock: 'string',
top_ask_price: 'float',
top_bid_price: 'float',
price_abc: 'float',
price_def: 'float',
ratio: 'float',
timestamp: 'date',
upper_bound:'float',
lower_bound:'float',
trigger_alert: 'float',
};

if (window.perspective && window.perspective.worker()) {
Expand All @@ -36,23 +39,26 @@ class Graph extends Component<IProps, {}> {
// Load the `table` in the `<perspective-viewer>` DOM reference.
elem.load(this.table);
elem.setAttribute('view', 'y_line');
elem.setAttribute('column-pivots', '["stock"]');
elem.setAttribute('row-pivots', '["timestamp"]');
elem.setAttribute('columns', '["top_ask_price"]');
elem.setAttribute('columns', '["ratio", "lower_bound", "upper_bound","trigger_alert"]');
elem.setAttribute('aggregates', JSON.stringify({
stock: 'distinctcount',
top_ask_price: 'avg',
top_bid_price: 'avg',
timestamp: 'distinct count',
price_abc: 'avg',
price_def: 'avg',
ratio: 'avg',
timestamp: 'distinct count',
upper_bound:'avg',
lower_bound:'avg',
trigger_alert: 'avg',
}));
}
}

componentDidUpdate() {
if (this.table) {
this.table.update(
this.table.update([
DataManipulator.generateRow(this.props.data),
);
] as unknown as TableData);

}
}
}
Expand Down