Difference between revisions of "MediaWiki:Common.js"

Jump to: navigation, search
 
(136 intermediate revisions by 4 users not shown)
Line 1: Line 1:
/* Arrays with data needed for the main page */
  lifeCycleTopics = [
    ['Image file','Impact Evaluation Design', 'A brief introduction to common IE methods, concept note, monitoring compliance and impact evaluation manual. The page also has links to sample IE concept note, protocol for monitoring compliance and impact evaluation manual.'],
    ['https://dimewiki.worldbank.org/images/3/3c/Sample_Size_Formula.png','Sampling & Power Calculations','This page discusses how to create a statistically valid sample representative of the population of interest for impact evaluation.'],
    ['Image file','Human Subjects Approval','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Preparing for Data Collection','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Survey Firm Procurement','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Questionnaire Design','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Questionnaire Translation','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Questionnaire Programming','This topic discusses how to take the questionnaire you developed during Questionnaire Design and make it a digital CAPI questionnaire. It discusses how to plan that work and best practices to remember to make the work flow as easy as possible for the enumerator as well as reducing the risk for lost or corrupted data.'],
    ['Image file','Survey Pilot','This page discusses what a survey pilot is, and also discusses the stages, timeline, people involved, and the structure of a survey pilot.'],
    ['Image file','Enumerator Training','This page highlights the best practices to follow during enumerator training and the development of enumerator manual.'],
    ['Image file','Monitoring Data Quality','This page discusses ways in which survey data can be monitored for quality. The page also includes practical tips on data quality management and tips on how to conduct duplicate and survey log checks, high frequency checks, and back checks.'],
    ['Image file','Data Management','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Data Cleaning','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Data Analysis','Fill this in by edit the page MediaWiki:Common.js'],
    ['Image file','Reproducible Research','Fill this in by edit the page MediaWiki:Common.js']
  ];
  standAloneTopics = [
    'Stata Coding Practices','SurveyCTO Coding Practices','Geo Spatial Data','Check Lists for Field Coordinators','i2i Trust Fund for Impact Evaluation','Impact Evaluation Team','Cost-effectiveness Analysis'];
  standAloneTopics.sort(function(a, b){return 0.5 - Math.random()});
