-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
193 lines (171 loc) · 5.58 KB
/
gulpfile.js
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
var pug = require('gulp-pug')
var gulp = require('gulp')
var rename = require('gulp-rename')
var data = require('gulp-data')
var connect = require('gulp-connect')
var replace = require('gulp-replace')
var ghPages = require('gulp-gh-pages')
var bower = require('gulp-bower')
var image = require('gulp-image')
var stylus = require('gulp-stylus')
var minify = require('gulp-minify')
var path = require('path')
var fs = require('fs')
var cheerio = require('cheerio')
var build_dir = 'data-centric-comp/' // good to have this be the same as the repo name for gh-pages purposes
var rankEntries = function (entries) {
entries.sort(function(a, b) {
return b.acc- a.acc;
})
for (var i = 0; i < entries.length; i++) {
var entry = entries[i]
if (i === 0) {
entry.rank = 1
} else {
var prevEntry = entries[i - 1]
var rank = prevEntry.rank
if (entry.acc < prevEntry.acc) rank++
entry.rank = rank
}
}
return entries
}
function assert (condition, message) {
if (!condition) {
throw message || 'Assertion failed'
}
}
var parseCompEntries = function (comp_file) {
var leaderboard = require(comp_file).leaderboard
var entries = []
for (var i = 0; i < leaderboard.length; i++) {
try {
var o_entry = leaderboard[i]
var entry = {}
entry.user = o_entry.submission.user_name
var description = o_entry.submission.description.trim()
var regex_match = description.match(/(.*) ?\((.*)\)(.*)/);
if (regex_match) {
entry.model_name = regex_match[1].trim();
entry.institution = regex_match[2].trim();
if (regex_match[3].lastIndexOf('http') !== -1) {
entry.link = regex_match[3].trim()
}
} else {
entry.model_name = description.substr(0, description.lastIndexOf('(')).trim()
var firstPart = description.substr(description.lastIndexOf('(') + 1)
entry.institution = firstPart.substr(0, firstPart.lastIndexOf(')'))
if (description.lastIndexOf('http') !== -1) {
entry.link = description.substr(description.lastIndexOf('http')).trim()
}
}
entry.date = o_entry.submission.created
entry.acc = parseFloat(o_entry.scores.accuracy)
if (entry.model_name !== '' && Number(entry.acc) == entry.acc) {
entries.push(entry);
}
} catch (err) {
console.error(err)
console.error(entry)
}
}
entries = rankEntries(entries)
return entries
}
var parseEntries = function (htmlStr) {
var $ = cheerio.load(htmlStr)
var parent = $('h1#leaderboard').closest('.ws-item').next()
var entries = []
$(parent).find('tbody > tr').each(function () {
var entry = {}
var cells = $(this).find('td')
entry.description = cells.eq(1).text().trim()
entry.model_name = entry.description.substr(0, entry.description.lastIndexOf('(')).trim()
var firstPart = entry.description.substr(entry.description.lastIndexOf('(') + 1)
entry.institution = firstPart.substr(0, firstPart.lastIndexOf(')'))
var httpPos = entry.description.lastIndexOf('http')
if (httpPos !== -1) {
entry.link = entry.description.substr(entry.description.lastIndexOf('http')).trim()
}
delete entry.description
entry.acc = parseFloat(cells.eq(4).text())
entry.date = cells.eq(2).text().trim()
entries.push(entry)
})
entries = rankEntries(entries)
return entries
}
gulp.task('bower', function () {
return bower()
.pipe(gulp.dest('./' + build_dir + 'bower_components/'))
})
gulp.task('image', function () {
return gulp.src('./views/images/*')
.pipe(image())
.pipe(gulp.dest('./' + build_dir))
})
gulp.task('scrape_website', function (cb) {
var Nightmare = require('nightmare')
var fs = require('fs')
var parse
var nightmare = new Nightmare({
switches: {
'ignore-certificate-errors': true
}
})
nightmare.goto('https://worksheets.codalab.org/worksheets/0x62eefc3e64e04430a1a24785a9293fff/')
.wait(2000)
.evaluate(function () {
return document.body.innerHTML
})
.end()
.then(function (result) {
var jsonfile = require('jsonfile')
var after = parseEntries(result)
jsonfile.writeFile('./test.json', after, cb)
})
})
gulp.task('connect', function () {
connect.server({
host: '0.0.0.0',
root: '.'
})
})
var dataset_folder = './dataset/'
var filepaths = [
dataset_folder + 'dev-v1.1.json',
]
var exploration_tasks = []
gulp.task('process_comp_output', function (cb) {
var jsonfile = require('jsonfile')
var entries1 = parseCompEntries('./leaderboard.json')
jsonfile.writeFile('./results.json', entries1, cb)
})
gulp.task('generate_index', ['process_comp_output'], function () {
var test = require('./results.json')
var moment = require('moment')
return gulp.src('views/index.pug')
.pipe(data(function () {
return { 'test': test,
'moment': moment}
}))
.pipe(pug())
.pipe(gulp.dest('./' + build_dir))
})
gulp.task('correct_link_paths', ['generate'], function () {
return gulp.src('./' + build_dir + '**/*.html')
.pipe(replace(/([^-](?:href|src)=[\'\"]\/)([^\'\"]*)([\'\"])/g, '$1' + build_dir + '$2$3'))
.pipe(gulp.dest('./' + build_dir))
})
gulp.task('css', function () {
return gulp.src('./views/styles/*.styl')
.pipe(stylus())
.pipe(gulp.dest('./' + build_dir + 'stylesheets'))
})
gulp.task('deploy', function () {
return gulp.src('./' + build_dir + '**/*')
.pipe(ghPages())
})
gulp.task('generate_exploration', exploration_tasks)
gulp.task('generate', ['bower', 'generate_exploration', 'generate_index', 'process_comp_output'])
gulp.task('default', ['generate', 'correct_link_paths', 'image', 'css'])