<commit_before>window.multigraph.util.namespace("window.multigraph.core", function (ns) {
    "use strict";

    var WebServiceData,
        Data = ns.Data,
        ArrayData = ns.ArrayData,
        DataValue = ns.DataValue,
        DataFormatter = ns.DataFormatter;

    WebServiceData = window.jermaine.Model(function () {
        var WebServiceData = this;

        this.isA(Data);
        this.hasA("serviceaddress").which.isA("string");
        this.hasA("serviceaddresspattern").which.isA("string");
        this.hasA("format").which.isA("string");
        this.hasA("formatter").which.validatesWith(DataFormatter.isInstance);
        this.isBuiltWith("columns", "serviceaddress", function () {
            this.initializeColumns();
            if (this.columns().size() > 0) {
                var column0Type = this.columns().at(0).type();
                if (this.format() === undefined) {
                    this.format(column0Type===DataValue.NUMBER ? "%f" : "%Y%M%D%H%i%s");
                }
                this.formatter(DataFormatter.create(column0Type, this.format()));
            }
        });

        this.hasA("arraydata").which.defaultsTo(null).and.validatesWith(function(arraydata) {
            return arraydata instanceof ns.ArrayData || arraydata === null;
        });

        /**
         * A pointer to the head WebServiceDataCacheNode in this WebServieData's cache
         */
        this.hasA("cacheHead").which.defaultsTo(null).and.validatesWith(function(x) {
            //NOTE: need "ns." prefix on WebServiceDataCacheNode below, because of file
            //  load order issues
            return x === null || x instanceof ns.WebServiceDataCacheNode;
        });

        /**
         * A pointer to the tail WebServiceDataCacheNode in this WebServieData's cache
         */
        this.hasA("cacheTail").which.defaultsTo(null).and.validatesWith(function(x) {
            //NOTE: need "ns." prefix on WebServiceDataCacheNode below, because of file
            //  load order issues
            return x === null || x instanceof ns.WebServiceDataCacheNode;
        });

        /**
         * Return a pointer to the first WebServiceDataCacheNode in this WebServieData's cache
         * that actually contains data, if any.  If the cache doesn't contain any data, return null.
         */
        this.respondsTo("dataHead", function() {
            var head = this.cacheHead();
            if (head === null) { return null; }
            if (head.hasData()) { return head; }
            return head.dataNext();
        });

        /**
         * Return a pointer to the last WebServiceDataCacheNode in this WebServieData's cache
         * that actually contains data, if any.  If the cache doesn't contain any data, return null.
         */
        this.respondsTo("dataTail", function() {
            var tail = this.cacheTail();
            if (tail === null) { return null; }
            if (tail.hasData()) { return tail; }
            return tail.dataPrev();
        });

        /**
         * Insert a WebServiceCacheNode into this WebService's cache.
         * If this node's coveredMin is less than the cache head's
         * coveredMin, insert it at the head; otherwise insert it at
         * the tail.  Note that nodes are only inserted either at the
         * head or at the tail of the cache --- not in the middle.
         */
        this.respondsTo("insertCacheNode", function(node) {
            var head = this.cacheHead(),
                tail = this.cacheTail();
            if (head === null) {
                this.cacheHead(node);
                this.cacheTail(node);
            } else {
                if (node.coveredMin().lt(head.coveredMin())) {
                    node.next(head);
                    head.prev(node);
                    this.cacheHead(node);
                } else {
                    node.prev(tail);
                    tail.next(node);
                    this.cacheTail(node);
                }
            }
        });

        this.respondsTo("constructRequestURL", function(min, max) {
            if (this.serviceaddress() === undefined) {
                throw new Error("WebServiceData.constructRequestURL: undefined service address");
            }
            if (this.formatter() === undefined) {
                throw new Error("WebServiceData.constructRequestURL: undefined formatter for column 0");
            }
            if (this.serviceaddresspattern() === undefined) {
                if ((this.serviceaddress().indexOf("$min") < 0)
                    &&
                    (this.serviceaddress().indexOf("$max") < 0)) {
                    this.serviceaddresspattern(this.serviceaddress() + "$min,$max");
                } else {
                    this.serviceaddresspattern(this.serviceaddress());
                }
            }
            return (this.serviceaddresspattern()
                    .replace("$min",this.formatter().format(min))
                    .replace("$max",this.formatter().format(max)));
        });

        this.hasA("coveredMin").which.defaultsTo(null).and.validatesWith(function(x) {
            return x === null || DataValue.isInstance(x);
        });
        this.hasA("coveredMax").which.defaultsTo(null).and.validatesWith(function(x) {
            return x === null || DataValue.isInstance(x);
        });

        /**
         * Initiate requests needed to fetch data between coveredMin and coveredMax, if any.
         */
        this.respondsTo("insureCoveredRange", function() {
            var head = this.cacheHead(),
                tail = this.cacheTail(),
                coveredMin = this.coveredMin(),
                coveredMax = this.coveredMax();

            if (coveredMin === null || coveredMax === null) {
                return;
            }
            if (head === null || tail === null) {
                this.requestSingleRange(coveredMin, coveredMax);
            } else {
                if (coveredMin.lt(head.coveredMin())) {
                    //                     head's min              tail's max
                    //  -----|-------------|-----------------------|----------------
                    //       coveredMin
                    this.requestSingleRange(coveredMin, head.coveredMin());
                }
                if (coveredMax.gt(tail.coveredMax())) {
                    //                     head's min              tail's max
                    //  -------------------|-----------------------|-----------|----
                    //                                                         coveredMax
                    this.requestSingleRange(tail.coveredMax(), coveredMax);
                }
            }
        });

        this.respondsTo("requestSingleRange", function(min, max) {
            var node,
                requestURL,
                that = this;

            // create the cache node that will hold the data in this range
            node = new ns.WebServiceDataCacheNode(min, max);

            // insert it into the cache linked list
            this.insertCacheNode(node);

            // construct the URL for fetching the data in this range
            requestURL = this.constructRequestURL(min, max);

            // initiate the fetch request
            $.ajax({
                url      : requestURL,
                dataType : "text",
                success  : function(data) {
                    // if data contains a <values> tag, extract its text string value
                    if (data.indexOf("<values>")) {
                        data = window.multigraph.parser.jquery.stringToJQueryXMLObj(data).find("values").text();
                    }
                    node.parseData(that.getColumns(), data);
                    if (that.readyCallback() !== undefined) {
                        that.readyCallback()(node.dataMin(), node.dataMax());
                    }
                }
            });
        });

        this.respondsTo("getIterator", function(columnIds, min, max, buffer) {
      
            var initialNode,
                initialIndex,
                n, b, i, tmp,
                finalNode,
                finalIndex,<commit_msg>oops; fixes a little bug in previous commit<commit_after>window.multigraph.util.namespace("window.multigraph.core", function (ns) {
    "use strict";

    var WebServiceData,
        Data = ns.Data,
        ArrayData = ns.ArrayData,
        DataValue = ns.DataValue,
        DataFormatter = ns.DataFormatter;

    WebServiceData = window.jermaine.Model(function () {
        var WebServiceData = this;

        this.isA(Data);
        this.hasA("serviceaddress").which.isA("string");
        this.hasA("serviceaddresspattern").which.isA("string");
        this.hasA("format").which.isA("string");
        this.hasA("formatter").which.validatesWith(DataFormatter.isInstance);
        this.isBuiltWith("columns", "serviceaddress", function () {
            this.initializeColumns();
            if (this.columns().size() > 0) {
                var column0Type = this.columns().at(0).type();
                if (this.format() === undefined) {
                    this.format(column0Type===DataValue.NUMBER ? "%f" : "%Y%M%D%H%i%s");
                }
                this.formatter(DataFormatter.create(column0Type, this.format()));
            }
        });

        this.hasA("arraydata").which.defaultsTo(null).and.validatesWith(function(arraydata) {
            return arraydata instanceof ns.ArrayData || arraydata === null;
        });

        /**
         * A pointer to the head WebServiceDataCacheNode in this WebServieData's cache
         */
        this.hasA("cacheHead").which.defaultsTo(null).and.validatesWith(function(x) {
            //NOTE: need "ns." prefix on WebServiceDataCacheNode below, because of file
            //  load order issues
            return x === null || x instanceof ns.WebServiceDataCacheNode;
        });

        /**
         * A pointer to the tail WebServiceDataCacheNode in this WebServieData's cache
         */
        this.hasA("cacheTail").which.defaultsTo(null).and.validatesWith(function(x) {
            //NOTE: need "ns." prefix on WebServiceDataCacheNode below, because of file
            //  load order issues
            return x === null || x instanceof ns.WebServiceDataCacheNode;
        });

        /**
         * Return a pointer to the first WebServiceDataCacheNode in this WebServieData's cache
         * that actually contains data, if any.  If the cache doesn't contain any data, return null.
         */
        this.respondsTo("dataHead", function() {
            var head = this.cacheHead();
            if (head === null) { return null; }
            if (head.hasData()) { return head; }
            return head.dataNext();
        });

        /**
         * Return a pointer to the last WebServiceDataCacheNode in this WebServieData's cache
         * that actually contains data, if any.  If the cache doesn't contain any data, return null.
         */
        this.respondsTo("dataTail", function() {
            var tail = this.cacheTail();
            if (tail === null) { return null; }
            if (tail.hasData()) { return tail; }
            return tail.dataPrev();
        });

        /**
         * Insert a WebServiceCacheNode into this WebService's cache.
         * If this node's coveredMin is less than the cache head's
         * coveredMin, insert it at the head; otherwise insert it at
         * the tail.  Note that nodes are only inserted either at the
         * head or at the tail of the cache --- not in the middle.
         */
        this.respondsTo("insertCacheNode", function(node) {
            var head = this.cacheHead(),
                tail = this.cacheTail();
            if (head === null) {
                this.cacheHead(node);
                this.cacheTail(node);
            } else {
                if (node.coveredMin().lt(head.coveredMin())) {
                    node.next(head);
                    head.prev(node);
                    this.cacheHead(node);
                } else {
                    node.prev(tail);
                    tail.next(node);
                    this.cacheTail(node);
                }
            }
        });

        this.respondsTo("constructRequestURL", function(min, max) {
            if (this.serviceaddress() === undefined) {
                throw new Error("WebServiceData.constructRequestURL: undefined service address");
            }
            if (this.formatter() === undefined) {
                throw new Error("WebServiceData.constructRequestURL: undefined formatter for column 0");
            }
            if (this.serviceaddresspattern() === undefined) {
                if ((this.serviceaddress().indexOf("$min") < 0)
                    &&
                    (this.serviceaddress().indexOf("$max") < 0)) {
                    this.serviceaddresspattern(this.serviceaddress() + "$min,$max");
                } else {
                    this.serviceaddresspattern(this.serviceaddress());
                }
            }
            return (this.serviceaddresspattern()
                    .replace("$min",this.formatter().format(min))
                    .replace("$max",this.formatter().format(max)));
        });

        this.hasA("coveredMin").which.defaultsTo(null).and.validatesWith(function(x) {
            return x === null || DataValue.isInstance(x);
        });
        this.hasA("coveredMax").which.defaultsTo(null).and.validatesWith(function(x) {
            return x === null || DataValue.isInstance(x);
        });

        /**
         * Initiate requests needed to fetch data between coveredMin and coveredMax, if any.
         */
        this.respondsTo("insureCoveredRange", function() {
            var head = this.cacheHead(),
                tail = this.cacheTail(),
                coveredMin = this.coveredMin(),
                coveredMax = this.coveredMax();

            if (coveredMin === null || coveredMax === null) {
                return;
            }
            if (head === null || tail === null) {
                this.requestSingleRange(coveredMin, coveredMax);
            } else {
                if (coveredMin.lt(head.coveredMin())) {
                    //                     head's min              tail's max
                    //  -----|-------------|-----------------------|----------------
                    //       coveredMin
                    this.requestSingleRange(coveredMin, head.coveredMin());
                }
                if (coveredMax.gt(tail.coveredMax())) {
                    //                     head's min              tail's max
                    //  -------------------|-----------------------|-----------|----
                    //                                                         coveredMax
                    this.requestSingleRange(tail.coveredMax(), coveredMax);
                }
            }
        });

        this.respondsTo("requestSingleRange", function(min, max) {
            var node,
                requestURL,
                that = this;

            // create the cache node that will hold the data in this range
            node = new ns.WebServiceDataCacheNode(min, max);

            // insert it into the cache linked list
            this.insertCacheNode(node);

            // construct the URL for fetching the data in this range
            requestURL = this.constructRequestURL(min, max);

            // initiate the fetch request
            $.ajax({
                url      : requestURL,
                dataType : "text",
                success  : function(data) {
                    // if data contains a <values> tag, extract its text string value
                    if (data.indexOf("<values>") > 0) {
                        data = window.multigraph.parser.jquery.stringToJQueryXMLObj(data).find("values").text();
                    }
                    node.parseData(that.getColumns(), data);
                    if (that.readyCallback() !== undefined) {
                        that.readyCallback()(node.dataMin(), node.dataMax());
                    }
                }
            });
        });

        this.respondsTo("getIterator", function(columnIds, min, max, buffer) {
      
            var initialNode,
                initialIndex,
                n, b, i, tmp,
                finalNode,
                finalIndex,
{'fraction_non_alphanumeric': 0.1280369290573372, 'fraction_numerical': 0.001032555879494655, 'mean_word_length': 1.47593984962406, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7433651', 'n_tokens_mistral': 4142, 'n_tokens_neox': 3904, 'n_words': 931}