change some

This commit is contained in:
2020-08-24 00:23:43 +08:00
parent 7d54a42da9
commit 3a987464e6
11 changed files with 344 additions and 233 deletions

View File

@@ -4,13 +4,14 @@ import (
"encoding/json"
"fmt"
"log"
"sync"
"time"
"github.com/474420502/focus/tree/heap"
"github.com/gin-gonic/gin"
)
var tagCounter = make(map[string]*tagcounter)
var tagCounter = &sync.Map{} // make(map[string]*tagcounter)
type taginfo struct {
Name string
@@ -28,12 +29,26 @@ func init() {
}
func AllTag(cxt *gin.Context) {
countTagInfo(cxt, func(cxt *gin.Context, cw *tagcounter) {
cxt.JSON(200, cw.CountWord)
})
}
func CountTag(cxt *gin.Context) {
countTagInfo(cxt, func(cxt *gin.Context, cw *tagcounter) {
cxt.JSON(200, cw.PQueue)
})
}
func countTagInfo(cxt *gin.Context, ret func(cxt *gin.Context, cw *tagcounter)) {
platform := cxt.Query("platform")
var cw *tagcounter
if cw, ok := tagCounter[platform]; ok {
if icw, ok := tagCounter.Load(platform); ok {
cw = icw.(*tagcounter)
if time.Now().Sub(cw.LastTime).Minutes() <= 10 {
cxt.JSON(200, cw.PQueue)
ret(cxt, cw)
return
}
}
@@ -49,7 +64,6 @@ func CountTag(cxt *gin.Context) {
cw.CountWord = make(map[string]*taginfo)
cw.Name = platform
cw.LastTime = time.Now()
tagCounter[platform] = cw
for rows.Next() {
var stag string
@@ -87,6 +101,11 @@ func CountTag(cxt *gin.Context) {
i++
}
if heap.Size() == 0 {
cxt.JSON(200, nil)
return
}
// heap.Put(other)
cw.PQueue = heap.Values()
other.Value = cw.PQueue[len(cw.PQueue)-1].(*taginfo).Value - 1
@@ -95,6 +114,8 @@ func CountTag(cxt *gin.Context) {
}
cw.PQueue = append(cw.PQueue, other)
cxt.JSON(200, cw.PQueue)
// cxt.JSON(200, cw.PQueue)
ret(cxt, cw)
cw.LastTime = time.Now()
tagCounter.Store(platform, cw)
}

View File

@@ -4,6 +4,7 @@ go 1.15
require (
github.com/474420502/focus v0.12.0
github.com/Pallinder/go-randomdata v1.1.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

View File

@@ -1,5 +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 h1:gUubB1IEUliFmzjqjhf+bgkg1o6uoFIkRsP3VrhEcx8=
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=

View File

@@ -52,7 +52,7 @@ func Cors() gin.HandlerFunc {
// 允许跨域设置 可以返回其他子段
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers,Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,FooBar") // 跨域关键设置 让浏览器可以解析
c.Header("Access-Control-Max-Age", "172800") // 缓存请求信息 单位为秒
c.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true
c.Header("Access-Control-Allow-Credentials", "false") // 跨域请求是否需要带cookie信息 默认设置为true
c.Set("content-type", "application/json") // 设置返回格式是json
}
@@ -185,5 +185,6 @@ func main() {
engine.GET("openrec/query", OpenrecQuery)
engine.GET("twitch/query", TwitchQuery)
engine.GET("tag/count", CountTag)
engine.GET("tag/allcount", CountTag)
engine.Run(":5500")
}

View File

@@ -1,13 +1,44 @@
package main
import (
"encoding/json"
"log"
"regexp"
"testing"
"github.com/Pallinder/go-randomdata"
)
func TestMain(t *testing.T) {
main()
}
func TestCountTag(t *testing.T) {
func estCountTag(t *testing.T) {
var a = `男人 女人 儿童 老人 母亲 父亲 爷爷 奶奶 老师 美女 帅哥 性格 善良 性格 品质 聪明 女儿 儿子 军人 坏蛋 心情 笑 哭 高兴
害怕 愤怒 激动 紧张 忧虑 着急 满足 眼睛 鼻子 嘴巴 头发 耳朵 牙齿 美 丑 眉毛 脸 手 脚 腰 腿
胖 瘦 矮 高 清明节 劳动节 端午节 七夕节 中秋节 重阳节 元宵节 服饰 鼠 牛 虎 兔 龙 蛇 马 羊
猴 狗 猪 鸡 颜色 聚会 时间短 时间 爱情 脚步声 水声 花 教堂 速度快 速度慢 桃花 幼苗 紫色 白色
黑色 红色 女性身材 男性身材 沙沙尘尘 猪甘蠢 猪 无脑 大唔透 玩世不恭 眼大无神 大细超 白鸽眼 咸湿 浪漫 靓仔 靓
女 猛男 咸猪手 西施 好色 色狼 色魔 畜牲 食碗面反碗底 抵死 恶死 曾眉凸眼 眉耒眼去 温柔体贴假细心 放荡 淫贱 荒唐 离谱 头尖额窄无厘贵格 肚满肠肥 两面三刀 反革命 红卫兵
`
tags := regexp.MustCompile("[^ \n\t]+").FindAllString(a, -1)
for {
var stags []string
for i := 0; i < randomdata.Number(1, 5); i++ {
tag := randomdata.StringSample(tags...)
stags = append(stags, tag)
}
data, _ := json.Marshal(stags)
sql := "update streamer set tags = ?, operator = 20 where operator != 20 limit 1"
_, err := StoreStreamer.Exec(sql, data)
if err != nil {
log.Println(err)
break
}
}
}

View File

@@ -92,7 +92,7 @@ class App extends React.Component {
break
default:
break;
}
}
}} >

View File

@@ -1,38 +1,44 @@
import React from 'react';
import ReactEcharts from 'echarts-for-react';
import apihost from './Var.js';
function parseData(cw = {}) {
function parseData(cw={}) {
var legendData = [];
var seriesData = [];
var selected = {};
for(var i =0; i < cw.length ; i++){
if (cw == null) {
seriesData.push({ name: "没有数据", value: 1 })
legendData.push(seriesData[0].name)
selected[seriesData[0].name] = true;
return { legendData: legendData, seriesData: seriesData, selected: selected }
}
for (var i = 0; i < cw.length; i++) {
// legendData.push(name);
var taginfo = cw[i];
var taginfo = cw[i];
seriesData.push({
name: taginfo.Name,
value: taginfo.Value
})
selected[taginfo.Name] = false;
}
}
seriesData.sort((a, b) => {
seriesData.sort((a, b) => {
return b.value - a.value
})
})
for(var i = 0; i < seriesData.length ; i ++) {
for (var i = 0; i < seriesData.length; i++) {
var o = seriesData[i];
legendData.push(o.name);
selected[o.name] = i <= 20;
}
}
return { legendData: legendData, seriesData: seriesData, selected:selected }
return { legendData: legendData, seriesData: seriesData, selected: selected }
}
function getOption(state={}) {
function getOption(state = {}) {
const { platform, data } = state;
const option = {
title: {
@@ -48,7 +54,7 @@ function getOption(state={}) {
legend: {
type: 'scroll',
orient: 'vertical',
right: 10,
right: 10,
top: 10,
bottom: 10,
data: data.legendData,
@@ -74,7 +80,7 @@ function getOption(state={}) {
return option;
}
class ChartsCount extends React.Component {
class ChartsCount extends React.Component {
state = {
option: {},
@@ -83,57 +89,51 @@ class ChartsCount extends React.Component {
}
changePlatform = (p) => {
this.setState({platform: p}, ()=>{
this.setState({ platform: p }, () => {
this.updateData();
} );
});
};
updateData = () => {
const { platform } = this.state;
fetch(`http://192.168.16.130:5500/tag/count?platform=${platform}`, {
fetch(`${apihost}/tag/count?platform=${platform}`, {
"mode": "cors"
}).then(
response => {
response.json().then( value => {
response.json().then(value => {
this.setState({
data: parseData(value)
}, ()=> {
}, () => {
var ins = this.echarts_react.getEchartsInstance();
ins.setOption( getOption(this.state) );
ins.setOption(getOption(this.state));
});
});
} );
});
}
)
};
};
componentDidMount() {
componentDidMount() {
this.updateData();
}
}
render() {
return ( <div style={{ padding: 24, background: '#fff', minHeight: 780 }} >
<ReactEcharts
notMerge={true}
ref={(e) => { this.echarts_react = e; }}
option={ getOption(this.state)}
style={{height: '600px', width: '100%'}}
className='react_for_echarts' />
</div>
return (<div style={{ padding: 24, background: '#fff', minHeight: 780 }} >
<ReactEcharts
notMerge={true}
ref={(e) => { this.echarts_react = e; }}
option={getOption(this.state)}
style={{ height: '600px', width: '100%' }}
className='react_for_echarts' />
</div>
);
}
};
export default ChartsCount;

View File

@@ -4,9 +4,6 @@ import DataTable from './Table.js';
class ContentTable extends React.Component {
changePlatform = (p) => {
// this.refs.table.firstPage();
// this.setState({platform: p});
// this.refs.table.setState({platform: p})
this.refs.table.updatePlatform(p);
}

View File

@@ -1,212 +1,236 @@
import React, { useState } from 'react';
import { Table, Input, InputNumber, Popconfirm, Form, Tag } from 'antd';
import reqwest from 'reqwest';
import './Table.less';
import { useForm } from 'antd/lib/form/Form';
import { Table, Input, Select, Tag, Row, Col } from 'antd';
import './Table.less';
import apihost from './Var';
const { Option } = Select;
const columns = [
{
title: '平台',
dataIndex: 'Platform',
editable: false,
key: 'Platform',
{
title: '平台',
dataIndex: 'Platform',
editable: false,
key: 'Platform',
// width: "8%",
},
{
title: 'userid',
dataIndex: 'UserId',
editable: false,
key: 'UserId',
},
{
title: 'userid',
dataIndex: 'UserId',
editable: false,
key: 'UserId',
// width: "7%",
},
{
title: '名称',
dataIndex: 'UserName',
editable: false,
key: 'UserName',
// width: "7%",
},
{
title: '标签',
dataIndex: 'Tags',
editable: false,
render: tags => (
<>
{
tags != null ?
tags.map( tag => {
let color = "purple";
if (tag.length < 3) {
color = 'green';
} else if (tag.length < 6) {
color = 'geekblue';
} else if (tag.length < 9) {
color = 'volcano';
}
return (
<Tag color={color} key={tag}>
{tag}
</Tag>
);
}
) : null}
</> )
},
{
title: '粉丝数(关注)',
dataIndex: 'Followers',
key: 'Followers',
width: "8%",
},
{
title: '礼物数(币|钱)',
dataIndex: 'Gratuity',
key: 'Gratuity',
width: "8%",
},
{
title: '数据更新时间',
dataIndex: 'UpdateTime',
key: 'UpdateTime',
// width: "7%",
},
];
},
{
title: '名称',
dataIndex: 'UserName',
editable: false,
key: 'UserName',
// width: "7%",
},
{
title: '标签',
dataIndex: 'Tags',
editable: false,
render: tags => (
<>
{
tags != null ?
tags.map(tag => {
let color = "purple";
if (tag.length < 3) {
color = 'green';
} else if (tag.length < 6) {
color = 'geekblue';
} else if (tag.length < 9) {
color = 'volcano';
}
return (
<Tag color={color} key={tag}>
{tag}
</Tag>
);
}
) : null}
</>)
},
{
title: '粉丝数(关注)',
dataIndex: 'Followers',
key: 'Followers',
width: "8%",
},
{
title: '礼物数(币|钱)',
dataIndex: 'Gratuity',
key: 'Gratuity',
width: "8%",
},
{
title: '数据更新时间',
dataIndex: 'UpdateTime',
key: 'UpdateTime',
// width: "7%",
},
];
const getRandomuserParams = params => {
return {
psize: params.pagination.pageSize,
page: params.pagination.current,
// ...params,
};
const getRandomuserParams = params => {
return {
psize: params.pagination.pageSize,
page: params.pagination.current,
// ...params,
};
};
class DataTable extends React.Component {
state = {
data: [],
platform: "openrec",
pagination: {
current: 1,
pageSize: 20,
position: ["topLeft"],
},
loading: false,
};
state = {
data: [],
platform: "openrec",
pagination: {
current: 1,
pageSize: 20,
position: ["topLeft"],
},
loading: false,
};
expandedRow = (record) => {
expandedRow = (record) => {
const ecolumns = [
{
title: 'uid',
dataIndex: 'Uid',
key: 'Uid',
},
{
title: '直播地址',
dataIndex: 'LiveUrl',
key: 'LiveUrl',
},
{
title: '直播标题',
dataIndex: 'LiveTitle',
key: 'LiveTitle',
},
{
title: '近直播开始时间',
dataIndex: 'LiveStartTime',
key: 'LiveStartTime',
},
{
title: '近直播结束时间',
dataIndex: 'LiveEndTime',
key: 'LiveEndTime',
},
];
const ecolumns = [
{
title: 'uid',
dataIndex: 'Uid',
key: 'Uid',
},
{
title: '直播地址',
dataIndex: 'LiveUrl',
key: 'LiveUrl',
},
{
title: '直播标题',
dataIndex: 'LiveTitle',
key: 'LiveTitle',
},
{
title: '近直播开始时间',
dataIndex: 'LiveStartTime',
key: 'LiveStartTime',
},
{
title: '近直播结束时间',
dataIndex: 'LiveEndTime',
key: 'LiveEndTime',
},
];
var data = [record];
return <Table rowClassName="subtable" size="small" bordered={true} columns={ecolumns} dataSource={data} pagination={false} />;
};
updatePlatform(p) {
var data = [record];
return <Table rowClassName="subtable" size="small" bordered={true} columns={ecolumns} dataSource={data} pagination={false} />;
};
const { pagination } = this.state;
pagination.current = 1;
this.setState({platform:p}, ()=>{
this.fetch({
pagination
});
});
}
componentDidMount() {
const {platform} = this.state;
this.updatePlatform(platform);
}
handleTableChange = (pagination, filters, sorter) => {
// console.log(filters, sorter);
this.fetch({
sortField: sorter.field,
sortOrder: sorter.order,
pagination,
...filters,
});
};
fetch = (params = {}) => {
this.setState({ loading: true });
const {platform} = this.state;
reqwest({
url: 'http://192.168.16.130:5500/' + platform + '/query',
method: 'get',
type: 'json',
data: getRandomuserParams(params),
}).then(data => {
updatePlatform(p) {
const { pagination } = this.state;
pagination.current = 1;
this.setState({ platform: p }, () => {
this.fetch({
pagination
});
});
}
componentDidMount() {
const { platform } = this.state;
this.updatePlatform(platform);
}
handleTableChange = (pagination, filters, sorter) => {
// console.log(filters, sorter);
this.fetch({
sortField: sorter.field,
sortOrder: sorter.order,
pagination,
...filters,
});
};
fetch = (params = {}) => {
this.setState({ loading: true });
const { platform, pagination } = this.state;
fetch(`${apihost}/${platform}/query?page=${pagination.current}&psize=${pagination.pageSize}`, { mode: "cors" }).then((response) => {
console.log(response);
response.json().then(
(data) => {
var result = JSON.parse(data)
this.setState({
loading: false,
data: result.Data?result.Data:[],
data: result.Data ? result.Data : [],
pagination: {
...params.pagination,
total: 100000,
},
});
});
};
render() {
const { data, pagination, loading } = this.state;
return (
<Table
bordered={true}
size={"middle"}
// scroll={{ x: "150vh", y:"800" }}
columns={columns}
dataSource={data}
pagination={pagination}
loading={loading}
onChange={this.handleTableChange}
expandable={{
expandedRowRender: this.expandedRow
}}
/>
);
}
};
}
)
})
};
render() {
const { data, pagination, loading } = this.state;
return (
<div>
<Row justify="start">
<Col span={6}>
<Input.Group compact size="small">
<Select size="small" defaultValue="operator">
<Option value="operator">operator</Option>
<Option value="uid">uid</Option>
</Select>
<Input size="small" style={{ width: '50%' }} defaultValue="123" />
</Input.Group>
</Col>
<Col span={6}>
<Input.Group compact size="small">
<Select size="small" defaultValue="Zhejiang">
<Option value="Zhejiang">Zhejiang</Option>
<Option value="Jiangsu">Jiangsu</Option>
</Select>
<Input size="small" style={{ width: '50%' }} defaultValue="Xihu District, Hangzhou" />
</Input.Group>
</Col>
</Row>
<Table
bordered={true}
size={"middle"}
columns={columns}
dataSource={data}
pagination={pagination}
loading={loading}
onChange={this.handleTableChange}
expandable={{
expandedRowRender: this.expandedRow
}} />
</div>
);
}
};
export default DataTable;
//

5
src/Var.js Normal file
View File

@@ -0,0 +1,5 @@
var apihost = "http://192.168.31.208:5500"
export default apihost;

View File

@@ -3936,6 +3936,21 @@ ecc-jsbn@~0.1.1:
jsbn "~0.1.0"
safer-buffer "^2.1.0"
echarts-for-react@^2.0.16:
version "2.0.16"
resolved "https://registry.npm.taobao.org/echarts-for-react/download/echarts-for-react-2.0.16.tgz#8134a53dff90882c1e6a95c45ceab21e00f6c9f5"
integrity sha1-gTSlPf+QiCweapXEXOqyHgD2yfU=
dependencies:
fast-deep-equal "^2.0.1"
size-sensor "^1.0.0"
echarts@^4.8.0:
version "4.8.0"
resolved "https://registry.npm.taobao.org/echarts/download/echarts-4.8.0.tgz#b2c1cfb9229b13d368ee104fc8eea600b574d4c4"
integrity sha1-ssHPuSKbE9No7hBPyO6mALV01MQ=
dependencies:
zrender "4.3.1"
ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
@@ -4495,6 +4510,11 @@ extsprintf@^1.2.0:
resolved "https://registry.npmjs.org/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=
fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.npm.taobao.org/fast-deep-equal/download/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
fast-deep-equal@^3.1.1:
version "3.1.1"
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
@@ -9985,6 +10005,11 @@ sisteransi@^1.0.4:
resolved "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==
size-sensor@^1.0.0:
version "1.0.1"
resolved "https://registry.npm.taobao.org/size-sensor/download/size-sensor-1.0.1.tgz#f84e46206d3e259faff1d548e4b3beca93219dbb"
integrity sha1-+E5GIG0+JZ+v8dVI5LO+ypMhnbs=
slash@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
@@ -11502,3 +11527,8 @@ yargs@^13.3.0, yargs@^13.3.2:
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^13.1.2"
zrender@4.3.1:
version "4.3.1"
resolved "https://registry.npm.taobao.org/zrender/download/zrender-4.3.1.tgz?cache=0&sync_timestamp=1597683473479&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fzrender%2Fdownload%2Fzrender-4.3.1.tgz#baf8aa6dc8187a2f819692d7d5f9bedfa2b90fa3"
integrity sha1-uviqbcgYei+BlpLX1fm+36K5D6M=