<commit_before>define(function() {

    var Metrics = {};

    Metrics.create = function(spec) {
        var that = {};

        that.MINIMUM_FLUID_VOLUME = 0.00001;
        that.GRAVITY = 5;

        that.pipes = spec.pipes;
        that.gravity = spec.hasOwnProperty('gravity') && spec.gravity ? spec.gravity : that.GRAVITY;

        that.pointsMatch = function(pointA, pointB) {
            return (pointA.x == pointB.x) && (pointA.y == pointB.y);
        };

        that.getAngle = function(pipe, point) {
            var up = {x: 0, y: -1},
                atanA = Math.atan2(up.x, up.y),
                atanB;

            if (that.pointsMatch(pipe.vb, point)) {
                atanB = Math.atan2(pipe.va.x - pipe.vb.x, pipe.va.y - pipe.vb.y);

            } else if (that.pointsMatch(pipe.va, point)) {
                atanB = Math.atan2(pipe.vb.x - pipe.va.x, pipe.vb.y - pipe.va.y);
            }

            return atanA - atanB;
        };

        that.getLength = function(pipe) {
            var xs = Math.pow(pipe.va.x - pipe.vb.x, 2),
                ys = Math.pow(pipe.va.y - pipe.vb.y, 2);
            return Math.sqrt(xs + ys);
        };

        that.calculateIncline = function(angle) {
            var half = Math.PI,
                quater = half * 0.5;
            return (angle <= half) ? (angle - quater) / quater : 1 - ((angle - half) / quater);
        };

        that.getFluidVelocity = function(pipe) {
            return pipe.incline * that.gravity;
        };

        that.getIncline = function(pipe, vertex) {
            return that.pointsMatch(pipe.va, vertex) ? pipe.incline : pipe.incline * -1;
        };

        that.getFluidAtVertex = function(pipe, vertex) {
            var fluidCount = pipe.fluids ? pipe.fluids.length : 0,
                fluid;

            while (fluidCount--) {
                fluid = pipe.fluids[fluidCount];

                if (
                    that.pointsMatch(pipe.va, vertex)
                    && fluid.position <= that.MINIMUM_FLUID_VOLUME
                ) {
                    return fluid;
                }

                if (
                    that.pointsMatch(pipe.vb, vertex)
                    && fluid.volume + fluid.position >= pipe.capacity - that.MINIMUM_FLUID_VOLUME
                ) {
                    return fluid;
                }
            }
        };

        that.getConnectedPipeIndexes = function(pipeIndex, vertex) {
            var pipes = [],
                pipe = that.pipes[pipeIndex],
                connectedPipes = (pipe.va == vertex) ? pipe.ca : pipe.cb,
                connectedPipeCount = connectedPipes ? connectedPipes.length : 0;
            while (connectedPipeCount--) {
                pipes.push(connectedPipes[connectedPipeCount]);
            }
            return pipes;
        };

        that.getConnectedPipes = function(pipe, vertex) {
            var pipeIndexes = that.getConnectedPipeIndexes(that.pipes.indexOf(pipe), vertex);
            var pipes = pipeIndexes.map(function(index) {
                return that.pipes[index];
            });
            return pipes;
        };

        that.getVertexPipes = function(pipe, vertex) {
            var pipes = that.getConnectedPipes(pipe, vertex);
            pipes.push(pipe);
            return pipes;
        };

        that.getAvailableCapacity = function(pipe) {
            if ( ! pipe.fluids || pipe.fluids.length === 0) {
                return pipe.capacity;
            }

            var fluidCount = pipe.fluids.length,
                fluid,<commit_msg>Remove the redundant and slightly ridiculous Metrics#getConnectedPipeIndexes method<commit_after>define(function() {

    var Metrics = {};

    Metrics.create = function(spec) {
        var that = {};

        that.MINIMUM_FLUID_VOLUME = 0.00001;
        that.GRAVITY = 5;

        that.pipes = spec.pipes;
        that.gravity = spec.hasOwnProperty('gravity') && spec.gravity ? spec.gravity : that.GRAVITY;

        that.pointsMatch = function(pointA, pointB) {
            return (pointA.x == pointB.x) && (pointA.y == pointB.y);
        };

        that.getAngle = function(pipe, point) {
            var up = {x: 0, y: -1},
                atanA = Math.atan2(up.x, up.y),
                atanB;

            if (that.pointsMatch(pipe.vb, point)) {
                atanB = Math.atan2(pipe.va.x - pipe.vb.x, pipe.va.y - pipe.vb.y);

            } else if (that.pointsMatch(pipe.va, point)) {
                atanB = Math.atan2(pipe.vb.x - pipe.va.x, pipe.vb.y - pipe.va.y);
            }

            return atanA - atanB;
        };

        that.getLength = function(pipe) {
            var xs = Math.pow(pipe.va.x - pipe.vb.x, 2),
                ys = Math.pow(pipe.va.y - pipe.vb.y, 2);
            return Math.sqrt(xs + ys);
        };

        that.calculateIncline = function(angle) {
            var half = Math.PI,
                quater = half * 0.5;
            return (angle <= half) ? (angle - quater) / quater : 1 - ((angle - half) / quater);
        };

        that.getFluidVelocity = function(pipe) {
            return pipe.incline * that.gravity;
        };

        that.getIncline = function(pipe, vertex) {
            return that.pointsMatch(pipe.va, vertex) ? pipe.incline : pipe.incline * -1;
        };

        that.getFluidAtVertex = function(pipe, vertex) {
            var fluidCount = pipe.fluids ? pipe.fluids.length : 0,
                fluid;

            while (fluidCount--) {
                fluid = pipe.fluids[fluidCount];

                if (
                    that.pointsMatch(pipe.va, vertex)
                    && fluid.position <= that.MINIMUM_FLUID_VOLUME
                ) {
                    return fluid;
                }

                if (
                    that.pointsMatch(pipe.vb, vertex)
                    && fluid.volume + fluid.position >= pipe.capacity - that.MINIMUM_FLUID_VOLUME
                ) {
                    return fluid;
                }
            }
        };

        that.getConnectedPipes = function(pipe, vertex) {
            var pipeIndexes = that.pointsMatch(pipe.va, vertex) ? pipe.ca : pipe.cb;
            if ( ! pipeIndexes) {
                return [];
            }
            var pipes = pipeIndexes.map(function(index) {
                return that.pipes[index];
            });
            return pipes;
        };

        that.getVertexPipes = function(pipe, vertex) {
            var pipes = that.getConnectedPipes(pipe, vertex);
            pipes.push(pipe);
            return pipes;
        };

        that.getAvailableCapacity = function(pipe) {
            if ( ! pipe.fluids || pipe.fluids.length === 0) {
                return pipe.capacity;
            }

            var fluidCount = pipe.fluids.length,
                fluid,
{'fraction_non_alphanumeric': 0.1202875165028605, 'fraction_numerical': 0.006014375825143025, 'mean_word_length': 1.394801545486477, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2082078', 'n_tokens_mistral': 2118, 'n_tokens_neox': 1957, 'n_words': 372}