change some

This commit is contained in:
eson 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

@ -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

@ -1,13 +1,20 @@
import React from 'react';
import ReactEcharts from 'echarts-for-react';
import apihost from './Var.js';
function parseData(cw = {}) {
var legendData = [];
var seriesData = [];
var selected = {};
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];
@ -18,7 +25,6 @@ function parseData(cw={}) {
selected[taginfo.Name] = false;
}
seriesData.sort((a, b) => {
return b.value - a.value
})
@ -88,24 +94,18 @@ class ChartsCount extends React.Component {
});
};
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 => {
this.setState({
data: parseData(value)
}, () => {
var ins = this.echarts_react.getEchartsInstance();
ins.setOption(getOption(this.state));
});
});

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,8 +1,9 @@
import React, { useState } from 'react';
import { Table, Input, InputNumber, Popconfirm, Form, Tag } from 'antd';
import reqwest from 'reqwest';
import { Table, Input, Select, Tag, Row, Col } from 'antd';
import './Table.less';
import { useForm } from 'antd/lib/form/Form';
import apihost from './Var';
const { Option } = Select;
const columns = [
{
@ -166,14 +167,12 @@ class DataTable extends React.Component {
fetch = (params = {}) => {
this.setState({ loading: true });
const {platform} = this.state;
const { platform, pagination } = this.state;
reqwest({
url: 'http://192.168.16.130:5500/' + platform + '/query',
method: 'get',
type: 'json',
data: getRandomuserParams(params),
}).then(data => {
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,
@ -183,17 +182,41 @@ class DataTable extends React.Component {
total: 100000,
},
});
});
}
)
})
};
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"}
// scroll={{ x: "150vh", y:"800" }}
columns={columns}
dataSource={data}
pagination={pagination}
@ -201,12 +224,13 @@ class DataTable extends React.Component {
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=