Skip to content
Open
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
23 changes: 0 additions & 23 deletions .gitignore

This file was deleted.

141 changes: 141 additions & 0 deletions 0001-Create-Patch-File-task3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
From 0d8437ae2fffd34d64c7c76deb114adb298f6e08 Mon Sep 17 00:00:00 2001
From: brahmateja37 <[email protected]>
Date: Tue, 4 Oct 2022 22:51:48 +0530
Subject: [PATCH] Create Patch File

---
.vscode/launch.json | 15 +++++++++++++++
src/DataManipulator.ts | 35 +++++++++++++++++++++++++----------
src/Graph.tsx | 25 +++++++++++++++----------
3 files changed, 55 insertions(+), 20 deletions(-)
create mode 100644 .vscode/launch.json

diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..7a9dfa0
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,15 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "pwa-chrome",
+ "request": "launch",
+ "name": "Launch Chrome against localhost",
+ "url": "http://localhost:8080",
+ "webRoot": "${workspaceFolder}"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/DataManipulator.ts b/src/DataManipulator.ts
index f6b15ff..1ebad3d 100644
--- a/src/DataManipulator.ts
+++ b/src/DataManipulator.ts
@@ -1,20 +1,35 @@
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[]): Row[] {
- 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 upper_bound = 1 + 0.04;
+ const lower_bound = 1 - 0.04;
+ return {
+ price_abc: priceABC,
+ price_def: priceDEF,
+ ratio,
+ timestamp: serverResponds[0].timestamp > serverResponds[1].timestamp ?
+ serverResponds[0].timestamp : serverResponds[1].timestamp,
+ upper_bound: upper_bound,
+ lower_bound: lower_bound,
+ trigger_alert: (ratio > upper_bound || ratio < lower_bound ) ? ratio : undefined,
+
+ };
+
}
+
}
diff --git a/src/Graph.tsx b/src/Graph.tsx
index 58fb997..79bd0d7 100644
--- a/src/Graph.tsx
+++ b/src/Graph.tsx
@@ -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,25 @@ 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',
+ 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),
- );
+ ]);
}
}
}
--
2.37.1.windows.1

72 changes: 0 additions & 72 deletions README.md

This file was deleted.

Loading