-
-
Save nayakrujul/2cb31d986046be2bca7b6cd15a7d52c5 to your computer and use it in GitHub Desktop.
This file contains 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, datetime, statistics | |
def timestamp(s): | |
return int(datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S').timestamp()) | |
with open('QueryResults.csv') as f: | |
lst = list(csv.DictReader(f)) | |
tags = {} | |
for record in lst: | |
tag_name = record["TagName"] | |
parent_id = record["ParentId"] | |
question_creation = timestamp(record["QuestionCreation"]) | |
answer_creation = timestamp(record["AnswerCreation"]) | |
time_passed = answer_creation - question_creation | |
if tag_name in tags: | |
if parent_id in tags[tag_name]: | |
if time_passed < tags[tag_name][parent_id]: | |
tags[tag_name][parent_id] = time_passed | |
else: | |
tags[tag_name][parent_id] = time_passed | |
else: | |
tags[tag_name] = {parent_id: time_passed} | |
means = {} | |
for tag, dct in tags.items(): | |
means[tag] = int(statistics.mean(dct.values())) | |
for key, val in sorted(means.items(), key=lambda r: r[1]): | |
print(' ', key, ' ' * (50 - len(key)), val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment