2014-09-16 07:27:27 +00:00
#!/usr/bin/env node
var mysql = require ( 'mysql' ) ;
var data = require ( './data.json' ) ;
var conn = mysql . createConnection ( {
host : 'localhost' ,
user : 'hscd' ,
database : 'hscd'
} ) ;
//
// Reviews
//
conn . query ( 'DROP TABLE IF EXISTS reviews' ) ;
2015-01-05 05:32:58 +00:00
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, distanceToStation FLOAT NOT NULL, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY)' ) ;
2014-09-16 07:27:27 +00:00
for ( var i = 0 , count = data . length ; i < count ; ++ i ) {
var record = data [ i ] ;
2015-01-05 05:32:58 +00:00
conn . query ( 'INSERT INTO reviews(name, url, delicious, accomodating, affordable, atmospheric, latitude, longitude, distanceToStation) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)' , [
2014-09-16 07:27:27 +00:00
record . name ,
record . relativeUrl ,
record . rating . food ,
record . rating . service ,
record . rating . value ,
2014-11-17 06:16:05 +00:00
record . rating . atmosphere ,
record . geo . latitude ,
2015-01-05 05:32:58 +00:00
record . geo . longitude ,
record . distanceToStation
2014-09-16 07:27:27 +00:00
] ) ;
}
//
// Keywords
//
conn . query ( 'DROP TABLE IF EXISTS keywords' ) ;
2015-01-05 05:32:58 +00:00
conn . query ( 'CREATE TABLE keywords(name VARCHAR(50) NOT NULL, delicious FLOAT NOT NULL, accomodating FLOAT NOT NULL, affordable FLOAT NOT NULL, atmospheric FLOAT NOT NULL, nearby FLOAT NOT NULL, PRIMARY KEY(name))' ) ;
2014-09-16 07:27:27 +00:00
var keywords = {
2014-11-17 07:49:02 +00:00
delicious : [ 1.0 , 0.0 , 0.0 , 0.0 , 0.0 ] ,
accommodating : [ 0.0 , 1.0 , 0.0 , 0.0 , 0.0 ] ,
affordable : [ 0.0 , 0.0 , 1.0 , 0.0 , 0.0 ] ,
atmospheric : [ 0.0 , 0.0 , 0.0 , 1.0 , 0.0 ]
2014-09-16 07:27:27 +00:00
} ;
for ( var keyword in keywords ) {
var record = keywords [ keyword ] ;
2014-11-17 07:49:02 +00:00
conn . query ( 'INSERT INTO keywords VALUES(?, ?, ?, ?, ?, ?)' , [ keyword ] . concat ( record ) ) ;
2014-09-16 07:27:27 +00:00
}
2014-09-20 09:31:39 +00:00
//
// Presets
//
conn . query ( 'DROP TABLE IF EXISTS presets' ) ;
conn . query ( 'CREATE TABLE presets(name VARCHAR(50) NOT NULL, PRIMARY KEY(name))' ) ;
for ( var keyword in keywords ) {
conn . query ( 'INSERT INTO presets VALUES(?)' , [ keyword ] ) ;
}
2014-09-16 07:27:27 +00:00
conn . end ( ) ;