-
Notifications
You must be signed in to change notification settings - Fork 15
/
codespeedinfo.py
65 lines (51 loc) · 1.95 KB
/
codespeedinfo.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
try:
import urllib.request as urllib2
import urllib.parse as urllib
except ImportError:
import urllib2
import urllib
import platform
import json
from datetime import datetime
import scrapy
import statistics
current_date = datetime.today()
CODESPEED_URL = 'http://localhost:8000/'
def get_latest_commit(owner, repo):
url = 'https://github.com/gitapi/repos/{owner}/{repo}/commits?per_page=1'.format(
owner=owner, repo=repo)
response = urllib2.urlopen(url).read()
data = json.loads(response.decode())
return data[0]
def get_env():
pyimplement = platform.python_implementation()
pyversion = platform.python_version()
scrapyversion = '.'.join(map(str, scrapy.version_info))
return pyimplement + " " + pyversion + " Scrapy " + scrapyversion
def uploadresult(test, w):
commit = get_latest_commit('scrapy', 'scrapy')
data = {
'commitid': commit['html_url'].rsplit('/', 1)[-1],
'branch': 'default', # Always use default for trunk/master/tip
'project': 'Scrapy-Bench',
'executable': 'bench.py',
'benchmark': test,
'environment': get_env(),
'result_value': statistics.mean(w),
}
data.update({
'revision_date': current_date, # Optional. Default is taken either
# from VCS integration or from current date
'result_date': current_date, # Optional, default is current date
'std_dev': statistics.pstdev(w), # Optional. Default is blank
#'max': 4001.6, # Optional. Default is blank
#'min': 3995.1, # Optional. Default is blank
})
params = urllib.urlencode(data).encode("utf-8")
response = "None"
print("Saving result for executable %s, revision %s, benchmark %s" % (
data['executable'], data['commitid'], data['benchmark']))
f = urllib2.urlopen(CODESPEED_URL + 'result/add/', params)
response = f.read()
f.close()
print("Server (%s) response: %s\n" % (CODESPEED_URL, response))