text:
import {Arrayable} from "core/types"
import {SpatialIndex, IndexedRect} from "core/util/spatial"
import * as p from "core/properties"
import {Glyph, GlyphView, GlyphData} from "./glyph"

export interface XYGlyphData extends GlyphData {
  _x: Arrayable<number>
  _y: Arrayable<number>

  sx: Arrayable<number>
  sy: Arrayable<number>
}

export interface XYGlyphView extends XYGlyphData {}

export abstract class XYGlyphView extends GlyphView {
  model: XYGlyph
  visuals: XYGlyph.Visuals

  protected _index_data(): SpatialIndex {
    const points: IndexedRect[] = []

    for (let i = 0, end = this._x.length; i < end; i++) {
      const x = this._x[i]
      const y = this._y[i]

      if (isNaN(x + y) || !isFinite(x + y))
        continue

      points.push({minX: x, minY: y, maxX: x, maxY: y, i})
    }

    return new SpatialIndex(points)
  }

  scenterx(i: number): number {
    return this.sx[i]
  }

  scentery(i: number): number {
    return this.sy[i]
  }
}

export namespace XYGlyph {
  export type Attrs = p.AttrsOf<Props>

  export type Props = Glyph.Props & {
    x: p.CoordinateSpec
    y: p.CoordinateSpec
  }

  export type Visuals = Glyph.Visuals
}

export interface XYGlyph extends XYGlyph.Attrs {}

export abstract class XYGlyph extends Glyph {
  properties: XYGlyph.Props

  constructor(attrs?: Partial<XYGlyph.Attrs>) {
    super(attrs)
  }

  static initClass(): void {
    this.prototype.type = "XYGlyph"

    this.coords([['x', 'y']])
  }
}
XYGlyph.initClass()


