Keep track of access count
This commit is contained in:
parent
b8237b18b1
commit
ad6d5dfcf3
@ -96,6 +96,7 @@
|
||||
<th>Distance to user</th>
|
||||
<th>Closest station</th>
|
||||
<th>Distance to station</th>
|
||||
<th>Access count</th>
|
||||
<th>Score</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -105,6 +106,7 @@
|
||||
<th>{{distanceToUser}} km</th>
|
||||
<th>{{closestStn}}</th>
|
||||
<th>{{distanceToStn}} km</th>
|
||||
<th>{{accessCount}}</th>
|
||||
<td>{{score}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
|
@ -142,9 +142,7 @@
|
||||
|
||||
var template = Handlebars.compile($('#template').html());
|
||||
$('#results').empty();
|
||||
$('#results').append(
|
||||
template({ results: results })
|
||||
);
|
||||
$('#results').append(template({results: results}));
|
||||
|
||||
if (results.length === 0) {
|
||||
$('#resultPanel').slideUp();
|
||||
|
@ -40,11 +40,11 @@ conn.query('USE hscd');
|
||||
//
|
||||
|
||||
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) {
|
||||
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.relativeUrl,
|
||||
record.rating.food,
|
||||
@ -54,7 +54,8 @@ for (var i = 0, count = data.length; i < count; ++i) {
|
||||
record.geo.latitude,
|
||||
record.geo.longitude,
|
||||
record.distanceToStn,
|
||||
record.closestStn
|
||||
record.closestStn,
|
||||
0
|
||||
]);
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -72,6 +72,7 @@ function findRecords(data, features, minScore) {
|
||||
distanceToUser: record.distanceToUser / 1000.0,
|
||||
distanceToStn: record.distanceToStn / 1000.0,
|
||||
closestStn: record.closestStn,
|
||||
accessCount: record.accessCount,
|
||||
id: record.id
|
||||
});
|
||||
});
|
||||
@ -147,6 +148,7 @@ function getRecords(context, callback) {
|
||||
id: row.id,
|
||||
closestStn: row.closestStn,
|
||||
distanceToStn: row.distanceToStn,
|
||||
accessCount: row.accessCount,
|
||||
geo: {
|
||||
latitude: row.latitude,
|
||||
longitude: row.longitude
|
||||
@ -161,7 +163,7 @@ function getRecords(context, callback) {
|
||||
});
|
||||
|
||||
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(
|
||||
records,
|
||||
function(record, callback) {
|
||||
@ -330,6 +332,7 @@ function accessReview(query, callback) {
|
||||
if (results.success) {
|
||||
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) {
|
||||
pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) {
|
||||
if (err) {
|
||||
@ -344,6 +347,7 @@ function accessReview(query, callback) {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
callback(results);
|
||||
|
Loading…
Reference in New Issue
Block a user