-
Notifications
You must be signed in to change notification settings - Fork 0
/
full_stats.py
executable file
·162 lines (115 loc) · 4.79 KB
/
full_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python2
from __future__ import print_function
import argparse
from collections import defaultdict
from datetime import datetime
import pymongo
import datasets.util
client = pymongo.MongoClient()
class Dates(object):
def __init__(self):
self.begin = datetime(2036, 12, 31)
self.end = datetime(1970, 1, 1)
def topcoder():
db = client.topcoder
nb_projects = 0
nb_finished_projects = 0
prize_sum = 0
dates = Dates()
lasting_days = 0.0
registering = defaultdict(int)
winning = defaultdict(int)
for challenge in db.challenges.find():
if not datasets.util.topcoder_is_ok(challenge):
continue
nb_projects += 1
prize_sum += sum(challenge[u"prize"])
postingDate = challenge[u"postingDate"]
if postingDate < dates.begin:
dates.begin = postingDate
elif postingDate > dates.end:
dates.end = postingDate
delta = challenge[u"submissionEndDate"] - postingDate
lasting_days += delta.total_seconds() / (24 * 60 * 60.0)
for registrant in challenge[u"registrants"]:
registering[registrant[u"handle"]] += 1
winner = datasets.util.topcoder_get_winner(challenge)
if winner is not None:
nb_finished_projects += 1
winning[winner] += 1
print("total project count:", nb_projects)
print("total developer count:", len(registering))
print("earliest project:", dates.begin)
print("latest project:", dates.end)
print("project average lasting days: %.1f days\n" % (lasting_days / nb_projects))
print("project average prize: $%.1f\n" % (prize_sum / float(nb_projects)))
users = registering.keys()
users.sort(key=lambda u: registering[u], reverse=True)
print("developer max registering times: ")
for i in xrange(5):
print(" %s: %d" % (users[i], registering[users[i]]))
nb_registering = sum(registering.values())
print("project average registrant count: %.1f" % (nb_registering / float(nb_projects)))
print("developer average registering count: %.1f\n" % (nb_registering / float(len(registering))))
users = winning.keys()
users.sort(key=lambda u: winning[u], reverse=True)
print("developer max winning times: ")
for i in xrange(5):
print(" %s: %d" % (users[i], winning[users[i]]))
print("developer average winning times: %.1f" % (nb_finished_projects / float(len(winning))))
def freelancer():
db = client.freelancer
nb_projects = 0
nb_finished_projects = 0
prize_sum = 0.0
dates = Dates()
registering = defaultdict(int)
winning = defaultdict(int)
for project in db.projects.find():
if (nb_projects + 1) % 100 == 0:
print("counter:", nb_projects + 1)
if u"result" not in project or u"bids" not in project[u"result"]:
continue
if u"bid_avg" not in project[u"bid_stats"]:
continue
nb_projects += 1
prize_sum += project[u"bid_stats"][u"bid_avg"]
postingDate = datetime.fromtimestamp(project[u"submitdate"])
if postingDate < dates.begin:
dates.begin = postingDate
elif postingDate > dates.end:
dates.end = postingDate
for bid in project[u"result"][u"bids"]:
user = bid[u"user"][u"username"]
registering[user] += 1
if "is_awarded" in bid and bid["is_awarded"]:
nb_finished_projects += 1
winning[user] += 1
print("total project count:", nb_projects)
print("total developer count:", len(registering))
print("earliest project:", dates.begin)
print("latest project:", dates.end)
print("project average prize: $%.1f\n" % (prize_sum / float(nb_projects)))
users = registering.keys()
users.sort(key=lambda u: registering[u], reverse=True)
print("developer max registering times: ")
for i in xrange(5):
print(" %s: %d" % (users[i], registering[users[i]]))
nb_registering = sum(registering.values())
print("project average registrant count: %.1f" % (nb_registering / float(nb_projects)))
print("developer average registering count: %.1f\n" % (nb_registering / float(len(registering))))
users = winning.keys()
users.sort(key=lambda u: winning[u], reverse=True)
print("developer max winning times: ")
for i in xrange(5):
print(" %s: %d" % (users[i], winning[users[i]]))
print("developer average winning times: %.1f" % (nb_finished_projects / float(len(winning))))
def main():
parser = argparse.ArgumentParser("full_stats")
parser.add_argument("dataset",
choices=("topcoder", "freelancer"),
help="the dataset to extract")
args = parser.parse_args()
globals()[args.dataset]()
if __name__ == "__main__":
main()