Last active
June 22, 2018 06:58
-
-
Save 8q/b41901eec8cb1422a10fd1c3f1c057a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSheet(name) { | |
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName(name); | |
} | |
function getEndRow(sheet, col) { | |
var endRow = 0; | |
var lastRow = sheet.getLastRow() | |
for(var i = 1; i <= lastRow; i++) { | |
if(sheet.getRange(i, col).getValue() === "") break; | |
endRow++; | |
} | |
return endRow; | |
} | |
function notifyGoogleHome(text) { | |
var url = getSheet('main').getRange(1, 5).getValue(); | |
var res = UrlFetchApp.fetch(url + "?text=" + text); | |
Logger.log(res.getContentText()); | |
} | |
function exec() { | |
var mainSheet = getSheet('main'); | |
var ruijiSheet = getSheet('ruiji_sample'); | |
var words = mainSheet.getRange(getEndRow(mainSheet, 2), 2).getValue().replace("おいしい", "美味しい").split(' '); | |
var maxScore = -100; | |
var maxScoreIndices = []; | |
var endRow = getEndRow(ruijiSheet, 1) | |
for(var i = 4; i <= endRow; i++) { | |
var matchWord = ruijiSheet.getRange(i, 12).getValue(); | |
var score = -matchWord.split(' ').length; | |
for(var j = 0; j < words.length; j++) { | |
if(words[j].length <= 1) continue; | |
if(matchWord.indexOf(words[j]) != -1) { | |
score += 2; | |
} | |
} | |
if(score > maxScore) { | |
maxScore = score; | |
maxScoreIndices = [i]; | |
} else if(score === maxScore) { | |
maxScoreIndices.push(i); | |
} | |
} | |
notifyGoogleHome(ruijiSheet.getRange(maxScoreIndices[Math.floor(Math.random() * maxScoreIndices.length)], 10).getValue()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment