Spaces:
Runtime error
Runtime error
mdj1412
commited on
Commit
ยท
4a5c163
1
Parent(s):
e9359a3
complete
Browse files- static/css/style.css +0 -3
- static/js/index.js +62 -54
- templates/index.html +1 -5
static/css/style.css
CHANGED
@@ -226,9 +226,6 @@
|
|
226 |
justify: ์์ชฝ ์ ๋ ฌ (์๋ ์ค๋ฐ๊ฟ์ ์ค๋ฅธ์ชฝ ๊ฒฝ๊ณ์ ๋ถ๋ถ ์ ๋ฆฌ)
|
227 |
*/
|
228 |
text-align: center;
|
229 |
-
|
230 |
-
|
231 |
-
padding-top: 50px;
|
232 |
}
|
233 |
|
234 |
|
|
|
226 |
justify: ์์ชฝ ์ ๋ ฌ (์๋ ์ค๋ฐ๊ฟ์ ์ค๋ฅธ์ชฝ ๊ฒฝ๊ณ์ ๋ถ๋ถ ์ ๋ฆฌ)
|
227 |
*/
|
228 |
text-align: center;
|
|
|
|
|
|
|
229 |
}
|
230 |
|
231 |
|
static/js/index.js
CHANGED
@@ -126,7 +126,7 @@ function nasdaq_table_init() {
|
|
126 |
*
|
127 |
*
|
128 |
*/
|
129 |
-
function chartInit(ticker) {
|
130 |
// HTML ์์
|
131 |
$("#nasdaq-table-container").hide();
|
132 |
$("#chart-container").show();
|
@@ -138,40 +138,39 @@ function chartInit(ticker) {
|
|
138 |
// Javascript -> Flask (Python) -> Javascript
|
139 |
let [chart_data, news_articles] = sendAjax_sync_about_chartData_and_newsArticles("/chart", {"ticker": ticker}, "json", handle_two_return);
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
151 |
}
|
152 |
|
153 |
|
154 |
-
// Javascript chart.js candlestick
|
155 |
-
let mychart = document.getElementById('myChart');
|
156 |
-
new Chart(mychart, {
|
157 |
-
type: 'candlestick',
|
158 |
-
data: {
|
159 |
-
datasets: [{
|
160 |
-
label: 'CHRT - '.concat(ticker),
|
161 |
-
data: data
|
162 |
-
}]
|
163 |
-
}
|
164 |
-
});
|
165 |
-
//////////////////////////////////////////////////////////////////
|
166 |
-
|
167 |
-
|
168 |
|
169 |
//////////////////////////////////////////////////////////////////
|
170 |
|
171 |
// Javascript๋ฅผ ์ด์ฉํด HTML์ ๋์ ์ผ๋ก ํ๊ทธ ์ถ๊ฐ
|
172 |
|
173 |
// a ํ๊ทธ onclick ์ ์ฉ
|
174 |
-
var execution_function = `javascript:chartInit('${ticker}')`;
|
175 |
const goTicker = document.querySelector('#chart-container .goticker');
|
176 |
goTicker.setAttribute('href', execution_function);
|
177 |
|
@@ -243,9 +242,9 @@ function chartInit(ticker) {
|
|
243 |
if (date_idx_in_key_list != -1) {
|
244 |
var diff = ((open_list[date_idx_in_key_list]-close_list[date_idx_in_key_list-1])/(open_list[date_idx_in_key_list]) * 100.0).toFixed(2);
|
245 |
}
|
246 |
-
else { var diff =
|
247 |
|
248 |
-
if (diff ==
|
249 |
var diff_html = '<th class="news diff">0.0 %</th>';
|
250 |
}
|
251 |
else if (diff > 0) {
|
@@ -281,7 +280,7 @@ function chartInit(ticker) {
|
|
281 |
var link = String(`/info_and_newsNER?ticker=${ ticker }&date=${ key }&title=${ sendTitle }&andSymbolInTitle=${ andSymbolInTitle }`);
|
282 |
linkList.push(link);
|
283 |
|
284 |
-
var execution_function = String(`javascript:getData(linkList[${ link_list_idx }]);`);
|
285 |
html = html + `<a href="${ execution_function }">${ title }</a><br>`;
|
286 |
link_list_idx = link_list_idx + 1;
|
287 |
}
|
@@ -293,19 +292,20 @@ function chartInit(ticker) {
|
|
293 |
|
294 |
|
295 |
linkList = [];
|
296 |
-
async function getData(link) {
|
297 |
try {
|
298 |
console.log("link : ", link);
|
299 |
|
300 |
await $.getJSON(link, function(data)
|
301 |
{
|
302 |
-
console.log("ticker : ", data.ticker);
|
303 |
-
console.log("date : ", data.date);
|
304 |
-
console.log("title : ", data.title);
|
305 |
-
console.log("url : ", data.url);
|
306 |
-
console.log("ents : ", data.ents);
|
|
|
307 |
|
308 |
-
newsInit(data.ticker, data.date, data.title, data.url, data.ents);
|
309 |
});
|
310 |
} catch (error) {
|
311 |
console.log("Error : ", error);
|
@@ -328,16 +328,16 @@ async function getData(link) {
|
|
328 |
*
|
329 |
*
|
330 |
*/
|
331 |
-
function newsInit(ticker, date, title, url, ents) {
|
332 |
-
|
333 |
// HTML ์์
|
334 |
$("#nasdaq-table-container").hide();
|
335 |
$("#chart-container").hide();
|
336 |
$("#news-container").show();
|
337 |
|
338 |
-
console.log(ticker);
|
339 |
-
console.log(date);
|
340 |
-
console.log(title);
|
341 |
|
342 |
|
343 |
|
@@ -345,16 +345,15 @@ function newsInit(ticker, date, title, url, ents) {
|
|
345 |
|
346 |
// Javascript๋ฅผ ์ด์ฉํด HTML์ ๋์ ์ผ๋ก ํ๊ทธ ์ถ๊ฐ
|
347 |
|
348 |
-
document.querySelector('#news-container .goticker .tickerName').textContent =
|
349 |
document.querySelector('#news-container .titleDate').textContent = "Date : " + date;
|
350 |
document.querySelector('#news-container .titleName').textContent = "Article : " + title;
|
351 |
document.querySelector('#news-container .newsURL .input-News-URL').textContent = "URL : " + url;
|
352 |
|
353 |
|
354 |
// a ํ๊ทธ onclick ์ ์ฉ
|
355 |
-
var execution_function = `javascript:chartInit('${ ticker }')`;
|
356 |
const goTicker = document.querySelector('#news-container .goticker');
|
357 |
-
console.log(goTicker);
|
358 |
goTicker.setAttribute('href', execution_function);
|
359 |
|
360 |
|
@@ -365,7 +364,10 @@ function newsInit(ticker, date, title, url, ents) {
|
|
365 |
|
366 |
// ๋ชจ๋ธ์์ ์ง๋ฌธ ์์ Ticker์ ์๋ง๊ฒ ์์ฑํ๊ธฐ
|
367 |
const model_input_example = document.querySelector('#model .text-form #text-input');
|
368 |
-
example = "
|
|
|
|
|
|
|
369 |
model_input_example.setAttribute('value', example);
|
370 |
|
371 |
|
@@ -379,12 +381,14 @@ function newsInit(ticker, date, title, url, ents) {
|
|
379 |
let news = ents['news'];
|
380 |
let numOfNER = ents['text'].length;
|
381 |
|
|
|
|
|
382 |
|
383 |
// ๋๋๋ง html ์์ ์์ฑ
|
384 |
news_ner = document.querySelector('.entities');
|
385 |
news_ner.innerHTML = '';
|
386 |
|
387 |
-
for (i=0; i<numOfNER
|
388 |
start_idx = (i == 0) ? 0 : ents['end_char'][i-1];
|
389 |
end_idx = ents['start_char'][i];
|
390 |
last_idx = ents['end_char'][i];
|
@@ -397,13 +401,17 @@ function newsInit(ticker, date, title, url, ents) {
|
|
397 |
else if (label == 'PRODUCT') { class_name = "entity_product"; }
|
398 |
else { console.log("[ Error !!! - New NER label_ ] : ", ents['label_'][i], ents['text'][i]); class_name = "none"; }
|
399 |
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
406 |
}
|
|
|
407 |
news_ner.innerHTML = news_ner.innerHTML + news.substring(ents['end_char'][numOfNER-1]);
|
408 |
|
409 |
|
@@ -427,12 +435,12 @@ function newsInit(ticker, date, title, url, ents) {
|
|
427 |
idx = sendTitle.indexOf('&', idx);
|
428 |
if (idx == -1) { break; }
|
429 |
sendTitle = sendTitle.substring(0, idx) + sendTitle.substring(idx+1, sendTitle.length);
|
430 |
-
console.log(sendTitle);
|
431 |
andSymbolInTitle.push(idx + andSymbolInTitle.length);
|
432 |
}
|
433 |
|
434 |
-
console.log(andSymbolInTitle);
|
435 |
-
console.log("Last String", sendTitle);
|
436 |
|
437 |
|
438 |
|
|
|
126 |
*
|
127 |
*
|
128 |
*/
|
129 |
+
function chartInit(ticker, already=false) {
|
130 |
// HTML ์์
|
131 |
$("#nasdaq-table-container").hide();
|
132 |
$("#chart-container").show();
|
|
|
138 |
// Javascript -> Flask (Python) -> Javascript
|
139 |
let [chart_data, news_articles] = sendAjax_sync_about_chartData_and_newsArticles("/chart", {"ticker": ticker}, "json", handle_two_return);
|
140 |
|
141 |
+
if (!already) {
|
142 |
+
// x์ถ๊ณผ data ์ค์
|
143 |
+
// data: [{'x': date, 'o': open, 'h': high, 'l': low, 'c': close}, { }, { }, ... ]
|
144 |
+
data = [];
|
145 |
+
key_list = Object.keys(chart_data.Close);
|
146 |
+
for (var i=key_list.length-15; i<key_list.length; i++) {
|
147 |
+
key = key_list[i];
|
148 |
+
const [year, month, day] = key.split("-");
|
149 |
+
const x = new Date(parseInt(year), parseInt(month), parseInt(day), 9, 0, 0, 0).getTime();
|
150 |
+
data.push({'x': x, 'o': chart_data.Open[key].toFixed(2), 'h': chart_data.High[key].toFixed(2), 'l': chart_data.Low[key].toFixed(2), 'c': chart_data.Close[key].toFixed(2)})
|
151 |
+
}
|
152 |
|
153 |
+
// Javascript chart.js candlestick
|
154 |
+
let mychart = document.getElementById('myChart');
|
155 |
+
new Chart(mychart, {
|
156 |
+
type: 'candlestick',
|
157 |
+
data: {
|
158 |
+
datasets: [{
|
159 |
+
label: 'CHRT - '.concat(ticker),
|
160 |
+
data: data
|
161 |
+
}]
|
162 |
+
}
|
163 |
+
});
|
164 |
}
|
165 |
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
//////////////////////////////////////////////////////////////////
|
169 |
|
170 |
// Javascript๋ฅผ ์ด์ฉํด HTML์ ๋์ ์ผ๋ก ํ๊ทธ ์ถ๊ฐ
|
171 |
|
172 |
// a ํ๊ทธ onclick ์ ์ฉ
|
173 |
+
var execution_function = `javascript:chartInit('${ticker}', true)`;
|
174 |
const goTicker = document.querySelector('#chart-container .goticker');
|
175 |
goTicker.setAttribute('href', execution_function);
|
176 |
|
|
|
242 |
if (date_idx_in_key_list != -1) {
|
243 |
var diff = ((open_list[date_idx_in_key_list]-close_list[date_idx_in_key_list-1])/(open_list[date_idx_in_key_list]) * 100.0).toFixed(2);
|
244 |
}
|
245 |
+
else { var diff = 0; }
|
246 |
|
247 |
+
if (diff == 0) {
|
248 |
var diff_html = '<th class="news diff">0.0 %</th>';
|
249 |
}
|
250 |
else if (diff > 0) {
|
|
|
280 |
var link = String(`/info_and_newsNER?ticker=${ ticker }&date=${ key }&title=${ sendTitle }&andSymbolInTitle=${ andSymbolInTitle }`);
|
281 |
linkList.push(link);
|
282 |
|
283 |
+
var execution_function = String(`javascript:getData(linkList[${ link_list_idx }], ${ diff });`);
|
284 |
html = html + `<a href="${ execution_function }">${ title }</a><br>`;
|
285 |
link_list_idx = link_list_idx + 1;
|
286 |
}
|
|
|
292 |
|
293 |
|
294 |
linkList = [];
|
295 |
+
async function getData(link, diff) {
|
296 |
try {
|
297 |
console.log("link : ", link);
|
298 |
|
299 |
await $.getJSON(link, function(data)
|
300 |
{
|
301 |
+
// console.log("ticker : ", data.ticker);
|
302 |
+
// console.log("date : ", data.date);
|
303 |
+
// console.log("title : ", data.title);
|
304 |
+
// console.log("url : ", data.url);
|
305 |
+
// console.log("ents : ", data.ents);
|
306 |
+
console.log("diff : ", diff);
|
307 |
|
308 |
+
newsInit(data.ticker, data.date, data.title, data.url, data.ents, diff);
|
309 |
});
|
310 |
} catch (error) {
|
311 |
console.log("Error : ", error);
|
|
|
328 |
*
|
329 |
*
|
330 |
*/
|
331 |
+
function newsInit(ticker, date, title, url, ents, diff) {
|
332 |
+
|
333 |
// HTML ์์
|
334 |
$("#nasdaq-table-container").hide();
|
335 |
$("#chart-container").hide();
|
336 |
$("#news-container").show();
|
337 |
|
338 |
+
// console.log(ticker);
|
339 |
+
// console.log(date);
|
340 |
+
// console.log(title);
|
341 |
|
342 |
|
343 |
|
|
|
345 |
|
346 |
// Javascript๋ฅผ ์ด์ฉํด HTML์ ๋์ ์ผ๋ก ํ๊ทธ ์ถ๊ฐ
|
347 |
|
348 |
+
document.querySelector('#news-container .goticker .tickerName').textContent = ticker + " Chart";
|
349 |
document.querySelector('#news-container .titleDate').textContent = "Date : " + date;
|
350 |
document.querySelector('#news-container .titleName').textContent = "Article : " + title;
|
351 |
document.querySelector('#news-container .newsURL .input-News-URL').textContent = "URL : " + url;
|
352 |
|
353 |
|
354 |
// a ํ๊ทธ onclick ์ ์ฉ
|
355 |
+
var execution_function = `javascript:chartInit('${ ticker }', true)`;
|
356 |
const goTicker = document.querySelector('#news-container .goticker');
|
|
|
357 |
goTicker.setAttribute('href', execution_function);
|
358 |
|
359 |
|
|
|
364 |
|
365 |
// ๋ชจ๋ธ์์ ์ง๋ฌธ ์์ Ticker์ ์๋ง๊ฒ ์์ฑํ๊ธฐ
|
366 |
const model_input_example = document.querySelector('#model .text-form #text-input');
|
367 |
+
if (diff == 0) { example = "What is your outlook for the future direction of this stock?" }
|
368 |
+
else if (diff > 0) { example = "Why did " + ticker + "'s stock go up?"; }
|
369 |
+
else if (diff < 0) { example = "Why did " + ticker + "'s stock go down?"; }
|
370 |
+
else { throw new Error('Error : diff Error '); }
|
371 |
model_input_example.setAttribute('value', example);
|
372 |
|
373 |
|
|
|
381 |
let news = ents['news'];
|
382 |
let numOfNER = ents['text'].length;
|
383 |
|
384 |
+
// console.log("total news : ", news);
|
385 |
+
|
386 |
|
387 |
// ๋๋๋ง html ์์ ์์ฑ
|
388 |
news_ner = document.querySelector('.entities');
|
389 |
news_ner.innerHTML = '';
|
390 |
|
391 |
+
for (i=0; i<numOfNER; i++) {
|
392 |
start_idx = (i == 0) ? 0 : ents['end_char'][i-1];
|
393 |
end_idx = ents['start_char'][i];
|
394 |
last_idx = ents['end_char'][i];
|
|
|
401 |
else if (label == 'PRODUCT') { class_name = "entity_product"; }
|
402 |
else { console.log("[ Error !!! - New NER label_ ] : ", ents['label_'][i], ents['text'][i]); class_name = "none"; }
|
403 |
|
404 |
+
add_html = news.substring(start_idx, end_idx);
|
405 |
+
add_html = add_html + '<mark class=' + class_name
|
406 |
+
+ ' style="line-height: 1;">'
|
407 |
+
+ news.substring(end_idx, last_idx)
|
408 |
+
+ '<span class="show-label" style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">'
|
409 |
+
+ label + '</span></mark>';
|
410 |
+
|
411 |
+
// console.log(add_html);
|
412 |
+
news_ner.innerHTML = news_ner.innerHTML + add_html;
|
413 |
}
|
414 |
+
// console.log("last html : ", news.substring(ents['end_char'][numOfNER-1]));
|
415 |
news_ner.innerHTML = news_ner.innerHTML + news.substring(ents['end_char'][numOfNER-1]);
|
416 |
|
417 |
|
|
|
435 |
idx = sendTitle.indexOf('&', idx);
|
436 |
if (idx == -1) { break; }
|
437 |
sendTitle = sendTitle.substring(0, idx) + sendTitle.substring(idx+1, sendTitle.length);
|
438 |
+
// console.log(sendTitle);
|
439 |
andSymbolInTitle.push(idx + andSymbolInTitle.length);
|
440 |
}
|
441 |
|
442 |
+
// console.log(andSymbolInTitle);
|
443 |
+
// console.log("Last String", sendTitle);
|
444 |
|
445 |
|
446 |
|
templates/index.html
CHANGED
@@ -98,10 +98,6 @@
|
|
98 |
<!-- table ํ๊ทธ : ํ
์ด๋ธ์ ๋ง๋ ๋ค. -->
|
99 |
<table class="table"
|
100 |
|
101 |
-
text-align="center"
|
102 |
-
align-items="center"
|
103 |
-
justify-content="center"
|
104 |
-
|
105 |
border="1"
|
106 |
width="90%"
|
107 |
height="200"
|
@@ -145,7 +141,7 @@
|
|
145 |
|
146 |
<!-- named entity recognition (NER) -->
|
147 |
<figure style="margin-bottom: 6rem">
|
148 |
-
<div class="entities" style="line-height:
|
149 |
|
150 |
</div>
|
151 |
</figure>
|
|
|
98 |
<!-- table ํ๊ทธ : ํ
์ด๋ธ์ ๋ง๋ ๋ค. -->
|
99 |
<table class="table"
|
100 |
|
|
|
|
|
|
|
|
|
101 |
border="1"
|
102 |
width="90%"
|
103 |
height="200"
|
|
|
141 |
|
142 |
<!-- named entity recognition (NER) -->
|
143 |
<figure style="margin-bottom: 6rem">
|
144 |
+
<div class="entities" style="line-height: 1.3; direction: ltr">
|
145 |
|
146 |
</div>
|
147 |
</figure>
|