dev/addPush
Zovjsra 4 years ago
parent 24f92cd6f0
commit efdd3ec965

@ -67,7 +67,7 @@ def ptt_push():
@app.route('/ptt_push/init', methods=['POST']) @app.route('/ptt_push/init', methods=['POST'])
def pttPushInit(): def pttPushInit():
author = 'yuetsu' author = 'a58461351'
pushes = pttPush.findAuthorPush( pushes = pttPush.findAuthorPush(
author=[author], stopwords=pttPush.defaultStopWords) author=[author], stopwords=pttPush.defaultStopWords)
result: dict = { result: dict = {

@ -31,6 +31,8 @@ with open('/home/vis/pttDatabase/PTTData/Gossiping/content/content.pck', 'rb') a
defaultStopWords = [] defaultStopWords = []
data = PTTData('Gossiping', '/home/vis/pttDatabase/PTTData') data = PTTData('Gossiping', '/home/vis/pttDatabase/PTTData')
sentence_length = 100
use_push_count = False
with open('resource/stopWords.txt', 'r', encoding='UTF-8') as file: with open('resource/stopWords.txt', 'r', encoding='UTF-8') as file:
for word in file.readlines(): for word in file.readlines():
@ -75,7 +77,7 @@ def contentProcess(content, text):
result = [] result = []
for i in cutted: for i in cutted:
result.append(i) result.append(i)
if (len(result) >= 50): if (len(result) >= sentence_length):
sentenses.append(result.copy()) sentenses.append(result.copy())
result = [] result = []
if (result != []): if (result != []):
@ -324,7 +326,7 @@ def getDefault(startDate, endDate):
'date': datetime.strptime(i['date'], '%Y%m%d%H%M%S').strftime("%a %b %d %H:%M:%S %Y"), 'date': datetime.strptime(i['date'], '%Y%m%d%H%M%S').strftime("%a %b %d %H:%M:%S %Y"),
'part': i['content'][max(0, cut[0] - 20): min(len(i['content']), cut[1])].replace('\n', '') 'part': i['content'][max(0, cut[0] - 20): min(len(i['content']), cut[1])].replace('\n', '')
} }
result.append([len(result), seq, 1000 + i['pushes']]) result.append([len(result), seq, (1000 + i['pushes'])if use_push_count else 3000])
fileString = io.StringIO() fileString = io.StringIO()
writer = csv.writer(fileString, delimiter='\t') writer = csv.writer(fileString, delimiter='\t')

@ -68,3 +68,8 @@
所以 所以
記者
媒體