/* Arrays with data needed for checklists */
{{Survey_checklist}} 
  questionnaire_chk_content = [
      [1,'Pre-pilot'],
        [2,'Are the conceptual / structural issues identified in the early questionnaire design process sufficiently explored?'],
        [2,'How might the composition of the focus (gender, age, religion, caste/socioeconomic status) affect responses?'],
        [2,'Try to get at how potential respondents think about the key indicators you are trying to measure'],
        [2,'Do you have a translator providing simultaneous translation? If not, does the amount of note-taking correspond to the amount of discussion?'],
      [1,'Survey Design'],
        [2,'Do the questions make sense to the respondent?'],
          [3,'Watch how the respondent reacts to each question – any confusion? How is the reaction time?'],
          [3,'Are there questions that require explanation by enumerator, or clarification from respondent?'],
          [3,'Follow-up with the enumerator (and possibly the respondent) on questions that seemed problematic: is the issue translation? Phrasing? Conceptual? Cultural?'],
        [2,'Are answer options comprehensive?'],
          [3,'Ensure that all ‘other’ responses are specified and recorded'],
        [2,'Is the enumerator following the scripted translations?'],
          [3,'If not, ask the enumerator to note any translation issues to discuss with the team.'],
          [3,'If you do not speak the language, you can still note if interviewer’s questions were noticeably longer/shorter than the written question.'],
      [1,'Interview flow and timing'],
        [2,'How is the flow of the interview?'],
          [3,'Any pauses? (likely areas where interviewers need more instructions)'],
          [3,'Are there times when the respondent looks bored? Uncomfortable? Losing interest?'],
        [2,'Could the order of modules be improved? The order of questions within modules?'],
        [2,'How long does the interview take?'],
          [3,'Check length of each module by noting start and stop time.'],
          [3,'Expect that pilot interviews will take much longer than actual interviews (likely twice as long) – interviewers are expected to do extra probing, take qualitative notes, and record open-ended responses, and the survey instrument may not yet flow well']
      ]
    questionnaire_chk_data = [
      [1,'Pre-pilot'],
        [2,'Are the conceptual / structural issues identified in the early questionnaire design process sufficiently explored?'],
        [2,'How might the composition of the focus (gender, age, religion, caste/socioeconomic status) affect responses?'],
        [2,'Try to get at how potential respondents think about the key indicators you are trying to measure'],
        [2,'Do you have a translator providing simultaneous translation? If not, does the amount of note-taking correspond to the amount of discussion?'],
      [1,'Programming'],
        [2,'Are all skip patterns working as expected?'],
        [2,'Are questions displaying properly on the screen?'],
          [3,'Are there any questions that should be grouped / ungrouped?'],
        [2,'Did all modules appear?'],
        [2,'Are built-in data checks (for outliers or inconsistent responses) working correctly?'],
      [1,'Interview flow and timing'],
        [2,'How is the flow of the interview?'],
          [3,'Any pauses? (likely areas where interviewers need more instructions)'],
          [3,'Are there times when the respondent looks bored? Uncomfortable? Losing interest?'],
        [2,'Could the order of modules be improved? The order of questions within modules?'],
        [2,'How long does the interview take?'],
          [3,'Check length of each module by noting start and stop time.'],
          [3,'Expect that pilot interviews will take much longer than actual interviews (likely twice as long) – interviewers are expected to do extra probing, take qualitative notes, and record open-ended responses, and the survey instrument may not yet flow well'],
      [1,'Data'],
        [2,'Export pilot data from servers to .csv files (if CAPI) and import it into Stata, using either odkmeta or the Stata template provided by Survey CTO.'],
          [3,'It is extremely important to make sure the export works as you expect and you are able to open and check the dataset in Stata!'],
        [2,'Do all modules appear? Do all variables in all modules appear?'],
          [3,'Pay close attention to tables and nested loops.'],
        [2,'Check labels'],
          [3,'Are all variables correctly labeled in English (and not too long for Stata)?'],
          [3,'Check that values for categorical responses are labeled in English (and not too long for Stata)'],
        [2,'Check that all skip patterns worked as expected'],
        [2,'Check for (unexpected) missing data by variable'],
        [2,'Check variance: both high and low.'],
          [3,'If all pilot respondents give the same answer, the data point may not be informative.'],
          [3,'High variance may indicate question needs to be more precise or checks built in to the survey instrument to alert enumerator of extreme values in real time.'],
          [3,'These checks depend on large sample (rough rule of thumb: not informative if n<30).'],
        [2,'Does all ‘pre-loaded’ data appear as expected?'],
      [1,'High frequency checks'],
        [2,'Use the dataset to program a do-file for high-frequency checks (see DIME template for example)'],
        [2,'Run the high-frequency do-file and de-bug as needed'],
        [2,'Export results of checks, and discuss and agree with the survey firm on a final format for communicating and resolving issues discovered in the checks']
    ]


