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>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}}

View File

@ -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();

View File

@ -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

View File

@ -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,20 +332,22 @@ function accessReview(query, callback) {
if (results.success) {
results.url = 'http://www.tripadvisor.com' + rows[0].url;
if (_.keys(query.profile).length > 0) {
pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) {
if (err) {
throw err;
}
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) {
throw err;
}
for (var categoryId in query.profile) {
pool.query(
'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)',
[categoryId, query.profile[categoryId], info.insertId]
);
}
});
}
for (var categoryId in query.profile) {
pool.query(
'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)',
[categoryId, query.profile[categoryId], info.insertId]
);
}
});
}
});
}
callback(results);