@ -112,6 +112,24 @@ html {
transition-duration: 0.5s; transition-duration: 0.5s;
} }
#pttPageWindowContent {
display: block;
position: fixed;
background-color: #FFF;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 90%;
height: 90%;
border: lightgray;
border-width: 1px;
border-style: solid;
border-radius: 20px;
padding: 26px;
z-index: 99;
box-shadow: 0px 5px 20px rgba(0, 0, 0, .3);
}
.deleteListElement { .deleteListElement {
position: absolute; position: absolute;
right: 0; right: 0;
@ -141,6 +159,18 @@ li a {
} }
.info { .info {
background-color: rgba(255, 255, 255, 0.6);
animation: fadeIn 0.2s;
animation-fill-mode: forwards;
position: fixed;
display: flex;
top: 0;
width: 100%;
height: 100%;
z-index: 90;
}
.info99 {
background-color: rgba(255, 255, 255, 0.6); background-color: rgba(255, 255, 255, 0.6);
animation: fadeIn 0.2s; animation: fadeIn 0.2s;
animation-fill-mode: forwards; animation-fill-mode: forwards;
@ -189,7 +219,7 @@ li a {
height: auto; height: auto;
border-radius: 15px; border-radius: 15px;
padding: 10px 15px; padding: 10px 15px;
z-index: 99; z-index: 90;
align-content: center; align-content: center;
} }

@ -76,7 +76,41 @@ function init() {
hideIdfEditor() hideIdfEditor()
} }
}) })
$('#pttPageWindow').click(function(e) {
if ($('#pttPageWindow').is(e.target)) {
hidePTTPage()
}
})
changeMode(0) changeMode(0)
destroyCurrentGraph()
buildSentetree()
}
function loadTemplate(num) {
templates = [{
startDate: '2020-12-01',
endDate: '2020-12-31',
keyword: '',
mode: 1
},
{
startDate: '2020-01-01',
endDate: '2020-03-01',
keyword: '衛生紙',
mode: 2
},
{
startDate: '2020-01-11',
endDate: '2020-01-12',
keyword: '',
mode: 2
}
]
chosenTemp = templates[num]
setDate(chosenTemp.startDate, chosenTemp.endDate)
$('#keywordBox').val(chosenTemp.keyword)
changeMode(chosenTemp.mode)
sendRequest()
} }
function clearStopWord() { function clearStopWord() {
@ -117,8 +151,6 @@ function changeMode(_mode) {
} }
} }
mode = _mode mode = _mode
destroyCurrentGraph()
buildSentetree()
} }
function scrollIdfList() { function scrollIdfList() {
@ -170,8 +202,12 @@ function showIdfEditor() {
.append($('<th>') .append($('<th>')
.attr('style', 'position: sticky; top: 0; background: white;') .attr('style', 'position: sticky; top: 0; background: white;')
.append('單詞')) .append('單詞'))
.append($('<th>')) .append($('<th>')
.append($('<th>').attr('class', 'w3-right-align') .attr('class', 'w3-center-align')
.attr('style', 'position: sticky; top: 0; background: white;')
.append('操作'))
.append($('<th>')
.attr('class', 'w3-right-align')
.attr('style', 'position: sticky; top: 0; background: white;') .attr('style', 'position: sticky; top: 0; background: white;')
.append('單詞頻率') .append('單詞頻率')
) )
@ -259,6 +295,15 @@ function hideIdfEditor() {
$('#idfEditorLayer').addClass('hidden') $('#idfEditorLayer').addClass('hidden')
} }
function showPTTPage(url) {
$('#pttPageWindowContent iframe').attr('src', url)
$('#pttPageWindow').removeClass('hidden')
}
function hidePTTPage() {
$('#pttPageWindow').addClass('hidden')
}
function updateIdfTable() { function updateIdfTable() {
let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => { let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => {
return [ return [
@ -315,6 +360,23 @@ function closeEventListner() {
} }
function sendRequest() { function sendRequest() {
content = getContent()
startDate = $('#startDate').val()
endDate = $('#endDate').val()
console.log(content)
$.ajax({
type: 'POST',
url: '/addRequest',
data: content,
contentType: 'application/json',
success: function(data) {
console.log(data)
changeGraph(data.Result)
}
})
}
function getContent() {
content = JSON.stringify({ content = JSON.stringify({
startDate: $('#startDate').val(), startDate: $('#startDate').val(),
endDate: $('#endDate').val(), endDate: $('#endDate').val(),
@ -330,19 +392,7 @@ function sendRequest() {
other: $('#other').is(':checked') other: $('#other').is(':checked')
} }
}) })
startDate = $('#startDate').val() return content
endDate = $('#endDate').val()
console.log(content)
$.ajax({
type: 'POST',
url: '/addRequest',
data: content,
contentType: 'application/json',
success: function(data) {
console.log(data)
changeGraph(data.Result)
}
})
} }
function changeGraph(data) { function changeGraph(data) {
@ -466,8 +516,9 @@ function buildSentetree() {
$('#titleListContainer').empty() $('#titleListContainer').empty()
for (i of titleList) { for (i of titleList) {
$('#titleListContainer').append( $('#titleListContainer').append(
$('<li>').attr('class', 'w3-panel').append( $('<li>').attr('class', 'w3-panel')
$('<a>').attr('href', i.url).attr('target', '_blank').append( .css('cursor', 'pointer').append(
$('<p>').attr('target', '_blank').append(
$('<h4>').html(i.title) $('<h4>').html(i.title)
).append( ).append(
$('<span>').attr('style', 'margin: 0px 10px').html(i.author) $('<span>').attr('style', 'margin: 0px 10px').html(i.author)
@ -476,7 +527,10 @@ function buildSentetree() {
).append( ).append(
$('<span>').attr('style', 'margin: 0px 10px').html('推文數:' + i.pushes) $('<span>').attr('style', 'margin: 0px 10px').html('推文數:' + i.pushes)
) )
) ).click(function() {
let indx = $(this).index()
showPTTPage((titleList[indx].url).replace('www.ptt.cc', 'www.pttweb.cc'))
})
) )
} }
}) })

@ -25,6 +25,7 @@ function init() {
console.log(wordPushList) console.log(wordPushList)
$('#idBox').val(data.Result.author) $('#idBox').val(data.Result.author)
buildSentetree(tsvString) buildSentetree(tsvString)
changeMode(2)
} }
}) })
$(document).ready(function() { $(document).ready(function() {
@ -66,6 +67,31 @@ function init() {
}) })
} }
function loadTemplate(num) {
templates = [{
userId: '',
aid: '1Vv4iFY6',
keyword: '',
mode: 0,
}, {
userId: '',
aid: '1VyJ2vP_',
keyword: '',
mode: 0
}, {
userId: 'xetherz3',
aid: '',
keyword: '',
mode: 0
}]
let chosenTemplate = templates[num]
$('#idBox').val(chosenTemplate.userId)
$('#titleBox').val(chosenTemplate.aid)
$('#keywordBox').val(chosenTemplate.keyword)
changeMode(0)
sendRequest()
}
function clearStopWord() { function clearStopWord() {
stopwords = [] stopwords = []
$('#sweContainer').html('') $('#sweContainer').html('')
@ -138,7 +164,10 @@ function showIdfEditor() {
.append($('<th>') .append($('<th>')
.attr('style', 'position: sticky; top: 0; background: white;') .attr('style', 'position: sticky; top: 0; background: white;')
.append('單詞')) .append('單詞'))
.append($('<th>')) .append($('<th>')
.attr('class', 'w3-center-align')
.attr('style', 'position: sticky; top: 0; background: white;')
.append('操作'))
.append($('<th>').attr('class', 'w3-right-align') .append($('<th>').attr('class', 'w3-right-align')
.attr('style', 'position: sticky; top: 0; background: white;') .attr('style', 'position: sticky; top: 0; background: white;')
.append('單詞頻率') .append('單詞頻率')

@ -19158,7 +19158,7 @@
maxc = value maxc = value
} }
} else { } else {
if (value < maxSupport && (value * Math.pow(distRatio, dist - 1)) > maxc && stopwords.indexOf(itemset[w]) < 0 && dist == 1) { if (value < maxSupport && value > maxc && dist < 2 && stopwords.indexOf(itemset[w]) < 0 && dist == 1) {
maxw = +w maxw = +w
maxc = value maxc = value
console.log(maxc) console.log(maxc)

@ -41,7 +41,8 @@
<button class="general-button" type="button" id="editSWButton" style="margin:10px 0px;" onclick="showStopwordEditor()">編輯停用詞</button> <button class="general-button" type="button" id="editSWButton" style="margin:10px 0px;" onclick="showStopwordEditor()">編輯停用詞</button>
</div> </div>
<div id='rawText' class=''> <div id='rawText' class=''>
<textarea id='rawTextBox' rows=25></textarea> <textarea id='rawTextBox' rows=25 placeholder="輸入要視覺化的文字
換行為斷句"></textarea>
<button class='general-button' style='margin: 10px 0px' onclick="submit()">提交</button> <button class='general-button' style='margin: 10px 0px' onclick="submit()">提交</button>
</div> </div>
<div> <div>

@ -15,6 +15,11 @@
<button class="w3-button w3-teal" type="button" onclick="location.href='/generalTxt'">泛用文字視覺化工具</button> <button class="w3-button w3-teal" type="button" onclick="location.href='/generalTxt'">泛用文字視覺化工具</button>
</div> </div>
<div id='pttPageWindow' class='info99 hidden'>
<div id='pttPageWindowContent'>
<iframe src="http://ptt.cc" style='width:100%; height:100%' frameborder=0></iframe>
</div>
</div>
<div id="nodeTitle" class="nodeTitle hidden"> <div id="nodeTitle" class="nodeTitle hidden">
<div id="nodeTitleContent"></div> <div id="nodeTitleContent"></div>
</div> </div>
@ -66,17 +71,19 @@
<div id="heading"> <div id="heading">
<h2>{{title}}</h2> <h2>{{title}}</h2>
<p>SentenTree <a href="https://github.com/twitter/SentenTree">https://github.com/twitter/SentenTree</a></p> <p>SentenTree <a href="https://github.com/twitter/SentenTree">https://github.com/twitter/SentenTree</a></p>
<p id="comment">同時使用關鍵詞和詞性搜尋的時候,必須選擇所設關鍵詞本身的詞性,否則會搜尋不到結果。</p> <p>可直接從下方範例搜尋條件中選擇</p>
<p id="comment">點選圖上的單詞可以查看單詞的資訊,觀看原始文章,也會快速切換關鍵字。</p> <div>
<p id="comment">若搜尋到的文章超過50篇圖表僅會顯示推文數最多的前50篇文章。</p> <button class='w3-button w3-green' onclick='loadTemplate(0)'>範例1</button>
<p id="comment">停用詞的處理改為將不直接忽略停用詞,但是停用詞不會被設為主要單詞,並且大小會比其他單詞更小。</p> <button class='w3-button w3-green' onclick='loadTemplate(1)'>範例2</button>
<button class='w3-button w3-green' onclick='loadTemplate(2)'>範例3</button>
</div>
<div id="searchingTarget"> <div id="searchingTarget">
<form name="form" enctype="multipart/form-data"> <form name="form" enctype="multipart/form-data">
<span>搜尋日期範圍 從</span> <span>搜尋日期範圍 從</span>
<input id="startDate" name="startDate" type="date"> <input id="startDate" name="startDate" type="date">
<span></span> <span></span>
<input id="endDate" name="endDate" type="date"> <input id="endDate" name="endDate" type="date">
<button class="general-button" type="button" id="resetDateButton" onclick="setDate(defaultStartDate, defaultEndDate)">預設日期</button> <button class="general-button" type="button" id="resetDateButton" onclick="setDate(defaultStartDate, defaultEndDate)">預設日期</button><br>
<input id="keywordBox" type="text" name="message" placeholder="輸入關鍵詞"> <input id="keywordBox" type="text" name="message" placeholder="輸入關鍵詞">
<button class="general-button" type="button" id="sendButton" onclick="sendRequest()">搜尋關鍵字</button> <button class="general-button" type="button" id="sendButton" onclick="sendRequest()">搜尋關鍵字</button>
<button class="general-button" type="button" id="resetButton" onclick="document.getElementById('keywordBox').value=''">清除關鍵字</button> <button class="general-button" type="button" id="resetButton" onclick="document.getElementById('keywordBox').value=''">清除關鍵字</button>
@ -97,10 +104,10 @@
</form> </form>
</div> </div>
<div id='modeSelector'> <div id='modeSelector'>
<button type="button" id='mode0' class='w3-button' onclick="changeMode(0)">相鄰詞模式</button> <button type="button" id='mode0' class='w3-button' onclick="changeMode(0);destroyCurrentGraph();buildSentetree()">相鄰詞模式</button>
<button type="button" id='mode1' class='w3-button ' onclick="changeMode(1)">Idf模式</button> <button type="button" id='mode1' class='w3-button ' onclick="changeMode(1);destroyCurrentGraph();buildSentetree()">Idf模式</button>
<button type="button" id='mode2' class='w3-button ' onclick="changeMode(2)">停用詞模式</button> <button type="button" id='mode2' class='w3-button ' onclick="changeMode(2);destroyCurrentGraph();buildSentetree()">停用詞模式</button>
<button type="button" id='mode3' class='w3-button ' onclick="changeMode(3)">根單詞停用模式</button> <button type="button" id='mode3' class='w3-button ' onclick="changeMode(3);destroyCurrentGraph();buildSentetree()">根單詞停用模式</button>
</div> </div>
</div> </div>
<div id="graphInfo"></div> <div id="graphInfo"></div>

@ -67,6 +67,12 @@
<p>SentenTree <a href="https://github.com/twitter/SentenTree">https://github.com/twitter/SentenTree</a></p> <p>SentenTree <a href="https://github.com/twitter/SentenTree">https://github.com/twitter/SentenTree</a></p>
<p id="comment">同時使用關鍵詞和詞性搜尋的時候,必須選擇所設關鍵詞本身的詞性,否則會搜尋不到結果。</p> <p id="comment">同時使用關鍵詞和詞性搜尋的時候,必須選擇所設關鍵詞本身的詞性,否則會搜尋不到結果。</p>
<p id="comment">鄉民ID和文章aid之中必須至少設定一個搜尋條件。</p> <p id="comment">鄉民ID和文章aid之中必須至少設定一個搜尋條件。</p>
<p>可直接從下方範例搜尋條件中選擇</p>
<div>
<button class='w3-button w3-green' onclick='loadTemplate(0)'>範例1</button>
<button class='w3-button w3-green' onclick='loadTemplate(1)'>範例2</button>
<button class='w3-button w3-green' onclick='loadTemplate(2)'>範例3</button>
</div>
<div id="searchingTarget"> <div id="searchingTarget">
<form name="form" enctype="multipart/form-data"> <form name="form" enctype="multipart/form-data">
<input id="idBox" class='searchBox' type="text" name="message" placeholder="輸入鄉民ID"> <input id="idBox" class='searchBox' type="text" name="message" placeholder="輸入鄉民ID">

Loading…
Cancel
Save