Skip to content

Code Progression

GosroPoorheydar edited this page Oct 30, 2020 · 2 revisions

Surveydata code.


let kolomNaam = "relatie"

let lijstAntwoorden = getAnswersForQuestion(surveyAnswers, kolomNaam)

console.log("All survey answers are: ", lijstAntwoorden);
console.log("All filtered survey answers are: ", getFilteredAnswers());

//lijstAntwoorden = getAnswersForQuestion(surveyAnswers, [kolomNaam])

// returns all answers for a specific question in an array.
function getAnswersForQuestion(answers, question) {

    if (answers.length === 0) {
        console.error("Array must have items in it")
        return
        //geef answers een waarde
    }

    let answersforQuestion = []
    for (answer of answers) {
        answersforQuestion.push(answer[question])

    }

    return answersforQuestion //array van antwoorden voor een specifieke vraag.

}


//Filtert antwoorden op antwoorden die "Soms" of "Zeg ik liever niet bevatten (Geholpen door Max en Nino)
//Geholpen door victor met de function aan de praat krijgen


function getFilteredAnswers(results) {

    const result = lijstAntwoorden.filter(results => results.length < 4);

    return result;

}

I made code capable of filtering out the relation data within the survey on data that is decisive.("ja" Or "Nee")

Results of my code

Results of my code. The first result is before the filter and the second result is after.

// Shows all unique values in an arry (Applicable to all data).

function findUniqueValues(valueArray) {
    let uniqueArray = []
    valueArray.map(item => {
        if (uniqueArray.indexOf(item) == -1) {
            uniqueArray.push(item)
        }
    })
    return uniqueArray
}

I added code to this project to find all unique values in a data column.

RDW data code

//Step 1: load in the RDW Data. 

//Step 2: Put the data in arrays.

//Step 3: Clean the data (To be done)

//Step 4: Transform the data for use in D3(To be done)


const geoParkeerGarages = 'https://opendata.rdw.nl/resource/t5pc-eb34.json'

const tariefBerekening = 'https://opendata.rdw.nl/resource/nfzq-8g7y.json'

let columnname = "areaid"

//let listanswers = getAnswersForQuestion(geoParkeerGarages, columnname)


//console.log(listanswers)




// Prepares the data from the first dataset to be used

getData(geoParkeerGarages)
    .then(result => {
        return result.json()
    })
    .then(GEOData => {
        console.log("All data: ", GEOData)
        con(getAnswersForQuestion(GEOData, columnname))
        // console.log("one datum", GEOData[4])

    })


// Prepares the data from the second dataset to be used

getData(tariefBerekening)
    .then(result => {
        return result.json()
    })
    .then(berekeningData => {
        // console.log("All data: ", berekeningData)
        // console.log("one datum", berekeningData[4])

    })

function getData(url) {
    return fetch(url)
}


// Find all unique valley in an array (Not functional yet)

function findUniqueValues(valueArray) {
    let uniqueArray = []
    valueArray.map(item => {
        if (uniqueArray.indexOf(item) == -1) {
            uniqueArray.push(item)
        }
    })
    return uniqueArray
}

// returns all answers for a specific question in an array.

function getAnswersForQuestion(answers, question) {


    let answersforQuestion = []
    for (answer of answers) {
        answersforQuestion.push(answer[question])

    }

    return answersforQuestion //array van antwoorden voor een specifieke vraag.

}

function con(data) {
    console.log(data)
}

Clone this wiki locally