Skip to content
Snippets Groups Projects
Unverified Commit b39adb27 authored by doseum's avatar doseum Committed by GitHub
Browse files

Merge branch 'master' into 정승우

parents db18de2e 5275eeb5
No related branches found
No related tags found
1 merge request!1스탯 전략 페이지 구현-그래프제외
......@@ -36,6 +36,7 @@ app.post('/api', function (req, res, next) {
querylist += query;
}
querylist += `select close,date from ckospi_index where date between '${date}' and '2019-11-20';`
connection.query(querylist,function(req,result){
console.log(result);
res.send(result);
......
//Importing Line class from the vue-chartjs wrapper
import {Line,mixins} from 'vue-chartjs'
const { reactiveProp } = mixins
//Exporting this so it can be used in other components
export default {
extends: Line,
data() {
return {
datacollection: {
//Data to be represented on x-axis
//labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',],
labels : this.$store.state.SS_chart_labels,
datasets: [
{
label: '내 포트폴리오',
fill: true,
lineTension: 0.5,
backgroundColor: 'rgba(247, 185, 36, 0.2)',
borderColor: '#f7b924',
borderCapStyle: 'round',
borderDash: [],
borderWidth: 4,
borderDashOffset: 0.0,
borderJoinStyle: 'round',
pointBorderColor: '#f7b924',
pointBackgroundColor: '#ffffff',
pointBorderWidth: 5,
pointHoverRadius: 6,
pointHoverBackgroundColor: '#ffffff',
pointHoverBorderColor: '#f7b924',
pointHoverBorderWidth: 2,
pointRadius: 4,
pointHitRadius: 10,
//data: [65, 59, 80, 81, 46, 55, 38, 59, 80, 72]
data : this.$store.state.SS_chart_data2
},
{
label: '코스피 인덱스 추종',
fill: true,
lineTension: 0.5,
backgroundColor: '#05CBE1',
borderColor: '#f7b924',
borderCapStyle: 'round',
borderDash: [],
borderWidth: 4,
borderDashOffset: 0.0,
borderJoinStyle: 'round',
pointBorderColor: '#f7b924',
pointBackgroundColor: '#ffffff',
pointBorderWidth: 5,
pointHoverRadius: 6,
pointHoverBackgroundColor: '#ffffff',
pointHoverBorderColor: '#f7b924',
pointHoverBorderWidth: 2,
pointRadius: 4,
pointHitRadius: 10,
//data: [65, 59, 80, 81, 46, 55, 38, 59, 80, 72]
data : this.$store.state.SS_chart_data1
}
]
},
//Chart.js options that controls the appearance of the chart
options: {
layout: {
padding: {
left: 0,
right: 8,
top: 0,
bottom: 0
}
},
scales: {
yAxes: [{
ticks: {
display: true,
beginAtZero: false
},
gridLines: {
display: false
}
}],
xAxes: [{
ticks: {
display: false
},
gridLines: {
display: false
}
}]
},
legend: {
display: false
},
responsive: true,
maintainAspectRatio: true
}
}
},
mounted() {
//renderChart function renders the chart with the datacollection and options object.
this.renderChart(this.datacollection, this.options)
},
}
\ No newline at end of file
//Importing Line class from the vue-chartjs wrapper
import {Line} from 'vue-chartjs'
//Exporting this so it can be used in other components
export default {
extends: Line,
data() {
return {
datacollection: {
//Data to be represented on x-axis
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',],
datasets: [
{
label: 'My First dataset',
fill: true,
lineTension: 0.5,
backgroundColor: 'rgba(48, 177, 255, 0.2)',
borderColor: '#30b1ff',
borderCapStyle: 'round',
borderDash: [],
borderWidth: 4,
borderDashOffset: 0.0,
borderJoinStyle: 'round',
pointBorderColor: '#30b1ff',
pointBackgroundColor: '#ffffff',
pointBorderWidth: 5,
pointHoverRadius: 6,
pointHoverBackgroundColor: '#ffffff',
pointHoverBorderColor: '#30b1ff',
pointHoverBorderWidth: 2,
pointRadius: 4,
pointHitRadius: 10,
data: [46, 55, 59, 80, 81, 38, 65, 59, 80,]
}
]
},
//Chart.js options that controls the appearance of the chart
options: {
layout: {
padding: {
left: 0,
right: 8,
top: 0,
bottom: 0
}
},
scales: {
yAxes: [{
ticks: {
display: false,
beginAtZero: true
},
gridLines: {
display: false
}
}],
xAxes: [{
ticks: {
display: false
},
gridLines: {
display: false
}
}]
},
legend: {
display: false
},
responsive: true,
maintainAspectRatio: false
}
}
},
mounted() {
//renderChart function renders the chart with the datacollection and options object.
this.renderChart(this.datacollection, this.options)
}
}
\ No newline at end of file
//Importing Line class from the vue-chartjs wrapper
import {Line} from 'vue-chartjs'
//Exporting this so it can be used in other components
export default {
extends: Line,
data() {
return {
datacollection: {
//Data to be represented on x-axis
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',],
datasets: [
{
label: 'My First dataset',
fill: true,
lineTension: 0.5,
backgroundColor: 'rgba(86, 196, 121, 0.2)',
borderColor: '#56c479',
borderCapStyle: 'round',
borderDash: [],
borderWidth: 4,
borderDashOffset: 0.0,
borderJoinStyle: 'round',
pointBorderColor: '#56c479',
pointBackgroundColor: '#ffffff',
pointBorderWidth: 5,
pointHoverRadius: 6,
pointHoverBackgroundColor: '#ffffff',
pointHoverBorderColor: '#56c479',
pointHoverBorderWidth: 2,
pointRadius: 4,
pointHitRadius: 10,
data: [65, 59, 80, 81, 55, 38, 59, 80, 46]
}
]
},
//Chart.js options that controls the appearance of the chart
options: {
layout: {
padding: {
left: 0,
right: 8,
top: 0,
bottom: 0
}
},
scales: {
yAxes: [{
ticks: {
display: false,
beginAtZero: true
},
gridLines: {
display: false
}
}],
xAxes: [{
ticks: {
display: false
},
gridLines: {
display: false
}
}]
},
legend: {
display: false
},
responsive: true,
maintainAspectRatio: false
}
}
},
mounted() {
//renderChart function renders the chart with the datacollection and options object.
this.renderChart(this.datacollection, this.options)
}
}
\ No newline at end of file
......@@ -57,7 +57,7 @@
</div>
</div>
<div class="widget-chart-wrapper he-auto opacity-10 m-0">
<chart1 :height="145"/>
<SSchart :height="145"/>
</div>
</div>
</div>
......@@ -103,13 +103,13 @@
</template>
<script>
import chart1 from './Dashboards/Analytics/chart1';
import SSchart from './Analytics/SS_chart1';
import VuePerfectScrollbar from 'vue-perfect-scrollbar';
export default {
components: {
VuePerfectScrollbar,
chart1,
SSchart,
},
name: "StrategySimulator",
data(){
......@@ -119,7 +119,7 @@
budget:'',
stockCode: [],
stockList: [],
ratio:[],
ratio: this.$store.state.SS_ratio,
tmp:0,
valid:false
......@@ -162,14 +162,10 @@
return false
}
else{
this.valid=true;
this.$store.dispatch('calculatePortfolio',{date:this.date,stockCode:this.stockCode,ratio:this.ratio});
//validation하고 맞으면 입력받은 date랑 stockCode를 back으로 보내
this.$store.dispatch('addDataToChart');
this.valid=true
this.$http.post('/test/api',{date:this.date,stockCode:this.stockCode,ratio:this.ratio})
.then(response=>{
console.log(response.data);
console.log(response.data[0].date);
});
}
},
datechangeInit: function () {
......
......@@ -8,8 +8,17 @@ export default new Vuex.Store({
{
chart1_labels : [],
chart1_data : [],
},
SS_init_money : 1000000,
SS_init_stocks : [],
SS_init_index_stock_num : 0,
SS_ratio : [],
SS_chart_labels : [],
SS_chart_data1 : [],
SS_chart_data2 : [],
},
// 전체돈 * ration / 주식개별
// 전체돈 * 코스닥 가격
/**
* Mutation is the simple state-changing operation
* that does not contain other Frontend logic and AJAX requests.
......@@ -31,6 +40,55 @@ export default new Vuex.Store({
addDataToChartFail(/*state, payload*/)
{
console.log('addDataToChart Error!');
},
calculatePortfolioSuccess(state, payload)
{
//살 종목의 개수 + 1(코스피)
var payloadSize = payload.data.length-1;
//날짜의 개수
var payloadNumSize = payload.data[payloadSize].length -1;
//첫날 코스피 산 개수
state.SS_init_index_stock_num = state.SS_init_money / payload.data[payloadSize][0].close;
for(var i=0; i<=payloadNumSize; i++)
{
var tdate = payload.data[payloadSize][i].date
state.SS_chart_labels.push(tdate);
var tvalue = state.SS_init_index_stock_num * payload.data[payloadSize][i].close;
state.SS_chart_data1.push(tvalue);
}
//날짜, 코스피 지수 차트저장 완료
console.log(state.SS_chart_data1);
for(var i=0; i<=payloadNumSize; i++)
{
state.SS_chart_data2.push(Number(0));
}
// 초기 구매 주식 개수
for(var i=0; i<payloadSize; i++)
{
var tinit_stocks = state.SS_init_money*state.SS_ratio[i] / payload.data[i][payloadSize].close/100;
state.SS_init_stocks.push(tinit_stocks);
}
console.log(state.SS_init_stocks);
// 포트폴리오 변동 계산.
for(var i=0; i<=payloadNumSize; i++)
{
for(var j=0; j<payloadSize; j++)
{
state.SS_chart_data2[i] += Number(state.SS_init_stocks[j] * payload.data[j][payloadNumSize-i].close);
}
}
console.log(state.SS_chart_data2);
},
calculatePortfolioFail(state, payload)
{
console.log(payload);
}
},
actions :
......@@ -41,8 +99,18 @@ export default new Vuex.Store({
.then((res) => {
commit('addDataToChartSuccess',res);
})
.catch((res) => {
commit('addDataToChartFail',res);
.catch((err) => {
commit('addDataToChartFail',err);
});
},
calculatePortfolio({commit},payload)
{
axios.post('/test/api',payload)
.then((res) => {
commit('calculatePortfolioSuccess',res);
})
.catch((err) => {
commit('calculatePortfolioFail',err);
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment