1

Work on server

This commit is contained in:
Alex Yatskov 2014-07-28 11:52:30 +09:00
parent 42aee030e1
commit ba8685b2a8
3 changed files with 76 additions and 69 deletions

View File

@ -147,77 +147,82 @@ function onAdjust(name, value) {
outputResults(results, wa.maxResults); outputResults(results, wa.maxResults);
} }
function onQuery() { function onSearch() {
var query = $('#query').val(); var params = {
var minScore = parseInt($('#minScore').val()) || 1.0; 'keyword': $('#keyword').val(),
var hintSteps = parseInt($('#hintSteps').val()) || 20; 'minScore': parseInt($('#minScore').val()),
var maxResults = parseInt($('#maxResults').val()) || 100; 'hintSteps': parseInt($('#hintSteps').val()),
var useLocalScale = true; 'maxResults': parseInt($('#maxResults').val()),
var useRelativeScale = true; 'useLocalScale': true,
'useRelativeScale': true
console.assert(query in DATA_KEYWORDS);
var queryParams = DATA_KEYWORDS[query];
var searchRange = new goog.math.Range(-1.0, 1.0);
var graphColumns = {};
for (var feature in queryParams) {
var hints = searchBuildHints(
queryParams,
minScore,
feature,
searchRange,
hintSteps
);
graphColumns[feature] = {
'color': '#607080',
'value': queryParams[feature],
'hints': hints,
'steps': hintSteps
}
}
window.adjuster = {
queryParams: queryParams,
searchRange: searchRange,
hintSteps: hintSteps,
minScore: minScore,
maxResults: maxResults
}; };
window.grapher = new Grapher('grapher', searchRange, useLocalScale, useRelativeScale); $.getJSON('/node/search', params, function(results) {
window.grapher.setColumns(graphColumns); alert('searched');
window.grapher.setValueChangedListener(onAdjust); });
var results = searchData(queryParams, minScore); // var queryParams = DATA_KEYWORDS[query];
outputResults(results, maxResults); // var searchRange = new goog.math.Range(-1.0, 1.0);
// var graphColumns = {};
$('#keyword').text(query); // for (var feature in queryParams) {
$('#useLocalScale').prop('checked', useLocalScale); // var hints = searchBuildHints(
$('#useRelativeScale').prop('checked', useRelativeScale); // queryParams,
$('#useLocalScale').click(function() { // minScore,
var useLocalScale = $('#useLocalScale').is(':checked'); // feature,
window.grapher.setUseLocalScale(useLocalScale); // searchRange,
}); // hintSteps
$('#useRelativeScale').click(function() { // );
var useRelativeScale = $('#useRelativeScale').is(':checked');
window.grapher.setUseRelativeScale(useRelativeScale); // graphColumns[feature] = {
}); // 'color': '#607080',
$('#input').fadeOut(function() { // 'value': queryParams[feature],
$('#output').fadeIn(); // 'hints': hints,
}); // 'steps': hintSteps
// }
// }
// window.adjuster = {
// queryParams: queryParams,
// searchRange: searchRange,
// hintSteps: hintSteps,
// minScore: minScore,
// maxResults: maxResults
// };
// window.grapher = new Grapher('grapher', searchRange, useLocalScale, useRelativeScale);
// window.grapher.setColumns(graphColumns);
// window.grapher.setValueChangedListener(onAdjust);
// var results = searchData(queryParams, minScore);
// outputResults(results, maxResults);
// $('#query').text(query);
// $('#useLocalScale').prop('checked', useLocalScale);
// $('#useRelativeScale').prop('checked', useRelativeScale);
// $('#useLocalScale').click(function() {
// var useLocalScale = $('#useLocalScale').is(':checked');
// window.grapher.setUseLocalScale(useLocalScale);
// });
// $('#useRelativeScale').click(function() {
// var useRelativeScale = $('#useRelativeScale').is(':checked');
// window.grapher.setUseRelativeScale(useRelativeScale);
// });
// $('#input').fadeOut(function() {
// $('#output').fadeIn();
// });
} }
$(document).ready(function() { $(document).ready(function() {
$.getJSON('/node/hscd/keywords', function(keywords) { $.getJSON('/node/keywords', function(keywords) {
for (var i = 0; i < keywords.length; ++i) { for (var i = 0; i < keywords.length; ++i) {
$('#query').append($('<option></option>', { $('#keyword').append($('<option></option>', {
'value': keywords[i], 'value': keywords[i],
'text': keywords[i] 'text': keywords[i]
})); }));
} }
$('#search').prop('disabled', false); $('#search').prop('disabled', false);
$('#search').click(onSearch);
}); });
}); });

View File

@ -15,9 +15,9 @@
<div id="input"> <div id="input">
<form class="form-horizontal"> <form class="form-horizontal">
<div class="form-group"> <div class="form-group">
<label for="query" class="col-md-2 control-label">Keyword</label> <label for="keyword" class="col-md-2 control-label">Keyword</label>
<div class="col-md-10"> <div class="col-md-10">
<select id="query" class="form-control" name="query"></select> <select id="keyword" class="form-control" name="keyword"></select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -51,7 +51,7 @@
<div id="output" style="display: none;"> <div id="output" style="display: none;">
<form> <form>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><big>Semantic tweaks to <span id="keyword" class="text-primary"></span></big></div> <div class="panel-heading"><big>Semantic tweaks to <span id="query" class="text-primary"></span></big></div>
<div class="row" style="padding: 10px;"> <div class="row" style="padding: 10px;">
<canvas id="grapher" width="500" height="550"></canvas><br> <canvas id="grapher" width="500" height="550"></canvas><br>
<label class="checkbox-inline"> <label class="checkbox-inline">

View File

@ -1,20 +1,22 @@
#!/usr/bin/env node #!/usr/bin/env node
var express = require('express'); var express = require('express');
var keywords = require('./db/keywords.json'); var keywords = require('./db/keywords.json');
var data = require('./db/data.json'); var data = require('./db/data.json');
var _ = require('underscore'); var _ = require('underscore');
function main() { function main() {
var app = express(); var app = express();
var router = express.Router();
router.use('/keywords', function(req, res, next) { app.use('/keywords', function(req, res) {
console.log('Requesting keywords'); console.log('Requesting keywords');
res.json(_.keys(keywords)); res.json(_.keys(keywords));
}); });
app.use('/hscd', router); app.use('/search', function(req, res) {
console.log(req.query);
});
app.listen(3000); app.listen(3000);
} }