index.html 5.12 KB
<html>
<head>

    <script type="text/javascript" src="../bower_components/csvjson/csvjson.min.js"></script>

    <script type="text/javascript" src="../src/ArrayUtils.js"></script>
    <script type="text/javascript" src="../src/DataTypesUtils.js"></script>
    <script type="text/javascript" src="../src/DataTypeConverter.js"></script>

    <link rel="import" href="../bower_components/polymer/polymer.html">
    <link rel="import" href="../bower_components/paper-progress/paper-progress.html">
    <script type="text/javascript" src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>

    <style is="custom-style">
        paper-progress {
            --paper-progress-active-color: #FFC107;
            --paper-progress-container-color: white;
            --paper-progress-height: 20px;
            border: 1px solid black;
        }
    </style>
</head>
<body>
    <h3>Dataset Visualizer</h3>

    Dataset URL: <input id="txtDatasetUrl" type="text" style="width: 75%;"
            value="http://ckan.routetopa.eu/dataset/fce7b89c-4c36-47c4-a486-7df5307a884e/resource/1b675fb7-8c9a-46d0-8f80-3e28afe4f4b5/download/litterwardennonulls.csv">
    <input id="btnLoad" type="button" value="Load dataset" onclick="btnLoad_OnClick();">

    <br/>




    <table border="0">
    <tr>
        <td>Data homogeneity:</td>
        <td><paper-progress id="barHomogeneity" value="0">sbiricuda</paper-progress></td>
        <td id="barHomogeneityValue"></td>
    </tr>

    <!--<tr>
        <td>Dataset Not Null Values:</td>
        <td><paper-progress id="barNotNull" value="0">sbiricuda</paper-progress></td>
        <td id="barNotNullValues"></td>
    </tr>-->

    <tr>
        <td>Dataset Consistent Values:</td>
        <td><paper-progress id="barErrors" value="0">sbiricuda</paper-progress></td>
        <td id="barErrorsValues"></td>
    </tr>
    </table>


    <br>
    <table border=1>
        <thead>
        <tr id="trHeader">

        </tr>
        <tr id="trHeaderType">

        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>
    </table>

    <script type="text/javascript">

        window.onload = function() {
            //var chartProcessor = new ChartProcessor();
            //chartProcessor.inferDataTypes(urllnk);
        }//EndFunction.

        var httpGetAsync = function(theUrl, callback) {
            var xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200)
                    callback(xhttp.responseText);
            };
            xhttp.open("GET", theUrl, true); // true for asynchronous
            xhttp.send(null);
        };//EndFunction.

        function btnLoad_OnClick() {
        //Take the url from the input text.
        var valDatasetUrl = document.getElementById('txtDatasetUrl').value;

        //Call Ajax to load the dataset content.
        httpGetAsync(valDatasetUrl, update);
        };//EndFunction.

        function update(csvContent) {
            console.log("update function.");
            var _arrUtils = new ArrayUtils();

            var reader =  new csvjson();
            var jsonDataset = reader.read(csvContent);

            var _converter = new DataTypeConverter();
            var path = [ "records", "*" ];
            var processingResult = _converter.inferJsonDataType(jsonDataset, path);
            var types = processingResult.types;

            //Create the header table.
            var trHeader = document.getElementById('trHeader');
            ArrayUtils.IteratorOverKeys(types, function(field) {
                var ntd = document.createElement("th");
                ntd.innerHTML = field.name;
                trHeader.appendChild(ntd);
            });

            debugger;
            var trHeaderType = document.getElementById('trHeaderType');
            ArrayUtils.IteratorOverKeys(types, function(field){
                var ntd = document.createElement("th");
                ntd.innerHTML = field.type + " (" + Math.round(field.typeConfidence * 100 * 100) / 100 + "%)";
                trHeaderType.appendChild(ntd);
            });

            var processingResults = _converter.convert(processingResult);

            var percentage = processingResult.qualityIndex.homogeneity*100;
            var barHomogeneity = document.getElementById("barHomogeneity");
            barHomogeneity.setAttribute("value", percentage);
            document.getElementById("barHomogeneityValue").innerHTML = Math.round(percentage*100)/100 + "%";

            /*var percentage = processingResult.qualityIndex.notNullValues*100;
            var barConsistency = document.getElementById("barNotNull");
            barConsistency.setAttribute("value", percentage);
            document.getElementById("barNotNullValues").innerHTML = Math.round(percentage*100)/100 + "%";*/

            var percentage = processingResult.qualityIndex.errors*100;
            var barConsistency = document.getElementById("barErrors");
            barConsistency.setAttribute("value", percentage);
            document.getElementById("barErrorsValues").innerHTML = Math.round(percentage*100)/100 + "%";

        }//EndFunction.
    </script>
</body>
</html>