From 988093e37b2ec7e0215609bce5445569a1a33612 Mon Sep 17 00:00:00 2001 From: Joe Ferrer Date: Wed, 1 Mar 2023 01:05:18 +1100 Subject: [PATCH 1/3] Move python files to datafeed dir --- requirements.txt => datafeed/requirements.txt | 0 server.py => datafeed/server3.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename requirements.txt => datafeed/requirements.txt (100%) rename server.py => datafeed/server3.py (100%) diff --git a/requirements.txt b/datafeed/requirements.txt similarity index 100% rename from requirements.txt rename to datafeed/requirements.txt diff --git a/server.py b/datafeed/server3.py similarity index 100% rename from server.py rename to datafeed/server3.py From fff04a00b36df8b558ed676f64bd52697e9af84a Mon Sep 17 00:00:00 2001 From: Dabhadevivek Date: Thu, 1 Aug 2024 18:06:49 +0530 Subject: [PATCH 2/3] Update DataManipulator and Graph components --- src/DataManipulator.ts | 31 +++++++++++++++++++++---------- src/Graph.tsx | 32 +++++++++++++++++++------------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts index 7f622955cc..6dcbfe840e 100644 --- a/src/DataManipulator.ts +++ b/src/DataManipulator.ts @@ -1,20 +1,31 @@ import { ServerRespond } from './DataStreamer'; export interface Row { - stock: string, - top_ask_price: number, + 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, - }; - }) + 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 277797d933..81d4aa88b6 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,14 @@ class Graph extends Component { const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement; const schema = { - stock: 'string', - top_ask_price: 'float', - top_bid_price: 'float', - timestamp: 'date', + 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 +40,25 @@ class Graph extends Component { // Load the `table` in the `` 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); } } } From e633e9c6e1aca7e0c51a1f1584d622dd31f970d8 Mon Sep 17 00:00:00 2001 From: Dabhadevivek Date: Thu, 1 Aug 2024 18:08:00 +0530 Subject: [PATCH 3/3] Created patch according to task --- ...DataManipulator-and-Graph-components.patch | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 0001-Update-DataManipulator-and-Graph-components.patch diff --git a/0001-Update-DataManipulator-and-Graph-components.patch b/0001-Update-DataManipulator-and-Graph-components.patch new file mode 100644 index 0000000000..e3b5c658b3 --- /dev/null +++ b/0001-Update-DataManipulator-and-Graph-components.patch @@ -0,0 +1,123 @@ +From fff04a00b36df8b558ed676f64bd52697e9af84a Mon Sep 17 00:00:00 2001 +From: Dabhadevivek +Date: Thu, 1 Aug 2024 18:06:49 +0530 +Subject: [PATCH] Update DataManipulator and Graph components + +--- + src/DataManipulator.ts | 31 +++++++++++++++++++++---------- + src/Graph.tsx | 32 +++++++++++++++++++------------- + 2 files changed, 40 insertions(+), 23 deletions(-) + +diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts +index 7f62295..6dcbfe8 100644 +--- a/src/DataManipulator.ts ++++ b/src/DataManipulator.ts +@@ -1,20 +1,31 @@ + import { ServerRespond } from './DataStreamer'; + + export interface Row { +- stock: string, +- top_ask_price: number, ++ 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, +- }; +- }) ++ 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..81d4aa8 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,14 @@ class Graph extends Component { + const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement; + + const schema = { +- stock: 'string', +- top_ask_price: 'float', +- top_bid_price: 'float', +- timestamp: 'date', ++ 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 +40,25 @@ class Graph extends Component { + // Load the `table` in the `` 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.38.1.windows.1 +