Skip to content

Instantly share code, notes, and snippets.

@jo32
Created June 23, 2014 13:25
Show Gist options
  • Save jo32/5da63d2cf27ded2bc5e1 to your computer and use it in GitHub Desktop.
Save jo32/5da63d2cf27ded2bc5e1 to your computer and use it in GitHub Desktop.
is-baidu-world-cup-prediction-reliable
import json
f = open('all.json')
json = json.loads(f.read())
f.close()
predicts = []
results = []
for i in json:
bodys = i['data']['body']
for body in bodys:
predict = [int(body['win_rate']), int(body['equal_rate']), int(body['fail_rate'])]
predicts.append(predict)
if int(body['home_score']) > int(body['away_score']):
result = 1
elif int(body['home_score']) == int(body['away_score']):
result = 0
else:
result = -1
results.append(result)
def baidu_predict(index):
return predicts[index];
def absolute_paul_predict(index):
if results[index] == 1:
return [100, 0, 0]
elif results[index] == 0:
return [0, 100, 0]
else:
return [0, 0, 100]
def monkey_predict(index):
return [33.33, 33.33, 33.33]
def gambler_predict(index):
return [50, 0, 50]
def test_predict(predict_func):
score = 0
for i in range(len(results)):
score += predict_func(i)[1 - results[i]]
return score
print len(results)
print test_predict(baidu_predict)
print test_predict(absolute_paul_predict)
print test_predict(monkey_predict)
print test_predict(gambler_predict)
import os.path
import json
time = 1402588800
fname = str(time) + '.json'
jsons = []
while os.path.isfile(fname):
f = open(fname, 'r')
_json = json.loads(f.read())
f.close()
jsons.append(_json)
time += 60 * 60 * 24
fname = str(time) + '.json'
f = open('all.json', 'w')
f.write(json.dumps(jsons))
f.close()
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1402588800 > 1402588800.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1402675200 > 1402675200.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1402761600 > 1402761600.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1402848000 > 1402848000.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1402934400 > 1402934400.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1403020800 > 1403020800.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1403107200 > 1403107200.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1403193600 > 1403193600.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1403280000 > 1403280000.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1403366400 > 1403366400.json
curl http://trends.baidu.com/worldcup/events/ajax/time?query=1403452800 > 1403452800.json
f = open('task.sh', 'w');
time = 1402588800
cmd_pattern = "curl http://trends.baidu.com/worldcup/events/ajax/time?query=%d > %d.json"
for i in range(13, 23 + 1):
f.write(cmd_pattern % (time, time) + "\n")
time += 60 * 60 * 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment