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' ) ;
2014-11-17 06:16:05 +00:00
conn . query ( 'CREATE TABLE reviews(name VARCHAR(100) NOT NULL, url VARCHAR(200) NOT NULL, food FLOAT NOT NULL, service FLOAT NOT NULL, value FLOAT NOT NULL, atmosphere FLOAT NOT NULL, latitude FLOAT NOT NULL, longitude 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 ] ;
2014-11-17 06:16:05 +00:00
conn . query ( 'INSERT INTO reviews(name, url, food, service, value, atmosphere, latitude, longitude) 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 ,
record . geo . longitude
2014-09-16 07:27:27 +00:00
] ) ;
}
//
// Keywords
//
conn . query ( 'DROP TABLE IF EXISTS keywords' ) ;
2014-11-17 07:49:02 +00:00
conn . query ( 'CREATE TABLE keywords(name VARCHAR(50) NOT NULL, food FLOAT NOT NULL, service FLOAT NOT NULL, value FLOAT NOT NULL, atmosphere FLOAT NOT NULL, proximity 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 ( ) ;