1

Keep track of access count

This commit is contained in:
Alex Yatskov 2015-03-17 18:41:52 +09:00
parent b8237b18b1
commit ad6d5dfcf3
5 changed files with 29 additions and 23 deletions

View File

@ -96,6 +96,7 @@
<th>Distance to user</th> <th>Distance to user</th>
<th>Closest station</th> <th>Closest station</th>
<th>Distance to station</th> <th>Distance to station</th>
<th>Access count</th>
<th>Score</th> <th>Score</th>
</tr> </tr>
</thead> </thead>
@ -105,6 +106,7 @@
<th>{{distanceToUser}} km</th> <th>{{distanceToUser}} km</th>
<th>{{closestStn}}</th> <th>{{closestStn}}</th>
<th>{{distanceToStn}} km</th> <th>{{distanceToStn}} km</th>
<th>{{accessCount}}</th>
<td>{{score}}</td> <td>{{score}}</td>
</tr> </tr>
{{/each}} {{/each}}

View File

@ -142,9 +142,7 @@
var template = Handlebars.compile($('#template').html()); var template = Handlebars.compile($('#template').html());
$('#results').empty(); $('#results').empty();
$('#results').append( $('#results').append(template({results: results}));
template({ results: results })
);
if (results.length === 0) { if (results.length === 0) {
$('#resultPanel').slideUp(); $('#resultPanel').slideUp();

View File

@ -40,11 +40,11 @@ conn.query('USE hscd');
// //
conn.query('DROP TABLE IF EXISTS reviews'); conn.query('DROP TABLE IF EXISTS reviews');
conn.query('CREATE TABLE reviews(name VARCHAR(100) NOT NULL, url VARCHAR(200) NOT NULL, delicious FLOAT NOT NULL, accomodating FLOAT NOT NULL, affordable FLOAT NOT NULL, atmospheric FLOAT NOT NULL, latitude FLOAT NOT NULL, longitude FLOAT NOT NULL, distanceToStn FLOAT NOT NULL, closestStn VARCHAR(100) NOT NULL, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) DEFAULT CHARACTER SET utf8'); conn.query('CREATE TABLE reviews(name VARCHAR(100) NOT NULL, url VARCHAR(200) NOT NULL, delicious FLOAT NOT NULL, accomodating FLOAT NOT NULL, affordable FLOAT NOT NULL, atmospheric FLOAT NOT NULL, latitude FLOAT NOT NULL, longitude FLOAT NOT NULL, distanceToStn FLOAT NOT NULL, closestStn VARCHAR(100) NOT NULL, accessCount INT NOT NULL, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) DEFAULT CHARACTER SET utf8');
for (var i = 0, count = data.length; i < count; ++i) { for (var i = 0, count = data.length; i < count; ++i) {
var record = data[i]; var record = data[i];
conn.query('INSERT INTO reviews(name, url, delicious, accomodating, affordable, atmospheric, latitude, longitude, distanceToStn, closestStn) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [ conn.query('INSERT INTO reviews(name, url, delicious, accomodating, affordable, atmospheric, latitude, longitude, distanceToStn, closestStn, accessCount) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
record.name, record.name,
record.relativeUrl, record.relativeUrl,
record.rating.food, record.rating.food,
@ -54,7 +54,8 @@ for (var i = 0, count = data.length; i < count; ++i) {
record.geo.latitude, record.geo.latitude,
record.geo.longitude, record.geo.longitude,
record.distanceToStn, record.distanceToStn,
record.closestStn record.closestStn,
0
]); ]);
} }

File diff suppressed because one or more lines are too long

View File

@ -72,6 +72,7 @@ function findRecords(data, features, minScore) {
distanceToUser: record.distanceToUser / 1000.0, distanceToUser: record.distanceToUser / 1000.0,
distanceToStn: record.distanceToStn / 1000.0, distanceToStn: record.distanceToStn / 1000.0,
closestStn: record.closestStn, closestStn: record.closestStn,
accessCount: record.accessCount,
id: record.id id: record.id
}); });
}); });
@ -147,6 +148,7 @@ function getRecords(context, callback) {
id: row.id, id: row.id,
closestStn: row.closestStn, closestStn: row.closestStn,
distanceToStn: row.distanceToStn, distanceToStn: row.distanceToStn,
accessCount: row.accessCount,
geo: { geo: {
latitude: row.latitude, latitude: row.latitude,
longitude: row.longitude longitude: row.longitude
@ -161,7 +163,7 @@ function getRecords(context, callback) {
}); });
computeRecordGeo(records, context); computeRecordGeo(records, context);
computeRecordCompat(records, context, callback); computeRecordPopularity(records, context, callback);
}); });
} }
@ -190,7 +192,7 @@ function computeRecordGeo(records, context) {
}); });
} }
function computeRecordCompat(records, context, callback) { function computeRecordPopularity(records, context, callback) {
async.each( async.each(
records, records,
function(record, callback) { function(record, callback) {
@ -330,6 +332,7 @@ function accessReview(query, callback) {
if (results.success) { if (results.success) {
results.url = 'http://www.tripadvisor.com' + rows[0].url; results.url = 'http://www.tripadvisor.com' + rows[0].url;
pool.query('UPDATE reviews SET accessCount = accessCount + 1 WHERE id = (?)', [query.id], function(err, info) {
if (_.keys(query.profile).length > 0) { if (_.keys(query.profile).length > 0) {
pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) { pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) {
if (err) { if (err) {
@ -344,6 +347,7 @@ function accessReview(query, callback) {
} }
}); });
} }
});
} }
callback(results); callback(results);