-
-
Save RandomOutput/6348986 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
import csv | |
import re | |
logFile = "sqlout.csv" | |
logFile2 = "out2.csv" | |
validNames = ['cody','cory', 'daniel','nate','chris','ian','amanda','mike'] | |
pos_results = list() | |
neg_results = list() | |
scores = {} | |
nameTuples = list() | |
def readLogs(): | |
csvReader = csv.DictReader(open(logFile)) | |
seachForPoints(csvReader) | |
csvReader = csv.DictReader(open(logFile2)) | |
seachForPoints(csvReader) | |
generateScores() | |
nameTuples = list() | |
print "Scores" | |
for key in scores.keys(): | |
if key in validNames: | |
nameTuples.append((key, scores[key])) | |
nameTuples = sorted(nameTuples, key= lambda nameTup: nameTup[1], reverse=True) | |
for nameTup in nameTuples: | |
print `nameTup[0]` + ": " + `nameTup[1]` | |
def generateScores(): | |
for point in pos_results: | |
nameFind = re.findall('[a-zA-Z]+', point) | |
for name in nameFind: | |
if name not in scores: | |
scores[name] = 1 | |
else: | |
scores[name]+=1 | |
for point in neg_results: | |
nameFind = re.findall('[a-zA-Z]+', point) | |
for name in nameFind: | |
if name not in scores: | |
scores[name] = -1 | |
else: | |
scores[name]-=1 | |
def seachForPoints(reader): | |
for row in reader: | |
testString = str(row["body_xml"]) | |
#if "++" in testString: | |
# print testString | |
res = re.findall('[a-zA-Z][a-zA-Z]+\+\+', testString) | |
if len(res) > 0: | |
for match in res: | |
pos_results.append(match.lower()) | |
res = re.findall('\+\+[a-zA-Z][a-zA-Z]+', testString) | |
if len(res) > 0: | |
for match in res: | |
pos_results.append(match.lower()) | |
res = re.findall('[a-zA-Z][a-zA-Z]+--', testString) | |
if len(res) > 0: | |
for match in res: | |
neg_results.append(match.lower()) | |
res = re.findall('--[a-zA-Z][a-zA-Z]+', testString) | |
if len(res) > 0: | |
for match in res: | |
neg_results.append(match.lower()) | |
res = re.findall('[a-zA-Z][a-zA-Z]+ \+\+', testString) | |
if len(res) > 0: | |
for match in res: | |
pos_results.append(match.lower()) | |
res = re.findall('\+\+ [a-zA-Z][a-zA-Z]+', testString) | |
if len(res) > 0: | |
for match in res: | |
pos_results.append(match.lower()) | |
res = re.findall('[a-zA-Z][a-zA-Z]+ --', testString) | |
if len(res) > 0: | |
for match in res: | |
neg_results.append(match.lower()) | |
res = re.findall('-- [a-zA-Z][a-zA-Z]+', testString) | |
if len(res) > 0: | |
for match in res: | |
neg_results.append(match.lower()) | |
if __name__ == "__main__": | |
readLogs() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment