Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User 38193 owns 42% (922 / 2171) of the final post
- User 2635 owns 28% (625 / 2171) of the final post
- User 116 owns 24% (529 / 2171) of the final post
- User 745 owns 3% (76 / 2171) of the final post
- User 13005 owns 0% (11 / 2171) of the final post
- User 18941 owns 0% (5 / 2171) of the final post
- User 8562 owns 0% (3 / 2171) of the final post
- 53 ms
- User 38193 owns 42% (922 / 2171) of the final post
- User 2635 owns 28% (625 / 2171) of the final post
- User 116 owns 24% (529 / 2171) of the final post
- User 745 owns 3% (76 / 2171) of the final post
- User 13005 owns 0% (11 / 2171) of the final post
- User 18941 owns 0% (5 / 2171) of the final post
- User 8562 owns 0% (3 / 2171) of the final post
- 53 ms
- #!/usr/bin/env python
- import collections
- import difflib
- import logging
- import pprint
- import urllib2
- import re
- class OwnageDeterminer(object):
- add_coefficient = 1
- remove_coefficient = .5
- def __init__(self, edits):
- self.edits = edits
- self.counts_by_username = {}
- def __call__(self):
- edits, counts_by_username = self.edits, self.counts_by_username
- for i, edit in enumerate(edits):
- username = edit['username']
- unique_counts = {'added': 0, 'removed': 0}
- existing_text = edits[i-1]['text'] if i > 0 else ''
- new_text = edits[i]['text']
- for char_diff in difflib.ndiff(existing_text, new_text):
- if char_diff.startswith('+'):
- unique_counts['added'] += 1
- elif char_diff.startswith('-'):
- unique_counts['removed'] += 1
- user_counts = counts_by_username.get(username, collections.defaultdict(int))
- user_counts['removed'] += self.remove_coefficient * unique_counts['removed']
- user_counts['added'] += self.add_coefficient * unique_counts['added']
- counts_by_username[username] = user_counts
- winner = None
- winning_score = 0
- score_by_username = {}
- for username, counts in counts_by_username.iteritems():
- score = counts['removed'] + counts['added']
- if score > winning_score:
- winner = username
- winning_score = score
- score_by_username[username] = score
- logging.debug('Scores: %s', pprint.pformat(score_by_username))
- return winner
- if __name__ == '__main__':
- logging.basicConfig(level=logging.DEBUG)
- site = urllib2.urlopen('http://stackoverflow.com/revisions/327973/list')
- contents = site.read()
- regex = re.compile(r'(/revisions/viewmarkup/d+).*?/users/d+/([w-]+)',
- re.MULTILINE|re.DOTALL)
- revisions = regex.findall(contents)
- print revisions
- edits = []
- for reluri, username in sorted(revisions, key=lambda t: t[0]):
- text = urllib2.urlopen('http://stackoverflow.com{0}'.format(reluri)).read()
- edit = {'username': username, 'text': text}
- edits.append(edit)
- od = OwnageDeterminer(edits)
- print od()
- DEBUG:root:Scores: {'blorgbeard': 0.5,
- 'dave-markle': 0.5,
- 'dbr': 1172.0,
- 'gatekiller': 69.5,
- 'joseph-ferris': 0.0,
- 'lkessler': 0.0,
- 'mark-harrison': 592.0,
- 'mdb': 3.0,
- 'onebyone-livejournal-com': 0.0,
- 'paul-oyster': 482.0,
- 'rob-wells': 0.0,
- 'simucal': 1070.5,
- 'skiphoppy': 0.0,
- 'thesoftwarejedi': 701.0}
- dbr
- Break latest revision into a set of sentences.
- //Sentence is any text fragment surrounded by punctuation
- For each Sentence
- Find which user created that sentence.
- Add 1 to the user who created the sentence
- Add 1 to the number of sentences
- For Each user
- % ownership = Count for that user / Number of sentences.
- Let n = total revisions
- Let m = the revision number of a poster
- Let post[it] = array with text of post at revision 'it'
- Let votes[it] = votes that revision 'it' received (also add bonus for comments/answers)
- value = 0
- for (it = m; it < n; ++it) {
- value += (Levenshtein(post[it-1], post[m]) / average_length_post) * (votes[it])
- }
Add Comment
Please, Sign In to add comment