forked from theforage/forage-jpmc-swe-task-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task-2_main.patch
162 lines (146 loc) · 5.27 KB
/
task-2_main.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
From d8768a7c6f3e1b0f8064cd2268716c5427f17c2b Mon Sep 17 00:00:00 2001
From: Sanat Kumar Gupta <[email protected]>
Date: Sun, 14 Jul 2024 00:26:54 +0530
Subject: [PATCH 1/2] Update App.tsx
---
src/App.tsx | 54 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 34 insertions(+), 20 deletions(-)
diff --git a/src/App.tsx b/src/App.tsx
index 0728518c0d..edf2a6accb 100755
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,13 +1,14 @@
-import React, { Component } from 'react';
-import DataStreamer, { ServerRespond } from './DataStreamer';
-import Graph from './Graph';
-import './App.css';
+import React, { Component } from "react";
+import DataStreamer, { ServerRespond } from "./DataStreamer";
+import Graph from "./Graph";
+import "./App.css";
/**
* State declaration for <App />
*/
interface IState {
- data: ServerRespond[],
+ data: ServerRespond[];
+ showGraph: boolean;
}
/**
@@ -22,6 +23,7 @@ class App extends Component<{}, IState> {
// data saves the server responds.
// We use this state to parse data down to the child element (Graph) as element property
data: [],
+ showGraph: false,
};
}
@@ -29,18 +31,30 @@ class App extends Component<{}, IState> {
* Render Graph react component with state.data parse as property data
*/
renderGraph() {
- return (<Graph data={this.state.data}/>)
+ if (this.state.showGraph) {
+ return <Graph data={this.state.data} />;
+ }
}
/**
* Get new data from server and update the state with the new data
*/
getDataFromServer() {
- DataStreamer.getData((serverResponds: ServerRespond[]) => {
- // Update the state by creating a new array of data that consists of
- // Previous data in the state and the new data from server
- this.setState({ data: [...this.state.data, ...serverResponds] });
- });
+ let x = 0;
+ const interval = setInterval(() => {
+ DataStreamer.getData((serverResponds: ServerRespond[]) => {
+ // Update the state by creating a new array of data that consists of
+ // Previous data in the state and the new data from server
+ this.setState({
+ data: serverResponds,
+ showGraph: true,
+ });
+ });
+ x++;
+ if (x > 1000) {
+ clearInterval(interval);
+ }
+ }, 100);
}
/**
@@ -49,25 +63,25 @@ class App extends Component<{}, IState> {
render() {
return (
<div className="App">
- <header className="App-header">
- Bank & Merge Co Task 2
- </header>
+ <header className="App-header">Bank & Merge Co Task 2</header>
<div className="App-content">
- <button className="btn btn-primary Stream-button"
+ <button
+ className="btn btn-primary Stream-button"
// when button is click, our react app tries to request
// new data from the server.
// As part of your task, update the getDataFromServer() function
// to keep requesting the data every 100ms until the app is closed
// or the server does not return anymore data.
- onClick={() => {this.getDataFromServer()}}>
+ onClick={() => {
+ this.getDataFromServer();
+ }}
+ >
Start Streaming Data
</button>
- <div className="Graph">
- {this.renderGraph()}
- </div>
+ <div className="Graph">{this.renderGraph()}</div>
</div>
</div>
- )
+ );
}
}
From 130e95748f3dad658a38b6e7dafbffd69ea43996 Mon Sep 17 00:00:00 2001
From: Sanat Kumar Gupta <[email protected]>
Date: Sun, 14 Jul 2024 00:41:59 +0530
Subject: [PATCH 2/2] Update Graph.tsx
---
src/Graph.tsx | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/Graph.tsx b/src/Graph.tsx
index 3b2a7da1a3..55b4be69f6 100644
--- a/src/Graph.tsx
+++ b/src/Graph.tsx
@@ -14,7 +14,7 @@ interface IProps {
* Perspective library adds load to HTMLElement prototype.
* This interface acts as a wrapper for Typescript compiler.
*/
-interface PerspectiveViewerElement {
+interface PerspectiveViewerElement extends HTMLElement {
load: (table: Table) => void,
}
@@ -32,7 +32,7 @@ class Graph extends Component<IProps, {}> {
componentDidMount() {
// Get element to attach the table from the DOM.
- const elem: PerspectiveViewerElement = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;
+ const elem = document.getElementsByTagName('perspective-viewer')[0] as unknown as PerspectiveViewerElement;
const schema = {
stock: 'string',
@@ -49,6 +49,16 @@ class Graph extends Component<IProps, {}> {
// Add more Perspective configurations here.
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('aggregates',`
+ {"stock": "distinct count",
+ "top_ask_price":"avg",
+ "top_bid_price": "avg",
+ "timestamp": "distinct count"
+ }`);
}
}