Skip to content

Instantly share code, notes, and snippets.

@neumantm
Created November 12, 2023 17:44
Show Gist options
  • Save neumantm/b455ede12187f50b5d4358d6f15a89af to your computer and use it in GitHub Desktop.
Save neumantm/b455ede12187f50b5d4358d6f15a89af to your computer and use it in GitHub Desktop.
ReqDoc Priority Questionnaire

This is a questionnaire to survey the priority of the various requirements.

For the full requirements document including some paragraphs of explanation, see the full requirements document.

Please fill out the following three values for each requirement (if you do not have an opinion on a requirement, please leave it blank):

  • Priority: The priority of the requirement. The higher the number, the more important the requirement is.
    • 0 means "I do not want this requirement to be fulfilled at all"
    • 1 means "I want this requirement to be fulfilled, but with the lowest priority"
    • ...
    • 9 means "I want this requirement to be fulfilled with the highest priority"
  • Satisfaction if fulfilled: How would you feel about this requirement being fulfilled:
    • ++ means "I like it (above excpectation)"
    • + means "I expect it"
    • 0 means "I am neutral"
    • - means "I tolerate it"
    • -- means "I dislike it (I don't want it to be fulfilled)"
  • Satisfaction if not fulfilled: How would you feel about this requirement not being fulfilled:
    • ++ means "I like it (I don't want it to be fulfilled)"
    • + means "I expect it (I'd rather not have it fulfilled)"
    • 0 means "I am neutral"
    • - means "I tolerate it (I'd rather have it fulfilled)"
    • -- means "I dislike it (I want it to be fulfilled)"

For entering the values effiecintly, I'd suggest using Tab and the numpad (including + and -).

The entered data is store in the browser's local storage and will be available for the next time you open this page (unless you clear your browsers local storage). If you want to make sure that your data is not lost, you can export the data using the button below and import it again later. To submit the data, export it and send it to .

const localStorage_key = "req_prio_questionnaire_data_json"
const jsonKey_prio = "prio"
const jsonKey_sat_f = "sat_f"
const jsonKey_sat_n = "sat_n"
const elementId_prio = "prio-"
const elementId_sat_f = "sat_f-"
const elementId_sat_n = "sat_n-"
function docReady(fn) {
// see if DOM is already available
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
function loadDataFormLocalStorage() {
data = window.localStorage.getItem(localStorage_key)
let data_parsed;
try {
data_parsed = JSON.parse(data)
} catch (e) {
alert('Internal error: The data in the local storage is not a valid JSON file.')
}
if (typeof data_parsed !== 'object' ||
Array.isArray(data_parsed) ||
data_parsed === null) {
alert('Internal error: The data in the local storage does not contain a JSON object as top level element.')
return;
}
return data_parsed
}
function setInputValues(data) {
for (element of document.querySelectorAll('input.data-prio,input.data-sat_f,input.data-sat_n')) {
req_id = element.id.split("-")[1]
if (data[req_id] == null) {
data[req_id] = {}
}
if (element.id.startsWith(elementId_prio)) {
element.value = data[req_id][jsonKey_prio] || ""
}
if (element.id.startsWith(elementId_sat_f)) {
element.value = data[req_id][jsonKey_sat_f] || ""
}
if (element.id.startsWith(elementId_sat_n)) {
element.value = data[req_id][jsonKey_sat_n] || ""
}
}
}
docReady(function () {
data = window.localStorage.getItem(localStorage_key)
if (data == null) {
alert('No data found in storage. Initializing empty dataset.')
window.localStorage.setItem(localStorage_key, "{}")
}
data_parsed = loadDataFormLocalStorage()
console.log("Loading data from storage. Got data for " + Object.keys(data_parsed).length + " requirements.")
setInputValues(data_parsed)
});
function updateInput(element) {
element.reportValidity()
console.log("Update:" + element.id)
data_parsed = loadDataFormLocalStorage()
req_id = element.id.split("-")[1]
if (data_parsed[req_id] == null) {
data_parsed[req_id] = {}
}
if (element.id.startsWith(elementId_prio)) {
data_parsed[req_id][jsonKey_prio] = element.value
}
if (element.id.startsWith(elementId_sat_f)) {
data_parsed[req_id][jsonKey_sat_f] = element.value
}
if (element.id.startsWith(elementId_sat_n)) {
data_parsed[req_id][jsonKey_sat_n] = element.value
}
data_new = JSON.stringify(data_parsed)
window.localStorage.setItem(localStorage_key, data_new)
}
function exportData() {
console.log("Export")
data = window.localStorage.getItem(localStorage_key)
console.log(data)
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data));
element.setAttribute('download', "tim_ma_requirements_prios_your_name.json");
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function importData() {
if (!confirm('Importing data will clear all current data. Are you sure you want to continue?')) {
return false;
}
console.log("Import")
let input = document.createElement('input');
input.type = 'file';
input.onchange = _ => {
// you can use this method to get file and perform respective operations
let files = Array.from(input.files);
if (files.length > 1) {
alert('Please select only one file.');
return;
}
if (files.length < 1) {
alert('You did not select a file.');
return;
}
var fr = new FileReader();
fr.onload = function () {
new_json = fr.result;
if (new_json.length == 0) {
alert('The selected file is empty.');
return;
}
let new_json_parsed;
try {
new_json_parsed = JSON.parse(new_json)
} catch (e) {
alert('The selected file is not a valid JSON file.');
return;
}
if (typeof new_json_parsed !== 'object' ||
Array.isArray(new_json_parsed) ||
new_json_parsed === null) {
alert('The selected file does not contain a JSON object as top level element.');
return;
}
console.log("Improting data. Got data for " + Object.keys(new_json_parsed).length + " requirements.")
window.localStorage.setItem(localStorage_key, new_json)
setInputValues(new_json_parsed)
}
fr.readAsText(files[0]);
};
input.click();
}
function resetData() {
if (!confirm('Are you sure you want to delete all entered data?')) {
return false;
}
console.log("Reset")
window.localStorage.setItem(localStorage_key, "{}")
setInputValues({})
}
input:invalid {
border-color: red;
}
input,
input:valid {
border-color: #ccc;
}
table,
th,
td {
border: 1px solid black;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment