From 7d54a42da961687cb97266f0e409786d7e0d3765 Mon Sep 17 00:00:00 2001 From: eson Date: Fri, 21 Aug 2020 19:36:05 +0800 Subject: [PATCH] finish charts --- goserver/count_tag.go | 47 +++++++++++-- goserver/go.mod | 1 + goserver/go.sum | 3 + src/App.js | 72 +++++++++++++++----- src/ChartsCount.js | 143 +++++++++++++++++++++++++++++++++++++++ src/ContentTable.js | 3 +- src/Graph.js | 151 ------------------------------------------ src/Table.js | 4 +- 8 files changed, 249 insertions(+), 175 deletions(-) create mode 100644 src/ChartsCount.js delete mode 100644 src/Graph.js diff --git a/goserver/count_tag.go b/goserver/count_tag.go index 9b5d976..2c08068 100644 --- a/goserver/count_tag.go +++ b/goserver/count_tag.go @@ -6,15 +6,22 @@ import ( "log" "time" + "github.com/474420502/focus/tree/heap" "github.com/gin-gonic/gin" ) var tagCounter = make(map[string]*tagcounter) +type taginfo struct { + Name string + Value int +} + type tagcounter struct { Name string LastTime time.Time - CountWord map[string]int + CountWord map[string]*taginfo + PQueue []interface{} } func init() { @@ -26,7 +33,7 @@ func CountTag(cxt *gin.Context) { var cw *tagcounter if cw, ok := tagCounter[platform]; ok { if time.Now().Sub(cw.LastTime).Minutes() <= 10 { - cxt.JSON(200, cw.CountWord) + cxt.JSON(200, cw.PQueue) return } } @@ -39,7 +46,7 @@ func CountTag(cxt *gin.Context) { } cw = &tagcounter{} - cw.CountWord = make(map[string]int) + cw.CountWord = make(map[string]*taginfo) cw.Name = platform cw.LastTime = time.Now() tagCounter[platform] = cw @@ -54,12 +61,40 @@ func CountTag(cxt *gin.Context) { json.Unmarshal([]byte(stag), &tag) for _, t := range tag { if _, ok := cw.CountWord[t]; ok { - cw.CountWord[t]++ + cw.CountWord[t].Value++ } else { - cw.CountWord[t] = 1 + cw.CountWord[t] = &taginfo{Name: t, Value: 1} } } } - cxt.JSON(200, cw.CountWord) + + heap := heap.New(func(a, b interface{}) int { + if a.(*taginfo).Value >= b.(*taginfo).Value { + return 1 + } + return -1 + + }) + + var other = &taginfo{Name: "Other...", Value: 0} + var i = 0 + for _, v := range cw.CountWord { + if i <= 99 { + heap.Put(v) + } else { + break + } + i++ + } + + // heap.Put(other) + cw.PQueue = heap.Values() + other.Value = cw.PQueue[len(cw.PQueue)-1].(*taginfo).Value - 1 + if other.Value == 0 { + other.Value = 1 + } + + cw.PQueue = append(cw.PQueue, other) + cxt.JSON(200, cw.PQueue) cw.LastTime = time.Now() } diff --git a/goserver/go.mod b/goserver/go.mod index 4e1b7c1..3fdf871 100644 --- a/goserver/go.mod +++ b/goserver/go.mod @@ -3,6 +3,7 @@ module initmate_server go 1.15 require ( + github.com/474420502/focus v0.12.0 github.com/gin-gonic/gin v1.6.3 github.com/go-sql-driver/mysql v1.5.0 github.com/jinzhu/gorm v1.9.16 // indirect diff --git a/goserver/go.sum b/goserver/go.sum index 61e2c1b..8cdfcf4 100644 --- a/goserver/go.sum +++ b/goserver/go.sum @@ -1,3 +1,6 @@ +github.com/474420502/focus v0.12.0 h1:+icbmj7IEOefvTegHt5EpcHt6WFbe2miIrceUJx2Evo= +github.com/474420502/focus v0.12.0/go.mod h1:d0PMjtMxFz1a9HIhwyFPkWa+JF+0LgOrEUfd8iZka6s= +github.com/Pallinder/go-randomdata v1.1.0/go.mod h1:yHmJgulpD2Nfrm0cR9tI/+oAgRqCQQixsA8HyRZfV9Y= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/src/App.js b/src/App.js index 9e89ba7..bea031b 100644 --- a/src/App.js +++ b/src/App.js @@ -2,22 +2,25 @@ import Icon, { MenuFoldOutlined, MenuUnfoldOutlined, DatabaseOutlined, DatabaseFilled } from '@ant-design/icons'; -import { Button, Layout, Menu } from 'antd'; +import { Row, Col, Divider } from 'antd'; +import { Button, Layout, Menu, Tabs } from 'antd'; import 'antd/dist/antd.css'; import React from 'react'; -import ReactDom from 'react-dom'; import './App.less'; import DataTable from './Table'; import ContentTable from './ContentTable'; import DataTableTest from './TableTest'; -import CountCharts from './Graph'; - +import ChartsCount from './ChartsCount'; +const { TabPane } = Tabs; +const bstyle = { width: "100px" }; const { Header, Content, Footer, Sider } = Layout; class App extends React.Component { state = { + platform: "openrec", collapsed: false, + tkey: "content_table", }; toggleCollapsed = () => { @@ -26,6 +29,14 @@ class App extends React.Component { }); }; + changePlatform = (p) => { + this.setState({platform: p}); + if (this.refs.tcharts && this.refs.tcharts.state.platform !== p) { + this.refs.tcharts.changePlatform(p) + } + this.refs.ctable.changePlatform(p); + } + render() { return ( @@ -36,33 +47,64 @@ class App extends React.Component { inlineCollapsed={this.state.collapsed} > - } onClick={(e)=>{ this.refs.ctable.changePlatform( e.key) ; }} > + } onClick={(e)=>{ this.changePlatform(e.key); }} > openrec - } onClick={(e)=>{ this.refs.ctable.changePlatform( e.key) ; }} > + } onClick={(e)=>{ this.changePlatform(e.key); ; }} > twitcasting - } onClick={(e)=>{ this.refs.ctable.changePlatform( e.key) ; }} > + } onClick={(e)=>{ this.changePlatform(e.key); }} > twitch
- - - 标题 - + + + + {/* */} + + +
- - {/* */} - + + { + const { platform } = this.state; + this.setState({key: e}) + + switch (e) { + case "content_table": + if (this.refs.ctable) { + this.refs.ctable.changePlatform(platform); + } + break; + case "tag_count": + if( this.refs.tcharts ) { + this.refs.tcharts.changePlatform(platform); + } + break + default: + break; + } + + }} > + + + + + + + + + +