From 5bd1f60a0b1b7f546935df4e3938010409febc0d Mon Sep 17 00:00:00 2001 From: Russell Date: Thu, 4 Feb 2016 09:41:43 -0500 Subject: [PATCH] Just some new banterbot trick and changes and things --- Code/irc/banterbot.py | 44 ++++- Code/irc/duckduckgo.py | 179 ++++++++++++++++++ Code/irc/evil.py | 6 + Code/irc/puzzle.py | 4 +- Code/irc/tildescores.txt | 14 +- Code/irc/topics_#bots.txt | 2 + Code/irc/topics_#tildetown.txt | 1 + Code/irc/topicscores.txt | 4 +- Code/irc/tumblr.py | 23 +++ Code/irc/welch.py | 6 + Code/irc/xkcdApropos.py | 24 +++ Code/python/chatbesties.py | 105 ++++++++++ public_html/chatchecker/index.html | 3 +- public_html/chatstats/index.html | 43 +++-- public_html/du/index.html | 4 + public_html/json/css/annotated.css | 46 +++++ public_html/json/css/html.css | 149 +++++++++++++++ public_html/json/data.json | 2 +- public_html/json/data2.json | 5 + public_html/json/index.html | 23 +++ .../json/js/jsondiffpatch-formatters.min.js | 17 ++ public_html/json/js/jsondiffpatch.min.js | 37 ++++ public_html/json/vdiff.html | 67 +++++++ public_html/mission/js/mission.js | 16 +- 24 files changed, 784 insertions(+), 40 deletions(-) create mode 100755 Code/irc/duckduckgo.py create mode 100644 Code/irc/evil.py create mode 100644 Code/irc/tumblr.py create mode 100644 Code/irc/welch.py create mode 100644 Code/irc/xkcdApropos.py create mode 100644 Code/python/chatbesties.py create mode 100644 public_html/json/css/annotated.css create mode 100644 public_html/json/css/html.css create mode 100644 public_html/json/data2.json create mode 100644 public_html/json/index.html create mode 100644 public_html/json/js/jsondiffpatch-formatters.min.js create mode 100644 public_html/json/js/jsondiffpatch.min.js create mode 100644 public_html/json/vdiff.html diff --git a/Code/irc/banterbot.py b/Code/irc/banterbot.py index 2f0603e..f2a8c24 100755 --- a/Code/irc/banterbot.py +++ b/Code/irc/banterbot.py @@ -19,6 +19,10 @@ from rhymesWith import getRhymes from rhymesWith import rhymeZone from defineWord import defWord from rainbow import makeRainbow +import welch +import evil +import tumblr +import xkcdApropos parser = OptionParser() @@ -129,14 +133,35 @@ def define_word(channel, user, text): ircsock.send("PRIVMSG " + channel + " :" + user + ": Couldn't find the definition of '" + word + "' :(\n") else: for entry in defs: - ircsock.send("PRIVMSG " + channel + " :" + user + ": Define '" + word + "'" + entry[0:200] + "\n") + ircsock.send("PRIVMSG " + channel + " :" + user + ": Define '" + word + "'" + entry[0:400] + "\n") def make_rainbow(channel, user, text): rbword = makeRainbow(text[9:]) ircsock.send("PRIVMSG " + channel + " :" + rbword + "\n") +def get_welch(channel): + ircsock.send("PRIVMSG " + channel + " :" + welch.get_thing()[0:400] + "\n") + +def get_evil(channel): + evilThing = evil.get_thing(); + for line in [evilThing[i:i+400] for i in range(0, len(evilThing), 400)]: + ircsock.send("PRIVMSG " + channel + " :" + line + "\n") + +def get_tumble(url, channel): + tumble = tumblr.tumble(url) + for line in [tumble[i:i+400] for i in range(0, len(tumble), 400)]: + ircsock.send("PRIVMSG " + channel + " :" + line + "\n") + +def get_xkcd(channel, text): + links = xkcdApropos.xkcd_links(text[6:]) + joined_links = ', '.join(links) + for line in [joined_links[i:i+400] for i in range(0, len(joined_links), 400)]: + ircsock.send("PRIVMSG " + channel + " :" + line + "\n") + #res = xkcdApropos.xkcd(text[6:]) + #ircsock.send("PRIVMSG " + channel + " :" + res + "\n") + def rollcall(channel): - ircsock.send("PRIVMSG "+ channel +" :U wot m8? I score all the top drawer #banter and #bantz on this channel! Find new top-shelf banter with !newbanter, !rhymes, and !define. Make your chatter #legend with !rainbow\n") + ircsock.send("PRIVMSG "+ channel +" :U wot m8? I score all the top drawer #banter and #bantz on this channel! Find new top-shelf banter with !newbanter, !rhymes, and !define. Make your chatter #legend with !rainbow and get jokes with !welch and !evil\n") def connect(server, channel, botnick): ircsock.connect((server, 6667)) @@ -192,6 +217,21 @@ def listen(): if ircmsg.find(":!rainbow") != -1: make_rainbow(channel, user, messageText) + if ircmsg.find("!welch") != -1: + get_welch(channel) + + if ircmsg.find("!evil") != -1: + get_evil(channel) + + if ircmsg.find("!kjp") != -1: + get_tumble('http://kingjamesprogramming.tumblr.com', channel) + + if ircmsg.find("!help") != -1: + get_tumble('http://thedoomthatcametopuppet.tumblr.com', channel) + + if ircmsg.find("!xkcd") != -1: + get_xkcd(channel, messageText) + if ircmsg.find(":!rollcall") != -1: rollcall(channel) diff --git a/Code/irc/duckduckgo.py b/Code/irc/duckduckgo.py new file mode 100755 index 0000000..04ed1a5 --- /dev/null +++ b/Code/irc/duckduckgo.py @@ -0,0 +1,179 @@ +import urllib +import urllib2 +import json as j +import sys + +__version__ = 0.242 + + +def query(query, useragent='python-duckduckgo '+str(__version__), safesearch=True, html=False, meanings=True, **kwargs): + """ + Query DuckDuckGo, returning a Results object. + + Here's a query that's unlikely to change: + + >>> result = query('1 + 1') + >>> result.type + 'nothing' + >>> result.answer.text + '1 + 1 = 2' + >>> result.answer.type + 'calc' + + Keword arguments: + useragent: UserAgent to use while querying. Default: "python-duckduckgo %d" (str) + safesearch: True for on, False for off. Default: True (bool) + html: True to allow HTML in output. Default: False (bool) + meanings: True to include disambiguations in results (bool) + Any other keyword arguments are passed directly to DuckDuckGo as URL params. + """ % __version__ + + safesearch = '1' if safesearch else '-1' + html = '0' if html else '1' + meanings = '0' if meanings else '1' + params = { + 'q': query, + 'o': 'json', + 'kp': safesearch, + 'no_redirect': '1', + 'no_html': html, + 'd': meanings, + } + params.update(kwargs) + encparams = urllib.urlencode(params) + url = 'http://api.duckduckgo.com/?' + encparams + + request = urllib2.Request(url, headers={'User-Agent': useragent}) + response = urllib2.urlopen(request) + json = j.loads(response.read()) + response.close() + + return Results(json) + + +class Results(object): + + def __init__(self, json): + self.type = {'A': 'answer', 'D': 'disambiguation', + 'C': 'category', 'N': 'name', + 'E': 'exclusive', '': 'nothing'}.get(json.get('Type',''), '') + + self.json = json + self.api_version = None # compat + + self.heading = json.get('Heading', '') + + self.results = [Result(elem) for elem in json.get('Results',[])] + self.related = [Result(elem) for elem in + json.get('RelatedTopics',[])] + + self.abstract = Abstract(json) + self.redirect = Redirect(json) + self.definition = Definition(json) + self.answer = Answer(json) + + self.image = Image({'Result':json.get('Image','')}) + + +class Abstract(object): + + def __init__(self, json): + self.html = json.get('Abstract', '') + self.text = json.get('AbstractText', '') + self.url = json.get('AbstractURL', '') + self.source = json.get('AbstractSource') + +class Redirect(object): + + def __init__(self, json): + self.url = json.get('Redirect', '') + +class Result(object): + + def __init__(self, json): + self.topics = json.get('Topics', []) + if self.topics: + self.topics = [Result(t) for t in self.topics] + return + self.html = json.get('Result') + self.text = json.get('Text') + self.url = json.get('FirstURL') + + icon_json = json.get('Icon') + if icon_json is not None: + self.icon = Image(icon_json) + else: + self.icon = None + + +class Image(object): + + def __init__(self, json): + self.url = json.get('Result') + self.height = json.get('Height', None) + self.width = json.get('Width', None) + + +class Answer(object): + + def __init__(self, json): + self.text = json.get('Answer') + self.type = json.get('AnswerType', '') + +class Definition(object): + def __init__(self, json): + self.text = json.get('Definition','') + self.url = json.get('DefinitionURL') + self.source = json.get('DefinitionSource') + + +def get_zci(q, web_fallback=True, priority=['answer', 'abstract', 'related.0', 'definition'], urls=True, **kwargs): + '''A helper method to get a single (and hopefully the best) ZCI result. + priority=list can be used to set the order in which fields will be checked for answers. + Use web_fallback=True to fall back to grabbing the first web result. + passed to query. This method will fall back to 'Sorry, no results.' + if it cannot find anything.''' + + ddg = query('\\'+q, **kwargs) + response = '' + + for p in priority: + ps = p.split('.') + type = ps[0] + index = int(ps[1]) if len(ps) > 1 else None + + result = getattr(ddg, type) + if index is not None: + if not hasattr(result, '__getitem__'): raise TypeError('%s field is not indexable' % type) + result = result[index] if len(result) > index else None + if not result: continue + + if result.text: response = result.text + if result.text and hasattr(result,'url') and urls: + if result.url: response += ' (%s)' % result.url + if response: break + + # if there still isn't anything, try to get the first web result + if not response and web_fallback: + if ddg.redirect.url: + response = ddg.redirect.url + + # final fallback + if not response: + response = 'Sorry, no results.' + + return response + +def main(): + if len(sys.argv) > 1: + q = query(' '.join(sys.argv[1:])) + keys = q.json.keys() + keys.sort() + for key in keys: + sys.stdout.write(key) + if type(q.json[key]) in [str,unicode]: print(':', q.json[key]) + else: + sys.stdout.write('\n') + for i in q.json[key]: print('\t',i) + else: + print('Usage: %s [query]' % sys.argv[0]) diff --git a/Code/irc/evil.py b/Code/irc/evil.py new file mode 100644 index 0000000..ac6af43 --- /dev/null +++ b/Code/irc/evil.py @@ -0,0 +1,6 @@ +import random + +def get_thing(): + file = "/home/krowbar/logs/evildata.txt" + thing = "" + return "If I Ever Become an Evil Overlord: " + random.choice(list(open(file))).rstrip() diff --git a/Code/irc/puzzle.py b/Code/irc/puzzle.py index cb94c38..8fe5481 100644 --- a/Code/irc/puzzle.py +++ b/Code/irc/puzzle.py @@ -37,8 +37,8 @@ def make_puzzle(): elif roll == 5: p1 = primes[random.randrange(0,len(primes))] p2 = primes[random.randrange(0,len(primes))] - answer = str(p1) + ',' + str(p2) - puzzle += p.number_to_words(p1 * p2) + " when factored into its two primes (answer in the form of the two primes with a comman between)" + answer = str(min(p1,p2)) + ',' + str(max(p1,p2)) + puzzle += p.number_to_words(p1 * p2) + " when factored into its two primes (answer in the form of the two primes with a comma between)" puzzle += "? (Answer with numbers)" diff --git a/Code/irc/tildescores.txt b/Code/irc/tildescores.txt index 48ac6db..2783a53 100644 --- a/Code/irc/tildescores.txt +++ b/Code/irc/tildescores.txt @@ -1,14 +1,14 @@ -krowbar&^%336&^%1452540446 +krowbar&^%399&^%1454593921 karlen&^%272&^%1449500011 endorphant&^%682&^%1444775660 jumblesale&^%24&^%1426171214 -marcus&^%834&^%1452521269 +marcus&^%877&^%1454436882 papa&^%179&^%1438878499 epicmorphism&^%5&^%1421937744 audy&^%78&^%1442345315 kc&^%18&^%1422326056 vilmibm&^%9&^%1445468087 -cmr&^%1074&^%1451719260 +cmr&^%1131&^%1454335852 imt&^%519&^%1424087616 cndorphant&^%788&^%1424094192 rain&^%17&^%1422310975 @@ -28,11 +28,13 @@ reppard&^%11&^%1437512059 jesse&^%6&^%1437569027 khoi&^%3&^%1438044039 sanqui&^%4&^%1438184911 -endorphan&^%57&^%1450367628 +endorphan&^%64&^%1452614950 cndorphbo&^%2&^%1447862524 santi&^%3&^%1447873216 insom&^%1&^%1450346059 tahnok&^%3&^%1450457276 -nilsding&^%8&^%1452449452 +nilsding&^%12&^%1454100197 vypr&^%3&^%1452470872 -synergian&^%1&^%1452541847 +synergian&^%21&^%1454583808 +dheeraj&^%2&^%1454438936 +demobot&^%6&^%1454439605 diff --git a/Code/irc/topics_#bots.txt b/Code/irc/topics_#bots.txt index 19eb8b1..e7a879a 100644 --- a/Code/irc/topics_#bots.txt +++ b/Code/irc/topics_#bots.txt @@ -18,3 +18,5 @@ 1444203916&^%cmr&^%http://tilde.town/~wiki/ircbots.html | cndorphbot: 1447252215&^%krowbar&^%#bots, the last bastion of the free 1451487092&^%krowbar&^%Bots rule! Users drool! +1453394948&^%krowbar&^%We'll leave it to the future to resolve the present +1453924207&^%krowbar&^%The best things happen when you're parsing diff --git a/Code/irc/topics_#tildetown.txt b/Code/irc/topics_#tildetown.txt index 7d587c7..6777306 100644 --- a/Code/irc/topics_#tildetown.txt +++ b/Code/irc/topics_#tildetown.txt @@ -130,3 +130,4 @@ 1449698715&^%vilmibm&^%hack the planet (with feels) 1451971379&^%vilmibm&^%let's talk about html & feels | welcome new users! 1452017977&^%vilmibm&^%let's talk about html & feels! | add yrself to the map of townies! http://tilde.town/~bear/where.html +1453427743&^%vilmibm&^%WHAT MOVIE SHOULD WE WATCH IN ASCII ON MOVIE NIGHT? | add yrself to the map http://tilde.town/~bear/where.html diff --git a/Code/irc/topicscores.txt b/Code/irc/topicscores.txt index 362e7a0..8926bf0 100644 --- a/Code/irc/topicscores.txt +++ b/Code/irc/topicscores.txt @@ -1,5 +1,5 @@ -krowbar&^%7&^%17 -vilmibm&^%0&^%19 +krowbar&^%9&^%19 +vilmibm&^%0&^%20 hardmath123&^%0&^%6 joe&^%1&^%1jumblesale audiodude&^%1&^%0 diff --git a/Code/irc/tumblr.py b/Code/irc/tumblr.py new file mode 100644 index 0000000..6e43aad --- /dev/null +++ b/Code/irc/tumblr.py @@ -0,0 +1,23 @@ +import urllib +from bs4 import BeautifulSoup +import random +import re + +def tumble(url): + #Find the max pages + soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser') + pages = soup.findAll('span', 'page-numbers')[0].text.split('/')[1] #this could totally fail several ways + page = random.randrange(1, int(pages)+1) + + #Parse a page + soup = BeautifulSoup(urllib.urlopen(url + '/page/' + str(page)).read(), 'html.parser') + article = random.choice(soup.findAll('article')) + quote = article.find('blockquote').text.replace('\n',''); + if len(article.find('footer').findAll('ul')) > 1: + quote += re.sub('\n+', ' ', article.find('footer').findAll('ul')[0].text); #the hash tags + quote += '(' + re.sub('\n+', ' ', article.find('footer').findAll('ul')[1].text) + ')'; #and the date and notes + else: + quote += '(' + re.sub('\n+', ' ', article.find('footer').findAll('ul')[0].text) + ')'; #just the date and notes + + return quote.encode('ascii', 'ignore') + diff --git a/Code/irc/welch.py b/Code/irc/welch.py new file mode 100644 index 0000000..eacf87b --- /dev/null +++ b/Code/irc/welch.py @@ -0,0 +1,6 @@ +import random + +def get_thing(): + file = "/home/krowbar/logs/welchdata.txt" + thing = "" + return "Thing Mr. Welch can no longer do in a RPG #" + random.choice(list(open(file))).rstrip() diff --git a/Code/irc/xkcdApropos.py b/Code/irc/xkcdApropos.py new file mode 100644 index 0000000..a3ae2f2 --- /dev/null +++ b/Code/irc/xkcdApropos.py @@ -0,0 +1,24 @@ +import duckduckgo +import urllib +from bs4 import BeautifulSoup + +def xkcd(query): + res = duckduckgo.get_zci('site:xkcd.com ' + query); + title = ""; + try: #ddg returns a url for these searches. i want a title as well + title = BeautifulSoup(urllib.urlopen(res).read(), 'html.parser').title.text + except: + pass #just swallow the error. maybe the result wasn't a url or something else bad happened + return (((title + ' - ') if title else '') + res).encode('ascii', 'ignore') + +def xkcd_links(query): + url = "https://duckduckgo.com/html/?q=site%3Axkcd.com+" + query.replace(' ', '+') + soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser') + links = filter(lambda a: a[0:8] == 'xkcd.com', [a.text.strip() for a in soup.find_all("div", class_="url")]) + def pretty_link(url): + data = BeautifulSoup(urllib.urlopen('http://'+url).read(), 'html.parser') + title = data.title.text if data.title else '' + return (title + ' - ' + url) if title else url + + links = map(lambda url: pretty_link(url), links) + return links diff --git a/Code/python/chatbesties.py b/Code/python/chatbesties.py new file mode 100644 index 0000000..aef363b --- /dev/null +++ b/Code/python/chatbesties.py @@ -0,0 +1,105 @@ +#!/usr/bin/python +import fileinput +import json +import time +import calendar +import shutil +import re +import math +import operator + +MAX_NODES = 3 + +logfile = "/home/jumblesale/Code/irc/log" +outfile = "/home/krowbar/logs/chatBesties.json" +outCircle = "/home/krowbar/logs/chatcircle.json" +userData = {} #hash keyed by "user" that contains a hash of mentioned other users with count +nameFix = { + 'jumblesal': 'jumblesale', + 'hardmath1': 'kc', + 'hardmath123': 'kc', + 'bendorphan': 'endorphant', + 'endorphan': 'endorphant', + 'synergian': 'synergiance' + } + +users = [] +#Get a list of all user names by checking the logs for people who have said things +with open(logfile, "r") as log: + for line in log: + try: + time, user, message = line.split("\t", 3) + if nameFix.has_key(user): + user = nameFix[user] + else: + user = user.lower() + + if user not in users: + users.append(user) + except ValueError: + continue #There are some bad lines in the log file that we'll ignore if we can't parse + +d3data = {} +d3data['nodes'] = [] + +#re-read the log and this time look for instances of user names in messages +with open(logfile, "r") as log: + for line in log: + try: + time, user, message = line.split("\t", 3) + if nameFix.has_key(user): + user = nameFix[user] + else: + user = user.lower() + except ValueError: + continue #There are some bad lines in the log file that we'll ignore if we can't parse + for word in message.split(' '): + word = re.sub('[^A-Za-z0-9]+', '', word) + if word in users: #SOMEONE MENTIONED SOMEONE + if userData.has_key(user): #This user is already set up + if userData[user]['data'].has_key(word): #This user has mentioned this person before + userData[user]['data'][word] += 1 + else: #This user never mentioned this person before + userData[user]['data'][word] = 1 + else: #This user was never set up + userData[user] = {} #make it a dictionary! + userData[user]['data'] = {} + userData[user]['data'][word] = 1 + userData[user]['id'] = len(d3data['nodes']) #so we know how to match people during the links phase + d3data['nodes'].append({"name": user, "group": 1}) + if not userData.has_key(word): #check if the target has not been set up + userData[word] = {} + userData[word]['data'] = {} + userData[word]['id'] = len(d3data['nodes']) + d3data['nodes'].append({"name": word, "group": 1}) + +d3data['links'] = [] +#Now connect all the pople to their stuff +for user, values in userData.iteritems(): + besties = sorted(values['data'].items(), key=operator.itemgetter(1), reverse=True)[0:MAX_NODES] #ONLY the top 5 besties + for target, score in besties: + try: + print "Adding link for " + user + " (" + str(values['id']) + ") to " + target + " (" + str(userData[target]['id']) + ") for " + str(score) + d3data['links'].append({"source": values['id'], "target": userData[target]['id'], "value": math.ceil(math.sqrt(score))}) + except KeyError: + print "Error when trying to link " + user + " to " + target + continue + if len(values['data']) > MAX_NODES: + print "...ignoring " + str(len(values['data']) - MAX_NODES) + " more connections" + +d3Circle = {} +d3Circle['names'] = [''] * len(userData) +d3Circle['matrix'] = [[0] * len(userData)] * len(userData) + +for user, values in userData.iteritems(): + d3Circle['names'][values['id']] = user + for name, score in values['data'].iteritems(): + d3Circle['matrix'][values['id']][userData[name]['id']] = score if score > 1 else 0 + +with open(outfile + ".tmp", "w") as tmpFile: + tmpFile.write(json.dumps(d3data)) +shutil.move(outfile + ".tmp", outfile) + +with open(outCircle + ".tmp", "w") as tmpFile: + tmpFile.write(json.dumps(d3Circle)) +shutil.move(outCircle + ".tmp", outCircle) diff --git a/public_html/chatchecker/index.html b/public_html/chatchecker/index.html index 181d822..b07a913 100644 --- a/public_html/chatchecker/index.html +++ b/public_html/chatchecker/index.html @@ -22,7 +22,8 @@ charset="utf-8">--> data.push([user, d, d]); }) }); - google.setOnLoadCallback(drawChart); + //google.setOnLoadCallback(drawChart); + $(drawChart); }); function drawChart() { diff --git a/public_html/chatstats/index.html b/public_html/chatstats/index.html index 4582ce0..1e6fa24 100644 --- a/public_html/chatstats/index.html +++ b/public_html/chatstats/index.html @@ -1,5 +1,5 @@ - + IRC chat stats @@ -12,6 +12,7 @@ charset="utf-8">--> google.load("visualization", "1.1", {packages:["table"]}); data = []; + jQuery.getJSON("/~krowbar/data/chatStats.json", function(json) { now = new Date(); nowSec = Math.round(now.getTime()/1000) @@ -27,12 +28,15 @@ charset="utf-8">--> Number((userData.responseTime / (userData.mentions ? userData.mentions : 1) / 60).toFixed(2)), ]); }); - google.setOnLoadCallback(drawTable); + console.log("* Loaded the data!"); + //google.setOnLoadCallback(drawTable); + $(drawTable) }); function drawTable() { var dataTable = new google.visualization.DataTable(); + var userFormatter = new google.visualization.PatternFormat('{0}'); var minFormatter = new google.visualization.NumberFormat({pattern: '##.## minutes'}); var dayFormatter = new google.visualization.NumberFormat({pattern: '## days'}); var wordFormatter = new google.visualization.NumberFormat({pattern: '##.## words'}); @@ -40,23 +44,24 @@ charset="utf-8">--> var streakFormatter = new google.visualization.NumberFormat({pattern: '## lines'}); var mentionsFormatter = new google.visualization.NumberFormat({pattern: '## mentions'}); - dataTable.addColumn('string', 'User'); //col0 - dataTable.addColumn('datetime', 'First Spoke'); //col1 - dataTable.addColumn('datetime', 'Last Spoke'); //col2 - dataTable.addColumn('number', 'Total Time'); //col3 - dataTable.addColumn('number', 'Active on'); //col4 - dataTable.addColumn('number', 'Active Ratio');//col5 - dataTable.addColumn('number', 'Lines'); //col6 - dataTable.addColumn('number', 'Words'); //col7 - dataTable.addColumn('number', 'per Line'); //col8 - dataTable.addColumn('number', 'Characters'); //col9 - dataTable.addColumn('number', 'per Line'); //col10 - dataTable.addColumn('number', 'Chat Streak'); //col11 - dataTable.addColumn('number', 'Popularity'); //col12 - dataTable.addColumn('number', 'Bot Use'); //col13 - dataTable.addColumn('number', 'Avg response time'); //col14 + dataTable.addColumn('string', 'User'); //col0 + dataTable.addColumn('datetime', 'First Spoke'); //col1 + dataTable.addColumn('datetime', 'Last Spoke'); //col2 + dataTable.addColumn('number', 'Total'); //col3 + dataTable.addColumn('number', 'Active on'); //col4 + dataTable.addColumn('number', 'Ratio'); //col5 + dataTable.addColumn('number', 'Lines'); //col6 + dataTable.addColumn('number', 'Words'); //col7 + dataTable.addColumn('number', 'per Line'); //col8 + dataTable.addColumn('number', 'Characters'); //col9 + dataTable.addColumn('number', 'per Line'); //col10 + dataTable.addColumn('number', 'Chat Streak'); //col11 + dataTable.addColumn('number', 'Popularity'); //col12 + dataTable.addColumn('number', 'Bot Use'); //col13 + dataTable.addColumn('number', 'Response time'); //col14 dataTable.addRows(data); + userFormatter.format(dataTable, [0]); dayFormatter.format(dataTable, 3); dayFormatter.format(dataTable, 4); wordFormatter.format(dataTable, 8); @@ -64,10 +69,12 @@ charset="utf-8">--> streakFormatter.format(dataTable, 11); mentionsFormatter.format(dataTable, 12); minFormatter.format(dataTable, 14); + console.log("* Set up the columns!"); var table = new google.visualization.Table(document.getElementById('statTable')); - table.draw(dataTable, {showRowNumber: false, width:'95%', height: '60%', sortColumn:2, sortAscending:false}); + table.draw(dataTable, {showRowNumber: false, width:'95%', height: '60%', sortColumn:2, sortAscending:false, allowHtml: true}); + console.log("* Drew the tables! (I hope.)"); } diff --git a/public_html/du/index.html b/public_html/du/index.html index b627b7d..5a11a58 100644 --- a/public_html/du/index.html +++ b/public_html/du/index.html @@ -49,6 +49,9 @@ linedata.addColumn('date', 'Date'); var userData = {}; _.forEach(json, function(set, idx) { + //only display 1/8 the points. (every 2 days instead of every 6 hours) page is loading too slow + //maybe i could add something to show more points but we're not losing too much granularity for the speed we gain + if(idx % 8 != 0) return; _.forEach(set.data, function(point) { if(point.du > 2000) { //the 'interesting' threshold is set at 20000kb if(!userData[point.user]) { @@ -63,6 +66,7 @@ }) }) _.forEach(json, function(set,idx) { + if(idx % 8 != 0) return; var d = new Date(0); d.setUTCSeconds(set.date); linedata.addRow([d].concat(_.map(userData, function(user) { return user[idx];}))); diff --git a/public_html/json/css/annotated.css b/public_html/json/css/annotated.css new file mode 100644 index 0000000..ac27638 --- /dev/null +++ b/public_html/json/css/annotated.css @@ -0,0 +1,46 @@ +.jsondiffpatch-annotated-delta { + font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier, monospace; + font-size: 12px; + margin: 0; + padding: 0 0 0 12px; + display: inline-block; +} +.jsondiffpatch-annotated-delta pre { + font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier, monospace; + font-size: 12px; + margin: 0; + padding: 0; + display: inline-block; +} +.jsondiffpatch-annotated-delta td { + margin: 0; + padding: 0; +} +.jsondiffpatch-annotated-delta td pre:hover { + font-weight: bold; +} +td.jsondiffpatch-delta-note { + font-style: italic; + padding-left: 10px; +} +.jsondiffpatch-delta-note > div { + margin: 0; + padding: 0; +} +.jsondiffpatch-delta-note pre { + font-style: normal; +} +.jsondiffpatch-annotated-delta .jsondiffpatch-delta-note { + color: #777; +} +.jsondiffpatch-annotated-delta tr:hover { + background: #ffc; +} +.jsondiffpatch-annotated-delta tr:hover > td.jsondiffpatch-delta-note { + color: black; +} +.jsondiffpatch-error { + background: red; + color: white; + font-weight: bold; +} diff --git a/public_html/json/css/html.css b/public_html/json/css/html.css new file mode 100644 index 0000000..375f3a9 --- /dev/null +++ b/public_html/json/css/html.css @@ -0,0 +1,149 @@ +.jsondiffpatch-delta { + font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier, monospace; + font-size: 12px; + margin: 0; + padding: 0 0 0 12px; + display: inline-block; +} +.jsondiffpatch-delta pre { + font-family: 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Courier, monospace; + font-size: 12px; + margin: 0; + padding: 0; + display: inline-block; +} +ul.jsondiffpatch-delta { + list-style-type: none; + padding: 0 0 0 20px; + margin: 0; +} +.jsondiffpatch-delta ul { + list-style-type: none; + padding: 0 0 0 20px; + margin: 0; +} +.jsondiffpatch-added .jsondiffpatch-property-name, +.jsondiffpatch-added .jsondiffpatch-value pre, +.jsondiffpatch-modified .jsondiffpatch-right-value pre, +.jsondiffpatch-textdiff-added { + background: #bbffbb; +} +.jsondiffpatch-deleted .jsondiffpatch-property-name, +.jsondiffpatch-deleted pre, +.jsondiffpatch-modified .jsondiffpatch-left-value pre, +.jsondiffpatch-textdiff-deleted { + background: #ffbbbb; + text-decoration: line-through; +} +.jsondiffpatch-unchanged, +.jsondiffpatch-movedestination { + color: gray; +} +.jsondiffpatch-unchanged, +.jsondiffpatch-movedestination > .jsondiffpatch-value { + transition: all 0.5s; + -webkit-transition: all 0.5s; + overflow-y: hidden; +} +.jsondiffpatch-unchanged-showing .jsondiffpatch-unchanged, +.jsondiffpatch-unchanged-showing .jsondiffpatch-movedestination > .jsondiffpatch-value { + max-height: 100px; +} +.jsondiffpatch-unchanged-hidden .jsondiffpatch-unchanged, +.jsondiffpatch-unchanged-hidden .jsondiffpatch-movedestination > .jsondiffpatch-value { + max-height: 0; +} +.jsondiffpatch-unchanged-hiding .jsondiffpatch-movedestination > .jsondiffpatch-value, +.jsondiffpatch-unchanged-hidden .jsondiffpatch-movedestination > .jsondiffpatch-value { + display: block; +} +.jsondiffpatch-unchanged-visible .jsondiffpatch-unchanged, +.jsondiffpatch-unchanged-visible .jsondiffpatch-movedestination > .jsondiffpatch-value { + max-height: 100px; +} +.jsondiffpatch-unchanged-hiding .jsondiffpatch-unchanged, +.jsondiffpatch-unchanged-hiding .jsondiffpatch-movedestination > .jsondiffpatch-value { + max-height: 0; +} +.jsondiffpatch-unchanged-showing .jsondiffpatch-arrow, +.jsondiffpatch-unchanged-hiding .jsondiffpatch-arrow { + display: none; +} +.jsondiffpatch-value { + display: inline-block; +} +.jsondiffpatch-property-name { + display: inline-block; + padding-right: 5px; + vertical-align: top; +} +.jsondiffpatch-property-name:after { + content: ': '; +} +.jsondiffpatch-child-node-type-array > .jsondiffpatch-property-name:after { + content: ': ['; +} +.jsondiffpatch-child-node-type-array:after { + content: '],'; +} +div.jsondiffpatch-child-node-type-array:before { + content: '['; +} +div.jsondiffpatch-child-node-type-array:after { + content: ']'; +} +.jsondiffpatch-child-node-type-object > .jsondiffpatch-property-name:after { + content: ': {'; +} +.jsondiffpatch-child-node-type-object:after { + content: '},'; +} +div.jsondiffpatch-child-node-type-object:before { + content: '{'; +} +div.jsondiffpatch-child-node-type-object:after { + content: '}'; +} +.jsondiffpatch-value pre:after { + content: ','; +} +li:last-child > .jsondiffpatch-value pre:after, +.jsondiffpatch-modified > .jsondiffpatch-left-value pre:after { + content: ''; +} +.jsondiffpatch-modified .jsondiffpatch-value { + display: inline-block; +} +.jsondiffpatch-modified .jsondiffpatch-right-value { + margin-left: 5px; +} +.jsondiffpatch-moved .jsondiffpatch-value { + display: none; +} +.jsondiffpatch-moved .jsondiffpatch-moved-destination { + display: inline-block; + background: #ffffbb; + color: #888; +} +.jsondiffpatch-moved .jsondiffpatch-moved-destination:before { + content: ' => '; +} +ul.jsondiffpatch-textdiff { + padding: 0; +} +.jsondiffpatch-textdiff-location { + color: #bbb; + display: inline-block; + min-width: 60px; +} +.jsondiffpatch-textdiff-line { + display: inline-block; +} +.jsondiffpatch-textdiff-line-number:after { + content: ','; +} +.jsondiffpatch-error { + background: red; + color: white; + font-weight: bold; +} diff --git a/public_html/json/data.json b/public_html/json/data.json index fe7bc6a..d1fc1cb 100644 --- a/public_html/json/data.json +++ b/public_html/json/data.json @@ -2,4 +2,4 @@ "data1": "foo", "data2": "bar", "data3": ["foo","bar","baz"] -}; +} diff --git a/public_html/json/data2.json b/public_html/json/data2.json new file mode 100644 index 0000000..85c2950 --- /dev/null +++ b/public_html/json/data2.json @@ -0,0 +1,5 @@ +{ + "data1": "foo", + "data4": "banana", + "data3": ["foo","bat","baz","bang"] +} diff --git a/public_html/json/index.html b/public_html/json/index.html new file mode 100644 index 0000000..5ea02f3 --- /dev/null +++ b/public_html/json/index.html @@ -0,0 +1,23 @@ + + + +JSON diff POC + + + + + + +
HERE'S SOME STUFF!
+ + + + + + diff --git a/public_html/json/js/jsondiffpatch-formatters.min.js b/public_html/json/js/jsondiffpatch-formatters.min.js new file mode 100644 index 0000000..0d726db --- /dev/null +++ b/public_html/json/js/jsondiffpatch-formatters.min.js @@ -0,0 +1,17 @@ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),(f.jsondiffpatch||(f.jsondiffpatch={})).formatters=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o
'),t.out(t.indentPad),t.out('
'),t.out(e),t.out('
'),t.out(n),t.out("
")}},AnnotatedFormatter.prototype.typeFormattterErrorFormatter=function(t,e){t.row("",'
'+e+"
")},AnnotatedFormatter.prototype.formatTextDiffString=function(t,e){var n=this.parseTextDiff(e);t.out('")},AnnotatedFormatter.prototype.rootBegin=function(t,e,n){t.out(''),"node"===e&&(t.row("{"),t.indent()),"array"===n&&t.row('"_t": "a",',"Array delta (member names indicate array indices)")},AnnotatedFormatter.prototype.rootEnd=function(t,e){"node"===e&&(t.indent(-1),t.row("}")),t.out("
")},AnnotatedFormatter.prototype.nodeBegin=function(t,e,n,o,r){t.row("""+e+"": {"),"node"===o&&t.indent(),"array"===r&&t.row('"_t": "a",',"Array delta (member names indicate array indices)")},AnnotatedFormatter.prototype.nodeEnd=function(t,e,n,o,r,a){"node"===o&&t.indent(-1),t.row("}"+(a?"":","))},AnnotatedFormatter.prototype.format_unchanged=function(){},AnnotatedFormatter.prototype.format_movedestination=function(){},AnnotatedFormatter.prototype.format_node=function(t,e,n){this.formatDeltaChildren(t,e,n)};var wrapPropertyName=function(t){return'
"'+t+""
"},deltaAnnotations={added:function(t,e,n,o){var r="
([newValue])
";return"undefined"==typeof o?"new value"+r:"number"==typeof o?"insert at index "+o+r:"add property "+wrapPropertyName(o)+r},modified:function(t,e,n,o){var r="
([previousValue, newValue])
";return"undefined"==typeof o?"modify value"+r:"number"==typeof o?"modify at index "+o+r:"modify property "+wrapPropertyName(o)+r},deleted:function(t,e,n,o){var r="
([previousValue, 0, 0])
";return"undefined"==typeof o?"delete value"+r:"number"==typeof o?"remove index "+o+r:"delete property "+wrapPropertyName(o)+r},moved:function(t,e,n,o){return'move from index '+o+' to index '+t[1]+""},textdiff:function(t,e,n,o){var r="undefined"==typeof o?"":"number"==typeof o?" at index "+o:" at property "+wrapPropertyName(o);return"text diff"+r+', format is a variation of Unidiff'}},formatAnyChange=function(t,e){var n=this.getDeltaType(e),o=deltaAnnotations[n],r=o&&o.apply(o,Array.prototype.slice.call(arguments,1)),a=JSON.stringify(e,null,2);"textdiff"===n&&(a=a.split("\\n").join('\\n"+\n "')),t.indent(),t.row(a,r),t.indent(-1)};AnnotatedFormatter.prototype.format_added=formatAnyChange,AnnotatedFormatter.prototype.format_modified=formatAnyChange,AnnotatedFormatter.prototype.format_deleted=formatAnyChange,AnnotatedFormatter.prototype.format_moved=formatAnyChange,AnnotatedFormatter.prototype.format_textdiff=formatAnyChange,exports.AnnotatedFormatter=AnnotatedFormatter;var defaultInstance;exports.format=function(t,e){return defaultInstance||(defaultInstance=new AnnotatedFormatter),defaultInstance.format(t,e)}; +},{"./base":4}],4:[function(require,module,exports){ +var isArray="function"==typeof Array.isArray?Array.isArray:function(e){return e instanceof Array},getObjectKeys="function"==typeof Object.keys?function(e){return Object.keys(e)}:function(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r);return t},trimUnderscore=function(e){return"_"===e.substr(0,1)?e.slice(1):e},arrayKeyToSortNumber=function(e){return"_t"===e?-1:"_"===e.substr(0,1)?parseInt(e.slice(1),10):parseInt(e,10)+.1},arrayKeyComparer=function(e,t){return arrayKeyToSortNumber(e)-arrayKeyToSortNumber(t)},BaseFormatter=function(){};BaseFormatter.prototype.format=function(e,t){var r={};return this.prepareContext(r),this.recurse(r,e,t),this.finalize(r)},BaseFormatter.prototype.prepareContext=function(e){e.buffer=[],e.out=function(){this.buffer.push.apply(this.buffer,arguments)}},BaseFormatter.prototype.typeFormattterNotFound=function(e,t){throw new Error("cannot format delta type: "+t)},BaseFormatter.prototype.typeFormattterErrorFormatter=function(e,t){return t.toString()},BaseFormatter.prototype.finalize=function(e){return isArray(e.buffer)?e.buffer.join(""):void 0},BaseFormatter.prototype.recurse=function(e,t,r,o,n,a,i){var f=t&&a,s=f?a.value:r;if("undefined"!=typeof t||"undefined"!=typeof o){var u=this.getDeltaType(t,a),p="node"===u?"a"===t._t?"array":"object":"";"undefined"!=typeof o?this.nodeBegin(e,o,n,u,p,i):this.rootBegin(e,u,p);var y;try{y=this["format_"+u]||this.typeFormattterNotFound(e,u),y.call(this,e,t,s,o,n,a)}catch(d){this.typeFormattterErrorFormatter(e,d,t,s,o,n,a),"undefined"!=typeof console&&console.error&&console.error(d.stack)}"undefined"!=typeof o?this.nodeEnd(e,o,n,u,p,i):this.rootEnd(e,u,p)}},BaseFormatter.prototype.formatDeltaChildren=function(e,t,r){var o=this;this.forEachDeltaKey(t,r,function(n,a,i,f){o.recurse(e,t[n],r?r[a]:void 0,n,a,i,f)})},BaseFormatter.prototype.forEachDeltaKey=function(e,t,r){var o,n=getObjectKeys(e),a="a"===e._t,i={};if("undefined"!=typeof t)for(o in t)"undefined"!=typeof e[o]||a&&"undefined"!=typeof e["_"+o]||n.push(o);for(o in e){var f=e[o];isArray(f)&&3===f[2]&&(i[f[1].toString()]={key:o,value:t&&t[parseInt(o.substr(1))]},this.includeMoveDestinations!==!1&&"undefined"==typeof t&&"undefined"==typeof e[f[1]]&&n.push(f[1].toString()))}a?n.sort(arrayKeyComparer):n.sort();for(var s=0,u=n.length;u>s;s++){var p=n[s];if(!a||"_t"!==p){var y=a?"number"==typeof p?p:parseInt(trimUnderscore(p),10):p,d=s===u-1;r(p,y,i[y],d)}}},BaseFormatter.prototype.getDeltaType=function(e,t){if("undefined"==typeof e)return"undefined"!=typeof t?"movedestination":"unchanged";if(isArray(e)){if(1===e.length)return"added";if(2===e.length)return"modified";if(3===e.length&&0===e[2])return"deleted";if(3===e.length&&2===e[2])return"textdiff";if(3===e.length&&3===e[2])return"moved"}else if("object"==typeof e)return"node";return"unknown"},BaseFormatter.prototype.parseTextDiff=function(e){for(var t=[],r=e.split("\n@@ "),o=0,n=r.length;n>o;o++){var a=r[o],i={pieces:[]},f=/^(?:@@ )?[-+]?(\d+),(\d+)/.exec(a).slice(1);i.location={line:f[0],chr:f[1]};for(var s=a.split("\n").slice(1),u=0,p=s.length;p>u;u++){var y=s[u];if(y.length){var d={type:"context"};"+"===y.substr(0,1)?d.type="added":"-"===y.substr(0,1)&&(d.type="deleted"),d.text=y.slice(1),i.pieces.push(d)}}t.push(i)}return t},exports.BaseFormatter=BaseFormatter; +},{}],5:[function(require,module,exports){ +function htmlEscape(t){for(var e=t,o=[[/&/g,"&"],[//g,">"],[/'/g,"'"],[/"/g,"""]],a=0;a'+e+"")},HtmlFormatter.prototype.formatValue=function(t,e){t.out("
"+htmlEscape(JSON.stringify(e,null,2))+"
")},HtmlFormatter.prototype.formatTextDiffString=function(t,e){var o=this.parseTextDiff(e);t.out('
    ');for(var a=0,r=o.length;r>a;a++){var i=o[a];t.out('
  • '+i.location.line+''+i.location.chr+'
    ');for(var n=i.pieces,s=0,d=n.length;d>s;s++){var f=n[s];t.out(''+htmlEscape(unescape(f.text))+"")}t.out("
  • ")}t.out("
")};var adjustArrows=function(t){t=t||document;var e=function(t){return t.textContent||t.innerText},o=function(t,e,o){for(var a=t.querySelectorAll(e),r=0,i=a.length;i>r;r++)o(a[r])},a=function(t,e){for(var o=0,a=t.children.length;a>o;o++)e(t.children[o],o)};o(t,".jsondiffpatch-arrow",function(t){var o=t.parentNode,r=t.children[0],i=r.children[1];r.style.display="none";var n,s=e(o.querySelector(".jsondiffpatch-moved-destination")),d=o.parentNode;if(a(d,function(t){t.getAttribute("data-key")===s&&(n=t)}),n)try{var f=n.offsetTop-o.offsetTop;r.setAttribute("height",Math.abs(f)+6),t.style.top=-8+(f>0?0:f)+"px";var l=f>0?"M30,0 Q-10,"+Math.round(f/2)+" 26,"+(f-4):"M30,"+-f+" Q-10,"+Math.round(-f/2)+" 26,4";i.setAttribute("d",l),r.style.display=""}catch(c){return}})};HtmlFormatter.prototype.rootBegin=function(t,e,o){var a="jsondiffpatch-"+e+(o?" jsondiffpatch-child-node-type-"+o:"");t.out('
')},HtmlFormatter.prototype.rootEnd=function(t){t.out("
"+(t.hasArrows?'":""))},HtmlFormatter.prototype.nodeBegin=function(t,e,o,a,r){var i="jsondiffpatch-"+a+(r?" jsondiffpatch-child-node-type-"+r:"");t.out('
  • '+o+"
    ")},HtmlFormatter.prototype.nodeEnd=function(t){t.out("
  • ")},HtmlFormatter.prototype.format_unchanged=function(t,e,o){"undefined"!=typeof o&&(t.out('
    '),this.formatValue(t,o),t.out("
    "))},HtmlFormatter.prototype.format_movedestination=function(t,e,o){"undefined"!=typeof o&&(t.out('
    '),this.formatValue(t,o),t.out("
    "))},HtmlFormatter.prototype.format_node=function(t,e,o){var a="a"===e._t?"array":"object";t.out('
      '),this.formatDeltaChildren(t,e,o),t.out("
    ")},HtmlFormatter.prototype.format_added=function(t,e){t.out('
    '),this.formatValue(t,e[0]),t.out("
    ")},HtmlFormatter.prototype.format_modified=function(t,e){t.out('
    '),this.formatValue(t,e[0]),t.out('
    '),this.formatValue(t,e[1]),t.out("
    ")},HtmlFormatter.prototype.format_deleted=function(t,e){t.out('
    '),this.formatValue(t,e[0]),t.out("
    ")},HtmlFormatter.prototype.format_moved=function(t,e){t.out('
    '),this.formatValue(t,e[0]),t.out('
    '+e[1]+"
    "),t.out('
    '),t.hasArrows=!0},HtmlFormatter.prototype.format_textdiff=function(t,e){t.out('
    '),this.formatTextDiffString(t,e[0]),t.out("
    ")};var showUnchanged=function(t,e,o){var a=e||document.body,r="jsondiffpatch-unchanged-",i={showing:r+"showing",hiding:r+"hiding",visible:r+"visible",hidden:r+"hidden"},n=a.classList;if(n){if(!o)return n.remove(i.showing),n.remove(i.hiding),n.remove(i.visible),n.remove(i.hidden),void(t===!1&&n.add(i.hidden));t===!1?(n.remove(i.showing),n.add(i.visible),setTimeout(function(){n.add(i.hiding)},10)):(n.remove(i.hiding),n.add(i.showing),n.remove(i.hidden));var s=setInterval(function(){adjustArrows(a)},100);setTimeout(function(){n.remove(i.showing),n.remove(i.hiding),t===!1?(n.add(i.hidden),n.remove(i.visible)):(n.add(i.visible),n.remove(i.hidden)),setTimeout(function(){n.remove(i.visible),clearInterval(s)},o+400)},o)}},hideUnchanged=function(t,e){return showUnchanged(!1,t,e)};exports.HtmlFormatter=HtmlFormatter,exports.showUnchanged=showUnchanged,exports.hideUnchanged=hideUnchanged;var defaultInstance;exports.format=function(t,e){return defaultInstance||(defaultInstance=new HtmlFormatter),defaultInstance.format(t,e)}; +},{"./base":4}],6:[function(require,module,exports){ +var environment=require("../environment");if(exports.base=require("./base"),exports.html=require("./html"),exports.annotated=require("./annotated"),!environment.isBrowser){var consoleModuleName="./console";exports.console=require(consoleModuleName)} +},{"../environment":2,"./annotated":3,"./base":4,"./html":5}]},{},[1])(1) +}); + + +//# sourceMappingURL=jsondiffpatch-formatters.min.map \ No newline at end of file diff --git a/public_html/json/js/jsondiffpatch.min.js b/public_html/json/js/jsondiffpatch.min.js new file mode 100644 index 0000000..2da7f4c --- /dev/null +++ b/public_html/json/js/jsondiffpatch.min.js @@ -0,0 +1,37 @@ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.jsondiffpatch=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;oa;a++)for(var n=e[a],l=0;i>l;l++){var s=t[l];if(n===s)return!0}}function matchItems(e,t,r,i,a){var n=e[r],l=t[i];if(n===l)return!0;if("object"!=typeof n||"object"!=typeof l)return!1;var s=a.objectHash;if(!s)return a.matchByPosition&&r===i;var o,f;return"number"==typeof r?(a.hashCache1=a.hashCache1||[],o=a.hashCache1[r],"undefined"==typeof o&&(a.hashCache1[r]=o=s(n,r))):o=s(n),"undefined"==typeof o?!1:("number"==typeof i?(a.hashCache2=a.hashCache2||[],f=a.hashCache2[i],"undefined"==typeof f&&(a.hashCache2[i]=f=s(l,i))):f=s(l),"undefined"==typeof f?!1:o===f)}var DiffContext=require("../contexts/diff").DiffContext,PatchContext=require("../contexts/patch").PatchContext,ReverseContext=require("../contexts/reverse").ReverseContext,lcs=require("./lcs"),ARRAY_MOVE=3,isArray="function"==typeof Array.isArray?Array.isArray:function(e){return e instanceof Array},arrayIndexOf="function"==typeof Array.prototype.indexOf?function(e,t){return e.indexOf(t)}:function(e,t){for(var r=e.length,i=0;r>i;i++)if(e[i]===t)return i;return-1},diffFilter=function(e){if(e.leftIsArray){var t,r,i,a,n={objectHash:e.options&&e.options.objectHash,matchByPosition:e.options&&e.options.matchByPosition},l=0,s=0,o=e.left,f=e.right,c=o.length,h=f.length;for(c>0&&h>0&&!n.objectHash&&"boolean"!=typeof n.matchByPosition&&(n.matchByPosition=!arraysHaveMatchByRef(o,f,c,h));c>l&&h>l&&matchItems(o,f,l,l,n);)t=l,a=new DiffContext(e.left[t],e.right[t]),e.push(a,t),l++;for(;c>s+l&&h>s+l&&matchItems(o,f,c-1-s,h-1-s,n);)r=c-1-s,i=h-1-s,a=new DiffContext(e.left[r],e.right[i]),e.push(a,i),s++;var u;if(l+s===c){if(c===h)return void e.setResult(void 0).exit();for(u=u||{_t:"a"},t=l;h-s>t;t++)u[t]=[f[t]];return void e.setResult(u).exit()}if(l+s===h){for(u=u||{_t:"a"},t=l;c-s>t;t++)u["_"+t]=[o[t],0,0];return void e.setResult(u).exit()}delete n.hashCache1,delete n.hashCache2;var d=o.slice(l,c-s),v=f.slice(l,h-s),p=lcs.get(d,v,matchItems,n),y=[];for(u=u||{_t:"a"},t=l;c-s>t;t++)arrayIndexOf(p.indices1,t-l)<0&&(u["_"+t]=[o[t],0,0],y.push(t));var x=!0;e.options&&e.options.arrays&&e.options.arrays.detectMove===!1&&(x=!1);var m=!1;e.options&&e.options.arrays&&e.options.arrays.includeValueOnMove&&(m=!0);var C=y.length;for(t=l;h-s>t;t++){var R=arrayIndexOf(p.indices2,t-l);if(0>R){var A=!1;if(x&&C>0)for(var _=0;C>_;_++)if(r=y[_],matchItems(d,v,r-l,t-l,n)){u["_"+r].splice(1,2,t,ARRAY_MOVE),m||(u["_"+r][0]=""),i=t,a=new DiffContext(e.left[r],e.right[i]),e.push(a,i),y.splice(_,1),A=!0;break}A||(u[t]=[f[t]])}else r=p.indices1[R]+l,i=p.indices2[R]+l,a=new DiffContext(e.left[r],e.right[i]),e.push(a,i)}e.setResult(u).exit()}};diffFilter.filterName="arrays";var compare={numerically:function(e,t){return e-t},numericallyBy:function(e){return function(t,r){return t[e]-r[e]}}},patchFilter=function(e){if(e.nested&&"a"===e.delta._t){var t,r,i=e.delta,a=e.left,n=[],l=[],s=[];for(t in i)if("_t"!==t)if("_"===t[0]){if(0!==i[t][2]&&i[t][2]!==ARRAY_MOVE)throw new Error("only removal or move can be applied at original array indices, invalid diff type: "+i[t][2]);n.push(parseInt(t.slice(1),10))}else 1===i[t].length?l.push({index:parseInt(t,10),value:i[t][0]}):s.push({index:parseInt(t,10),delta:i[t]});for(n=n.sort(compare.numerically),t=n.length-1;t>=0;t--){r=n[t];var o=i["_"+r],f=a.splice(r,1)[0];o[2]===ARRAY_MOVE&&l.push({index:o[1],value:f})}l=l.sort(compare.numericallyBy("index"));var c=l.length;for(t=0;c>t;t++){var h=l[t];a.splice(h.index,0,h.value)}var u,d=s.length;if(d>0)for(t=0;d>t;t++){var v=s[t];u=new PatchContext(e.left[v.index],v.delta),e.push(u,v.index)}return e.children?void e.exit():void e.setResult(e.left).exit()}};patchFilter.filterName="arrays";var collectChildrenPatchFilter=function(e){if(e&&e.children&&"a"===e.delta._t){for(var t,r=e.children.length,i=0;r>i;i++)t=e.children[i],e.left[t.childName]=t.result;e.setResult(e.left).exit()}};collectChildrenPatchFilter.filterName="arraysCollectChildren";var reverseFilter=function(e){if(!e.nested)return void(e.delta[2]===ARRAY_MOVE&&(e.newName="_"+e.delta[1],e.setResult([e.delta[0],parseInt(e.childName.substr(1),10),ARRAY_MOVE]).exit()));if("a"===e.delta._t){var t,r;for(t in e.delta)"_t"!==t&&(r=new ReverseContext(e.delta[t]),e.push(r,t));e.exit()}};reverseFilter.filterName="arrays";var reverseArrayDeltaIndex=function(e,t,r){if("string"==typeof t&&"_"===t[0])return parseInt(t.substr(1),10);if(isArray(r)&&0===r[2])return"_"+t;var i=+t;for(var a in e){var n=e[a];if(isArray(n))if(n[2]===ARRAY_MOVE){var l=parseInt(a.substr(1),10),s=n[1];if(s===+t)return l;i>=l&&s>i?i++:l>=i&&i>s&&i--}else if(0===n[2]){var o=parseInt(a.substr(1),10);i>=o&&i++}else 1===n.length&&i>=a&&i--}return i},collectChildrenReverseFilter=function(e){if(e&&e.children&&"a"===e.delta._t){for(var t,r=e.children.length,i={_t:"a"},a=0;r>a;a++){t=e.children[a];var n=t.newName;"undefined"==typeof n&&(n=reverseArrayDeltaIndex(e.delta,t.childName,t.result)),i[n]!==t.result&&(i[n]=t.result)}e.setResult(i).exit()}};collectChildrenReverseFilter.filterName="arraysCollectChildren",exports.diffFilter=diffFilter,exports.patchFilter=patchFilter,exports.collectChildrenPatchFilter=collectChildrenPatchFilter,exports.reverseFilter=reverseFilter,exports.collectChildrenReverseFilter=collectChildrenReverseFilter; +},{"../contexts/diff":3,"../contexts/patch":4,"../contexts/reverse":5,"./lcs":11}],10:[function(require,module,exports){ +var diffFilter=function(t){t.left instanceof Date?(t.right instanceof Date?t.left.getTime()!==t.right.getTime()?t.setResult([t.left,t.right]):t.setResult(void 0):t.setResult([t.left,t.right]),t.exit()):t.right instanceof Date&&t.setResult([t.left,t.right]).exit()};diffFilter.filterName="dates",exports.diffFilter=diffFilter; +},{}],11:[function(require,module,exports){ +var defaultMatch=function(t,e,n,r){return t[n]===e[r]},lengthMatrix=function(t,e,n,r){var c,a,i=t.length,u=e.length,f=[i+1];for(c=0;i+1>c;c++)for(f[c]=[u+1],a=0;u+1>a;a++)f[c][a]=0;for(f.match=n,c=1;i+1>c;c++)for(a=1;u+1>a;a++)n(t,e,c-1,a-1,r)?f[c][a]=f[c-1][a-1]+1:f[c][a]=Math.max(f[c-1][a],f[c][a-1]);return f},backtrack=function(t,e,n,r,c,a){if(0===r||0===c)return{sequence:[],indices1:[],indices2:[]};if(t.match(e,n,r-1,c-1,a)){var i=backtrack(t,e,n,r-1,c-1,a);return i.sequence.push(e[r-1]),i.indices1.push(r-1),i.indices2.push(c-1),i}return t[r][c-1]>t[r-1][c]?backtrack(t,e,n,r,c-1,a):backtrack(t,e,n,r-1,c,a)},get=function(t,e,n,r){r=r||{};var c=lengthMatrix(t,e,n||defaultMatch,r),a=backtrack(c,t,e,t.length,e.length,r);return"string"==typeof t&&"string"==typeof e&&(a.sequence=a.sequence.join("")),a};exports.get=get; +},{}],12:[function(require,module,exports){ +var DiffContext=require("../contexts/diff").DiffContext,PatchContext=require("../contexts/patch").PatchContext,ReverseContext=require("../contexts/reverse").ReverseContext,collectChildrenDiffFilter=function(e){if(e&&e.children){for(var t,l=e.children.length,r=e.result,i=0;l>i;i++)t=e.children[i],"undefined"!=typeof t.result&&(r=r||{},r[t.childName]=t.result);r&&e.leftIsArray&&(r._t="a"),e.setResult(r).exit()}};collectChildrenDiffFilter.filterName="collectChildren";var objectsDiffFilter=function(e){if(!e.leftIsArray&&"object"===e.leftType){var t,l;for(t in e.left)l=new DiffContext(e.left[t],e.right[t]),e.push(l,t);for(t in e.right)"undefined"==typeof e.left[t]&&(l=new DiffContext(void 0,e.right[t]),e.push(l,t));return e.children&&0!==e.children.length?void e.exit():void e.setResult(void 0).exit()}};objectsDiffFilter.filterName="objects";var patchFilter=function(e){if(e.nested&&!e.delta._t){var t,l;for(t in e.delta)l=new PatchContext(e.left[t],e.delta[t]),e.push(l,t);e.exit()}};patchFilter.filterName="objects";var collectChildrenPatchFilter=function(e){if(e&&e.children&&!e.delta._t){for(var t,l=e.children.length,r=0;l>r;r++)t=e.children[r],e.left.hasOwnProperty(t.childName)&&void 0===t.result?delete e.left[t.childName]:e.left[t.childName]!==t.result&&(e.left[t.childName]=t.result);e.setResult(e.left).exit()}};collectChildrenPatchFilter.filterName="collectChildren";var reverseFilter=function(e){if(e.nested&&!e.delta._t){var t,l;for(t in e.delta)l=new ReverseContext(e.delta[t]),e.push(l,t);e.exit()}};reverseFilter.filterName="objects";var collectChildrenReverseFilter=function(e){if(e&&e.children&&!e.delta._t){for(var t,l=e.children.length,r={},i=0;l>i;i++)t=e.children[i],r[t.childName]!==t.result&&(r[t.childName]=t.result);e.setResult(r).exit()}};collectChildrenReverseFilter.filterName="collectChildren",exports.collectChildrenDiffFilter=collectChildrenDiffFilter,exports.objectsDiffFilter=objectsDiffFilter,exports.patchFilter=patchFilter,exports.collectChildrenPatchFilter=collectChildrenPatchFilter,exports.reverseFilter=reverseFilter,exports.collectChildrenReverseFilter=collectChildrenReverseFilter; +},{"../contexts/diff":3,"../contexts/patch":4,"../contexts/reverse":5}],13:[function(require,module,exports){ +var TEXT_DIFF=2,DEFAULT_MIN_LENGTH=60,cachedDiffPatch=null,getDiffMatchPatch=function(t){if(!cachedDiffPatch){var e;if("undefined"!=typeof diff_match_patch)e="function"==typeof diff_match_patch?new diff_match_patch:new diff_match_patch.diff_match_patch;else if("function"==typeof require)try{var i="diff_match_patch_uncompressed",f=require("../../public/external/"+i);e=new f.diff_match_patch}catch(r){e=null}if(!e){if(!t)return null;var a=new Error("text diff_match_patch library not found");throw a.diff_match_patch_not_found=!0,a}cachedDiffPatch={diff:function(t,i){return e.patch_toText(e.patch_make(t,i))},patch:function(t,i){for(var f=e.patch_apply(e.patch_fromText(i),t),r=0;re;e++){r=f[e];var o=r.slice(0,1);"@"===o?(h=d.exec(r),c=e,l=null,n=null,f[c]="@@ -"+h[3]+","+h[4]+" +"+h[1]+","+h[2]+" @@"):"+"===o?(l=e,f[e]="-"+f[e].slice(1),"+"===f[e-1].slice(0,1)&&(a=f[e],f[e]=f[e-1],f[e-1]=a)):"-"===o&&(n=e,f[e]="+"+f[e].slice(1))}return f.join("\n")},reverseFilter=function(t){t.nested||t.delta[2]===TEXT_DIFF&&t.setResult([textDeltaReverse(t.delta[0]),0,TEXT_DIFF]).exit()};reverseFilter.filterName="texts",exports.diffFilter=diffFilter,exports.patchFilter=patchFilter,exports.reverseFilter=reverseFilter; +},{}],14:[function(require,module,exports){ +var isArray="function"==typeof Array.isArray?Array.isArray:function(e){return e instanceof Array},diffFilter=function(e){if(e.left===e.right)return void e.setResult(void 0).exit();if("undefined"==typeof e.left){if("function"==typeof e.right)throw new Error("functions are not supported");return void e.setResult([e.right]).exit()}if("undefined"==typeof e.right)return void e.setResult([e.left,0,0]).exit();if("function"==typeof e.left||"function"==typeof e.right)throw new Error("functions are not supported");return e.leftType=null===e.left?"null":typeof e.left,e.rightType=null===e.right?"null":typeof e.right,e.leftType!==e.rightType?void e.setResult([e.left,e.right]).exit():"boolean"===e.leftType||"number"===e.leftType?void e.setResult([e.left,e.right]).exit():("object"===e.leftType&&(e.leftIsArray=isArray(e.left)),"object"===e.rightType&&(e.rightIsArray=isArray(e.right)),e.leftIsArray!==e.rightIsArray?void e.setResult([e.left,e.right]).exit():void 0)};diffFilter.filterName="trivial";var patchFilter=function(e){return"undefined"==typeof e.delta?void e.setResult(e.left).exit():(e.nested=!isArray(e.delta),e.nested?void 0:1===e.delta.length?void e.setResult(e.delta[0]).exit():2===e.delta.length?void e.setResult(e.delta[1]).exit():3===e.delta.length&&0===e.delta[2]?void e.setResult(void 0).exit():void 0)};patchFilter.filterName="trivial";var reverseFilter=function(e){return"undefined"==typeof e.delta?void e.setResult(e.delta).exit():(e.nested=!isArray(e.delta),e.nested?void 0:1===e.delta.length?void e.setResult([e.delta[0],0,0]).exit():2===e.delta.length?void e.setResult([e.delta[1],e.delta[0]]).exit():3===e.delta.length&&0===e.delta[2]?void e.setResult([e.delta[0]]).exit():void 0)};reverseFilter.filterName="trivial",exports.diffFilter=diffFilter,exports.patchFilter=patchFilter,exports.reverseFilter=reverseFilter; +},{}],15:[function(require,module,exports){ +var Pipe=function(t){this.name=t,this.filters=[]};Pipe.prototype.process=function(t){if(!this.processor)throw new Error("add this pipe to a processor before using it");for(var e=this.debug,r=this.filters.length,i=t,s=0;r>s;s++){var o=this.filters[s];if(e&&this.log("filter: "+o.filterName),o(i),"object"==typeof i&&i.exiting){i.exiting=!1;break}}!i.next&&this.resultCheck&&this.resultCheck(i)},Pipe.prototype.log=function(t){console.log("[jsondiffpatch] "+this.name+" pipe, "+t)},Pipe.prototype.append=function(){return this.filters.push.apply(this.filters,arguments),this},Pipe.prototype.prepend=function(){return this.filters.unshift.apply(this.filters,arguments),this},Pipe.prototype.indexOf=function(t){if(!t)throw new Error("a filter name is required");for(var e=0;e + + + + + + + + + + +
    + + +
    + +
    + +
    +
    +
    + + + diff --git a/public_html/mission/js/mission.js b/public_html/mission/js/mission.js index 4f6656a..96144ef 100644 --- a/public_html/mission/js/mission.js +++ b/public_html/mission/js/mission.js @@ -7,21 +7,21 @@ var self = this; -var adjectives = Array('Bold','Breaking','Brilliant','Crescent','Dark|Darkness','Desert|Desert','Eternal','Evening|Darkness','Final','First','Forever','Glorious','Joyful','July','Last','Liberty|Liberty','Magic|Magic','Morning|Morning','Power|Power','Phantom','Present','Roaring|Roar|Scream','Rolling','Sand','Screaming|Roar|Scream','Soaring','Standing|Stand','Star|Star','Twisted','Urgent','Utopian','Valiant'); -var nouns = Array('Action','Alert','Beauty','Claw','Darkness','Dawn','Day','Desert','Envy','Fall','Fist','Flight','Fury','Guard','Hammer','Hand','Honor','Hope','Hurricane','Liberty','Light','Lightning','Magic','Morning','October','Power','Rain','Repose','Roar','Scream','Skull','Sky','Skies','Shield','Stand','Star','Storm','Streak','Strike','Sun','Thunder','Victory','Whisper','Wind','Wrath'); -var colors = Array('Black','Blue','Brown','Gray','Green','Indego','Orange','Purple','Rainbow','Red','Scarlet','Silver','Violet','White','Yellow'); -var actors = Array('Cobra','Condor','Dragon','Eagle','Guardian','Hawk','Hydra','Jackal','King','Knight','Lady','Lion','Scorpion','Spartan','Titan','Victor','Viking','Warrior'); +var adjectives = Array('Ancient','Bold','Breaking','Brightest','Brilliant','Crescent','Dark|Darkness','Darkest|Darkness','Desert|Desert','Eternal','Evening|Darkness','Final','First','Forever','Giant|Giant','Glorious|Glory','Joyful|Joy','July','Last','Liberty|Liberty','Magic|Magic','Morning|Morning','Power|Power','Phantom','Present','Righteous','Roaring|Roar|Scream','Rolling','Sand','Screaming|Roar|Scream','Silent','Soaring','Standing|Stand','Star|Star','Stunning','Super','Thunderous|Thunder','Twisted','Urgent','Utopian','Valiant'); +var nouns = Array('Action','Alert','Bane','Beauty','Claw','Darkness','Dawn','Day','Defense','Desert','Envy','Fall','Fist','Flight','Fury','Guard','Glory','Hammer','Hand','Honor','Hope','Hunt','Hurricane','Joy','Liberty','Light','Lightning','Magic','Morning','October','Power','Rain','Response','Repose','Roar','Scream','Skull','Sky','Skies','Shield','Shout','Stand','Star','Storm','Streak','Strike','Sun','Thunder','Victory','Whisper','Wind','Wrath'); +var colors = Array('Black','Blue','Brown','Golden','Gray','Green','Indego','Orange','Purple','Rainbow','Red','Scarlet','Silver','Violet','White','Yellow'); +var actors = Array('Cobra','Condor','Dragon','Eagle','Giant','Guardian','Hawk','Hydra','Jackal','King','Knight','Lady','Lion','Scorpion','Spartan','Stranger','Titan','Victor','Viking','Warrior'); var mission_grammars = Array( {chance:30, grammar: "{adj1} {noun1}"}, {chance:20, grammar: "{adj1} {actor}"}, {chance:10, grammar: "{color} {noun1}"}, {chance:10, grammar: "{color} {actor}"}, - {chance:10, grammar: "{actor}'s {noun1}"}, - {chance:10, grammar: "{noun1} of the {noun2}"}, + {chance:20, grammar: "{actor}'s {noun1}"}, + //{chance:10, grammar: "{noun1} of the {noun2}"}, //this one has been producing too many odd lines {chance:10, grammar: "{noun1} of the {actor}"}, {chance:10, grammar: "{actor} of the {noun1}"}, - {chance:10, grammar: "{noun1} of {noun2}"}, - {chance:10, grammar: "{noun1} of {color} {noun2}"}, + {chance:5, grammar: "{noun1} of {noun2}"}, + {chance:5, grammar: "{noun1} of {color} {noun2}"}, {chance:10, grammar: "{adj1} {noun1} and {adj2} {noun2}"}, {chance:3, grammar: "Attack of the {actor}s"}, {chance:3, grammar: "Return of the {actor}s"}