Commit 24875757 authored by Romain Loth's avatar Romain Loth

rename histogram APIs to multivacV1 and V2 and make V2 configurable

parent 11399334
......@@ -206,9 +206,10 @@ TW.conf = (function(TW){
// flag name is div class to be removed if false
// *and* subdirectory of modules path to import if true
// see also activateModules()
TWConf.ModulesFlags["histogramModule"] = true ;
TWConf.ModulesFlags["histogramDailyVariantModule"] = false ;
// TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE
TWConf.ModulesFlags["multivacV1HistogramModule"] = true ;
// cf. twmodules/multivacV2HistogramModule/multivacV2Settings.js for settings
TWConf.ModulesFlags["multivacV2HistogramModule"] = false ;
// cf. twmodules/crowdsourcingModule/README.md to initialize the associated db
TWConf.ModulesFlags["crowdsourcingModule"] = true ;
......
......@@ -6,7 +6,7 @@
// - a DivsFlag for settings_explorerjs
// - our current dir for this module's files (and this init.js)
// - the class of module's html elements
module_name="histogramModule"
module_name="multivacV1HistogramModule"
module_dir=TW.conf.paths.modules+'/'+module_name
// ---- INIT main part -------- (listing all things to load)
......
......@@ -2,7 +2,6 @@
/* --------------------- search histogram ----------------------- */
/* ---------------------------------------------------------------- */
// TODO be able to expose things from module like a histo.graph object
var hg
// constant values of total docs per year, for normalization
......
// Histogram module
// =================
// Presents a histogram from WOS API
// Presents a histogram from https://api.iscpif.fr (v2 endpoints)
// Our module_name is simultaneously 3 things:
// - a DivsFlag for settings_explorerjs
// - our current dir for this module's files (and this init.js)
// - the class of module's html elements
module_name="histogramDailyVariantModule"
module_name="multivacV2HistogramModule"
module_dir=TW.conf.paths.modules+'/'+module_name
// create an exposed namespace
mvacV2Hg = {}
// ---- INIT main part -------- (listing all things to load)
// our histogram wrapper styles
loadCSS(module_dir+"/histogram.css") ;
// our histogram settings
loadJS(module_dir+"/multivacV2Settings.js") ;
// our histogram controller
loadJS(module_dir+"/dailyHistogram.js") ;
loadJS(module_dir+"/multivacV2Histogram.js") ;
// dygraph library
// loadCSS(module_name+"/dygraph/gallery.css") ;
......
......@@ -2,11 +2,14 @@
/* --------------------- search histogram ----------------------- */
/* ---------------------------------------------------------------- */
// TODO be able to expose things from module like a histo.graph object
var hg
// init and settings exposed in mvacV2Hg var
mvacV2Hg.init = (function(mvacV2Hg){
var $search_histogram = $("#search_histogram2")
var apiEndpoint = mvacV2Hg.settings.endpoint || '/pvt/politic/france/twitter/histogram'
var apiInterval = mvacV2Hg.settings.interval || 'day'
//method for calling the ISC-API and get pubs-distribution of the suggested term
function search_proposed_terms_and_draw( the_queries ) {
......@@ -25,10 +28,19 @@ function search_proposed_terms_and_draw( the_queries ) {
var args = {
// luc_q is a str
"q": luc_q,
"interval": "day"
"interval": apiInterval
}
// no since and until unless specified in settings: we want the entire period
if (mvacV2Hg.settings.since) args.since = mvacV2Hg.settings.since
if (mvacV2Hg.settings.until) args.until = mvacV2Hg.settings.until
// no since and until: we want the entire period
// time window depending on interval
var twindow = 7
if (mvacV2Hg.settings.avgWindowPerInterval && mvacV2Hg.settings.avgWindowPerInterval[apiInterval]) {
twindow = mvacV2Hg.settings.avgWindowPerInterval[apiInterval]
}
var docs_days = [] ;
$search_histogram
......@@ -36,7 +48,7 @@ function search_proposed_terms_and_draw( the_queries ) {
$.ajax({
type: "GET",
url: 'https://api.iscpif.fr/v2/pub/politic/france/twitter/histogram',
url: 'https://api.iscpif.fr' + apiEndpoint,
data: args,
dataType: "json",
success : function(data, textStatus, jqXHR) {
......@@ -70,7 +82,7 @@ function search_proposed_terms_and_draw( the_queries ) {
// console.log("docs_days",docs_days)
// counts_by_year_array
draw_histogram(docs_days) ;
draw_histogram(docs_days, twindow) ;
return true ;
}
},
......@@ -136,14 +148,14 @@ function newnodesHistogramBehavior(selectedNodeIds, unusedQuery) {
// use dygraph lib to draw below the crowdsourcing div
function draw_histogram(counts_by_days_array) {
function draw_histogram(counts_by_days_array, cumulatedWindow) {
// 1) layout for the div#search_histogram
// /!\ this div *needs* padding:0 /!\;
$search_histogram.height("15em").show()
// 2) data preparation
// (cumulated sliding window over [J-7; J])
// (cumulated sliding window over [T-cumulatedWindow; T])
var cumulated_res = [] ;
for (i in counts_by_days_array) {
......@@ -155,7 +167,7 @@ function draw_histogram(counts_by_days_array) {
var sum = 0
var nvalues = 0
for (var j=i; j >= Math.max(i-6, 0); j--) {
for (var j=i; j >= Math.max(i-cumulatedWindow-1, 0); j--) {
sum += counts_by_days_array[j][1]
nvalues++
}
......@@ -210,3 +222,5 @@ function draw_histogram(counts_by_days_array) {
function clean_histogram() {
$("#search_histogram").html("") ;
}
})(mvacV2Hg)
/* --------------------- histogram settings ----------------------- */
mvacV2Hg.settings = {
// ------------------
// MANDATORY SETTINGS
// ------------------
// the endpoint must end in 'histogram'
// (choose any endpoint from https://api.iscpif.fr/docs/)
'apiEndpoint': '/pvt/climate/twitter/histogram',
// if your endpoint starts with '/pvt', you will also need an API key
'APIKey': '',
// -----------------
// OPTIONAL SETTINGS (leave them to null for default values)
// -----------------
// query settings
'since': null,
'until': null,
'interval': 'day', // accepted: 'day', 'week', 'month', 'year'
// cumulated window settings (over how many intervals do we average ?)
'avgWindowPerInterval': {
'day': 7,
'week': 3,
'month': 3,
'year': 2
}
}
......@@ -203,9 +203,10 @@ TW.conf = (function(TW){
// flag name is div class to be removed if false
// *and* subdirectory of modules path to import if true
// see also activateModules()
TWConf.ModulesFlags["histogramModule"] = false ;
TWConf.ModulesFlags["histogramDailyVariantModule"] = false ;
// TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE
TWConf.ModulesFlags["multivacV1HistogramModule"] = false ;
// cf. twmodules/multivacV2HistogramModule/multivacV2Settings.js for settings
TWConf.ModulesFlags["multivacV2HistogramModule"] = false ;
// cf. twmodules/crowdsourcingModule/README.md to initialize the associated db
TWConf.ModulesFlags["crowdsourcingModule"] = false ;
......
......@@ -206,9 +206,10 @@ TW.conf = (function(TW){
// flag name is div class to be removed if false
// *and* subdirectory of modules path to import if true
// see also activateModules()
TWConf.ModulesFlags["histogramModule"] = true ;
TWConf.ModulesFlags["histogramDailyVariantModule"] = false ;
// TODO more generic module integrating the variants cf. experiments/histogramModule_STUB_GENERIQUE
TWConf.ModulesFlags["multivacV1HistogramModule"] = false ;
// cf. twmodules/multivacV2HistogramModule/multivacV2Settings.js for settings
TWConf.ModulesFlags["multivacV2HistogramModule"] = true ;
// cf. twmodules/crowdsourcingModule/README.md to initialize the associated db
TWConf.ModulesFlags["crowdsourcingModule"] = true ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment