Skip to content

Commit

Permalink
lines chart in stock check result
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Jul 16, 2021
1 parent a97258d commit 1dd7fb4
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 28 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.4.0
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/avast/retry-go v3.0.0+incompatible
github.com/axiaoxin-com/goutils v1.0.18-0.20210712041447-3fcbf074cbdf
github.com/axiaoxin-com/goutils v1.0.19
github.com/axiaoxin-com/logging v1.2.11-0.20210710005236-5a960a1422ba
github.com/axiaoxin-com/ratelimiter v1.0.3
github.com/deckarep/golang-set v1.7.1
Expand Down Expand Up @@ -54,5 +54,5 @@ require (
gorm.io/driver/postgres v1.1.0 // indirect
gorm.io/driver/sqlite v1.1.4 // indirect
gorm.io/driver/sqlserver v1.0.7 // indirect
gorm.io/gorm v1.21.11
gorm.io/gorm v1.21.12
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ github.com/axiaoxin-com/goutils v0.0.0-20200909093258-aaf2fefcde7a/go.mod h1:F2a
github.com/axiaoxin-com/goutils v1.0.3-0.20201019024427-66fe97b27be4/go.mod h1:ZuL0c9e5Nw6b6eirSmB9VaOeojiHS3BrmzGyKiKYLD0=
github.com/axiaoxin-com/goutils v1.0.18-0.20210712041447-3fcbf074cbdf h1:z4xg96zQspm46yNq69q9lppGye5OVPi7hzwfk2ZWuCA=
github.com/axiaoxin-com/goutils v1.0.18-0.20210712041447-3fcbf074cbdf/go.mod h1:5TkHWwl5j2M2u4vFDxtelwB4Ts7JgyfpRJrs8v19+VM=
github.com/axiaoxin-com/goutils v1.0.18-0.20210716022755-adca40994719 h1:khnOQaIqwVs+qyjLKcGU4kY6FdoHB+KgmmoTxoiXvuc=
github.com/axiaoxin-com/goutils v1.0.18-0.20210716022755-adca40994719/go.mod h1:5TkHWwl5j2M2u4vFDxtelwB4Ts7JgyfpRJrs8v19+VM=
github.com/axiaoxin-com/goutils v1.0.19 h1:Y+jXz7v8Ax1o7SY1UOPX+NfCTq/GIljSACZRNvOif/o=
github.com/axiaoxin-com/goutils v1.0.19/go.mod h1:5TkHWwl5j2M2u4vFDxtelwB4Ts7JgyfpRJrs8v19+VM=
github.com/axiaoxin-com/logging v1.2.3/go.mod h1:WM8Q9JLUi1jDh51XirUBDn8QXkxc8AO2oApFXHiEXf4=
github.com/axiaoxin-com/logging v1.2.11-0.20210710005236-5a960a1422ba h1:cAErRDYhJOQr4MWHIBKYn5WI+/qnxTa41ycLyenreUE=
github.com/axiaoxin-com/logging v1.2.11-0.20210710005236-5a960a1422ba/go.mod h1:Jx322YD47doa/j9kn3pNPntze8b9bOVxf3So0LmdRMg=
Expand Down Expand Up @@ -1355,6 +1359,8 @@ gorm.io/gorm v1.21.4/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.21.9/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.11 h1:CxkXW6Cc+VIBlL8yJEHq+Co4RYXdSLiMKNvgoZPjLK4=
gorm.io/gorm v1.21.11/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.12 h1:3fQM0Eiz7jcJEhPggHEpoYnsGZqynMzverL77DV40RM=
gorm.io/gorm v1.21.12/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
108 changes: 107 additions & 1 deletion routes/stock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"fmt"
"net/http"
"strings"
"time"

"github.com/axiaoxin-com/goutils"
"github.com/axiaoxin-com/x-stock/core"
"github.com/axiaoxin-com/x-stock/datacenter/eastmoney"
"github.com/axiaoxin-com/x-stock/models"
Expand Down Expand Up @@ -112,6 +114,17 @@ func StockChecker(c *gin.Context) {
stockNames := []string{}
finaReportNames := []string{}
finaAppointPublishDates := []string{}
lines := [][]gin.H{}
yearLabels := []string{}
year := time.Now().Year()
for i := param.CheckerOptions.CheckYears; i > 0; i-- {
yearLabels = append(yearLabels, fmt.Sprint(year-i))
}

type dataset struct {
Label string `json:"label"`
Data []float64 `json:"data"`
}
for _, stock := range stocks {
result, _ := checker.CheckFundamentals(c, stock)
results = append(results, result)
Expand All @@ -125,12 +138,105 @@ func StockChecker(c *gin.Context) {
finaReportNames = append(finaReportNames, finaReportName)

finaAppointPublishDates = append(finaAppointPublishDates, strings.Split(stock.FinaAppointPublishDate, " ")[0])
line0 := gin.H{
"title": "",
"xLable": "年",
"yLabel": "",
"data": gin.H{
"labels": yearLabels,
"datasets": []dataset{
{
Label: "ROE",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeROE,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
{
Label: "EPS",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeEPS,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
{
Label: "ROA",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeROA,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
{
Label: "毛利率",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeMLL,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
{
Label: "净利率",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeJLL,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
},
},
}
line1 := gin.H{
"title": "",
"xLable": "年",
"yLabel": "",
"data": gin.H{
"labels": yearLabels,
"datasets": []dataset{
{
Label: "营收",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeRevenue,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
{
Label: "毛利",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeGrossProfit,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
{
Label: "净利",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeNetProfit,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
},
},
},
}
lines = append(lines, []gin.H{line0, line1})
}
data["Results"] = results
data["StockNames"] = stockNames
data["FinaReportNames"] = finaReportNames
data["FinaAppointPublishDates"] = finaAppointPublishDates
data["Line"] = gin.H{}
data["Lines"] = lines
c.JSON(http.StatusOK, data)
return
}
1 change: 0 additions & 1 deletion statics/html/stock_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,4 @@ <h4 class="center">筛选结果</h4>
<div id="checker_results" class="row hide">
<h4 class="center">检测结果</h4>
</div>
<svg class="line-chart hide"></svg>
{{ template "footer" . }}
46 changes: 22 additions & 24 deletions statics/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ $(document).ready(function () {
$("#load_modal").modal("close");
return;
}
$("title").text(data.PageTitle);
$("#stock_forms").remove();
$("#checker_results").removeClass("hide");
if (data.Results.length == 0) {
$("#checker_results h4").text("暂不支持对该股进行检测");
} else {
Expand Down Expand Up @@ -332,32 +335,27 @@ $(document).ready(function () {
"</td></tr>"
);
});
const svg = document.querySelector(".line-chart");
// new chartXkcd.Line(svg, {
// title: "历史数据",
// xLabel: "年",
// yLabel: "",
// data: {
// labels: ["", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
// datasets: [
// {
// label: "Plan",
// data: [30, 70, 200, 300, 500, 800, 1500, 2900, 5000, 8000],
// },
// {
// label: "Reality",
// data: [0, 1, 30, 70, 80, 100, 50, 80, 40, 150],
// },
// ],
// },
// options: {},
// });
// $(".line-chart").removeClass("hide");
$("#checker_result_" + i).append(
'<div class="row">' +
'</br><h6 class="center">年报数据趋势概览</h6>' +
'<div class="col s12 m12 l6">' +
'<svg id="line-chart-' +
i +
'-0"></svg>' +
"</div>" +
'<div class="col s12 m12 l6">' +
'<svg id="line-chart-' +
i +
'-1"></svg>' +
"</div>" +
"</div>"
);
for (let j = 0; j < 2; j++) {
const svg = document.querySelector(`#line-chart-${i}-${j}`);
new chartXkcd.Line(svg, data.Lines[i][j]);
}
});
}
$("title").text(data.PageTitle);
$("#stock_forms").remove();
$("#checker_results").removeClass("hide");
$("html, body").animate({ scrollTop: 0 }, 0);
$("#load_modal").modal("close");
},
Expand Down

0 comments on commit 1dd7fb4

Please sign in to comment.