/* Functions creating divs ready to be loaded at the wiki */
/* Functions creating divs ready to be loaded at the wiki */
$(function () {
$(function () {
/*nothing is done with this array yet*/
  elements = [
    ['dimewiki-mainpage-lc-js'  ,dispTopics_lc  ,lifeCycleTopics],
    ['dimewiki-mainpage-sa-js'  ,dispTopics_sa  ,standAloneTopics],
    ['dimewiki-chk-surveyprep'  ,checklistTable ,chk_surveyprep],
    ['dimewiki-chk-questcont'  ,checklistTable ,questionnaire_chk_content],
    ['dimewiki-chk-questdata'  ,checklistTable ,questionnaire_chk_data]
  ]




  /*console.log(Questionnaire_chk_Content);*/
//This is a list of all checklist. Add to this array when you add a new checklist. For any other edits to the checklists, see the instructions here: https://github.com/worldbank/DIMEwiki/Topics/Checklists
checklists = [
  'chk_surveyprep', 'chk_questcont', 'chk_questdata',
  'chk_microdata', 'chk_datacleaning', 'checklist1',
  'chk_submittable', 'chk_reviewgraphs', 'chk_surveyprotocols'
];


  if (document.getElementById("dimewiki-mainpage-lc-js") != null ) {
//Loop over all the checklists
    document.getElementById('dimewiki-mainpage-lc-js').innerHTML = dispTopics_lc(lifeCycleTopics);
for (chkNum in checklists) {
  }
  if (document.getElementById("dimewiki-mainpage-sa-js") != null ) {
    document.getElementById('dimewiki-mainpage-sa-js').innerHTML = dispTopics_sa(standAloneTopics);
  }
  if (document.getElementById("dimewiki-chk-surveyprep") != null ) {
    document.getElementById('dimewiki-chk-surveyprep').innerHTML = checklistTable(chk_surveyprep);
  }
  if (document.getElementById("dimewiki-chk-questcont") != null ) {
    document.getElementById('dimewiki-chk-questcont').innerHTML = checklistTable(questionnaire_chk_content);
  }
  if (document.getElementById("dimewiki-chk-questdata") != null ) {
    document.getElementById('dimewiki-chk-questdata').innerHTML = checklistTable(questionnaire_chk_data);
  }


  //Get checklist name
  var chkName = checklists[chkNum];


  //Test if a div with the name of the checklist exist on the article just loaded
  if (document.getElementById(chkName) != null ) {


}());
    //If a div with that name exist, generate the checklist and put it in that div
    getChecklist(chkName);
  }
}


function getChecklist(chklistname) {


/* Functions needed for checklists */
var requri  =  'https://api.github.com/repos/worldbank/DIMEwiki/contents/Topics/Checklists/checklists/'+ chklistname + '.js';


function checklistTable(chkarray) {
//Call the GitHub API
requestJSON(requri, function(json) {


  var tableString = '<table class="chk_table">';
  //If call unsuccessful, give error message
  tableString += '<tr><th rowspan="4" colspan="3">DIME Image (Coming)</th>';
  if(json.message == "Not Found" ) {
  tableString += '<tr><th>Project name: _______________________________________________</th>';
      document.getElementById(chklistname).innerHTML = "<h3>Checklist not found, check the name of the checklist</h3>"
  tableString += '<tr><th>Country: _______________________________________________</th>';
  tableString += '<tr><th>District: _______________________________________________</th>';
  tableString += '<tr><td></td><td>Initials</td><td>#No</td><td>Checklist Item</td></tr>';


  var levelTracker = [0]
    } else {


  for ( row = 0 ; row < chkarray.length ; ++row ) {
      //Call is successfull
    var thisLevel =chkarray[row][0];
    var thisIndex = thisLevel - 1;
    var thisItem =chkarray[row][1];




      //Function to decode result from GitHub
      function b64DecodeUnicode(str) {
        //Source https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
        // Going backwards: from bytestream, to percent-encoding, to original string.
          return decodeURIComponent(atob(str).split('').map(function(c) {
            return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
        }).join(''));
      }


    if ( levelTracker.length > thisLevel) {
      //Decode result and put it in parse it to JSON format
      levelTracker.splice(thisLevel, levelTracker.length - (thisLevel));
      var checklistSTR = b64DecodeUnicode(json.content);
    } else if ( levelTracker.length < thisLevel) {
      var checklist = JSON.parse("[" + checklistSTR + "]");
      levelTracker.push(0)
    }


    ++levelTracker[thisIndex]
      //Create the checklist table and put it to the html div.
      document.getElementById(chklistname).innerHTML =  createChecklistTable(checklist,chklistname);


    }
  }); // end requestJSON Ajax call
}


    var number = levelTracker.join(".")
//The function that calls the GitHub API
 
function requestJSON(url, callback) {
    tableString += checklistRow(thisLevel, thisItem, number)
$.ajax({
  }
  url: url,
  tableString += '</table>'
  complete: function(xhr) {
 
    callback.call(null, xhr.responseJSON);
  return tableString
  }
 
});
}
}




function checklistRow(thisLevel, thisItem, number)
/* Functions needed for checklists */
{


  var  tableString = '';
function createChecklistTable(chkarray, chkName) {


  var checkbox = (thisLevel == 1 ? '' : '[ __ ]')
var tableString = '<table class="chk_table">';
tableString += '<tr><th rowspan="5" colspan="3" style="text-align: center;"><img alt="DIME Image" src="/images/a/a8/DIMEi2i.png" class="chk_logo_img"></th>';
tableString += '<tr><th class="chk_header">Project name: _______________________________________</th>';
  tableString += '<tr><th class="chk_header">Country: ___________________________________________</th>';
tableString += '<tr><th class="chk_header">District: ____________________________________________</th>';
tableString += '<tr><th class="chk_header">Year, Month and/or Day:  _____________________________</th>';


  switch (thisLevel) {
var levelTracker = [0]
      case 1:
          tr_class = 'class="chk_row1"';
          break;
      case 2:
          tr_class = 'class="chk_row2"';
          break;
      case 3:
          tr_class = 'class="chk_row3"';
          break;
      case 4:
          tr_class = 'class="chk_row4"';
          break;
      default:
        /*implicitly 5 or above*/
          tr_class = 'class="chk_row5"';
  }


  return '<tr '+tr_class+'><td nowrap>'+checkbox+'</td><td></td><td nowrap class="chk_number">'+ number +'</td><td class="chk_item">'+ thisItem +'</td></tr>';
for ( row = 0 ; row < chkarray.length ; ++row ) {
  var thisLevel =chkarray[row][0];
  var thisIndex = thisLevel - 1;
  var thisItem =chkarray[row][1];


}
  if ( levelTracker.length > thisLevel) {
    levelTracker.splice(thisLevel, levelTracker.length - (thisLevel));
  } else if ( levelTracker.length < thisLevel) {
    levelTracker.push(0)
  }


  ++levelTracker[thisIndex]


/* Functions needed for the main page */
  var number = levelTracker.join(".")


  tableString += checklistRow(thisLevel, thisItem, number)
}


var tableFooter = '<tr><td colspan="4">The checklist are edited through Git Hub. This checklist corresponds to the file with the name <b>' + chkName+ '.js</b>. To read a simple step by step guide on how to edit the checklist, see this documentation:<br><a href="https://github.com/worldbank/DIMEwiki/tree/master/Topics/Checklists">https://github.com/worldbank/DIMEwiki/tree/master/Topics/Checklists</a>.</td></tr>'


function dispTopics_lc(topicArray)
tableString += tableFooter +'</table>'
  {
    var topicTable = '<div class="table-div"><table style="width:100%">';
    topicTable += '<col width=20%><col width=80%><tr>';


    for ( topic = 0 ; topic < topicArray.length ; ++topic ) {
return tableString
}


      topicTable += '<td rowspan="2"><a href="/wiki/'+ topicArray[topic][1] +'"><img alt="'+ topicArray[topic][1] +' Image" src="'+ topicArray[topic][0] +'" class="dw-mp-topicimg"></td>';
      topicTable += '<td class="td_lc_titl"><a href="/wiki/'+ topicArray[topic][1] +'">'+ topicArray[topic][1] +'</a></td>';
      topicTable += '</tr><tr>';
      topicTable += '<td class="td_lc_desc">'+ topicArray[topic][2] +'</td></tr>';


    }
function checklistRow(thisLevel, thisItem, number)
 
{
    topicTable += '</table></div>';


    return topicTable;
var  tableString = '';
  }


  function dispTopics_sa(topicArray)
if (thisLevel == 1) {
  {
    tableString += '<tr class="chk_row1"><td colspan="4">'+ number +'. '+ thisItem +'</td></tr>';
    tableString += '<tr><td></td><td>Initials</td><td>#No</td><td>Checklist Item</td></tr>';
    return tableString


    var topicTable = '<div class="table-div"><table style="width:100%">';
} else {


    for ( topic = 0 ; topic < topicArray.length ; ++topic ) {
  switch (thisLevel) {
      case 2:
          tr_class = 'class="chk_row2"';
          break;
      case 3:
          tr_class = 'class="chk_row3"';
          break;
      case 4:
          tr_class = 'class="chk_row4"';
          break;
      default:
        /*implicitly 5 or above*/
          tr_class = 'class="chk_row5"';
  }


      topicTable += '<tr><td class="td_sa"><a href="/wiki/'+ topicArray[topic] +'">'+ topicArray[topic] +'</a></td></tr>';
  tableString += '<tr '+tr_class+'><td nowrap>[ __ ]</td><td></td><td nowrap class="chk_number">'+ number +'</td><td class="chk_item">'+ thisItem +'</td></tr>';
    }


    topicTable += '</table></div>';
  return tableString
}
}


    return topicTable;
}());
  }

