predict_edb_info.go 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/data_manage"
  8. "hongze/hz_crm_api/models/data_manage/request"
  9. "hongze/hz_crm_api/models/data_manage/response"
  10. "hongze/hz_crm_api/services/data"
  11. "hongze/hz_crm_api/services/elastic"
  12. "hongze/hz_crm_api/utils"
  13. "sort"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // PredictEdbInfoController 预测指标
  19. type PredictEdbInfoController struct {
  20. controllers.BaseAuthController
  21. }
  22. // EdbChartList
  23. // @Title 预测指标列表接口
  24. // @Description 预测指标列表接口
  25. // @Param PageSize query int true "每页数据条数"
  26. // @Param CurrentIndex query int true "当前页页码,从1开始"
  27. // @Param ClassifyId query int true "分类id"
  28. // @Param Keyword query string true "搜索关键词"
  29. // @Param AdminId query int false "创建人id"
  30. // @Param IsOnlyMe query bool false "是否只看我的"
  31. // @Success 200 {object} response.PredictEdbInfoListResp
  32. // @router /predict_edb_info/chart/list [get]
  33. func (this *PredictEdbInfoController) EdbChartList() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. sysUser := this.SysUser
  40. if sysUser == nil {
  41. br.Msg = "请登录"
  42. br.ErrMsg = "请登录,SysUser Is Empty"
  43. br.Ret = 408
  44. return
  45. }
  46. classifyId, _ := this.GetInt("ClassifyId")
  47. pageSize, _ := this.GetInt("PageSize")
  48. currentIndex, _ := this.GetInt("CurrentIndex")
  49. keyword := this.GetString("Keyword")
  50. adminId, _ := this.GetInt("AdminId")
  51. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  52. var total int
  53. page := paging.GetPaging(currentIndex, pageSize, total)
  54. var startSize int
  55. if pageSize <= 0 {
  56. pageSize = utils.PageSize20
  57. }
  58. if currentIndex <= 0 {
  59. currentIndex = 1
  60. }
  61. startSize = paging.StartIndex(currentIndex, pageSize)
  62. var condition string
  63. var pars []interface{}
  64. // 预测指标
  65. condition += ` AND edb_info_type = ? `
  66. pars = append(pars, 1)
  67. // 筛选分类
  68. if classifyId > 0 {
  69. _, err := data_manage.GetEdbClassifyById(classifyId)
  70. if err != nil && err.Error() != utils.ErrNoRow() {
  71. br.Msg = "获取分类信息失败"
  72. br.ErrMsg = "获取分类信息失败,GetEdbClassifyById,Err:" + err.Error()
  73. return
  74. }
  75. condition += " AND classify_id = ? "
  76. pars = append(pars, classifyId)
  77. }
  78. if keyword != "" {
  79. condition += ` AND ( excel_name LIKE ? )`
  80. pars = append(pars, `%`+keyword+`%`)
  81. }
  82. if adminId > 0 {
  83. condition += " AND sys_user_id = ? "
  84. pars = append(pars, adminId)
  85. }
  86. if isOnlyMe {
  87. condition += " AND sys_user_id = ? "
  88. pars = append(pars, sysUser.AdminId)
  89. }
  90. // 获取当前账号的不可见指标
  91. obj := data_manage.EdbInfoNoPermissionAdmin{}
  92. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  93. if err != nil && err.Error() != utils.ErrNoRow() {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  96. return
  97. }
  98. noPermissionEdbInfoIdList := make([]int, 0)
  99. for _, v := range confList {
  100. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  101. }
  102. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  103. if noPermissionEdbInfoIdNum > 0 {
  104. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  105. pars = append(pars, noPermissionEdbInfoIdList)
  106. }
  107. //获取指标信息
  108. dataCount, list, err := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  109. if err != nil && err.Error() != utils.ErrNoRow() {
  110. br.Success = true
  111. br.Msg = "获取预测指标列表失败"
  112. br.ErrMsg = "获取预测指标列表失败,Err:" + err.Error()
  113. return
  114. }
  115. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  116. list = make([]*data_manage.EdbInfoList, 0)
  117. } else {
  118. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  119. }
  120. resp := response.PredictEdbInfoListResp{
  121. Paging: page,
  122. List: list,
  123. }
  124. br.Ret = 200
  125. br.Success = true
  126. br.Msg = "获取成功"
  127. br.Data = resp
  128. }
  129. // List
  130. // @Title 指标数据列表接口
  131. // @Description 指标数据列表接口
  132. // @Param PageSize query int true "每页数据条数"
  133. // @Param CurrentIndex query int true "当前页页码,从1开始"
  134. // @Param EdbInfoId query int true "指标id"
  135. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  136. // @Success 200 {object} data_manage.EdbInfoListResp
  137. // @router /predict_edb_info/list [get]
  138. func (this *PredictEdbInfoController) List() {
  139. br := new(models.BaseResponse).Init()
  140. defer func() {
  141. this.Data["json"] = br
  142. this.ServeJSON()
  143. }()
  144. edbInfoId, _ := this.GetInt("EdbInfoId")
  145. keyWord := this.GetString("KeyWord")
  146. pageSize, _ := this.GetInt("PageSize")
  147. currentIndex, _ := this.GetInt("CurrentIndex")
  148. var total int
  149. page := paging.GetPaging(currentIndex, pageSize, total)
  150. var startSize int
  151. if pageSize <= 0 {
  152. pageSize = utils.PageSize20
  153. }
  154. if currentIndex <= 0 {
  155. currentIndex = 1
  156. }
  157. startSize = paging.StartIndex(currentIndex, pageSize)
  158. var condition string
  159. var pars []interface{}
  160. // 指标类型,0:普通指标,1:预测指标
  161. condition += " AND edb_info_type=? "
  162. pars = append(pars, 1)
  163. if edbInfoId > 0 {
  164. condition += " AND edb_info_id=? "
  165. pars = append(pars, edbInfoId)
  166. }
  167. if keyWord != "" {
  168. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  169. //pars = append(pars, keyWord)
  170. //pars = append(pars, keyWord)
  171. }
  172. resp := data_manage.EdbInfoListResp{}
  173. if condition == "" {
  174. item := new(data_manage.EdbInfoList)
  175. resp.Paging = page
  176. resp.Item = item
  177. br.Ret = 200
  178. br.Success = true
  179. br.Msg = "获取成功"
  180. return
  181. }
  182. //获取指标信息
  183. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  184. if err != nil && err.Error() != utils.ErrNoRow() {
  185. br.Success = true
  186. br.Msg = "获取指标信息失败"
  187. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  188. return
  189. }
  190. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  191. item := new(data_manage.EdbInfoList)
  192. resp.Paging = page
  193. resp.Item = item
  194. br.Ret = 200
  195. br.Success = true
  196. br.Msg = "获取成功"
  197. return
  198. }
  199. //获取英文频度
  200. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  201. //查询目录
  202. resultList, _ := data_manage.GetClassifyAllByClassifyId(edbInfoItem.ClassifyId)
  203. // 未来的指标预测数据
  204. predictDataList := make([]*data_manage.EdbData, 0)
  205. var existCondition string
  206. var existPars []interface{}
  207. existCondition += " AND edb_info_id=? "
  208. existPars = append(existPars, edbInfoId)
  209. //查询出所有的关联指标
  210. sourceEdbInfoCalculateMappingList, err := data_manage.GetEdbInfoCalculateListByCondition(existCondition, existPars)
  211. if err != nil {
  212. br.Msg = "获取失败"
  213. br.ErrMsg = "获取预测指标关联信息失败,Err:" + err.Error()
  214. return
  215. }
  216. if len(sourceEdbInfoCalculateMappingList) <= 0 {
  217. br.Msg = "获取失败"
  218. br.ErrMsg = "查找预测指标关联信息失败"
  219. return
  220. }
  221. if edbInfoItem.EdbType == 1 { //普通的预测指标
  222. // 查找该预测指标配置
  223. predictEdbConfList, err := data_manage.GetPredictEdbConfListById(edbInfoId)
  224. if err != nil && err.Error() != utils.ErrNoRow() {
  225. br.Msg = "获取失败"
  226. br.ErrMsg = "获取预测指标配置信息失败,Err:" + err.Error()
  227. return
  228. }
  229. if len(predictEdbConfList) == 0 {
  230. br.Msg = "找不到该预测指标配置"
  231. br.ErrMsg = "找不到该预测指标配置"
  232. return
  233. }
  234. predictEdbConf := predictEdbConfList[0]
  235. //预测数据的配置
  236. edbInfoItem.RuleType = predictEdbConf.RuleType
  237. edbInfoItem.FixedValue = predictEdbConf.FixedValue
  238. // 来源指标
  239. //sourceEdbInfoId := sourceEdbInfoCalculateMappingList[0].FromEdbInfoId
  240. sourceEdbInfoId := predictEdbConf.SourceEdbInfoId
  241. sourceEdbInfoItem, err := data_manage.GetEdbInfoById(sourceEdbInfoId)
  242. if err != nil {
  243. br.Msg = "获取来源指标信息失败"
  244. br.ErrMsg = "获取来源指标信息失败"
  245. if err.Error() != utils.ErrNoRow() {
  246. br.ErrMsg = "获取来源指标信息失败,Err:" + err.Error()
  247. }
  248. br.Success = true
  249. return
  250. }
  251. //获取指标数据(实际已生成)
  252. {
  253. var dataCondition string
  254. var dataPars []interface{}
  255. dataCondition += ` AND edb_info_id=? `
  256. dataPars = append(dataPars, sourceEdbInfoItem.EdbInfoId)
  257. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, sourceEdbInfoItem.Source)
  258. if err != nil && err.Error() != utils.ErrNoRow() {
  259. br.Msg = "获取指标信息失败"
  260. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  261. return
  262. }
  263. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  264. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, sourceEdbInfoItem.Source, pageSize, startSize)
  265. if err != nil {
  266. br.Msg = "获取指标信息失败"
  267. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  268. return
  269. }
  270. edbInfoItem.DataList = dataList
  271. }
  272. // 第一页才需要 获取预测指标未来的数据
  273. if currentIndex == 1 {
  274. allDataList, err := data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, "", "")
  275. if err != nil {
  276. br.Msg = "获取失败"
  277. br.Msg = "获取失败,Err:" + err.Error()
  278. return
  279. }
  280. predictEdbConfDataList := make([]data_manage.PredictEdbConfAndData, 0)
  281. for _, v := range predictEdbConfList {
  282. predictEdbConfDataList = append(predictEdbConfDataList, data_manage.PredictEdbConfAndData{
  283. ConfigId: v.ConfigId,
  284. PredictEdbInfoId: v.PredictEdbInfoId,
  285. SourceEdbInfoId: v.SourceEdbInfoId,
  286. RuleType: v.RuleType,
  287. FixedValue: v.FixedValue,
  288. Value: v.Value,
  289. EndDate: v.EndDate,
  290. ModifyTime: v.ModifyTime,
  291. CreateTime: v.CreateTime,
  292. DataList: make([]*data_manage.EdbDataList, 0),
  293. })
  294. }
  295. tmpPredictDataList, _, _, err, _ := data.GetChartPredictEdbInfoDataListByConfList(predictEdbConfDataList, sourceEdbInfoItem.LatestDate, sourceEdbInfoItem.LatestDate, edbInfoItem.EndDate, sourceEdbInfoItem.Frequency, allDataList)
  296. if err != nil {
  297. br.Msg = "获取预测指标数据失败"
  298. br.ErrMsg = "获取预测指标数据失败" + err.Error()
  299. return
  300. }
  301. lenTmpPredictDataList := len(tmpPredictDataList)
  302. if lenTmpPredictDataList > 0 {
  303. for i := lenTmpPredictDataList - 1; i >= 0; i-- {
  304. v := tmpPredictDataList[i]
  305. predictDataList = append(predictDataList, &data_manage.EdbData{
  306. EdbDataId: v.EdbDataId,
  307. EdbInfoId: v.EdbInfoId,
  308. DataTime: v.DataTime,
  309. Value: v.Value,
  310. })
  311. }
  312. }
  313. }
  314. } else {
  315. //获取指标数据(实际已生成)
  316. {
  317. var dataCondition string
  318. var dataPars []interface{}
  319. dataCondition += ` AND edb_info_id=? AND data_time <= ? `
  320. dataPars = append(dataPars, edbInfoItem.EdbInfoId, edbInfoItem.LatestDate)
  321. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  322. if err != nil && err.Error() != utils.ErrNoRow() {
  323. br.Msg = "获取指标信息失败"
  324. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  325. return
  326. }
  327. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  328. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  329. if err != nil {
  330. br.Msg = "获取指标信息失败"
  331. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  332. return
  333. }
  334. edbInfoItem.DataList = dataList
  335. }
  336. // 第一页才需要 获取预测指标未来的数据
  337. if currentIndex == 1 {
  338. var dataCondition string
  339. var dataPars []interface{}
  340. dataCondition += ` AND edb_info_id=? AND data_time > ? `
  341. dataPars = append(dataPars, edbInfoItem.EdbInfoId, edbInfoItem.LatestDate)
  342. predictDataList, err = data_manage.GetAllEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source)
  343. if err != nil {
  344. br.Msg = "获取指标信息失败"
  345. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  346. return
  347. }
  348. if err != nil {
  349. br.Msg = "获取预测指标数据失败"
  350. br.ErrMsg = "获取预测指标数据失败" + err.Error()
  351. return
  352. }
  353. }
  354. }
  355. // 如果预测数据没有,那么返回空数组
  356. if predictDataList == nil {
  357. predictDataList = make([]*data_manage.EdbData, 0)
  358. }
  359. edbInfoItem.PredictDataList = predictDataList
  360. // 如果实际数据没有,那么返回空数组
  361. if edbInfoItem.DataList == nil {
  362. edbInfoItem.DataList = make([]*data_manage.EdbData, 0)
  363. }
  364. resp.Paging = page
  365. resp.Item = edbInfoItem
  366. resp.ClassifyList = resultList
  367. br.Ret = 200
  368. br.Success = true
  369. br.Msg = "获取成功"
  370. br.Data = resp
  371. }
  372. // Add
  373. // @Title 新增指标接口
  374. // @Description 新增指标接口
  375. // @Param request body request.AddPredictEdbInfoReq true "type json string"
  376. // @Success 200 {object} response.AddEdbInfoResp
  377. // @router /predict_edb_info/add [post]
  378. func (this *PredictEdbInfoController) Add() {
  379. br := new(models.BaseResponse).Init()
  380. defer func() {
  381. this.Data["json"] = br
  382. this.ServeJSON()
  383. }()
  384. sysUser := this.SysUser
  385. if sysUser == nil {
  386. br.Msg = "请登录"
  387. br.ErrMsg = "请登录,SysUser Is Empty"
  388. br.Ret = 408
  389. return
  390. }
  391. deleteCache := true
  392. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  393. defer func() {
  394. if deleteCache {
  395. utils.Rc.Delete(cacheKey)
  396. }
  397. }()
  398. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  399. deleteCache = false
  400. br.Msg = "系统处理中,请稍后重试!"
  401. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  402. return
  403. }
  404. var req request.AddPredictEdbInfoReq
  405. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  406. if err != nil {
  407. br.Msg = "参数解析异常!"
  408. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  409. return
  410. }
  411. sourceEdbInfoId := req.SourceEdbInfoId
  412. if sourceEdbInfoId <= 0 {
  413. br.Msg = "请选择来源指标"
  414. br.IsSendEmail = false
  415. return
  416. }
  417. if req.EdbName == "" {
  418. br.Msg = "指标名称不能为空"
  419. br.IsSendEmail = false
  420. return
  421. }
  422. if req.ClassifyId <= 0 {
  423. br.Msg = "请选择分类"
  424. br.IsSendEmail = false
  425. return
  426. }
  427. if len(req.RuleList) <= 0 {
  428. br.Msg = "请填写预测规则"
  429. br.IsSendEmail = false
  430. return
  431. }
  432. // 根据截止日期重新排序
  433. ruleList := make([]request.RuleConfig, 0)
  434. {
  435. ruleMap := make(map[string]request.RuleConfig)
  436. dateIntList := make([]int64, 0)
  437. for _, v := range req.RuleList {
  438. confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
  439. if err != nil {
  440. br.Msg = "配置项中时间异常,请重新选择"
  441. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  442. br.IsSendEmail = false
  443. return
  444. }
  445. dateIntList = append(dateIntList, confEndDate.Unix())
  446. ruleMap[v.EndDate] = v
  447. }
  448. sort.Slice(dateIntList, func(i, j int) bool {
  449. return dateIntList[i] < dateIntList[j]
  450. })
  451. for _, dateInt := range dateIntList {
  452. currDateTime := time.Unix(dateInt, 0)
  453. item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
  454. if !ok {
  455. br.Msg = "配置项中时间异常,请重新选择"
  456. br.ErrMsg = "配置项中时间异常,请重新选择"
  457. br.IsSendEmail = false
  458. return
  459. }
  460. ruleList = append(ruleList, item)
  461. }
  462. }
  463. req.RuleList = ruleList
  464. //传入操作人
  465. req.AdminId = sysUser.AdminId
  466. req.AdminName = sysUser.RealName
  467. // 添加计算指标
  468. reqJson, err := json.Marshal(req)
  469. if err != nil {
  470. br.Msg = "参数解析异常!"
  471. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  472. return
  473. }
  474. respItem, err := data.SaveBasePredictEdbData(string(reqJson))
  475. if err != nil {
  476. br.Msg = "获取失败"
  477. br.ErrMsg = "获取失败,Err:" + err.Error()
  478. return
  479. }
  480. if respItem.Ret != 200 {
  481. br.Msg = respItem.Msg
  482. br.ErrMsg = respItem.ErrMsg
  483. return
  484. }
  485. resp := respItem.Data
  486. //添加es
  487. data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
  488. br.Ret = 200
  489. br.Success = true
  490. br.Msg = "保存成功"
  491. br.Data = resp
  492. br.IsAddLog = true
  493. }
  494. // ChartImageSet
  495. // @Title 设置指标的图表图片
  496. // @Description 设置指标的图表图片接口
  497. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  498. // @Success Ret=200 保存成功
  499. // @router /predict_edb_info/image/set [post]
  500. func (this *PredictEdbInfoController) ChartImageSet() {
  501. br := new(models.BaseResponse).Init()
  502. defer func() {
  503. this.Data["json"] = br
  504. this.ServeJSON()
  505. }()
  506. sysUser := this.SysUser
  507. if sysUser == nil {
  508. br.Msg = "请登录"
  509. br.ErrMsg = "请登录,SysUser Is Empty"
  510. br.Ret = 408
  511. return
  512. }
  513. var req data_manage.SetEdbInfoImageReq
  514. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  515. if err != nil {
  516. br.Msg = "参数解析异常!"
  517. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  518. return
  519. }
  520. if req.EdbInfoId > 0 && req.ImageUrl != "" {
  521. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  522. if err != nil {
  523. br.Msg = "保存失败"
  524. br.ErrMsg = "保存失败,Err:" + err.Error()
  525. if err.Error() == utils.ErrNoRow() {
  526. br.Msg = "找不到该指标"
  527. br.ErrMsg = "找不到该指标"
  528. br.IsSendEmail = false
  529. }
  530. return
  531. }
  532. edbInfo.ChartImage = req.ImageUrl
  533. err = edbInfo.Update([]string{"ChartImage"})
  534. if err != nil {
  535. br.Msg = "保存失败"
  536. br.ErrMsg = "保存失败,Err:" + err.Error()
  537. return
  538. }
  539. //修改es数据
  540. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  541. }
  542. br.Ret = 200
  543. br.Success = true
  544. br.Msg = "保存成功"
  545. }
  546. // Edit
  547. // @Title 编辑指标接口
  548. // @Description 编辑指标接口
  549. // @Success 200 {object} request.EditEdbInfoReq
  550. // @router /predict_edb_info/edit [post]
  551. func (this *PredictEdbInfoController) Edit() {
  552. br := new(models.BaseResponse).Init()
  553. defer func() {
  554. this.Data["json"] = br
  555. this.ServeJSON()
  556. }()
  557. sysUser := this.SysUser
  558. if sysUser == nil {
  559. br.Msg = "请登录"
  560. br.ErrMsg = "请登录,SysUser Is Empty"
  561. br.Ret = 408
  562. return
  563. }
  564. var req request.AddPredictEdbInfoReq
  565. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  566. if err != nil {
  567. br.Msg = "参数解析异常!"
  568. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  569. return
  570. }
  571. edbInfoId := req.EdbInfoId
  572. if edbInfoId <= 0 {
  573. br.Msg = "请选择预测指标"
  574. br.IsSendEmail = false
  575. return
  576. }
  577. if req.EdbName == "" {
  578. br.Msg = "指标名称不能为空"
  579. br.IsSendEmail = false
  580. return
  581. }
  582. if req.ClassifyId <= 0 {
  583. br.Msg = "请选择分类"
  584. br.IsSendEmail = false
  585. return
  586. }
  587. if len(req.RuleList) <= 0 {
  588. br.Msg = "请填写预测规则"
  589. br.IsSendEmail = false
  590. return
  591. }
  592. // 根据截止日期重新排序
  593. ruleList := make([]request.RuleConfig, 0)
  594. {
  595. ruleMap := make(map[string]request.RuleConfig)
  596. dateIntList := make([]int64, 0)
  597. for _, v := range req.RuleList {
  598. confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
  599. if err != nil {
  600. br.Msg = "配置项中时间异常,请重新选择"
  601. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  602. br.IsSendEmail = false
  603. return
  604. }
  605. dateIntList = append(dateIntList, confEndDate.Unix())
  606. ruleMap[v.EndDate] = v
  607. }
  608. sort.Slice(dateIntList, func(i, j int) bool {
  609. return dateIntList[i] < dateIntList[j]
  610. })
  611. for _, dateInt := range dateIntList {
  612. currDateTime := time.Unix(dateInt, 0)
  613. item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
  614. if !ok {
  615. br.Msg = "配置项中时间异常,请重新选择"
  616. br.ErrMsg = "配置项中时间异常,请重新选择"
  617. br.IsSendEmail = false
  618. return
  619. }
  620. ruleList = append(ruleList, item)
  621. }
  622. }
  623. req.RuleList = ruleList
  624. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  625. if err != nil {
  626. br.Msg = "修改失败"
  627. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  628. return
  629. }
  630. // 编辑权限校验
  631. button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId)
  632. if !button.OpButton {
  633. br.Msg = "无权限操作"
  634. br.IsSendEmail = false
  635. return
  636. }
  637. //传入操作人
  638. req.AdminId = sysUser.AdminId
  639. req.AdminName = sysUser.RealName
  640. // 添加计算指标
  641. reqJson, err := json.Marshal(req)
  642. if err != nil {
  643. br.Msg = "参数解析异常!"
  644. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  645. return
  646. }
  647. respItem, err := data.SaveBasePredictEdbData(string(reqJson))
  648. if err != nil {
  649. br.Msg = "获取失败"
  650. br.ErrMsg = "获取失败,Err:" + err.Error()
  651. return
  652. }
  653. if respItem.Ret != 200 {
  654. br.Msg = respItem.Msg
  655. br.ErrMsg = respItem.ErrMsg
  656. return
  657. }
  658. resp := respItem.Data
  659. //修改es
  660. data.AddOrEditEdbInfoToEs(resp.EdbInfoId)
  661. // 刷新关联指标
  662. go data.EdbInfoRefreshAllFromBaseV2(resp.EdbInfoId, true)
  663. br.Ret = 200
  664. br.Success = true
  665. br.Msg = "修改成功"
  666. br.IsAddLog = true
  667. }
  668. // Refresh
  669. // @Title 指标刷新接口
  670. // @Description 指标刷新接口
  671. // @Param EdbInfoId query int true "指标id"
  672. // @Success Ret=200 刷新成功
  673. // @router /predict_edb_info/refresh [get]
  674. func (this *PredictEdbInfoController) Refresh() {
  675. br := new(models.BaseResponse).Init()
  676. defer func() {
  677. this.Data["json"] = br
  678. this.ServeJSON()
  679. }()
  680. sysUser := this.SysUser
  681. if sysUser == nil {
  682. br.Msg = "请登录"
  683. br.ErrMsg = "请登录,SysUser Is Empty"
  684. br.Ret = 408
  685. return
  686. }
  687. edbInfoId, _ := this.GetInt("EdbInfoId")
  688. if edbInfoId <= 0 {
  689. br.Msg = "参数错误"
  690. br.ErrMsg = "参数错误"
  691. return
  692. }
  693. _, err, errMsg := data.RefreshPredictEdbInfo(edbInfoId, false)
  694. if errMsg != `` {
  695. br.Msg = errMsg
  696. br.ErrMsg = errMsg
  697. if err != nil {
  698. br.ErrMsg = err.Error()
  699. } else {
  700. br.IsSendEmail = false
  701. }
  702. return
  703. }
  704. br.Ret = 200
  705. br.Success = true
  706. br.Msg = "刷新成功"
  707. br.IsAddLog = true
  708. }
  709. // Move
  710. // @Title 移动指标接口
  711. // @Description 移动指标接口
  712. // @Success 200 {object} data_manage.MoveEdbInfoReq
  713. // @router /predict_edb_info/move [post]
  714. func (this *PredictEdbInfoController) Move() {
  715. br := new(models.BaseResponse).Init()
  716. defer func() {
  717. this.Data["json"] = br
  718. this.ServeJSON()
  719. }()
  720. sysUser := this.SysUser
  721. if sysUser == nil {
  722. br.Msg = "请登录"
  723. br.ErrMsg = "请登录,SysUser Is Empty"
  724. br.Ret = 408
  725. return
  726. }
  727. var req data_manage.MoveEdbInfoReq
  728. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  729. if err != nil {
  730. br.Msg = "参数解析异常!"
  731. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  732. return
  733. }
  734. if req.EdbInfoId <= 0 {
  735. br.Msg = "参数错误"
  736. br.ErrMsg = "指标id小于等于0"
  737. return
  738. }
  739. if req.ClassifyId <= 0 {
  740. br.Msg = "请选择分类"
  741. return
  742. }
  743. // 移动预测指标
  744. err, errMsg := data.MovePredictEdbInfo(req.EdbInfoId, req.ClassifyId, req.PrevEdbInfoId, req.NextEdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
  745. if errMsg != `` {
  746. br.Msg = errMsg
  747. br.ErrMsg = errMsg
  748. if err != nil {
  749. br.ErrMsg = errMsg + ";Err:" + err.Error()
  750. } else {
  751. br.IsSendEmail = false
  752. }
  753. return
  754. }
  755. br.Ret = 200
  756. br.Success = true
  757. br.Msg = "移动成功"
  758. }
  759. // Detail
  760. // @Title 获取指标详情
  761. // @Description 获取指标详情接口
  762. // @Param EdbInfoId query int true "指标id"
  763. // @Success 200 {object} response.PredictEdbInfo
  764. // @router /predict_edb_info/detail [get]
  765. func (this *PredictEdbInfoController) Detail() {
  766. br := new(models.BaseResponse).Init()
  767. defer func() {
  768. this.Data["json"] = br
  769. this.ServeJSON()
  770. }()
  771. sysUser := this.SysUser
  772. if sysUser == nil {
  773. br.Msg = "请登录"
  774. br.ErrMsg = "请登录,SysUser Is Empty"
  775. br.Ret = 408
  776. return
  777. }
  778. edbInfoId, _ := this.GetInt("EdbInfoId")
  779. if edbInfoId <= 0 {
  780. br.Msg = "参数错误"
  781. br.ErrMsg = "参数错误"
  782. return
  783. }
  784. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  785. if err != nil {
  786. br.Msg = "获取失败"
  787. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  788. return
  789. }
  790. var ruleType int
  791. var fixedValue float64
  792. calculateList := make([]*data_manage.EdbInfoCalculateDetail, 0)
  793. predictEdbConfList := make([]data_manage.PredictEdbConfDetail, 0)
  794. calculateList, err = data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
  795. if err != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取失败,Err:" + err.Error()
  798. return
  799. }
  800. if edbInfo.EdbType == 1 {
  801. // 获取所有的指标预测规则配置
  802. tmpPredictEdbConfList, err := data_manage.GetPredictEdbConfListById(edbInfoId)
  803. if err != nil && err.Error() != utils.ErrNoRow() {
  804. br.Msg = "获取失败"
  805. br.ErrMsg = "获取预测指标配置信息失败,Err:" + err.Error()
  806. return
  807. }
  808. for _, v := range tmpPredictEdbConfList {
  809. var tmpPredictEdbConfCalculateMappingDetail []*data_manage.PredictEdbConfCalculateMappingDetail
  810. if v.RuleType == 9 || v.RuleType == 14 {
  811. tmpPredictEdbConfCalculateMappingDetail, err = data_manage.GetPredictEdbConfCalculateMappingDetailListByConfigId(v.PredictEdbInfoId, v.ConfigId)
  812. if err != nil && err.Error() != utils.ErrNoRow() {
  813. br.Msg = "获取失败"
  814. br.ErrMsg = "获取预测指标配置与关联指标信息失败,Err:" + err.Error()
  815. return
  816. }
  817. }
  818. if len(tmpPredictEdbConfCalculateMappingDetail) <= 0 {
  819. tmpPredictEdbConfCalculateMappingDetail = make([]*data_manage.PredictEdbConfCalculateMappingDetail, 0)
  820. }
  821. tmp := data_manage.PredictEdbConfDetail{
  822. ConfigId: v.ConfigId,
  823. PredictEdbInfoId: v.PredictEdbInfoId,
  824. SourceEdbInfoId: v.SourceEdbInfoId,
  825. RuleType: v.RuleType,
  826. FixedValue: v.FixedValue,
  827. Value: v.Value,
  828. EndDate: v.EndDate,
  829. ModifyTime: v.ModifyTime,
  830. CreateTime: v.CreateTime,
  831. CalculateList: tmpPredictEdbConfCalculateMappingDetail,
  832. }
  833. predictEdbConfList = append(predictEdbConfList, tmp)
  834. }
  835. //calculateList, err = data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
  836. //if err != nil {
  837. // br.Msg = "获取失败"
  838. // br.ErrMsg = "获取失败,Err:" + err.Error()
  839. // return
  840. //}
  841. if len(predictEdbConfList) == 0 {
  842. br.Msg = "找不到该预测指标配置"
  843. br.ErrMsg = "找不到该预测指标配置"
  844. return
  845. }
  846. predictEdbConf := predictEdbConfList[0]
  847. ruleType = predictEdbConf.RuleType
  848. fixedValue = predictEdbConf.FixedValue
  849. }
  850. resp := response.PredictEdbInfo{
  851. EdbInfo: *edbInfo,
  852. RuleType: ruleType,
  853. FixedValue: fixedValue,
  854. CalculateList: calculateList,
  855. RuleList: predictEdbConfList,
  856. }
  857. br.Ret = 200
  858. br.Success = true
  859. br.Msg = "获取成功"
  860. br.Data = resp
  861. }
  862. // FilterByEs
  863. // @Title 指标筛选接口
  864. // @Description 指标筛选接口
  865. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  866. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  867. // @Param Frequency query string false "频度"
  868. // @Param IsOnlyMe query bool false "是否只看我的"
  869. // @Param PageSize query int true "每页数据条数"
  870. // @Param CurrentIndex query int true "当前页页码,从1开始"
  871. // @Success 200 {object} data_manage.EdbInfoList
  872. // @router /predict_edb_info/filter_by_es [get]
  873. func (this *PredictEdbInfoController) FilterByEs() {
  874. br := new(models.BaseResponse).Init()
  875. defer func() {
  876. this.Data["json"] = br
  877. this.ServeJSON()
  878. }()
  879. pageSize, _ := this.GetInt("PageSize")
  880. currentIndex, _ := this.GetInt("CurrentIndex")
  881. var total int64
  882. var startSize int
  883. if pageSize <= 0 {
  884. pageSize = utils.PageSize20
  885. }
  886. if currentIndex <= 0 {
  887. currentIndex = 1
  888. }
  889. startSize = paging.StartIndex(currentIndex, pageSize)
  890. keyWord := this.GetString("Keyword")
  891. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  892. //兼容前端
  893. if keyWord == `` {
  894. keyWord = this.GetString("KeyWord")
  895. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  896. }
  897. filterSource, _ := this.GetInt("FilterSource")
  898. if filterSource <= 0 {
  899. filterSource = 1
  900. }
  901. //指标来源
  902. source, _ := this.GetInt("Source")
  903. frequency := this.GetString("Frequency") //频度
  904. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  905. var edbInfoList []*data_manage.EdbInfoList
  906. var err error
  907. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  908. // 获取当前账号的不可见指标
  909. {
  910. obj := data_manage.EdbInfoNoPermissionAdmin{}
  911. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  912. if err != nil && err.Error() != utils.ErrNoRow() {
  913. br.Msg = "获取失败"
  914. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  915. return
  916. }
  917. for _, v := range confList {
  918. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  919. }
  920. }
  921. if keyWord != "" {
  922. var keyWordArr []string
  923. keyWordArr = append(keyWordArr, keyWord)
  924. newKeyWord := strings.Split(keyWord, " ")
  925. keyWordArr = append(keyWordArr, newKeyWord...)
  926. if isOnlyMe {
  927. total, edbInfoList, err = elastic.SearchEdbInfoDataByAdminId(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, this.SysUser.AdminId)
  928. } else {
  929. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 1, frequency, noPermissionEdbInfoIdList)
  930. }
  931. } else {
  932. var condition string
  933. var pars []interface{}
  934. // 预测指标
  935. condition += ` AND edb_info_type = ? `
  936. pars = append(pars, 1)
  937. // 无权限指标id
  938. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  939. if lenNoPermissionEdbInfoIdList > 0 {
  940. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  941. pars = append(pars, noPermissionEdbInfoIdList)
  942. }
  943. switch filterSource {
  944. case 2:
  945. condition += ` AND frequency='月度' `
  946. case 3:
  947. condition += ` AND frequency <> '日度' `
  948. case 4:
  949. condition += ` AND edb_type = 1 `
  950. case 5:
  951. condition += ` AND source = 32 ` //来源(预测同比值)
  952. case 6:
  953. condition += ` AND frequency != ? `
  954. pars = append(pars, "年度")
  955. }
  956. //频度
  957. if frequency != "" {
  958. condition += ` AND frequency = ? `
  959. pars = append(pars, frequency)
  960. }
  961. if isOnlyMe {
  962. condition += " AND sys_user_id = ? "
  963. pars = append(pars, this.SysUser.AdminId)
  964. }
  965. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  966. }
  967. if err != nil {
  968. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  969. }
  970. page := paging.GetPaging(currentIndex, pageSize, int(total))
  971. edbInfoListLen := len(edbInfoList)
  972. for i := 0; i < edbInfoListLen; i++ {
  973. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  974. }
  975. for i := 0; i < edbInfoListLen; i++ {
  976. for j := 0; j < edbInfoListLen; j++ {
  977. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  978. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  979. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  980. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  981. }
  982. }
  983. }
  984. //新增搜索词记录
  985. {
  986. searchKeyword := new(data_manage.SearchKeyword)
  987. searchKeyword.KeyWord = keyWord
  988. searchKeyword.CreateTime = time.Now()
  989. go data_manage.AddSearchKeyword(searchKeyword)
  990. }
  991. resp := data_manage.EdbInfoFilterDataResp{
  992. Paging: page,
  993. List: edbInfoList,
  994. }
  995. br.Ret = 200
  996. br.Success = true
  997. br.Msg = "获取成功"
  998. br.Data = resp
  999. }
  1000. // RefreshAll
  1001. // @Title 指标全部刷新接口
  1002. // @Description 指标全部刷新接口
  1003. // @Param EdbInfoId query int true "指标id"
  1004. // @Success Ret=200 全部刷新成功
  1005. // @router /predict_edb_info/refresh/all [get]
  1006. func (this *PredictEdbInfoController) RefreshAll() {
  1007. br := new(models.BaseResponse).Init()
  1008. defer func() {
  1009. this.Data["json"] = br
  1010. this.ServeJSON()
  1011. }()
  1012. sysUser := this.SysUser
  1013. if sysUser == nil {
  1014. br.Msg = "请登录"
  1015. br.ErrMsg = "请登录,SysUser Is Empty"
  1016. br.Ret = 408
  1017. return
  1018. }
  1019. edbInfoId, _ := this.GetInt("EdbInfoId")
  1020. if edbInfoId <= 0 {
  1021. br.Msg = "参数错误"
  1022. br.ErrMsg = "参数错误"
  1023. return
  1024. }
  1025. _, err, errMsg := data.RefreshPredictEdbInfo(edbInfoId, true)
  1026. if errMsg != `` {
  1027. br.Msg = errMsg
  1028. br.ErrMsg = errMsg
  1029. if err != nil {
  1030. br.ErrMsg = err.Error()
  1031. } else {
  1032. br.IsSendEmail = false
  1033. }
  1034. return
  1035. }
  1036. br.Ret = 200
  1037. br.Success = true
  1038. br.Msg = "刷新成功"
  1039. }
  1040. // DataList
  1041. // @Title 获取指标数据
  1042. // @Description 获取指标数据
  1043. // @Param EdbInfoId query int true "指标ID"
  1044. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  1045. // @Param StartDate query string true "自定义开始日期"
  1046. // @Param EndDate query string true "自定义结束日期"
  1047. // @Param Calendar query string true "公历/农历"
  1048. // @Param SeasonStartDate query string true "季节性图开始日期"
  1049. // @Param SeasonEndDate query string true "季节性图结束日期"
  1050. // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
  1051. // @Success 200 {object} data_manage.EdbInfoDataResp
  1052. // @router /predict_edb_info/data [get]
  1053. func (this *PredictEdbInfoController) DataList() {
  1054. br := new(models.BaseResponse).Init()
  1055. defer func() {
  1056. this.Data["json"] = br
  1057. this.ServeJSON()
  1058. }()
  1059. sysUser := this.SysUser
  1060. if sysUser == nil {
  1061. br.Msg = "请登录"
  1062. br.ErrMsg = "请登录,SysUser Is Empty"
  1063. br.Ret = 408
  1064. return
  1065. }
  1066. edbInfoId, _ := this.GetInt("EdbInfoId")
  1067. if edbInfoId <= 0 {
  1068. br.Msg = "参数错误"
  1069. return
  1070. }
  1071. dateType, _ := this.GetInt("DateType")
  1072. if dateType <= 0 {
  1073. dateType = 3
  1074. }
  1075. edbInfoType, _ := this.GetInt("EdbInfoType")
  1076. if edbInfoType < 0 {
  1077. edbInfoType = 1
  1078. }
  1079. startDate := this.GetString("StartDate")
  1080. endDate := this.GetString("EndDate")
  1081. seasonStartDate := this.GetString("SeasonStartDate")
  1082. seasonEndDate := this.GetString("SeasonEndDate")
  1083. chartType, _ := this.GetInt("ChartType")
  1084. if chartType <= 0 {
  1085. chartType = 1
  1086. }
  1087. calendar := this.GetString("Calendar")
  1088. if calendar == "" {
  1089. calendar = "公历"
  1090. }
  1091. isTimeBetween := false //是否是时间区间
  1092. if chartType == 2 {
  1093. dateType = 0
  1094. if seasonStartDate != "" {
  1095. startDate = seasonStartDate + "-01-01"
  1096. } else {
  1097. fivePre := time.Now().AddDate(-4, 0, 0).Year()
  1098. startDate = strconv.Itoa(fivePre) + "-01-01"
  1099. }
  1100. if seasonEndDate != "" {
  1101. endDate = seasonEndDate + "-12-31"
  1102. isTimeBetween = true
  1103. } else {
  1104. endDate = "" //time.Now().AddDate(2, 0, 0).Format(utils.FormatDate)
  1105. }
  1106. }
  1107. switch dateType {
  1108. case 1:
  1109. startDate = "2000-01-01"
  1110. endDate = time.Now().Format(utils.FormatDate)
  1111. case 2:
  1112. startDate = "2010-01-01"
  1113. endDate = time.Now().Format(utils.FormatDate)
  1114. case 3:
  1115. startDate = "2015-01-01"
  1116. endDate = time.Now().Format(utils.FormatDate)
  1117. case 4:
  1118. //startDate = strconv.Itoa(time.Now().Year()) + "-01-01"
  1119. startDate = "2021-01-01"
  1120. endDate = time.Now().Format(utils.FormatDate)
  1121. case 5:
  1122. startDate = startDate + "-01"
  1123. endDate = endDate + "-01"
  1124. isTimeBetween = true
  1125. case 6:
  1126. startDate = startDate + "-01"
  1127. endDate = time.Now().Format(utils.FormatDate)
  1128. case 7:
  1129. startDate = "2018-01-01"
  1130. endDate = time.Now().Format(utils.FormatDate)
  1131. case 8:
  1132. startDate = "2019-01-01"
  1133. endDate = time.Now().Format(utils.FormatDate)
  1134. case 9:
  1135. startDate = "2020-01-01"
  1136. endDate = time.Now().Format(utils.FormatDate)
  1137. case 10:
  1138. startDate = ""
  1139. endDate = ""
  1140. case 11:
  1141. startDate = "2022-01-01"
  1142. endDate = time.Now().Format(utils.FormatDate)
  1143. //default:
  1144. //startDate = startDate + "-01"
  1145. //endDate = endDate + "-01"
  1146. }
  1147. // 获取预测指标信息
  1148. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1149. if err != nil {
  1150. br.Msg = "获取预测指标信息失败"
  1151. br.ErrMsg = "获取预测指标信息失败,Err:" + err.Error()
  1152. return
  1153. }
  1154. // 按钮校验
  1155. button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId)
  1156. button.AddButton = false
  1157. dataList, _, _, err, _ := data.GetPredictDataListByPredictEdbInfo(edbInfo, startDate, endDate, isTimeBetween)
  1158. //lenDataList := len(dataList)
  1159. //if lenDataList > 0 {
  1160. // tmpValue := dataList[lenDataList-1]
  1161. //
  1162. // // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  1163. // if edbInfo.MaxValue < tmpValue.Value {
  1164. // edbInfo.MaxValue = tmpValue.Value
  1165. // }
  1166. //
  1167. // // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  1168. // if edbInfo.MinValue > tmpValue.Value {
  1169. // edbInfo.MinValue = tmpValue.Value
  1170. // }
  1171. //}
  1172. // 季节性图、公历、农历处理
  1173. resultDataList, err := data.GetChartDataList(dataList, chartType, calendar, edbInfo.LatestDate, startDate)
  1174. if err != nil {
  1175. br.Msg = "获取失败"
  1176. br.ErrMsg = "获取失败,Err:" + err.Error()
  1177. return
  1178. }
  1179. resp := response.PredictEdbInfoDataResp{
  1180. EdbInfo: edbInfo,
  1181. DataList: resultDataList,
  1182. Button: button,
  1183. }
  1184. br.Ret = 200
  1185. br.Success = true
  1186. br.Msg = "获取成功"
  1187. br.Data = resp
  1188. }
  1189. // ChartDataList
  1190. // @Title 获取指标数据
  1191. // @Description 获取指标数据
  1192. // @Param request body data_manage.AddPredictEdbInfoReq true "type json string"
  1193. // @Success 200 {object} data_manage.EdbInfoDataResp
  1194. // @router /predict_edb_info/chart/data/list [post]
  1195. func (this *PredictEdbInfoController) ChartDataList() {
  1196. br := new(models.BaseResponse).Init()
  1197. defer func() {
  1198. this.Data["json"] = br
  1199. this.ServeJSON()
  1200. }()
  1201. sysUser := this.SysUser
  1202. if sysUser == nil {
  1203. br.Msg = "请登录"
  1204. br.ErrMsg = "请登录,SysUser Is Empty"
  1205. br.Ret = 408
  1206. return
  1207. }
  1208. var req request.PredictEdbInfoChartDataReq
  1209. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1210. if req.SourceEdbInfoId <= 0 {
  1211. br.Msg = "参数错误"
  1212. return
  1213. }
  1214. dateType := req.DateType
  1215. startDate := req.StartDate
  1216. endDate := req.EndDate
  1217. seasonStartDate := req.SeasonStartDate
  1218. seasonEndDate := req.SeasonEndDate
  1219. calendar := req.Calendar
  1220. if calendar == "" {
  1221. calendar = "公历"
  1222. }
  1223. isTimeBetween := false //是否是时间区间
  1224. if req.ChartType == 2 {
  1225. dateType = 0
  1226. if seasonStartDate != "" {
  1227. startDate = seasonStartDate + "-01-01"
  1228. } else {
  1229. fivePre := time.Now().AddDate(-4, 0, 0).Year()
  1230. startDate = strconv.Itoa(fivePre) + "-01-01"
  1231. }
  1232. if seasonEndDate != "" {
  1233. endDate = seasonEndDate + "-12-31"
  1234. isTimeBetween = true
  1235. } else {
  1236. endDate = "" //time.Now().AddDate(2, 0, 0).Format(utils.FormatDate)
  1237. }
  1238. }
  1239. switch dateType {
  1240. case 1:
  1241. startDate = "2000-01-01"
  1242. endDate = time.Now().Format(utils.FormatDate)
  1243. case 2:
  1244. startDate = "2010-01-01"
  1245. endDate = time.Now().Format(utils.FormatDate)
  1246. case 3:
  1247. startDate = "2015-01-01"
  1248. endDate = time.Now().Format(utils.FormatDate)
  1249. case 4:
  1250. //startDate = strconv.Itoa(time.Now().Year()) + "-01-01"
  1251. startDate = "2021-01-01"
  1252. endDate = time.Now().Format(utils.FormatDate)
  1253. case 5:
  1254. startDate = startDate + "-01"
  1255. endDate = endDate + "-01"
  1256. isTimeBetween = true
  1257. case 6:
  1258. startDate = startDate + "-01"
  1259. endDate = time.Now().Format(utils.FormatDate)
  1260. case 7:
  1261. startDate = "2018-01-01"
  1262. endDate = time.Now().Format(utils.FormatDate)
  1263. case 8:
  1264. startDate = "2019-01-01"
  1265. endDate = time.Now().Format(utils.FormatDate)
  1266. case 9:
  1267. startDate = "2020-01-01"
  1268. endDate = time.Now().Format(utils.FormatDate)
  1269. case 10:
  1270. startDate = ""
  1271. endDate = ""
  1272. case 11:
  1273. startDate = "2022-01-01"
  1274. endDate = time.Now().Format(utils.FormatDate)
  1275. //default:
  1276. // startDate = startDate + "-01"
  1277. // endDate = endDate + "-01"
  1278. }
  1279. // 规则列表
  1280. // 根据截止日期重新排序
  1281. ruleList := make([]request.RuleConfig, 0)
  1282. {
  1283. ruleMap := make(map[string]request.RuleConfig)
  1284. dateIntList := make([]int64, 0)
  1285. for _, v := range req.RuleList {
  1286. confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
  1287. if err != nil {
  1288. br.Msg = "配置项中时间异常,请重新选择"
  1289. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  1290. br.IsSendEmail = false
  1291. return
  1292. }
  1293. dateIntList = append(dateIntList, confEndDate.Unix())
  1294. ruleMap[v.EndDate] = v
  1295. }
  1296. sort.Slice(dateIntList, func(i, j int) bool {
  1297. return dateIntList[i] < dateIntList[j]
  1298. })
  1299. for _, dateInt := range dateIntList {
  1300. currDateTime := time.Unix(dateInt, 0)
  1301. item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
  1302. if !ok {
  1303. br.Msg = "配置项中时间异常,请重新选择"
  1304. br.ErrMsg = "配置项中时间异常,请重新选择"
  1305. br.IsSendEmail = false
  1306. return
  1307. }
  1308. ruleList = append(ruleList, item)
  1309. }
  1310. }
  1311. // 预测指标配置
  1312. predictEdbConfAndDataList := make([]data_manage.PredictEdbConfAndData, 0)
  1313. endDateStr := `` //数据的结束日期
  1314. for _, v := range ruleList {
  1315. endDateStr = v.EndDate //预测指标的结束日期
  1316. confEndDate, err := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
  1317. if err != nil {
  1318. br.Msg = "配置项中时间异常,请重新选择"
  1319. br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
  1320. return
  1321. }
  1322. // 没有数据,自己瞎测试
  1323. //switch v.RuleType {
  1324. //case 3: //3:同比
  1325. // v.Value = "0.1"
  1326. //case 4: //4:同差
  1327. // v.Value = "10"
  1328. //case 5: //5:环比
  1329. // v.Value = "0.1"
  1330. //case 6: //6:环差
  1331. // v.Value = "0.1"
  1332. //case 7: //7:N期移动均值
  1333. // v.Value = "5"
  1334. //case 8: //8:N期段线性外推值
  1335. // v.Value = "5"
  1336. //}
  1337. tmpDataList := make([]*data_manage.EdbDataList, 0)
  1338. switch v.RuleType {
  1339. case 9:
  1340. // 获取计算参数
  1341. formula, edbInfoList, edbInfoIdBytes, err, errMsg := data.GetCalculateByRuleByNineParams(v)
  1342. if err != nil {
  1343. br.Msg = "计算失败"
  1344. if errMsg != "" {
  1345. br.Msg = errMsg
  1346. }
  1347. br.Msg = err.Error()
  1348. br.IsSendEmail = false
  1349. return
  1350. }
  1351. // 获取计算数据
  1352. tmpDataList, err = data.CalculateByRuleByNine(formula, edbInfoList, edbInfoIdBytes)
  1353. if err != nil {
  1354. br.Msg = "计算失败"
  1355. br.ErrMsg = err.Error()
  1356. br.IsSendEmail = false
  1357. return
  1358. }
  1359. }
  1360. tmpPredictEdbConfAndData := data_manage.PredictEdbConfAndData{
  1361. ConfigId: 0,
  1362. PredictEdbInfoId: 0,
  1363. SourceEdbInfoId: req.SourceEdbInfoId,
  1364. RuleType: v.RuleType,
  1365. FixedValue: 0,
  1366. Value: v.Value,
  1367. EndDate: confEndDate,
  1368. ModifyTime: time.Now(),
  1369. CreateTime: time.Now(),
  1370. DataList: tmpDataList,
  1371. }
  1372. predictEdbConfAndDataList = append(predictEdbConfAndDataList, tmpPredictEdbConfAndData)
  1373. }
  1374. // 来源指标
  1375. sourceEdbInfoItem, err := data_manage.GetEdbInfoById(req.SourceEdbInfoId)
  1376. if err != nil {
  1377. br.Msg = "获取来源指标信息失败"
  1378. br.ErrMsg = "获取来源指标信息失败"
  1379. if err.Error() != utils.ErrNoRow() {
  1380. br.ErrMsg = "获取来源指标信息失败,Err:" + err.Error()
  1381. }
  1382. br.Success = true
  1383. return
  1384. }
  1385. minValue := sourceEdbInfoItem.MinValue
  1386. maxValue := sourceEdbInfoItem.MaxValue
  1387. allDataList := make([]*data_manage.EdbDataList, 0)
  1388. //获取指标数据(实际已生成)
  1389. dataList, err := data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, startDate, endDate)
  1390. if err != nil {
  1391. br.Msg = "获取失败"
  1392. br.Msg = "获取失败,Err:" + err.Error()
  1393. return
  1394. }
  1395. // 如果选择了日期,那么需要筛选所有的数据,用于未来指标的生成
  1396. if startDate != `` {
  1397. allDataList, err = data_manage.GetEdbDataList(sourceEdbInfoItem.Source, sourceEdbInfoItem.EdbInfoId, "", "")
  1398. if err != nil {
  1399. br.Msg = "获取失败"
  1400. br.Msg = "获取失败,Err:" + err.Error()
  1401. return
  1402. }
  1403. } else {
  1404. allDataList = dataList
  1405. }
  1406. // 获取预测指标未来的数据
  1407. if len(predictEdbConfAndDataList) > 0 {
  1408. predictDataList := make([]*data_manage.EdbDataList, 0)
  1409. if isTimeBetween { //如果是时间区间,那么
  1410. reqEndDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
  1411. endDateTime, _ := time.ParseInLocation(utils.FormatDate, req.PredictEndDate, time.Local)
  1412. // 如果选择的时间区间结束日期 晚于 当天,那么预测数据截止到当天
  1413. if reqEndDateTime.Before(endDateTime) {
  1414. endDateStr = endDate
  1415. }
  1416. }
  1417. // 获取预测数据
  1418. var predictMinValue, predictMaxValue float64
  1419. predictDataList, predictMinValue, predictMaxValue, err, errMsg := data.GetChartPredictEdbInfoDataListByConfList(predictEdbConfAndDataList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, sourceEdbInfoItem.Frequency, allDataList)
  1420. if err != nil {
  1421. br.Msg = "获取预测指标数据失败"
  1422. if errMsg != `` {
  1423. br.Msg = errMsg
  1424. }
  1425. br.ErrMsg = "获取预测指标数据失败:" + err.Error()
  1426. return
  1427. }
  1428. dataList = append(dataList, predictDataList...)
  1429. if len(predictDataList) > 0 {
  1430. // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  1431. if minValue > predictMinValue {
  1432. minValue = predictMinValue
  1433. }
  1434. // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  1435. if maxValue < predictMaxValue {
  1436. maxValue = predictMaxValue
  1437. }
  1438. }
  1439. }
  1440. // 季节性图、公历、农历处理
  1441. resultDataList, err := data.GetChartDataList(dataList, req.ChartType, calendar, sourceEdbInfoItem.LatestDate, startDate)
  1442. if err != nil {
  1443. br.Msg = "获取失败"
  1444. br.ErrMsg = "获取失败,Err:" + err.Error()
  1445. return
  1446. }
  1447. resp := response.PredictEdbInfoChartDataResp{
  1448. MinValue: minValue,
  1449. MaxValue: maxValue,
  1450. DataList: resultDataList,
  1451. }
  1452. br.Ret = 200
  1453. br.Success = true
  1454. br.Msg = "获取成功"
  1455. br.Data = resp
  1456. }
  1457. // PredictRuleCalculateByNine
  1458. // @Title 根据预测规则9来计算数据
  1459. // @Description 获取指标数据
  1460. // @Param request body data_manage.RuleConfig true "type json string"
  1461. // @Success 200 {object} data_manage.EdbInfoDataResp
  1462. // @router /predict_edb_info/rule/calculate_by_nine [post]
  1463. func (this *PredictEdbInfoController) PredictRuleCalculateByNine() {
  1464. br := new(models.BaseResponse).Init()
  1465. defer func() {
  1466. this.Data["json"] = br
  1467. this.ServeJSON()
  1468. }()
  1469. sysUser := this.SysUser
  1470. time.Now().AddDate(0, -1, -1).Format(utils.FormatDate)
  1471. if sysUser == nil {
  1472. br.Msg = "请登录"
  1473. br.ErrMsg = "请登录,SysUser Is Empty"
  1474. br.Ret = 408
  1475. return
  1476. }
  1477. var req request.RuleConfig
  1478. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1479. // 获取计算参数
  1480. formula, edbInfoList, edbInfoIdBytes, err, errMsg := data.GetCalculateByRuleByNineParams(req)
  1481. if err != nil {
  1482. br.Msg = "计算失败"
  1483. if errMsg != "" {
  1484. br.Msg = errMsg
  1485. }
  1486. br.Msg = err.Error()
  1487. br.IsSendEmail = false
  1488. return
  1489. }
  1490. // 获取计算数据
  1491. dataList, err := data.CalculateByRuleByNine(formula, edbInfoList, edbInfoIdBytes)
  1492. if err != nil {
  1493. br.Msg = "数据计算失败"
  1494. br.ErrMsg = "数据计算失败:Err:" + err.Error()
  1495. br.IsSendEmail = false
  1496. return
  1497. }
  1498. latestDate := time.Now()
  1499. for _, v := range edbInfoList {
  1500. tmpLatestDate, err := time.ParseInLocation(utils.FormatDate, v.LatestDate, time.Local)
  1501. if err != nil {
  1502. continue
  1503. }
  1504. if tmpLatestDate.Before(latestDate) {
  1505. latestDate = tmpLatestDate
  1506. }
  1507. }
  1508. newDataList := make([]*data_manage.EdbDataList, 0)
  1509. lenData := len(dataList)
  1510. if lenData > 0 {
  1511. for i := lenData - 1; i >= 0; i-- {
  1512. newDataList = append(newDataList, dataList[i])
  1513. }
  1514. }
  1515. resp := response.PredictRuleCalculateByNineResp{
  1516. LatestDate: latestDate.Format(utils.FormatDate),
  1517. DataList: newDataList,
  1518. }
  1519. br.Ret = 200
  1520. br.Success = true
  1521. br.Msg = "获取成功"
  1522. br.Data = resp
  1523. }
  1524. // Modify
  1525. // @Title 修改指标信息接口
  1526. // @Description 编辑指标接口
  1527. // @Success 200 {object} request.EditEdbInfoReq
  1528. // @router /predict_edb_info/modify [post]
  1529. func (this *PredictEdbInfoController) Modify() {
  1530. br := new(models.BaseResponse).Init()
  1531. defer func() {
  1532. this.Data["json"] = br
  1533. this.ServeJSON()
  1534. }()
  1535. sysUser := this.SysUser
  1536. if sysUser == nil {
  1537. br.Msg = "请登录"
  1538. br.ErrMsg = "请登录,SysUser Is Empty"
  1539. br.Ret = 408
  1540. return
  1541. }
  1542. var req request.ModifyPredictEdbInfoReq
  1543. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1544. if err != nil {
  1545. br.Msg = "参数解析异常!"
  1546. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1547. return
  1548. }
  1549. edbInfoId := req.EdbInfoId
  1550. if edbInfoId <= 0 {
  1551. br.Msg = "请选择预测指标"
  1552. br.IsSendEmail = false
  1553. return
  1554. }
  1555. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  1556. if err != nil {
  1557. br.Msg = "修改失败"
  1558. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1559. return
  1560. }
  1561. // 编辑权限校验
  1562. button := data.GetPredictEdbOpButton(this.SysUser, edbInfo.SysUserId)
  1563. if !button.OpButton {
  1564. br.Msg = "无权限操作"
  1565. br.IsSendEmail = false
  1566. return
  1567. }
  1568. edbInfo.MaxValue = req.MaxValue
  1569. edbInfo.MinValue = req.MinValue
  1570. edbInfo.ModifyTime = time.Now()
  1571. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ModifyTime"})
  1572. if err != nil {
  1573. br.Msg = "获取失败"
  1574. br.ErrMsg = "获取失败,Err:" + err.Error()
  1575. return
  1576. }
  1577. //修改es
  1578. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  1579. br.Ret = 200
  1580. br.Success = true
  1581. br.Msg = "修改成功"
  1582. br.IsAddLog = true
  1583. }
  1584. //func init() {
  1585. // r := new(regression.Regression)
  1586. // r.SetObserved("Murders per annum per 1,000,000 inhabitants")
  1587. // r.SetVar(0, "Inhabitants")
  1588. // r.SetVar(1, "Percent with incomes below $5000")
  1589. // r.SetVar(2, "Percent unemployed")
  1590. // r.Train(
  1591. // regression.DataPoint(11.2, []float64{587000, 16.5, 6.2}),
  1592. // regression.DataPoint(13.4, []float64{643000, 20.5, 6.4}),
  1593. // regression.DataPoint(40.7, []float64{635000, 26.3, 9.3}),
  1594. // regression.DataPoint(5.3, []float64{692000, 16.5, 5.3}),
  1595. // regression.DataPoint(24.8, []float64{1248000, 19.2, 7.3}),
  1596. // regression.DataPoint(12.7, []float64{643000, 16.5, 5.9}),
  1597. // regression.DataPoint(20.9, []float64{1964000, 20.2, 6.4}),
  1598. // regression.DataPoint(35.7, []float64{1531000, 21.3, 7.6}),
  1599. // regression.DataPoint(8.7, []float64{713000, 17.2, 4.9}),
  1600. // regression.DataPoint(9.6, []float64{749000, 14.3, 6.4}),
  1601. // regression.DataPoint(14.5, []float64{7895000, 18.1, 6}),
  1602. // regression.DataPoint(26.9, []float64{762000, 23.1, 7.4}),
  1603. // regression.DataPoint(15.7, []float64{2793000, 19.1, 5.8}),
  1604. // regression.DataPoint(36.2, []float64{741000, 24.7, 8.6}),
  1605. // regression.DataPoint(18.1, []float64{625000, 18.6, 6.5}),
  1606. // regression.DataPoint(28.9, []float64{854000, 24.9, 8.3}),
  1607. // regression.DataPoint(14.9, []float64{716000, 17.9, 6.7}),
  1608. // regression.DataPoint(25.8, []float64{921000, 22.4, 8.6}),
  1609. // regression.DataPoint(21.7, []float64{595000, 20.2, 8.4}),
  1610. // regression.DataPoint(25.7, []float64{3353000, 16.9, 6.7}),
  1611. // )
  1612. // r.Run()
  1613. //
  1614. // fmt.Printf("Regression formula:\n%v\n", r.Formula)
  1615. // //fmt.Printf("Regression:\n%s\n", r)
  1616. //}
  1617. //func init() {
  1618. // //data := []float64{4080, 4070, 4070, 4020, 4020, 4010, 3950, 3980, 4000, 3990, 4020}
  1619. // //median, _ := stats.Median(data)
  1620. // //fmt.Println(median) // 3.65
  1621. // //stats.LinearRegression()
  1622. //
  1623. // //data := []float64{ , , , , , , , , }
  1624. //
  1625. // data := []Coordinate{
  1626. // {1, 4080},
  1627. // {2, 4070},
  1628. // {3, 4070},
  1629. // {4, 4020},
  1630. // {5, 4020},
  1631. // {6, 4010},
  1632. // {7, 3950},
  1633. // {8, 3980},
  1634. // {9, 4000},
  1635. // {10, 3990},
  1636. // {11, 4020},
  1637. // }
  1638. //
  1639. // //r, _ := ct(data)
  1640. //
  1641. // ct(data)
  1642. // //fmt.Println(r)
  1643. //
  1644. //}
  1645. //func init() {
  1646. // data.AddOrEditAllEdbInfoToEs()
  1647. //}