text:
title: "Application Navigation with the New Angular 2 Router"
layout: post
description:
categories: [blog]
tags: [angular2]
comments: true
modified: 2016-06-24T09:45:23-07:00
---
We are building an application on Angular 2. We've beeing working with Angular 2
since Beta 8. Recently we have made the upgrade from RC1 to RC3. In this upgrade,
it seems as if the [official Angular 2 docs have been updated](https://angular.io/docs/ts/latest/guide/router.html)
to reflect usage of the 'new' router. Note the big disclaimer at the top.

>> The Component Router is in alpha release. This is the recommended Angular 2 router
>> and supersedes the earlier deprecated beta and v2 routers.

There is also a great article on [thoughtram.io](http://thoughtram.io),
[Routing in Angular 2 Revisited](http://blog.thoughtram.io/angular/2016/06/14/routing-in-angular-2-revisited.html),
written by [Pascal Precht](http://twitter.com/pascalprecht), which does a great job
outlining the new features of the new router.

## Out with the old, In with the new ##

Managing the way our application handles navigation has been somewhat static to date.
Mostly a navigation component with static `routeLinks` littered throughout. We have
always wanted to make this component a bit more dynamic. But, our investigations with
the "old" router, always led us into complex solutions.

So, with the news, we decided to take the "new" router for a spin to see if we can't
more simply solve some of our navigation issues, with something more native and simple.

If you are interested, the entire example is [available here](http://plnkr.co/edit/lomzsQ?p=preview).
This example is forked from [Pascal Precht](http://twitter.com/pascalprecht) example mentioned earlier.

## Gettings things setup ##

One of the most interesting things you'll find with the new router is that you can
use a plain `<any>[]`. TypeScript will cast it to the correct `RouterConfig` type.
Which boils down to an interface array of type `Route`. All of fields are marked
nullable, which makes this very simple to configure.

Because this is an interface we can provide members that are not part of the `Route`
type and the router won't get upset. This is super cool because now we can tie
information that is relevant to the route, directly to the route config itself.

{% gist d2154bbd34a416642767c00f085442a5 app-routes.ts %}

As you can see in my example, we've attached members `name, description, showInNav` which
are not required by the router. In order to feed this into the router, you'll need to use
the `providerRouter()` and send the result into the providers array on your bootstrapper.

{% gist d2154bbd34a416642767c00f085442a5 main.ts %}

Viola! That's pretty much all you'll need to get things going.

## Generating some navigation ##

Now that the router is all wired up you can go upon your normal business using `routerLink`
very similarly to how you used to. But, since this information is stored in an `<any>[]`
why not use it as a data source for your navigation.

{% gist d2154bbd34a416642767c00f085442a5 nav.component.ts %}

As you can see it's fairly straight-forward to use the same `RouterConfig` supplied to
the router for consumption elsewhere. Now you could have done this before, however,
it required you to reflect data out of the `@RouteConfig` metadata. The new router makes
this very much less painful.

## Just for kicks ##

Just for kicks, I wanted to exercise again, how cool it is to have this data readily
available. We wanted the application header to respond to route events. Allowing us to
create a consistent, and generic application header.

{% gist d2154bbd34a416642767c00f085442a5 header.component.ts %}

What we've done here was have our `HeaderComponent` subscribe to the events being
emitted by the router. There are several types of events, but, we only care about
the `RoutesRecognized` events. Simply filter them out and subscribe. When the `RoutesRecognized`
events fire off, the `HeaderComponent` will retrieve the `Route.path` and find a
match in our `AppRoutes` constant, and assign the result to the `routeData` member.

## Conclusion ##

We are very much impressed with how easy and flexible the new Angular 2 Router is.
It allows for a bunch of new scenarios natively, without having to resort to "workarounds"
or "hacks" to get the desired behavior.

If you are interested, the entire example is [available here](http://plnkr.co/edit/lomzsQ?p=preview).
This example is forked from [Pascal Precht](http://twitter.com/pascalprecht) example mentioned earlier.

redpajama_set_name: RedPajamaGithub


text:
package main_test

import (
	"net"
	"reflect"
	"testing"
	"time"

	"gitlab.cern.ch/lb-experts/golbd/lbcluster"
)

func getExpectedHostMetric() map[string]lbcluster.Node {
	return map[string]lbcluster.Node{
		"monit-kafkax-17be060b0d.cern.ch": lbcluster.Node{Load: 816, IPs: []net.IP{net.ParseIP("188.184.108.100")}},
		"lxplus132.cern.ch":               lbcluster.Node{Load: 2, IPs: []net.IP{net.ParseIP("2001:1458:d00:2c::100:a6"), net.ParseIP("188.184.108.98")}},
		"lxplus041.cern.ch":               lbcluster.Node{Load: 3, IPs: []net.IP{net.ParseIP("2001:1458:d00:32::100:51"), net.ParseIP("188.184.116.81")}},
		"lxplus130.cern.ch":               lbcluster.Node{Load: 27, IPs: []net.IP{net.ParseIP("188.184.108.100")}},
		"lxplus133.subdo.cern.ch":         lbcluster.Node{Load: 27, IPs: []net.IP{net.ParseIP("188.184.108.101")}}}
}

func TestFindBestHosts(t *testing.T) {

	c := getTestCluster("test01.cern.ch")

	hosts_to_check := getHostsToCheck(c)

	expected_host_metric_table := getExpectedHostMetric()

	expected_current_best_ips := []net.IP{net.ParseIP("2001:1458:d00:2c::100:a6"), net.ParseIP("188.184.108.98"), net.ParseIP("2001:1458:d00:32::100:51"), net.ParseIP("188.184.116.81")}

	if !c.FindBestHosts(hosts_to_check) {
		t.Errorf("e.Find_best_hosts: returned false, expected true")
	}
	if !reflect.DeepEqual(c.Host_metric_table, expected_host_metric_table) {
		t.Errorf("e.Find_best_hosts: c.Host_metric_table: got\n%v\nexpected\n%v", c.Host_metric_table, expected_host_metric_table)
	}
	if !reflect.DeepEqual(c.Current_best_ips, expected_current_best_ips) {
		t.Errorf("e.Find_best_hosts: c.Current_best_hosts: got\n%v\nexpected\n%v", c.Current_best_ips, expected_current_best_ips)
	}
	if c.Time_of_last_evaluation.Add(time.Duration(2) * time.Second).Before(time.Now()) {
		t.Errorf("e.Find_best_hosts: c.Time_of_last_evaluation: got\n%v\ncurrent time\n%v", c.Time_of_last_evaluation, time.Now())
	}
}

func TestFindBestHostsNoValidHostCmsfrontier(t *testing.T) {

	c := getTestCluster("testbad.cern.ch")

	c.Parameters.Metric = "cmsfrontier"

	bad_hosts_to_check := getBadHostsToCheck(c)

	expected_current_best_ips := []net.IP{}

	expected_time_of_last_evaluation := c.Time_of_last_evaluation

	if c.FindBestHosts(bad_hosts_to_check) {
		t.Errorf("e.Find_best_hosts: returned true, expected false")
	}
	if !reflect.DeepEqual(c.Current_best_ips, expected_current_best_ips) {
		t.Errorf("e.Find_best_hosts: c.Current_best_hosts: got\n%v\nexpected\n%v", c.Current_best_ips, expected_current_best_ips)
	}
	if c.Time_of_last_evaluation.Add(time.Duration(2) * time.Second).Before(expected_time_of_last_evaluation) {
		t.Errorf("e.Find_best_hosts: c.Time_of_last_evaluation: got\n%v\nexpected time\n%v", c.Time_of_last_evaluation, expected_time_of_last_evaluation)
	}
}

func TestFindBestHostsNoValidHostMinino(t *testing.T) {

	c := getTestCluster("testbad.cern.ch")

	c.Parameters.Metric = "minino"

	bad_hosts_to_check := getBadHostsToCheck(c)

	expected_current_best_ips := []net.IP{}

	if !c.FindBestHosts(bad_hosts_to_check) {
		t.Errorf("e.Find_best_hosts: returned false, expected true")
	}
	if !reflect.DeepEqual(c.Current_best_ips, expected_current_best_ips) {
		t.Errorf("e.Find_best_hosts: c.Current_best_hosts: got\n%v\nexpected\n%v", c.Current_best_ips, expected_current_best_ips)
	}
	if c.Time_of_last_evaluation.Add(time.Duration(2) * time.Second).Before(time.Now()) {
		t.Errorf("e.Find_best_hosts: c.Time_of_last_evaluation: got\n%v\ncurrent time\n%v", c.Time_of_last_evaluation, time.Now())
	}
}

func TestFindBestHostsNoValidHostMinimum(t *testing.T) {

	c := getTestCluster("testbad.cern.ch")

	c.Parameters.Metric = "minimum"

	bad_hosts_to_check := getBadHostsToCheck(c)

	not_expected_current_best_ips := []net.IP{}

	if !c.FindBestHosts(bad_hosts_to_check) {
		t.Errorf("e.Find_best_hosts: returned false, expected true")
	}
	if reflect.DeepEqual(c.Current_best_ips, not_expected_current_best_ips) {
		t.Errorf("e.Find_best_hosts: c.Current_best_hosts: got\n%v\nwhich is not expected", c.Current_best_ips)
	}
	if c.Time_of_last_evaluation.Add(time.Duration(2) * time.Second).Before(time.Now()) {
		t.Errorf("e.Find_best_hosts: c.Time_of_last_evaluation: got\n%v\ncurrent time\n%v", c.Time_of_last_evaluation, time.Now())
	}
}


text:
declare module "string-occurrence" {
  declare module.exports: (
    input: string,
    search: string | string[],
    opts?: { caseInsensitive?: boolean }
  ) => number;
}


text:
using namespace foundation;
using namespace std;

namespace renderer
{

namespace
{
    //
    // Specular BRDF.
    //

    const char* Model = "specular_brdf";

    class SpecularBRDFImpl
      : public BSDF
    {
      public:
        SpecularBRDFImpl(
            const char*         name,
            const ParamArray&   params)
          : BSDF(name, Reflective, ScatteringMode::Specular, params)
        {
            m_inputs.declare("reflectance", InputFormatSpectralReflectance);
            m_inputs.declare("reflectance_multiplier", InputFormatScalar, "1.0");
        }

        virtual void release() APPLESEED_OVERRIDE
        {
            delete this;
        }

        virtual const char* get_model() const APPLESEED_OVERRIDE
        {
            return Model;
        }

        APPLESEED_FORCE_INLINE virtual void sample(
            SamplingContext&    sampling_context,
            const void*         data,
            const bool          adjoint,
            const bool          cosine_mult,
            BSDFSample&         sample) const APPLESEED_OVERRIDE
        {
            // No reflection below the shading surface.
            const Vector3d& shading_normal = sample.get_shading_normal();
            const double cos_on = dot(sample.m_outgoing.get_value(), shading_normal);
            if (cos_on < 0.0)
                return;

            // Compute the incoming direction.
            const Vector3d incoming(
                force_above_surface(
                    reflect(sample.m_outgoing.get_value(), shading_normal),
                    sample.get_geometric_normal()));

            // No reflection below the shading surface.
            const double cos_in = dot(incoming, shading_normal);
            if (cos_in < 0.0)
                return;

            // Compute the BRDF value.
            const InputValues* values = static_cast<const InputValues*>(data);
            sample.m_value = values->m_reflectance;
            sample.m_value *= static_cast<float>(values->m_reflectance_multiplier / cos_in);

            // The probability density of the sampled direction is the Dirac delta.
            sample.m_probability = DiracDelta;

            // Set the scattering mode.
            sample.m_mode = ScatteringMode::Specular;

            sample.m_incoming = Dual3d(incoming);
            sample.compute_reflected_differentials();
        }

        APPLESEED_FORCE_INLINE virtual double evaluate(
            const void*         data,
            const bool          adjoint,
            const bool          cosine_mult,
            const Vector3d&     geometric_normal,
            const Basis3d&      shading_basis,
            const Vector3d&     outgoing,
            const Vector3d&     incoming,
            const int           modes,
            Spectrum&           value) const APPLESEED_OVERRIDE
        {
            return 0.0;
        }

        APPLESEED_FORCE_INLINE virtual double evaluate_pdf(
            const void*         data,
            const Vector3d&     geometric_normal,
            const Basis3d&      shading_basis,
            const Vector3d&     outgoing,
            const Vector3d&     incoming,
            const int           modes) const APPLESEED_OVERRIDE
        {
            return 0.0;
        }

      private:
        typedef SpecularBRDFInputValues InputValues;
    };

    typedef BSDFWrapper<SpecularBRDFImpl> SpecularBRDF;
}

//
// SpecularBRDFFactory class implementation.
//

const char* SpecularBRDFFactory::get_model() const
{
    return Model;
}

Dictionary SpecularBRDFFactory::get_model_metadata() const
{
    return
        Dictionary()
            .insert("name", Model)
            .insert("label", "Specular BRDF");
}

DictionaryArray SpecularBRDFFactory::get_input_metadata() const
{
    DictionaryArray metadata;

    metadata.push_back(
        Dictionary()
            .insert("name", "reflectance")
            .insert("label", "Reflectance")
            .insert("type", "colormap")
            .insert("entity_types",
                Dictionary()
                    .insert("color", "Colors")
                    .insert("texture_instance", "Textures"))
            .insert("use", "required")
            .insert("default", "0.5"));

    metadata.push_back(
        Dictionary()
            .insert("name", "reflectance_multiplier")
            .insert("label", "Reflectance Multiplier")
            .insert("type", "colormap")
            .insert("entity_types",
                Dictionary().insert("texture_instance", "Textures"))
            .insert("use", "optional")
            .insert("default", "1.0"));

    return metadata;
}

auto_release_ptr<BSDF> SpecularBRDFFactory::create(
    const char*         name,
    const ParamArray&   params) const
{
    return auto_release_ptr<BSDF>(new SpecularBRDF(name, params));
}

auto_release_ptr<BSDF> SpecularBRDFFactory::static_create(
    const char*         name,
    const ParamArray&   params)
{
    return auto_release_ptr<BSDF>(new SpecularBRDF(name, params));
}

}   // namespace renderer


text:
package christophedelory.playlist.smil;

import christophedelory.lang.StringUtils;

/**
 * The root layout determines the value of the layout properties of the root element,
 * which in turn determines the size of the window in which the SMIL presentation is rendered.
 * @version $Revision: 92 $
 * @author Christophe Delory
 * @castor.class xml="root-layout"
 */
public class RootLayout extends Core
{
    /**
     * Specifies the background color used to fill the area of a region displaying media that is not filled by the media.
     */
    private String _backgroundColor = null;

    /**
     * The attribute may be used to specify an image that may be placed as the background of a region.
     */
    private String _backgroundImage = null;

    /**
     * The use and definition of this attribute are identical to the "height" property in the CSS2 specification.
     */
    private String _height = null;

    /**
     * The use and definition of this attribute are identical to the "width" property in the CSS2 specification.
     */
    private String _width = null;

    /**
     * The skip content controls whether the content of an element is evaluated or should be skipped.
     */
    private Boolean _skipContent = null;

    /**
     * Returns the background color used to fill the area of a region displaying media that is not filled by the media.
     * @return the background color. May be null.
     * @see #setBackgroundColor
     * @castor.field
     *  get-method="getBackgroundColor"
     *  set-method="setBackgroundColor"
     * @castor.field-xml
     *  name="backgroundColor"
     *  node="attribute"
     */
    public String getBackgroundColor()
    {
        return _backgroundColor;
    }

    /**
     * Initializes the background color.
     * @param color the background color. May be null.
     * @see #getBackgroundColor
     */
    public void setBackgroundColor(final String color)
    {
        _backgroundColor = StringUtils.normalize(color);
    }

    /**
     * Returns the background image as a string.
     * The attribute may be used to specify an image that may be placed as the background of a region.
     * Default value is none.
     * @return the background image as a string. May be null.
     * @see #setBackgroundImage
     * @castor.field
     *  get-method="getBackgroundImage"
     *  set-method="setBackgroundImage"
     * @castor.field-xml
     *  name="backgroundImage"
     *  node="attribute"
     */
    public String getBackgroundImage()
    {
        return _backgroundImage;
    }

    /**
     * Initializes the background image as a string.
     * @param image the background image. May be null.
     * @see #getBackgroundImage
     */
    public void setBackgroundImage(final String image)
    {
        _backgroundImage = StringUtils.normalize(image);
    }

    /**
     * Returns the height of this root layout as a string.
     * The use and definition of this attribute are identical to the "height" property in the CSS2 specification.
     * @return a height. May be null.
     * @see #setHeightString
     * @castor.field
     *  get-method="getHeightString"
     *  set-method="setHeightString"
     * @castor.field-xml
     *  name="height"
     *  node="attribute"
     */
    public String getHeightString()
    {
        return _height;
    }

    /**
     * Initializes the height of this root layout as a string.
     * @param height a height. May be null.
     * @see #getHeightString
     * @see #setHeight
     */
    public void setHeightString(final String height)
    {
        _height = StringUtils.normalize(height);
    }

    /**
     * Initializes the height of this root layout as an integer.
     * @param height a height.
     * @see #setHeightString
     */
    public void setHeight(final int height)
    {
        _height = Integer.toString(height);
    }

    /**
     * Returns the width of this root layout as a string.
     * The use and definition of this attribute are identical to the "width" property in the CSS2 specification.
     * @return a width. May be null.
     * @see #setWidthString
     * @castor.field
     *  get-method="getWidthString"
     *  set-method="setWidthString"
     * @castor.field-xml
     *  name="width"
     *  node="attribute"
     */
    public String getWidthString()
    {
        return _width;
    }

    /**
     * Initializes the width of this root layout as a string.
     * @param width a width. May be null.
     * @see #getWidthString
     * @see #setWidth
     */
    public void setWidthString(final String width)
    {
        _width = StringUtils.normalize(width);
    }

    /**
     * Initializes the width of this root layout as an integer.
     * @param width a width.
     * @see #setWidthString
     */
    public void setWidth(final int width)
    {
        _width = Integer.toString(width);
    }

    /**
     * Checks if the content may be skipped or not.
     * @return the associated boolean.
     * @see #getSkipContent
     */
    public boolean isSkipContent()
    {
        return (_skipContent == null) ? false : _skipContent.booleanValue();
    }

    /**
     * Checks if the content may be skipped or not.
     * The skip content controls whether the content of an element is evaluated or should be skipped.
     * @return the associated boolean. May be null.
     * @see #setSkipContent
     * @castor.field
     *  get-method="getSkipContent"
     *  set-method="setSkipContent"
     * @castor.field-xml
     *  name="skip-content"
     *  node="attribute"
     */
    public Boolean getSkipContent()
    {
        return _skipContent;
    }

    /**
     * Specifies if the content may be skipped or not.
     * @param skipContent the associated boolean. May be null.
     * @see #getSkipContent
     */
    public void setSkipContent(final Boolean skipContent)
    {
        _skipContent = skipContent;
    }

    /**
     * Accepts the specified SMIL playlist visitor.
     * @param visitor a SMIL playlist visitor. Shall not be null.
     * @throws NullPointerException if visitor is null.
     */
    public void acceptDown(final SmilVisitor visitor)
    {
        visitor.beginVisitRootLayout(this); // Throws NullPointerException if visitor is null.

        visitor.endVisitRootLayout(this);
    }
}


text:
class Aisle < ActiveRecord::Base
  belongs_to :store
  has_many :items
  default_scope { order(:position) }
  validates :store, presence: true
  validates :name, presence: true, uniqueness: { scope: :store_id }

  def name_and_description
    [name, description].join(': ')
  end
end


text:
import objectHelper from '../../object-helper';

const startsWithFilterStrategy = {
  apply: (items, filter) => {
    let filteredItems = items.slice(0);
    for (let i = filteredItems.length - 1; i > -1; i--) {
      if (!startsWithFilterStrategy.matchesFilter(filteredItems[i], filter)) {
        filteredItems.splice(i, 1);
      }
    }
    return filteredItems;
  },

  matchesFilter: (item, filter) => {
    let bindingObject = objectHelper.getDeepestObjectFromPath(item, filter.property);
    let bindingProperty = objectHelper.getDeepestPropertyFromPath(filter.property);

    let property = (bindingObject[bindingProperty] + '').toString().toLowerCase();
    return property.startsWith(filter.value.toString().toLowerCase());
  }
};

export default startsWithFilterStrategy;


text:
 /************************************************************************/
 /*                                                                      */
 /*                Centre for Speech Technology Research                 */
 /*                     University of Edinburgh, UK                      */
 /*                       Copyright (c) 1996,1997                        */
 /*                        All Rights Reserved.                          */
 /*                                                                      */
 /*  Permission is hereby granted, free of charge, to use and distribute */
 /*  this software and its documentation without restriction, including  */
 /*  without limitation the rights to use, copy, modify, merge, publish, */
 /*  distribute, sublicense, and/or sell copies of this work, and to     */
 /*  permit persons to whom this work is furnished to do so, subject to  */
 /*  the following conditions:                                           */
 /*   1. The code must retain the above copyright notice, this list of   */
 /*      conditions and the following disclaimer.                        */
 /*   2. Any modifications must be clearly marked as such.               */
 /*   3. Original authors' names are not deleted.                        */
 /*   4. The authors' names are not used to endorse or promote products  */
 /*      derived from this software without specific prior written       */
 /*      permission.                                                     */
 /*                                                                      */
 /*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK       */
 /*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING     */
 /*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT  */
 /*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE    */
 /*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   */
 /*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  */
 /*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,         */
 /*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF      */
 /*  THIS SOFTWARE.                                                      */
 /*                                                                      */
 /************************************************************************/

#ifndef __EST_CHANNELTYPE_H__
#define __EST_CHANNELTYPE_H__

/**@name Channel Types
  */
//@{

/** Symbolic names for coefficient types.
  *
  * Used to record what kinds of information are in a track and
  * anywhere else we need to refer to coefficient types.
  *
  * @see EST_ChannelType
  */

enum EST_CoefficientType
{
  /// Linear prediction filter
  cot_lpc=0,
  /// guaranteed to be the first known type
  cot_first=cot_lpc,
  /// reflection coefficients.
  cot_reflection,
  /// Cepstral coefficients
  cot_cepstrum,
  /// Mel Scale Cepstrum
  cot_melcepstrum,
  /// Mel Scale filter bank
  cot_fbank,
  /// Line spectral pairs.
  cot_lsf,
  /// Tube areas for filter.
  cot_tubearea,
  /// Unknown filter type.
  cot_filter,
  /// Free for experimentation
  cot_user1,
  /// Free for experimentation
  cot_user2,
  /// Guaranteed to be one more than last legal coefficient type
  cot_free
};

/**@name Channel Type Numbering Scheme
  *
  * Channel types are given numbers containing the following information:
  * \begin{itemize}
  *	\item A numeric index.
  *	\item A Number of differentiations 0-2
  *	\item 0 for start, 1 for end
  * \end{itemize}
  * Things which do not require all these features are packed in according
  * to the following rules:
  * \begin{itemize}
  *	\item Single values which can be differentiated are paired as
  *		if they were start and end positions of an unknown type
  *		of coefficient.
  *	\item Single values which can't be differentiated are put in the
  *		positions where the 3rd derivatives would logically be
  *		found.
  * \end{itemize}
  */
//@{

/// extract the coefficient type
#define EST_ChannelTypeCT(T) ( (T) >> 3 )
/// extract the number of differentiations
#define EST_ChannelTypeD(T) ( (T) >> 1 & 3 )
/// extract the start/end flag.
#define EST_ChannelTypeSE(T) ( (T) & 1 )

/// get start from end
#define EST_ChannelTypeStart(T) EST_CoefChannelId(\
						 EST_ChannelTypeCT(T),  \
						 EST_ChannelTypeD(T), \
						 0)
/// get end from start
#define EST_ChannelTypeEnd(T) EST_CoefChannelId(\
						 EST_ChannelTypeCT(T),  \
						 EST_ChannelTypeD(T), \
						 1)
/// differentiate once
#define EST_ChannelTypeIncD(T) EST_CoefChannelId(\
						 EST_ChannelTypeCT(T),  \
						 EST_ChannelTypeD(T)+1, \
						 EST_ChannelTypeSE(T))
/// differentiate N times
#define EST_ChannelTypeDelta(T, N) EST_CoefChannelId(\
						 EST_ChannelTypeCT(T),  \
						 EST_ChannelTypeD(T)+(N), \
						 EST_ChannelTypeSE(T))
/// integrate once
#define EST_ChannelTypeDecD(T) EST_CoefChannelId(\
						 EST_ChannelTypeCT(T),  \
						 EST_ChannelTypeD(T)-1, \
						 EST_ChannelTypeSE(T))

/** Build a number representing a channel type for a coefficient type.
  *
  * CT = coefficient type
  * D  = Number of levels of differentiation.
  * SE = Start=0 end=1
  */
#define EST_CoefChannelId(CT,D,SE) ( (CT)<<3 | ((D)<<1 & 6) | ((SE)&1) )

/** Build a number representing a channel type for a single value which can
  * N = count starting from 0
  * D  = Number of levels of differentiation.
  * be differentiated.
  */

#define EST_DiffChannelId(N,D) ( EST_CoefChannelId(((N)>>1)+(int)cot_free, D, (N)&1) )

/** Build a number representing a channel type for a simple value
  * such as length or voicing probability.
  */

#define EST_ChannelId(N) EST_CoefChannelId((N)>>1, 3, (N)&1)
//@}

/** Symbolic names for track channels.
  * Used in track maps to label channels so they can be accessed without
  * knowing exactly where in the track they are.
  *
  * @see EST_CoefficientType
  * @see EST_TrackMap
  * @see EST_Track
  * @see EST_TrackMap:example
  * @author Richard Caley <rjc@cstr.ed.ac.uk>
  * @version $Id: EST_ChannelType.h,v 1.4 2009/07/03 17:13:56 awb Exp $
  */

enum EST_ChannelType {
  /// Value to return for errors, never occurs in TrackMaps
  channel_unknown	=  EST_ChannelId(0),
  /// order of analysis.
  channel_order		= EST_ChannelId(1),
  /// So we know how many there are
  first_channel_type=channel_order,
  /// Peak amplitude.
  channel_peak		= EST_ChannelId(2),
  /// Duration of section of signal.
  channel_duration	= EST_ChannelId(3),
  /// Length of section in samples.
  channel_length	= EST_ChannelId(4),
  /// Offset from frame center to center of window
  channel_offset	= EST_ChannelId(5),
  /// Voicing decision.
  channel_voiced	= EST_ChannelId(6),
  /// Number of related frame in another track.
  channel_frame		= EST_ChannelId(7),
  /// Time in seconds this frame refers to.
  channel_time		= EST_ChannelId(8),

  /// RMS power of section of signal.
  channel_power		= EST_DiffChannelId(0,0),
  channel_power_d	= EST_DiffChannelId(0,1),
  channel_power_a	= EST_DiffChannelId(0,2),
  /// RMS energy of section of signal.
  channel_energy	= EST_DiffChannelId(1,0),
  channel_energy_d	= EST_DiffChannelId(1,1),
  channel_energy_a	= EST_DiffChannelId(1,2),
  /// F0 in Hz.
  channel_f0		= EST_DiffChannelId(2,0),
  channel_f0_d		= EST_DiffChannelId(2,1),
  channel_f0_a		= EST_DiffChannelId(2,2),

  channel_lpc_0			= EST_CoefChannelId(cot_lpc,0,0),
  channel_lpc_N			= EST_CoefChannelId(cot_lpc,0,1),
  channel_lpc_d_0		= EST_CoefChannelId(cot_lpc,1,0),
  channel_lpc_d_N		= EST_CoefChannelId(cot_lpc,1,1),
  channel_lpc_a_0		= EST_CoefChannelId(cot_lpc,2,0),
  channel_lpc_a_N		= EST_CoefChannelId(cot_lpc,2,1),

  channel_reflection_0		= EST_CoefChannelId(cot_reflection,0,0),
  channel_reflection_N		= EST_CoefChannelId(cot_reflection,0,1),
  channel_reflection_d_0	= EST_CoefChannelId(cot_reflection,1,0),
  channel_reflection_d_N	= EST_CoefChannelId(cot_reflection,1,1),
  channel_reflection_a_0	= EST_CoefChannelId(cot_reflection,2,0),
  channel_reflection_a_N	= EST_CoefChannelId(cot_reflection,2,1),

  channel_cepstrum_0		= EST_CoefChannelId(cot_cepstrum,0,0),
  channel_cepstrum_N		= EST_CoefChannelId(cot_cepstrum,0,1),
  channel_cepstrum_d_0		= EST_CoefChannelId(cot_cepstrum,1,0),
  channel_cepstrum_d_N		= EST_CoefChannelId(cot_cepstrum,1,1),
  channel_cepstrum_a_0		= EST_CoefChannelId(cot_cepstrum,2,0),
  channel_cepstrum_a_N		= EST_CoefChannelId(cot_cepstrum,2,1),

  channel_melcepstrum_0		= EST_CoefChannelId(cot_melcepstrum,0,0),
  channel_melcepstrum_N		= EST_CoefChannelId(cot_melcepstrum,0,1),
  channel_melcepstrum_d_0	= EST_CoefChannelId(cot_melcepstrum,1,0),
  channel_melcepstrum_d_N	= EST_CoefChannelId(cot_melcepstrum,1,1),
  channel_melcepstrum_a_0	= EST_CoefChannelId(cot_melcepstrum,2,0),
  channel_melcepstrum_a_N	= EST_CoefChannelId(cot_melcepstrum,2,1),

  channel_fbank_0		= EST_CoefChannelId(cot_fbank,0,0),
  channel_fbank_N		= EST_CoefChannelId(cot_fbank,0,1),
  channel_fbank_d_0		= EST_CoefChannelId(cot_fbank,1,0),
  channel_fbank_d_N		= EST_CoefChannelId(cot_fbank,1,1),
  channel_fbank_a_0		= EST_CoefChannelId(cot_fbank,2,0),
  channel_fbank_a_N		= EST_CoefChannelId(cot_fbank,2,1),

  channel_lsf_0			= EST_CoefChannelId(cot_lsf,0,0),
  channel_lsf_N			= EST_CoefChannelId(cot_lsf,0,1),
  channel_lsf_d_0		= EST_CoefChannelId(cot_lsf,1,0),
  channel_lsf_d_N		= EST_CoefChannelId(cot_lsf,1,1),
  channel_lsf_a_0		= EST_CoefChannelId(cot_lsf,2,0),
  channel_lsf_a_N		= EST_CoefChannelId(cot_lsf,2,1),

  channel_tubearea_0		= EST_CoefChannelId(cot_tubearea,0,0),
  channel_tubearea_N		= EST_CoefChannelId(cot_tubearea,0,1),
  channel_tubearea_d_0		= EST_CoefChannelId(cot_tubearea,1,0),
  channel_tubearea_d_N		= EST_CoefChannelId(cot_tubearea,1,1),
  channel_tubearea_a_0		= EST_CoefChannelId(cot_tubearea,2,0),
  channel_tubearea_a_N		= EST_CoefChannelId(cot_tubearea,2,1),

  channel_filter_0		= EST_CoefChannelId(cot_filter,0,0),
  channel_filter_N		= EST_CoefChannelId(cot_filter,0,1),
  channel_filter_d_0		= EST_CoefChannelId(cot_filter,1,0),
  channel_filter_d_N		= EST_CoefChannelId(cot_filter,1,1),
  channel_filter_a_0		= EST_CoefChannelId(cot_filter,2,0),
  channel_filter_a_N		= EST_CoefChannelId(cot_filter,2,1),

  channel_user1_0		= EST_CoefChannelId(cot_user1,0,0),
  channel_user1_N		= EST_CoefChannelId(cot_user1,0,1),
  channel_user1_d_0		= EST_CoefChannelId(cot_user1,1,0),
  channel_user1_d_N		= EST_CoefChannelId(cot_user1,1,1),
  channel_user1_a_0		= EST_CoefChannelId(cot_user1,2,0),
  channel_user1_a_N		= EST_CoefChannelId(cot_user1,2,1),

  channel_user2_0		= EST_CoefChannelId(cot_user2,0,0),
  channel_user2_N		= EST_CoefChannelId(cot_user2,0,1),
  channel_user2_d_0		= EST_CoefChannelId(cot_user2,1,0),
  channel_user2_d_N		= EST_CoefChannelId(cot_user2,1,1),
  channel_user2_a_0		= EST_CoefChannelId(cot_user2,2,0),
  channel_user2_a_N		= EST_CoefChannelId(cot_user2,2,1),

  last_channel_type = channel_f0_a,
  /// Can be used to size arrays etc.
  num_channel_types
};
//@}
typedef enum EST_ChannelType EST_ChannelType;

#endif


text:
import BaseService from 'services/BaseService';

/**
 * Class used for all about barrel types
 */
class BarrelTypeService extends BaseService {

    constructor() {
        super('barreltype');
    }

    /**
     * Make a request to set the number of barrels for a type
     *
     * @param {string} id Type id
     * @param {number} number Number of barrels wanted
     * @return {Promise}
     */
    setBarrelNumber(id, number) {
        return this._makeRequest({
            method: 'post',
            url: '/barreltype/barrel',
            data: { id, number },
        });
    }

}

export default new BarrelTypeService();