Latest revision as of 18:27, 21 January 2021

/* Functions creating divs ready to be loaded at the wiki */
$(function () {


//This is a list of all checklist. Add to this array when you add a new checklist. For any other edits to the checklists, see the instructions here: https://github.com/worldbank/DIMEwiki/Topics/Checklists
checklists = [
  'chk_surveyprep', 'chk_questcont', 'chk_questdata',
  'chk_microdata', 'chk_datacleaning', 'checklist1',
  'chk_submittable', 'chk_reviewgraphs', 'chk_surveyprotocols'
];

//Loop over all the checklists
for (chkNum in checklists) {

  //Get checklist name
  var chkName = checklists[chkNum];

  //Test if a div with the name of the checklist exist on the article just loaded
  if (document.getElementById(chkName) != null ) {

    //If a div with that name exist, generate the checklist and put it in that div
    getChecklist(chkName);
  }
}

function getChecklist(chklistname) {

 var requri   =   'https://api.github.com/repos/worldbank/DIMEwiki/contents/Topics/Checklists/checklists/'+ chklistname + '.js';

 //Call the GitHub API
 requestJSON(requri, function(json) {

   //If call unsuccessful, give error message
   if(json.message == "Not Found" ) {
      document.getElementById(chklistname).innerHTML = "<h3>Checklist not found, check the name of the checklist</h3>"

    } else {

      //Call is successfull


      //Function to decode result from GitHub
      function b64DecodeUnicode(str) {
         //Source https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
         // Going backwards: from bytestream, to percent-encoding, to original string.
           return decodeURIComponent(atob(str).split('').map(function(c) {
             return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
         }).join(''));
       }

       //Decode result and put it in parse it to JSON format
       var checklistSTR = b64DecodeUnicode(json.content);
       var checklist = JSON.parse("[" + checklistSTR + "]");

       //Create the checklist table and put it to the html div.
       document.getElementById(chklistname).innerHTML =  createChecklistTable(checklist,chklistname);

     }
  }); // end requestJSON Ajax call
}

//The function that calls the GitHub API
function requestJSON(url, callback) {
 $.ajax({
   url: url,
   complete: function(xhr) {
     callback.call(null, xhr.responseJSON);
   }
 });
}


/* Functions needed for checklists */

function createChecklistTable(chkarray, chkName) {

 var tableString = '<table class="chk_table">';
 tableString += '<tr><th rowspan="5" colspan="3" style="text-align: center;"><img alt="DIME Image" src="/images/a/a8/DIMEi2i.png" class="chk_logo_img"></th>';
 tableString += '<tr><th class="chk_header">Project name: _______________________________________</th>';
 tableString += '<tr><th class="chk_header">Country: ___________________________________________</th>';
 tableString += '<tr><th class="chk_header">District: ____________________________________________</th>';
 tableString += '<tr><th class="chk_header">Year, Month and/or Day:  _____________________________</th>';

var levelTracker = [0]

 for ( row = 0 ; row < chkarray.length ; ++row ) {
   var thisLevel =chkarray[row][0];
   var thisIndex = thisLevel - 1;
   var thisItem =chkarray[row][1];

   if ( levelTracker.length > thisLevel) {
     levelTracker.splice(thisLevel, levelTracker.length - (thisLevel));
   } else if ( levelTracker.length < thisLevel) {
     levelTracker.push(0)
   }

   ++levelTracker[thisIndex]

   var number = levelTracker.join(".")

   tableString += checklistRow(thisLevel, thisItem, number)
 }

 var tableFooter = '<tr><td colspan="4">The checklist are edited through Git Hub. This checklist corresponds to the file with the name <b>' + chkName+ '.js</b>. To read a simple step by step guide on how to edit the checklist, see this documentation:<br><a href="https://github.com/worldbank/DIMEwiki/tree/master/Topics/Checklists">https://github.com/worldbank/DIMEwiki/tree/master/Topics/Checklists</a>.</td></tr>'

 tableString += tableFooter +'</table>'

 return tableString
}


function checklistRow(thisLevel, thisItem, number)
{

 var  tableString = '';

 if (thisLevel == 1) {
     tableString += '<tr class="chk_row1"><td colspan="4">'+ number +'. '+ thisItem +'</td></tr>';
     tableString += '<tr><td></td><td>Initials</td><td>#No</td><td>Checklist Item</td></tr>';
     return tableString

 } else {

   switch (thisLevel) {
       case 2:
           tr_class = 'class="chk_row2"';
           break;
       case 3:
           tr_class = 'class="chk_row3"';
           break;
       case 4:
           tr_class = 'class="chk_row4"';
           break;
       default:
         /*implicitly 5 or above*/
           tr_class = 'class="chk_row5"';
   }

   tableString += '<tr '+tr_class+'><td nowrap>[ __ ]</td><td></td><td nowrap class="chk_number">'+ number +'</td><td class="chk_item">'+ thisItem +'</td></tr>';

   return tableString
 }
}

}());