text:
{% extends "core/article_page.html" %}
{% load wagtailcore_tags molo_commenting_tags gem_tags %}
{% block content %}
  {% get_comments_content_object for form as self %}
  {% pageurl self as the_url %}

    {% trans "Back to article" %}

{% trans "Your thoughts" %}

      {% with comment as node %}

          {% if node.user.is_staff %}
              {% if settings.gem.GemSettings.moderator_name %}
                {{settings.gem.GemSettings.moderator_name}}
              {% else %}
                {% trans "Big Sister" %}
              {% endif %}

                - {% trans "Moderator" %}

          {% elif node.user_name.lower == 'anonymous' %}
            {% trans "Anonymous" %}
          {% else %}
            {% if not node.user.profile.alias %}
              {% trans "Anonymous" %}
            {% else %}
              {{node.user.profile.alias}}
            {% endif %}
          {% endif %}

          {% if node.is_removed %}

            {% trans "This comment has been removed by the community. Please read our platform rules." %}

          {% else %}
          {% if truncate_comment %}

{{ node.comment|smarttruncatechars:100 }}

            {% if node.comment.200 %}

            {% trans "Read More"%}
            {% endif %}
          {% else %}

{{ node.comment }}

          {% endif %}

              {{node.submit_date|timesince}} {% trans "ago" %}

              {% if not node.user|is_in_admin_group %}

                  {% trans "Report" %}

              {% endif %}
              {% if node.parent == None %}

                  {% trans "Reply"%}

                {% if do_not_link_replies or node.get_children.count == 0 %}

                    {{ node.get_children.count }}
                    {% if node.get_children.count == 0 or node.get_children.count == 1 %}
                      {% trans "Reply" %}
                    {% else %}
                      {% trans "Replies" %}
                    {% endif %}

                {% else %}

                    {{ node.get_children.count }}
                    {% if node.get_children.count == 0 or node.get_children.count == 1 %}
                      {% trans "Reply" %}
                    {% else %}
                      {% trans "Replies" %}
                    {% endif %}

                {% endif %}
            {% endif %}

          {% endif %}

      {% endwith %}

    {% with comment as node %}

      {% if node.parent == None and node.get_children.count != 0 %}

{% trans "Recent Replies"%}

      {% endif %}
    {% endwith %}

      {% if do_not_link_replies or node.get_children.count == 0 %}

          {% if page == 1 %}
            {% trans "Recent replies" %}
            {% else %}
            {% trans "Earlier replies" %}
          {% endif %}

      {% endif %}
      {% for node in replies reversed %}

          {% if node.user.is_staff %}
              {% if settings.gem.GemSettings.moderator_name %}
                {{settings.gem.GemSettings.moderator_name}}
              {% else %}
                {% trans "Big Sister" %}
              {% endif %}

                - {% trans "Moderator" %}

          {% elif node.user_name.lower == 'anonymous' %}
            {% trans "Anonymous" %}
          {% else %}
            {% if not node.user.profile.alias %}
              {% trans "Anonymous" %}
            {% else %}
              {{node.user.profile.alias}}
            {% endif %}
          {% endif %}

          {% if node.is_removed %}

              {% trans "This comment has been removed by the community. Please read our platform rules." %}

          {% else %}
            {% if truncate_comment %}

{{ node.comment|smarttruncatechars:100 }}

              {% if node.comment.200 %}

              {% trans "Read More"%}
              {% endif %}
            {% else %}

{{ node.comment }}

            {% endif %}

              {{node.submit_date|timesince}} {% trans "ago" %}

              {% if not node.user|is_in_admin_group %}

                  {% trans "Report" %}

              {% endif %}
              {% if node.parent == None %}

                  {% trans "Reply"%}

Reply =>

                {% if do_not_link_replies or node.get_children.count == 0 %}

                    {{ node.get_children.count }}
                    {% if node.get_children.count == 0 or node.get_children.count == 1 %}
                      {% trans "Reply" %}
                    {% else %}
                      {% trans "Replies" %}
                    {% endif %}

                {% else %}

                    {{ node.get_children.count }}
                    {% if node.get_children.count == 0 or node.get_children.count == 1 %}
                      {% trans "Reply" %}
                    {% else %}
                      {% trans "Replies" %}
                    {% endif %}

                {% endif %}
              {% endif %}

          {% endif %}

          {% if node.parent == None and node.get_children.count != 0 %}

{% trans "Recent Replies"%}

          {% endif %}

      {% endfor %}

      {% if replies.has_previous %}

      {% endif %}

        {% trans "Page" %} {{ replies.number }} {% trans "of" %} {{ replies.paginator.num_pages }}

      {% if replies.has_next %}

      {% endif %}

    {% if self.allow_commenting %}

{% trans "Add your reply" %}

        {% if request.user.is_authenticated %}
          <form id="comment-form" action="{% url 'molo.commenting:molo-comments-post' %}#comments-list" method="post" class="comments__form" novalidate>
            {% csrf_token %}

              {% if form.errors %}

{% trans "Please correct the error below" %}

              {% endif %}
              {{ form.comment }}
              {% if form.comment.errors %}{{ form.comment.errors }}{% endif %}

            <button type="submit" name="submit" class="call-to-action__button call-to-action__button--primary">{% trans "Comment" %}</button>
            <button type="submit" name="submit_anonymously" class="call-to-action__button call-to-action__button--primary call-to-action__button--secondary">{% trans "Comment Anonymously" %}</button>
            {{ form.object_pk }}
            {{ form.content_type }}
            {{ form.timestamp }}
            {{ form.security_hash }}
            <input type="hidden" name="next" value="{% pageurl self %}" />
            {% if comment.id %}
            <input type="hidden" name="parent" id="parent_id" value="{{ comment.id }}" />
            {% endif %}
          </form>
        {% else %}

                {% trans "Please log in to leave a comment." %}

        {% endif %}

    {% else %}

{% trans "Add your reply" %}

{% trans "Commenting on this article is currently disabled" %}.

    {% endif %}

      {% trans "Back to article" %}

{% endblock %}


text:
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using DataAccess.Predictions;

namespace DataAccess
{
    [Table("Months")]
    public class Month
    {
        [Key]
        public virtual Guid Id { get; set; }
        // Foreign key and navigation property back to site
        public virtual Guid SiteId { get; set; }
        [ForeignKey("SiteId")]
        public virtual Site Site { get; set; }
        [Display(Name = "Month")]
        [Column(TypeName = "DateTime2")]
        public virtual DateTime MonthTime { get; set; }

        public int IncomeTotal
        {
            get
            {
                var incomeTotal = this.IncomeAdmissions ?? default(int);
                incomeTotal += this.IncomeRetail ?? default(int);
                incomeTotal += this.IncomeRefreshment ?? default(int);
                incomeTotal += this.IncomeDonation ?? default(int);
                incomeTotal += this.IncomeAdditionalEvents ?? default(int);
                return incomeTotal;
            }
        }

        #region ATTENTION
        [Display(Name = "Marketing Effort", Description = "Approximately how many person hours were spent on marketing tasks this month?")]
        public virtual int? MarketingEffort { get; set; }
        [Display(Name = "Website Visitors", Description = "How many visitors did your website get this month?")]
        public virtual int? WebsiteVisitors { get; set; }

        [Display(Name = "Regional TV", Description = "Has your site featured on regional TV this month?")]
        public virtual bool RegionalTv { get; set; }
        [Display(Name = "National TV", Description = "Has your site featured on national TV this month?")]
        public virtual bool NationalTv { get; set; }
        [Display(Name = "Overseas TV", Description = "Has your site featured on TV in another country this month?")]
        public virtual bool OverseasTv { get; set; }
        [Display(Name = "Regional Radio", Description = "Has your site featured on a regional radio station this month?")]
        public virtual bool RegionalRadio { get; set; }
        [Display(Name = "National Radio", Description = "Has your site featured on national radio this month?")]
        public virtual bool NationalRadio { get; set; }
        [Display(Name = "Regional Newspaper", Description = "Has your been site featured in a regional newspaper or magazine?")]
        public virtual bool RegionalNewsPaper { get; set; }
        [Display(Name = "National Newspaper", Description = "Has your site featured in a national newspaper or magazine?")]
        public virtual bool NationalNewsPaper { get; set; }

        [Display(Name = "Website Url", Description = "What is your web site address?")]
        public virtual String WebsiteUrl { get; set; }
        public Boolean IsWebsitePresent
        {
            get { return !String.IsNullOrEmpty(WebsiteUrl); }
        }

        [Display(Name = "Facebook Url", Description = "If you have a Facebook page, what it the address?")]
        public virtual String FacebookUrl { get; set; }
        [Display(Name = "Twitter Account", Description = "If you have a Twitter account, what is your account name?")]
        public virtual String TwitterUrl { get; set; }
        [Display(Name = "Youtube Url", Description = "If you have a Youtube page, what it the address?")]
        public virtual String YoutubeUrl { get; set; }
        #endregion

        #region ARRIVING
        [Display(Name = "General Visitors", Description = "How many general visitors came to your site this month?")]
        public virtual int? VisitorsGeneral { get; set; }
        [Display(Name = "Member Visitors", Description = "How many visitors were members/season ticket holders at your site this month?")]
        public virtual int? VisitorsMember { get; set; }
        [Display(Name = "Schools Visitors", Description = "How many school visitors came to your site this month?")]
        public virtual int? VisitorsSchool { get; set; }
        #region Visitor Calculations
        public int VisitorsTotal
        {
            get
            {
                // this.NumberVisitorsAdditional is not included because it wasn't in the modelling
                var visitorsTotal = this.VisitorsGeneral ?? default(int);
                visitorsTotal += this.VisitorsMember ?? default(int);
                visitorsTotal += this.VisitorsSchool ?? default(int);
                return visitorsTotal;
            }
        }

        /// <summary>
        /// Calculations for the total number of visitors require the month
        /// and the site.
        /// </summary>
        private VisitorsTotal _visitorsTotal
        {
            get
            {
                // When the month is being saved the site is null so this calculation
                // throws an exception.
                if (this.Site == null) return new VisitorsTotal();
                var visitorsTotal = new VisitorsTotal
                {
                    MonthNumber = this.MonthTime.Month,
                    IsMuseum = Convert.ToInt32(this.Site.IsMuseum),
                    IsCastle = Convert.ToInt32(this.Site.IsCastle),
                    IsWorldHeritageSite = Convert.ToInt32(this.Site.IsWorldHeritageSite),
                    AreaIndoorSquareMetres = this.Site.AreaIndoorSquareMetres,
                    IsWebsitePresent = Convert.ToInt32(this.IsWebsitePresent),
                    IsRefreshment = Convert.ToInt32(this.IsRefreshment ?? true)
                };
                return visitorsTotal;
            }
        }

        public double VisitorsTotalModel
        {
            get
            {
                var visitorsTotal = this._visitorsTotal;
                return Math.Round(visitorsTotal.Predicted);
            }
        }

        public double VisitorsTotalModelUpper
        {
            get
            {
                var visitorsTotal = this._visitorsTotal;
                return Math.Round(visitorsTotal.PredictedUpper);
            }
        }
        #endregion

        [Display(Name = "Admission Income", Description = "What was the gross income (not profit) from visitor admissions this month? Excluding VAT")]
        public virtual int? IncomeAdmissions { get; set; }
        #region Admission Calculations
        private AdmissionsIncomeTotal _admissionsIncomeTotal
        {
            get
            {
                if (this.Site == null) return new AdmissionsIncomeTotal();
                var admissionsIncomeTotal = new AdmissionsIncomeTotal
                {
                    VisitorsTotal = this.VisitorsTotal,
                    AreaIndoorSquareMetres = this.Site.AreaIndoorSquareMetres,
                    WardDensity = this.Site.SiteCircumstance.WardDensity,
                    WardApproximatedSocialGradeAllCategories =
                        this.Site.SiteCircumstance.WardApproximatedSocialGradeAllCategories,
                    WardApproximatedSocialGradeC2 =
                        this.Site.SiteCircumstance.WardApproximatedSocialGradeC2,
                    MarketingEffort = Convert.ToInt32(this.MarketingEffort ?? 0),
                    IsRefreshment = Convert.ToInt32(this.IsRefreshment ?? true)
                };
                return admissionsIncomeTotal;
            }
        }

        public double IncomeAdmissionsModel
        {
            get
            {
                var admissionsIncomeTotal = this._admissionsIncomeTotal;
                return Math.Round(admissionsIncomeTotal.Predicted);
            }
        }

        public double IncomeAdmissionsModelUpper
        {
            get
            {
                var admissionsIncomeTotal = this._admissionsIncomeTotal;
                return Math.Round(admissionsIncomeTotal.PredictedUpper);
            }
        }
        #endregion

        [Display(Name = "Not with Family", Description = "What percentage of visitors were not with a family? If you don't know please estimate")]
        public virtual int VisitorsPercentNoFamily { get; set; }
        [Display(Name = "In a Family", Description = "What percentage of visitors were with a family? If you don't know please estimate")]
        public virtual int VisitorsPercentFamily { get; set; }

        [Display(Name = "Children", Description = "What percentage of visitors were children under 16 years old? If you don't know please estimate")]
        public virtual int VisitorsPercentChildren { get; set; }
        [Display(Name = "Working Age Adults", Description = "What percentage of visitors were adults of working age? If you don't know please estimate")]
        public virtual int VisitorsPercentAdult { get; set; }
        [Display(Name = "Retired", Description = "What percentage of visitors were over 65, retired or semi-retired? If you don't know please estimate")]
        public virtual int VisitorsPercentRetired { get; set; }

        [Display(Name = "Hours Monday", Description = "How many hours were you open on Mondays?")]
        [Range(minimum: 0, maximum: 24, ErrorMessage = "Enter between 0 and 24 hours")]
        public virtual float HoursMonday { get; set; }
        [Display(Name = "Hours Tuesday", Description = "How many hours were you open on Tuesdays?")]
        [Range(minimum: 0, maximum: 24, ErrorMessage = "Enter between 0 and 24 hours")]
        public virtual float HoursTuesday { get; set; }
        [Display(Name = "Hours Wednesday", Description = "How many hours were you open on Wednesdays?")]
        [Range(minimum: 0, maximum: 24, ErrorMessage = "Enter between 0 and 24 hours")]
        public virtual float HoursWednesday { get; set; }
        [Display(Name = "Hours Thursday", Description = "How many hours were you open on Thursdays?")]
        [Range(minimum: 0, maximum: 24, ErrorMessage = "Enter between 0 and 24 hours")]
        public virtual float HoursThursday { get; set; }
        [Display(Name = "Hours Friday", Description = "How many hours were you open on Fridays?")]
        [Range(minimum: 0, maximum: 24, ErrorMessage = "Enter between 0 and 24 hours")]
        public virtual float HoursFriday { get; set; }
        [Display(Name = "Hours Saturday", Description = "How many hours were you open on Saturdays?")]
        [Range(minimum: 0, maximum: 24, ErrorMessage = "Enter between 0 and 24 hours")]
        public virtual float HoursSaturday { get; set; }
        [Display(Name = "Hours Sunday", Description = "How many hours were you open on Sundays?")]
        [Range(minimum: 0, maximum: 24, ErrorMessage = "Enter between 0 and 24 hours")]
        public virtual float HoursSunday { get; set; }

        #endregion

        #region SHOPPING
        [Display(Name = "Do you have a shop?", Description = "Was there a shop or retail outlet open on your site this month?")]
        public virtual bool? IsRetail { get; set; }
        [Display(Name = "Retail Income", Description = "How much was your retail gross income (not profit) this month? Excluding VAT")]
        public virtual int? IncomeRetail { get; set; }
        [Display(Name = "Shop behind pay barrier?", Description = "Do visitors have to pay to get to the shop?")]
        public virtual bool PayToShop { get; set; }
        [Display(Name = "Shop visible from entrance?", Description = "Can you see the shop before you enter?")]
        public virtual bool ShopVisibleFromEntrance { get; set; }
        [Display(Name = "Exit through the shop?", Description = "Do visitors have leave via the shop?")]
        public virtual bool ExitViaShop { get; set; }
        [Display(Name = "Distance to Shop", Description = "How far is it from the entrance to the shop?")]
        public virtual int? DistanceToShop { get; set; }
        public virtual int DistanceToShopUnits { get; set; }
        [Display(Name = "Area of Shop", Description = "How big is the shop?  In square feet or square metres.")]
        public virtual int? AreaShop { get; set; }
        public virtual int AreaShopUnits { get; set; }
        [Display(Name = "Number of Products", Description = "How many product lines does the shop have?")]
        public virtual int? NumberProducts { get; set; }
        [Display(Name = "Exhibition Related Products", Description = "How many of those product lines are directly related to your exhibitions this month?")]
        public virtual int? PercentageRelatedProducts { get; set; }
        #region Retail Income Calculations

        public double RetailIncomePerVisitor
        {
            get
            {
                // if the retail income is empty assume it is zero
                // cast the values to doubles, otherwise you get integer division
                var incomeRetail = Convert.ToDouble(this.IncomeRetail ?? 0.0);
                var retailIncomePerVisitor = Convert.ToDouble(incomeRetail/this.VisitorsTotal);
                // In case the IncomeRetail or VisitorsTotal are zero (= infinity)
                retailIncomePerVisitor = Double.IsInfinity(retailIncomePerVisitor) ? 0.0 : retailIncomePerVisitor;
                // In case both IncomeRetail and VisitorsTotal are zero (= NAN)
                retailIncomePerVisitor = Double.IsNaN(retailIncomePerVisitor) ? 0.0 : retailIncomePerVisitor;
                return Math.Round(retailIncomePerVisitor, 2);
            }
        }

        // TODO: Move the type conversions into the prediction object.
        private RetailIncomePerVisitor _retailIncomePerVisitor
        {
            get
            {
                if (this.Site == null) return new RetailIncomePerVisitor();
                var retailIncomePerVisitor = new RetailIncomePerVisitor
                {
                    VisitorsTotal = this.VisitorsTotal,
                    IsPayToEnter = (this.IncomeAdmissions > 0) ? 1: 0,
                    IsArtsCentre = Convert.ToInt32(this.Site.IsArtsCentre),
                    IsMuseum = Convert.ToInt32(this.Site.IsMuseum),
                    IsWebsitePresent = String.IsNullOrWhiteSpace(this.WebsiteUrl) ? 0: 1,
                    PayToShop = Convert.ToInt32(this.PayToShop),
                    ShopVisibleFromEntrance = Convert.ToInt32(this.ShopVisibleFromEntrance),
                    IncomeRefreshment = Convert.ToDouble(this.IncomeRefreshment),
                    IsAdditionalEvents = Convert.ToInt32(this.IsAdditionalEvents)
                };
                return retailIncomePerVisitor;
            }
        }
        public double RetailIncomePerVisitorModel
        {
            get
            {
                var retailIncomePerVisitor = this._retailIncomePerVisitor;
                return Math.Round(retailIncomePerVisitor.Predicted, 2);
            }
        }

        public double RetailIncomePerVisitorModelUpper
        {
            get
            {
                var retailIncomePerVisitor = this._retailIncomePerVisitor;
                return Math.Round(retailIncomePerVisitor.PredictedUpper, 2);
            }
        }

        #endregion
        #endregion

        #region REFRESHMENT

        [Display(Name = "Refreshments Available?", Description = "Did you provide refreshments for visitors this month?")]
        public bool? IsRefreshment { get; set; }
        [Display(Name = "Refreshments Income", Description = "What was your gross income (not profit) from refreshments sales this month? Excluding VAT")]
        public virtual int? IncomeRefreshment { get; set; }
        [Display(Name = "Behind Pay Barrier?", Description = "Do visitors have to pay to enter before they can get refreshments?")]
        public virtual bool PayToRefreshment { get; set; }
        [Display(Name = "Visible from Entrance?", Description = "Can you see the refreshment service before you enter the site?")]
        public virtual bool RefreshmentVisibleFromEntrance { get; set; }
        [Display(Name = "Distance to Refreshments", Description = "How far is it from the entrance to the refreshment service?")]
        public virtual int? DistanceToRefreshment { get; set; }
        public virtual int DistanceToRefreshmentUnits { get; set; }
        [Display(Name = "Indoor Seats", Description = "How many people can the café or restaurant seat indoors?")]
        public virtual int? NumberSeatsIndoors { get; set; }
        [Display(Name = "Outdoor Seats", Description = "How seats are available outside?")]
        public virtual int? NumberSeatsOutside { get; set; }

        [Display(Name = "Vending Machines", Description = "Are refreshment provided by vending machines?")]
        public virtual bool IsVending { get; set; }
        [Display(Name = "Cafeteria", Description = "Do visitors select and collect their own refreshments?")]
        public virtual bool IsCafeteria { get; set; }
        [Display(Name = "Table Service", Description = "Do you provide a waiter table service?")]
        public virtual bool IsTableService { get; set; }
        [Display(Name = "Outside Hours", Description = "Is your refreshment service open outside normal site hours?")]
        public virtual bool IsRefreshmentOutsideHours { get; set; }

        [Display(Name = "Teas and Coffee", Description = "Are tea and coffee available?")]
        public virtual bool IsTeaAndCoffee { get; set; }
        [Display(Name = "Cakes and Desserts", Description = "Are cakes, desserts and cookies available?")]
        public virtual bool IsCakeAndBiscuit { get; set; }
        [Display(Name = "Light Meals", Description = "Are snacks, sandwiches and light meals available?")]
        public virtual bool IsLightMeals { get; set; }
        [Display(Name = "Full Meals", Description = "Do you provide large or main meals?")]
        public virtual bool IsFullMeal { get; set; }

        [Display(Name = "Organic or Local", Description = "Are any of your refreshments organic or locally sourced?")]
        public virtual bool IsOrganic { get; set; }
        [Display(Name = "Vegetarian or Vegan", Description = "Are vegetarian or vegan options available?")]
        public virtual bool IsVegetarian { get; set; }
        [Display(Name = "Gluten Free", Description = "Are gluten free options available?")]
        public virtual bool IsGlutenFree { get; set; }
        [Display(Name = "Alcohol", Description = "Do you serve alcohol?")]
        public virtual bool IsAlcohol { get; set; }
        [Display(Name = "In House", Description = "Are refreshments provided by in house staff?")]
        public virtual bool IsCateringInHouse { get; set; }
        [Display(Name = "Out sourced", Description = "Are the refreshments out sourced to another organisation?")]
        public virtual bool IsCateringOutSourced { get; set; }
        #region Refreshment Income Calculations

        public double RefreshmentIncomePerVisitor
        {
            get
            {
                // if the refreshment income is empty assume it is zero
                // cast the values to doubles to avoid integer division
                var incomeRefreshment = Convert.ToDouble(this.IncomeRefreshment ?? 0.0);
                var refreshmentIncomePerVisitor = Convert.ToDouble(incomeRefreshment / this.VisitorsTotal);
                // In case the IncomeRetail or VisitorsTotal are zero (= infinity)
                refreshmentIncomePerVisitor = Double.IsInfinity(refreshmentIncomePerVisitor) ? 0.0 : refreshmentIncomePerVisitor;
                // In case both IncomeRetail and VisitorsTotal are zero (= NAN)
                refreshmentIncomePerVisitor = Double.IsNaN(refreshmentIncomePerVisitor) ? 0.0 : refreshmentIncomePerVisitor;
                return Math.Round(refreshmentIncomePerVisitor, 2);
            }
        }

        private RefreshmentIncomePerVisitor _refreshmentIncomePerVisitor
        {
            get
            {
                if (this.Site == null) return new RefreshmentIncomePerVisitor();
                var refreshmentIncomePerVisitor = new RefreshmentIncomePerVisitor
                {
                    IsPark = Convert.ToInt32(this.Site.IsPark),
                    IsHistoricHouse = Convert.ToInt32(this.Site.IsHistoricHouse),
                    IsWorldHeritageSite = Convert.ToInt32(this.Site.IsWorldHeritageSite),
                    GoogleRating = this.Site.SiteCircumstance.GoogleRating ?? 4.5, // Assume 4.5 if not given
                    AuthorityDensity = this.Site.SiteCircumstance.AuthorityDensity,
                    IncomeRetail = this.IncomeRetail ?? 0, // Assume no income if not given
                    VisitorsTotal = this.VisitorsTotal,
                    IsVending = Convert.ToInt32(this.IsVending),
                    IsTableService = Convert.ToInt32(this.IsTableService),
                    IsTeaAndCoffee = Convert.ToInt32(this.IsTeaAndCoffee),
                    IsCakeAndBiscuit = Convert.ToInt32(this.IsCakeAndBiscuit),
                    IsFullMeal = Convert.ToInt32(this.IsFullMeal),
                    IsVegetarian = Convert.ToInt32(this.IsVegetarian),
                    IsAlcohol = Convert.ToInt32(this.IsAlcohol)
                };
                return refreshmentIncomePerVisitor;
            }
        }

        public double RefreshmentIncomePerVisitorModel
        {
            get
            {
                var refreshmentIncomePerVisitor = this._refreshmentIncomePerVisitor;
                return Math.Round(refreshmentIncomePerVisitor.Predicted, 2);
            }
        }

        public double RefreshmentIncomePerVisitorModelUpper
        {
            get
            {
                var refreshmentIncomePerVisitor = this._refreshmentIncomePerVisitor;
                return Math.Round(refreshmentIncomePerVisitor.PredictedUpper, 2);
            }
        }

        #endregion
        #endregion

        #region DONATION
        [Display(Name = "Donation Opportunity?", Description = "Do you provide visitors with opportunites to make donations?")]
        public virtual bool? IsDonationOpportunity { get; set; }

        [Display(Name = "Donation Income", Description = "What was your gross income from donations for this month? Excluding Gift Aid")]
        public virtual int? IncomeDonation { get; set; }
        [Display(Name = "Behind Pay Barrier?", Description = "Do visitors have to pay to enter before they can make a donation?")]
        public virtual bool PayToDonate { get; set; }
        [Display(Name = "Visible from Entrance?", Description = "Can you see the donation opportunity before you enter the site?")]
        public virtual bool DonationVisibleFromEntrance { get; set; }
        [Display(Name = "Distance to Donation", Description = "How far is it from the entrance to the first opportunity to make a donation?")]
        public virtual int? DistanceToDonation { get; set; }
        public virtual int DistanceToDonationUnits { get; set; }
        [Display(Name = "Number of Donation Boxes", Description = "How many donation opportunites does your site offer?")]
        public virtual int? NumberDonationOpportunities { get; set; }
        #endregion

        #region EXPERIENCE
        [Display(Name = "Events?", Description = "Did you have any special events this month? e.g. after hours tours, venue hire, weddings etc...")]
        public virtual bool? IsAdditionalEvents { get; set; }

        [Display(Name = "Events", Description = "How many events did you run at your site this month?")]
        public virtual int? NumberAdditionalEvents { get; set; }
        [Display(Name = "Events Numbers", Description = "How many visitors took part in events at your site this month?")]
        public virtual int? NumberVisitorsAdditional { get; set; }
        [Display(Name = "Events Income", Description = "What was the income from events this month?")]
        public virtual int? IncomeAdditionalEvents { get; set; }

        [Display(Name = "Number of Artefacts", Description = "Approximately how many artefacts are in your collections?")]
        public virtual int? NumberArtefacts { get; set; }
        [Display(Name = "Artefacts on Display", Description = "Approximately what percentage of the artefacts are on display?")]
        public virtual int? ArtefactsDisplay { get; set; }
        [Display(Name = "Designated Collections", Description = "Do you have any collections designated 'Outstanding' by the Arts Council?")]
        public virtual bool IsCollectionsOutstanding { get; set; }
        [Display(Name = "Describe your Programme", Description = "On this scale from niche interest to mass appeal?")]
        public virtual int ProgrammeMassAppeal { get; set; }
        #endregion

        /// <summary>
        /// Copy the stuff that probably hasn't changed.
        /// </summary>
        /// <returns></returns>
        public Month ShallowCopy()
        {
            var newMonth = new Month()
            {
                // Attention
                WebsiteUrl = this.WebsiteUrl,
                FacebookUrl = this.FacebookUrl,
                TwitterUrl = this.TwitterUrl,
                YoutubeUrl = this.YoutubeUrl,
                // Arriving
                VisitorsPercentNoFamily = this.VisitorsPercentNoFamily,
                VisitorsPercentFamily = this.VisitorsPercentFamily,
                VisitorsPercentChildren = this.VisitorsPercentChildren,
                VisitorsPercentAdult = this.VisitorsPercentAdult,
                VisitorsPercentRetired = this.VisitorsPercentRetired,
                HoursMonday = this.HoursMonday,
                HoursTuesday = this.HoursTuesday,
                HoursWednesday = this.HoursWednesday,
                HoursThursday = this.HoursThursday,
                HoursFriday = this.HoursFriday,
                HoursSaturday = this.HoursSaturday,
                HoursSunday = this.HoursSunday,
                // Shop
                IsRetail = this.IsRetail,
                PayToShop = this.PayToShop,
                ShopVisibleFromEntrance = this.ShopVisibleFromEntrance,
                ExitViaShop = this.ExitViaShop,
                DistanceToShop = this.DistanceToShop,
                DistanceToShopUnits = this.DistanceToShopUnits,
                AreaShop = this.AreaShop,
                AreaShopUnits = this.AreaShopUnits,
                NumberProducts = this.NumberProducts,
                PercentageRelatedProducts = this.PercentageRelatedProducts,
                // Refreshment
                IsRefreshment = this.IsRefreshment,
                PayToRefreshment = this.PayToRefreshment,
                RefreshmentVisibleFromEntrance = this.RefreshmentVisibleFromEntrance,
                DistanceToRefreshment = this.DistanceToRefreshment,
                DistanceToRefreshmentUnits = this.DistanceToRefreshmentUnits,
                NumberSeatsIndoors = this.NumberSeatsIndoors,
                NumberSeatsOutside = this.NumberSeatsOutside,
                IsVending = this.IsVending,
                IsCafeteria = this.IsCafeteria,
                IsTableService = this.IsTableService,
                IsRefreshmentOutsideHours = this.IsRefreshmentOutsideHours,
                IsTeaAndCoffee = this.IsTeaAndCoffee,
                IsCakeAndBiscuit  = this.IsCakeAndBiscuit,
                IsLightMeals = this.IsLightMeals,
                IsFullMeal = this.IsFullMeal,
                IsOrganic = this.IsOrganic,
                IsVegetarian = this.IsVegetarian,
                IsGlutenFree = this.IsGlutenFree,
                IsAlcohol = this.IsAlcohol,
                IsCateringInHouse = this.IsCateringInHouse,
                IsCateringOutSourced = this.IsCateringOutSourced,
                // Donation
                IsDonationOpportunity = this.IsDonationOpportunity,
                NumberDonationOpportunities = this.NumberDonationOpportunities,
                DonationVisibleFromEntrance = this.DonationVisibleFromEntrance,
                PayToDonate = this.PayToDonate,
                DistanceToDonation = this.DistanceToDonation,
                DistanceToDonationUnits = this.DistanceToDonationUnits,

                // Experience
                IsAdditionalEvents = this.IsAdditionalEvents,
                NumberArtefacts = this.NumberArtefacts,
                ArtefactsDisplay = this.ArtefactsDisplay,
                IsCollectionsOutstanding = this.IsCollectionsOutstanding,
                ProgrammeMassAppeal = this.ProgrammeMassAppeal
            };
            return newMonth;
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Especialidad_model extends CI_Model {
    function __construct() {
        parent::__construct();
        $this->load->database();
    }

    function getEspecialidades() {
        $this->db->order_by('nombre', 'ASC');
        $query = $this->db->get('especialidad');
        if($query->num_rows() > 0) return $query;
        else return false;
    }
}


text:
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20190907170257 extends AbstractMigration
{
    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('CREATE TABLE thing (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, createdAt DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('DROP TABLE thing');
    }
}


text:
Gravatarify.options[:default] = 'identicon'
Gravatarify.options[:secure] = true


text:
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Copyright 2006 Google Inc. All Rights Reserved.

/**
 * @fileoverview Datastructure: Set.
 *
 *
 * This class implements a set data structure. Adding and removing is O(1). It
 * supports both object and primitive values. Be careful because you can add
 * both 1 and new Number(1), beacuse these are not the same. You can even add
 * multiple new Number(1) because these are not equal.
 */

goog.provide('goog.structs.Set');

goog.require('goog.structs');
goog.require('goog.structs.Map');

/**
 * Class for Set datastructure.
 *
 * @param {Array|Object} opt_values Initial values to start with.
 * @constructor
 */
goog.structs.Set = function(opt_values) {
  this.map_ = new goog.structs.Map;
  if (opt_values) {
    this.addAll(opt_values);
  }
};

/**
 * This is used to get the key or the hash. We are not using getHashCode
 * because it only works with objects.
 * @param {*} val Object or primitive value to get a key for.
 * @return {string} A unique key for this value/object.
 * @private
 */
goog.structs.Set.getKey_ = function(val) {
  var type = typeof val;
  if (type == 'object' && val || type == 'function') {
    return 'o' + goog.getHashCode(/** @type {Object} */ (val));
  } else {
    return type.substr(0, 1) + val;
  }
};

/**
 * @return {number} The number of objects in the Set.
 */
goog.structs.Set.prototype.getCount = function() {
  return this.map_.getCount();
};

/**
 * Add an object to the set.
 * @param {*} obj The object to add.
 */
goog.structs.Set.prototype.add = function(obj) {
  this.map_.set(goog.structs.Set.getKey_(obj), obj);
};

/**
 * Adds all objects from one goog.structs.Set to the current one. This can
 * take an array as well.
 * @param {Array|Object} set The set or array to add objects from.
 */
goog.structs.Set.prototype.addAll = function(set) {
  var values = goog.structs.getValues(set);
  var l = values.length;
  for (var i = 0; i < l; i++) {
    this.add(values[i]);
  }
};

/**
 * Removes all objects in one goog.structs.Set from the current one. This can
 * take an array as well.
 * @param {Array|Object} set The set or array to remove objects from.
 */
goog.structs.Set.prototype.removeAll = function(set) {
  var values = goog.structs.getValues(set);
  var l = values.length;
  for (var i = 0; i < l; i++) {
    this.remove(values[i]);
  }
};

/**
 * Removes an object from the set.
 * @param {*} obj The object to remove.
 * @return {boolean} Whether object was removed.
 */
goog.structs.Set.prototype.remove = function(obj) {
  return this.map_.remove(goog.structs.Set.getKey_(obj));
};

/**
 * Removes all objects from the set.
 */
goog.structs.Set.prototype.clear = function() {
  this.map_.clear();
};

/**
 * Whether the set contains no objects.
 * @return {boolean} True if there are no objects in the goog.structs.Set.
 */
goog.structs.Set.prototype.isEmpty = function() {
  return this.map_.isEmpty();
};

/**
 * Whether the goog.structs.Set contains an object or not.
 * @param {*} obj The object to test for.
 * @return {boolean} True if the set contains the object.
 */
goog.structs.Set.prototype.contains = function(obj) {
  return this.map_.containsKey(goog.structs.Set.getKey_(obj));
};

/**
 * Whether the goog.structs.Set contains all elements of the collection.
 * Ignores identical elements, e.g. set([1, 2]) contains [1, 1].
 * @param {Object} col A collection-like object.
 * @return {boolean} True if the set contains all elements.
 */
goog.structs.Set.prototype.containsAll = function(col) {
  return goog.structs.every(col, this.contains, this);
};

/**
 * Find all elements present in both this and the given set.
 * @param {Array|Object} set The set or array to test against.
 * @return {goog.structs.Set} A new set containing all elements present in both
 *     this object and specified set.
 */
goog.structs.Set.prototype.intersection = function(set) {
  var result = new goog.structs.Set();

  var values = goog.structs.getValues(set);
  for (var i = 0; i < values.length; i++) {
    var value = values[i];
    if (this.contains(value)) {
      result.add(value);
    }
  }

  return result;
};

/**
 * Inserts the objects in the set into a new Array.
 * @return {Array} An array of all the values in the Set.
 */
goog.structs.Set.prototype.getValues = function() {
  return this.map_.getValues();
};

/**
 * Does a shallow clone of the goog.structs.Set.
 * @return {goog.structs.Set} The cloned Set.
 */
goog.structs.Set.prototype.clone = function() {
  return new goog.structs.Set(this);
};

/**
 * Compares this set with the input collection for equality.
 * Its time complexity is O(|col|) and uses equals (==) to test the existence
 * of the elements.
 * @param {Object} col A collection-like object.
 * @return {boolean} True if the collection consists of the same elements as
 *     the set in arbitrary order.
 */
goog.structs.Set.prototype.equals = function(col) {
  return this.getCount() == goog.structs.getCount(col) && this.isSubsetOf(col);
};

/**
 * Decides if the input collection contains all elements of this set.
 * Its time complexity is O(|col|) and uses equals (==) to test the existence
 * of the elements.
 * @param {Object} col A collection-like object.
 * @return {boolean} True if the set is a subset of the collection.
 */
goog.structs.Set.prototype.isSubsetOf = function(col) {
  var colCount = goog.structs.getCount(col);
  if (this.getCount() > colCount) {
    return false;
  }
  // TODO Find the minimal collection size where the conversion makes
  // the contains() method faster.
  if (!(col instanceof goog.structs.Set) && colCount > 5) {
    // Make the goog.structs.contains(col, value) faster if necessary.
    col = new goog.structs.Set(col);
  }
  return goog.structs.every(this, function(value) {
    return goog.structs.contains(col, value);
  });
};

/**
 * Returns an iterator that iterates over the elements in the set.
 * @param {boolean} opt_keys Ignored for sets.
 * @return {goog.iter.Iterator} An iterator over the elements in the set.
 */
goog.structs.Set.prototype.__iterator__ = function(opt_keys) {
  return this.map_.__iterator__(false);
};


text:
package com.digitaslbi.selenium.common.controls;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriverException;

public class InvalidSelectorFormatException extends RuntimeException {
    public <T extends BaseElement> InvalidSelectorFormatException(Class<T> clazz, By by, WebDriverException e) {
        super("Could not create an element using the LOCATOR within " + clazz.getSimpleName() +
              "\nThe subtype of the original 'By' used (e.g. ID/CSS selector/XPATH/tag name) is not available via reflection," +
              "\nbut please recheck that the declared subtype aligns with the value used below:\n\n\t" + by.toString() + "\n\n", e);
    }
}


text:
/**
 * @module list-autorollers-sk
 * @description
list-autorollers-sk

 *
 *

 *   Displays a div that allows users to select a state (Caution/Closed) and
 *   a list of autorollers. Dynamically populates the tree status field with
 *   these selections. Also includes a submit button.
 *

 *
 * @evt set-tree-status Sent when the user selects a state and list of
 *    autorollers. The detail includes the tree status message.
 *
 *

 *      detail : "Caution: Waiting for Chrome, Flutter rollers to land"
 *

 *
 */

import { define } from 'elements-sk/define';
import { html } from 'lit-html';
import { findParent } from 'common-sk/modules/dom';
import { CheckOrRadio } from 'elements-sk/checkbox-sk/checkbox-sk';
import { ElementSk } from '../../../infra-sk/modules/ElementSk';
import { AutorollerSnapshot } from '../json';

import 'elements-sk/checkbox-sk';
import 'elements-sk/radio-sk';

export class ListAutorollersSk extends ElementSk {
  private checkedAutorollers: Set<string> = new Set();

  private autorollersData: AutorollerSnapshot[] = [];

  private selectedTreeStatus: string = '';

  constructor() {
    super(ListAutorollersSk.template);
  }

  private static template = (ele: ListAutorollersSk) => html`

    Choose state:

    <radio-sk label="Caution" name=tree_state ?checked=${ele.selectedTreeStatus === 'Caution'} @change=${() => ele.radioHandler('Caution')}></radio-sk>
    <radio-sk label="Closed" name=tree_state ?checked=${ele.selectedTreeStatus === 'Closed'} @change=${() => ele.radioHandler('Closed')}></radio-sk>

    Choose rollers to wait for:

      ${ele.autorollerRow()}

          <button @click=${ele.submit}>Submit</button>

  `;

  // resets the textfield, radio buttons and check boxes.
  public reset(): void {
    this.setTreeStatus('');
    this.checkedAutorollers = new Set();
    this.selectedTreeStatus = '';
    this.setAttribute('collapsed', '');
    this._render();
  }

  public getSelectedRollerNames(): string {
    return Array.from(this.checkedAutorollers).join(', ');
  }

  connectedCallback(): void {
    super.connectedCallback();
    this._render();
  }

  private autorollerRow() {
    return this.autorollers.map((autoroller) => html`

      <checkbox-sk ?checked=${this.checkedAutorollers.has(autoroller.name)} @change=${this.clickHandler} id=${autoroller.name}></checkbox-sk>

      ${autoroller.name}

      [Failing: ${autoroller.num_failed}]

  `);
  }

  // The list of autorollers.
  get autorollers(): AutorollerSnapshot[] {
    return this.autorollersData;
  }

  set autorollers(val: AutorollerSnapshot[]) {
    this.autorollersData = val;
    this._render();
  }

  private submit() {
    this.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter' }));
  }

  private clickHandler(e: Event) {
    const checkbox = findParent(e.target as HTMLElement, 'CHECKBOX-SK') as CheckOrRadio;
    if (checkbox.checked) {
      this.checkedAutorollers.add(checkbox.id);
    } else {
      this.checkedAutorollers.delete(checkbox.id);
    }
    this.setTreeStatus(this.getTreeStatusFromAutorollers());
  }

  private getTreeStatusFromAutorollers(): string {
    let treeStatus = this.selectedTreeStatus;
    const rollerNamesStr = this.getSelectedRollerNames();
    if (rollerNamesStr) {
      treeStatus = `${treeStatus}: Waiting for ${rollerNamesStr} roller${this.checkedAutorollers.size > 1 ? 's' : ''} to land`;
    }
    return treeStatus;
  }

  private setTreeStatus(treeStatus: string) {
    this.dispatchEvent(new CustomEvent('set-tree-status', { detail: treeStatus, bubbles: true }));
  }

  private radioHandler(state: string) {
    this.selectedTreeStatus = state;
    this.setTreeStatus(this.getTreeStatusFromAutorollers());
  }
}

define('list-autorollers-sk', ListAutorollersSk);


text:
Twitch_Username = 'Boulderbot'  # Twitch.TV username for the bot, must be a registered username!
Twitch_Password = 'oauth:hsb3gwu5kvwv6oqm6z5aglrsiy51g6m'  # OAuth for above Twitch.TV account, http://www.twitchapps.com/tmi/
Twitch_Channel = 'raysfireispoopy'  # Twitch.TV channel to connect to

#I connect to raysfireispoopy to have a separate channel to test on

# NOW DON'T TOUCH ANYTHING ELSE, UNLESS YOU KNOW WHAT YOU'RE DOING

# If you do want to improve the code, though, feel free.
# I'd like if you then made a pull request on GitHub for everyone to
# benefit from the improved code, but you aren't required to do so.

import socket
import time
import imp
import os
import traceback
import re
import inspect
from threading import Thread
from plugins.BasePlugin import BasePlugin

class Twitchy:
    def __init__(self):
        print("Welcome to Boulderbot version 1.5!")
        self.ircSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.ircServ = 'irc.twitch.tv'
        self.ircChan = '#'+ Twitch_Channel.lower()

        self.connected = False
        # Plugin system loosely based on blog post by lkjoel
        # http://lkubuntu.wordpress.com/2012/10/02/writing-a-python-plugin-api/
        self._pluginFolder = './plugins/'
        self._mainModule = 'plugin'
        self._plugins = [] #used for cleanup

        self.commands = []
        self.triggers = []
        self.joinPartHandlers = []
        self.modHandlers = []
        self.ignoredUsers = []
        self.loadedPluginNames = []
        self.spamMessages = ['codes4free.net', 'g2a.com/r/', 'prizescode.net']

    def kill(self): #changes all plugins to None, having no commands or triggers
        for p in self._plugins:
            p._kill()

    def sendMessage(self, message): #Sends message to the channel. Bread and butter stuff here
        self.ircSock.send(str('PRIVMSG %s :%s\n' % (self.ircChan, message)).encode('UTF-8'))

    def connect(self, port): #connects to IRC channel
        self.ircSock.connect((self.ircServ, port))
        self.ircSock.send(str("Pass " + Twitch_Password + "\r\n").encode('UTF-8'))
        self.ircSock.send(str("NICK " + Twitch_Username + "\r\n").encode('UTF-8'))
        self.ircSock.send(str("JOIN " + self.ircChan + "\r\n").encode('UTF-8'))

    def loadPlugins(self): #instantiates all the plugins in the plugin directory
        potentialPlugins = []
        allplugins = os.listdir(self._pluginFolder)
        for i in allplugins:
            location = os.path.join(self._pluginFolder, i)
            if not os.path.isdir(location) or not self._mainModule + ".py" in os.listdir(location):
                continue
            info = imp.find_module(self._mainModule, [location])
            potentialPlugins.append({"name": i, "info": info})

        print("Found plugin classes:")
        for i in potentialPlugins:
            try:
                plugin = imp.load_module(self._mainModule, *i["info"])
                pluginClasses = inspect.getmembers(plugin, inspect.isclass)
                for className, classObj in pluginClasses:
                    if className == "BasePlugin" or className in self.loadedPluginNames or not issubclass(classObj, BasePlugin):
                        continue #Exclude BasePlugin & any classes that are not a subclass of it
                    print(className)
                    pluginInstance = classObj(self)
                    self._plugins.append(pluginInstance)
                    self.loadedPluginNames.append(className)
            except Exception as e:
                print("Error loading plugin.")
                print(traceback.format_exc())

    ###The 4 types of functions the bot can look for
    ###Note, when registering in the plugin, self is excluded
    def registerCommand(self, command, pluginFunction): #to trigger, start message with "!<command> <arguments>"
        self.commands.append( {'regex': command, 'handler':pluginFunction} )

    def registerTrigger(self, trigger, pluginFunction): #to trigger, include <trigger> in the message
        self.triggers.append( {'regex': trigger, 'handler':pluginFunction} )

    def registerForJoinPartNotifications(self, pluginFunction): #Automatically tracks users joining and leaving
        self.joinPartHandlers.append( pluginFunction )

    def registerForModNotifications(self, pluginFunction): #Automaticaly tracks moderators joining and leaving
        self.modHandlers.append( pluginFunction )

    def handleIRCMessage(self, ircMessage): #Reads and processes an IRC Message, looking for commands, triggers, etc
        if ircMessage.find(' PRIVMSG '+ self.ircChan +' :') != -1:
            nick = ircMessage.split('!')[0][1:]
            if nick.lower() in self.ignoredUsers: #return None if user is listed as an ignored user
                return
            msg = ircMessage.split(' PRIVMSG '+ self.ircChan +' :')[1]

            if re.search('^!ignore', msg, re.IGNORECASE): #return None if user is meant to be ignored, adds them to ignored users
                args = msg.split(" ")
                self.ignoredUsers.append(args[1])
                return

            for pluginDict in self.commands:
                if re.search('^!'+pluginDict['regex'], msg, re.IGNORECASE):
                    handler = pluginDict['handler']
                    args = msg.split(" ")
                    handler(nick, args)

            for pluginDict in self.triggers:
                if re.search('^'+pluginDict['regex'], msg, re.IGNORECASE):
                    handler = pluginDict['handler']
                    handler(nick, msg)

            for spam in self.spamMessages: #Timeout user that spams chat with a user-set spam message
                if re.search(spam, msg, re.IGNORECASE):
                    time.sleep(1) # Instant timeout might not be picked up by twitch web chat
                    self.sendMessage(".timeout " + nick + "\n")
                    print("Timed out " + nick + " for spam: " + spam + ". Message was: " + msg)

        elif ircMessage.find('PING ') != -1: #Responds to pings with pongs
            self.ircSock.send(str("PING :pong\n").encode('UTF-8'))

        elif ircMessage.find('JOIN ') != -1: #triggers joinpart handler(joining) if user joins
            nick = ircMessage.split('!')[0][1:]
            print(nick +" joined chat")
            for handler in self.joinPartHandlers:
                handler(nick, True)

        elif ircMessage.find('PART ') != -1: #triggers joinpart handler(parting if user leaves
            nick = ircMessage.split('!')[0][1:]
            print(nick +" left chat")
            for handler in self.joinPartHandlers:
                handler(nick, False)

        elif ircMessage.find('MODE '+ self.ircChan +' +o') != -1: #triggers modHandler(joining) if mod joins
            nick = ircMessage.split(' ')[-1]
            if nick.lower() != Twitch_Username.lower():
                print("Mod joined: "+nick)
                for handler in self.modHandlers:
                    handler(nick, True)

        elif ircMessage.find('MODE '+ self.ircChan +' -o') != -1: #triggers modHandler(parting) if mod leaves
            nick = ircMessage.split(' ')[-1]
            if nick.lower() != Twitch_Username.lower():
                print("Mod left: "+nick)
                for handler in self.modHandlers:
                    handler(nick, False)

        else:
            print(ircMessage)

    def run(self):#here's where the magic happens
        line_sep_exp = re.compile(b'\r?\n')
        socketBuffer = b''
        while True:
            try:
                self.connected = True
                socketBuffer += self.ircSock.recv(1024)

                ircMsgs = line_sep_exp.split(socketBuffer)

                socketBuffer = ircMsgs.pop()

                # Deal with them
                for ircMsg in ircMsgs:
                    msg = ircMsg.decode('utf-8')
                    Thread(target=self.handleIRCMessage, args=(msg,)).start()
            except:
                raise

# 'main'
if __name__ == "__main__":
    while True:
        twitchy = Twitchy()
        try:
            twitchy.loadPlugins()
            twitchy.connect(6667)#connect to the irc server
            twitchy.run()#Make moves, son
        except Exception as e:
            print(traceback.format_exc())
        # If we get here, try to shutdown the bot then restart in 5 seconds
        twitchy.kill()
        time.sleep(5)


text:
TolarCoin (TOL)

Testing ex Slovenian currency...


text:
using System;
using Skybrud.Social.Instagram.Endpoints.Raw;
using Skybrud.Social.Instagram.Objects;
using Skybrud.Social.Instagram.Options.Locations;
using Skybrud.Social.Instagram.Responses;

namespace Skybrud.Social.Instagram.Endpoints {

    /// <see cref="http://instagram.com/developer/endpoints/locations/"/>
    public class InstagramLocationsEndpoint {

        #region Properties

        public InstagramService Service { get; private set; }

        /// <summary>
        /// A reference to the raw endpoint.
        /// </summary>
        public InstagramLocationsRawEndpoint Raw {
            get { return Service.Client.Locations; }
        }

        #endregion

        #region Constructors

        internal InstagramLocationsEndpoint(InstagramService service) {
            Service = service;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Gets information about a location with the specified ID. If a location isn't found, an exception will be thrown.
        /// </summary>
        /// <param name="locationId">The ID of the location.</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations"/>
        public InstagramLocationResponse GetLocation(int locationId) {
            return InstagramLocationResponse.ParseResponse(Raw.GetLocation(locationId));
        }

        /// <summary>
        /// Get a list of recent media objects from a given location.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations_media_recent"/>
        public InstagramLocationRecentMediaResponse GetRecentMedia(InstagramLocation location) {
            if (location == null) throw new ArgumentNullException("location");
            return GetRecentMedia(location.Id);
        }

        /// <summary>
        /// Get a list of recent media objects from a given location.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="options">The options for the search.</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations_media_recent"/>
        public InstagramLocationRecentMediaResponse GetRecentMedia(InstagramLocation location, InstagramLocationRecentMediaOptions options) {
            if (location == null) throw new ArgumentNullException("location");
            return GetRecentMedia(location.Id, options);
        }

        /// <summary>
        /// Get a list of recent media objects from a given location.
        /// </summary>
        /// <param name="locationId">The ID of the location.</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations_media_recent"/>
        public InstagramLocationRecentMediaResponse GetRecentMedia(int locationId) {
            return InstagramLocationRecentMediaResponse.ParseResponse(Raw.GetRecentMedia(locationId));
        }

        /// <summary>
        /// Get a list of recent media objects from a given location.
        /// </summary>
        /// <param name="locationId">The ID of the location.</param>
        /// <param name="options">The options for the search.</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations_media_recent"/>
        public InstagramLocationRecentMediaResponse GetRecentMedia(int locationId, InstagramLocationRecentMediaOptions options) {
            return InstagramLocationRecentMediaResponse.ParseResponse(Raw.GetRecentMedia(locationId, options));
        }

        /// <summary>
        /// Search for a location by geographic coordinate within a 1000 meters.
        /// </summary>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations_search"/>
        public InstagramLocationsResponse Search(double latitude, double longitude) {
            return InstagramLocationsResponse.ParseResponse(Raw.Search(latitude, longitude));
        }

        /// <summary>
        /// Search for a location by geographic coordinate.
        /// </summary>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <param name="distance">The distance is meters (max: 5000m)</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations_search"/>
        public InstagramLocationsResponse Search(double latitude, double longitude, int distance) {
            return InstagramLocationsResponse.ParseResponse(Raw.Search(latitude, longitude, distance));
        }

        /// <summary>
        /// Search for a location by geographic coordinate.
        /// </summary>
        /// <param name="options">The options for the call to the API.</param>
        /// <see cref="http://instagram.com/developer/endpoints/locations/#get_locations_search"/>
        public InstagramLocationsResponse Search(InstagramLocationSearchOptions options) {
            return InstagramLocationsResponse.ParseResponse(Raw.Search(options));
        }

        #endregion

    }

}


text:
> Simple yeoman generator that scaffolds out a front-end web application using gulp as the build system.

## Installation

First, install [Yeoman](http://yeoman.io) and generator-web-app using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo
npm install -g generator-web-app
```

Then generate your new project:

```bash
yo web-app
```

## Getting To Know Yeoman

 * Yeoman has a heart of gold.
 * Yeoman is a person with feelings and opinions, but is very easy to work with.
 * Yeoman can be too opinionated at times but is easily convinced not to be.
 * Feel free to [learn more about Yeoman](http://yeoman.io/).

## License

MIT © [Alexander Zaytsev](alexander-zaytsev.me)

[npm-image]: https://badge.fury.io/js/generator-web-app.svg
[npm-url]: https://npmjs.org/package/generator-web-app
[travis-image]: https://travis-ci.org/alexander-zaytsev/generator-web-app.svg?branch=master
[travis-url]: https://travis-ci.org/alexander-zaytsev/generator-web-app
[daviddm-image]: https://david-dm.org/alexander-zaytsev/generator-web-app.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/alexander-zaytsev/generator-web-app
[coveralls-image]: https://coveralls.io/repos/alexander-zaytsev/generator-web-app/badge.svg
[coveralls-url]: https://coveralls.io/r/alexander-zaytsev/generator-web-app


text:
from django.contrib.sites.models import get_current_site
from django.conf import settings

from foundry.utils import get_preference

def foundry(request):
    # get_preference, get_current_site do caching
    return {
        'FOUNDRY': settings.FOUNDRY,
        'LAYER_PATH': settings.LAYERS['layers'][-1] + '/',
        'CURRENT_SITE': get_current_site(request),
        'ANALYTICS_TAGS': get_preference('GeneralPreferences', 'analytics_tags'),
        'SITE_DESCRIPTION': get_preference('GeneralPreferences', 'site_description'),
        'FOUNDRY_HAS_FACEBOOK_CONNECT': getattr(settings, 'FACEBOOK_APP_ID', '') != '',
        'FOUNDRY_HAS_TWITTER_OAUTH': getattr(settings, 'TWITTER_CONSUMER_KEY', '') != '',
        'FOUNDRY_HAS_GOOGLE_OAUTH2': getattr(settings, 'GOOGLE_OAUTH2_CLIENT_ID', '') != '',
        'FOUNDRY_HAS_GALLERY': 'gallery' in settings.INSTALLED_APPS,
        'FOUNDRY_HAS_BANNER': 'banner' in settings.INSTALLED_APPS,

    }


text:
import test from 'ava';
const routes = require('../routes');

test('findProject returns correct project', function* (t) {
  const response = {};
  yield routes.findProject.call(response, 'project1');
  t.is(response.body[0]._id, 11);
});

test('findContributor returns correct contributor', function* (t) {
  const response = {};
  yield routes.findContributor.call(response, 'contributor3');
  t.is(response.body[0]._id, 3);
});

test('listProjects returns all projects', function* (t) {
  const response = {};
  yield routes.listProjects.call(response);
  t.true(response.body.length >= 8);
});

test('listContributors returns all contributors', function* (t) {
  const response = {};
  yield routes.listContributors.call(response);
  t.true(response.body.length >= 8);
});

test('filterContributors returns correct number of contributors', function* (t) {
  const response = {};
  yield routes.filterContributors.call(response, 'javascript:2,ramda:1');
  t.true(response.body.length === 6);
});

test('filterProjects returns correct number of projects', function* (t) {
  const response = {};
  yield routes.filterProjects.call(response, 'python:1,koa:0');
  t.true(response.body.length === 2);
});

test('addContributor adds new contributor', function* (t) {
  const response = {};
  yield routes.addContributor.call(response, 'contributor9');
  t.true(response.body.username === 'contributor9');
});

test('addProject adds new project', function* (t) {
  const response = {};
  yield routes.addProject.call(response, 'project9');
  t.true(response.body.username === 'project9');
});


text:
using System;
using System.Diagnostics;
using System.Collections;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Security;
using PdfSharp.Pdf.Internal;

namespace PdfSharp.Pdf.Advanced
{
  /// <summary>
  /// Represents a PDF trailer dictionary. Even trailers are dictionaries their never have a cross
  /// reference entry in PdfReferenceTable.
  /// </summary>
  internal sealed class PdfTrailer : PdfDictionary
  {
    /// <summary>
    /// Initializes a new instance of PdfTrailer.
    /// </summary>
    public PdfTrailer(PdfDocument document) : base(document)
    {
      this.document = document;
    }

    public int Size
    {
      get {return Elements.GetInteger(Keys.Size);}
      set {Elements.SetInteger(Keys.Size, value);}
    }

    // TODO: needed when linearized...
    //public int Prev
    //{
    //  get {return Elements.GetInteger(Keys.Prev);}
    //}

    public PdfDocumentInformation Info
    {
      get {return (PdfDocumentInformation)Elements.GetValue(Keys.Info, VCF.CreateIndirect);}
    }

    /// <summary>
    /// (Required; must be an indirect reference)
    /// The catalog dictionary for the PDF document contained in the file.
    /// </summary>
    public PdfCatalog Root
    {
      get {return (PdfCatalog)Elements.GetValue(PdfTrailer.Keys.Root, VCF.CreateIndirect);}
    }

    /// <summary>
    /// Gets the first or second document identifier.
    /// </summary>
    public string GetDocumentID(int index)
    {
      if (index < 0 || index > 1)
        throw new ArgumentOutOfRangeException("index", index, "Index must be 0 or 1.");

      PdfArray array = Elements[Keys.ID] as PdfArray;
      if (array == null || array.Elements.Count < 2)
        return "";
      PdfItem item = array.Elements[index];
      if (item is PdfString)
        return ((PdfString)item).Value;
      return "";
    }

    /// <summary>
    /// Sets the first or second document identifier.
    /// </summary>
    public void SetDocumentID(int index, string value)
    {
      if (index < 0 || index > 1)
        throw new ArgumentOutOfRangeException("index", index, "Index must be 0 or 1.");

      PdfArray array = Elements[Keys.ID] as PdfArray;
      if (array == null || array.Elements.Count < 2)
        array = CreateNewDocumentIDs();
      array.Elements[index] = new PdfString(value, PdfStringFlags.HexLiteral);
    }

    /// <summary>
    /// Creates and sets two identical new document IDs.
    /// </summary>
    internal PdfArray CreateNewDocumentIDs()
    {
      PdfArray array = new PdfArray(this.document);
      byte[] docID = Guid.NewGuid().ToByteArray();
      string id = PdfEncoders.RawEncoding.GetString(docID, 0, docID.Length);
      array.Elements.Add(new PdfString(id, PdfStringFlags.HexLiteral));
      array.Elements.Add(new PdfString(id, PdfStringFlags.HexLiteral));
      Elements[Keys.ID] = array;
      return array;
    }

    /// <summary>
    /// Gets the standard security handler.
    /// </summary>
    public PdfStandardSecurityHandler SecurityHandler
    {
      get
      {
        if (this.securityHandler == null)
          this.securityHandler = (PdfStandardSecurityHandler)Elements.GetValue(Keys.Encrypt, VCF.CreateIndirect);
        return this.securityHandler;
      }
    }
    internal PdfStandardSecurityHandler securityHandler;

    //internal override void WriteDictionaryElement(PdfSharp.Pdf.IO.PdfWriter writer, PdfName key)
    //{
    //  //if (key == Keys.ID)
    //  //{
    //  //  PdfArray array = Elements[key] as PdfArray;
    //  //  PdfItem item = array.Elements[0];
    //  //  //base.WriteDictionaryElement(writer, key);
    //  //  return;
    //  //}
    //  base.WriteDictionaryElement (writer, key);
    //}

    internal override void WriteObject(PdfWriter writer)
    {
      // Delete /XRefStm entry, if any
      this.elements.Remove(Keys.XRefStm);

      // Don't encypt myself
      PdfStandardSecurityHandler securityHandler = writer.SecurityHandler;
      writer.SecurityHandler = null;
      base.WriteObject(writer);
      writer.SecurityHandler = securityHandler;
    }

    /// <summary>
    /// Replace temporary irefs by their correct counterparts from the iref table.
    /// </summary>
    internal void Finish()
    {
      // \Root
      PdfReference iref = document.trailer.Elements[PdfTrailer.Keys.Root] as PdfReference;
      if (iref != null && iref.Value == null)
      {
        iref = document.irefTable[iref.ObjectID];
        Debug.Assert(iref.Value != null);
        this.document.trailer.Elements[PdfTrailer.Keys.Root] = iref;
      }

      // \Info
      iref = this.document.trailer.Elements[PdfTrailer.Keys.Info] as PdfReference;
      if (iref != null && iref.Value == null)
      {
        iref = document.irefTable[iref.ObjectID];
        Debug.Assert(iref.Value != null);
        this.document.trailer.Elements[PdfTrailer.Keys.Info] = iref;
      }

      // \Encrypt
      iref = this.document.trailer.Elements[PdfTrailer.Keys.Encrypt] as PdfReference;
      if (iref != null)
      {
        iref = document.irefTable[iref.ObjectID];
        Debug.Assert(iref.Value != null);
        this.document.trailer.Elements[PdfTrailer.Keys.Encrypt] = iref;

        // The encryption dictionary (security handler) was read in before the XRefTable construction
        // was completed. The next lines fix that state (it take several hours to find that bugs...).
        iref.Value = this.document.trailer.securityHandler;
        this.document.trailer.securityHandler.Reference = iref;
        iref.Value.Reference = iref;
      }

      Elements.Remove(Keys.Prev);

      this.document.irefTable.IsUnderConstruction = false;
    }

    /// <summary>
    /// Predefined keys of this dictionary.
    /// </summary>
    internal sealed class Keys : KeysBase
    {
      /// <summary>
      /// (Required; must not be an indirect reference) The total number of entries in the file's
      /// cross-reference table, as defined by the combination of the original section and all
      /// update sections. Equivalently, this value is 1 greater than the highest object number
      /// used in the file.
      /// Note: Any object in a cross-reference section whose number is greater than this value is
      /// ignored and considered missing.
      /// </summary>
      [KeyInfo(KeyType.Integer | KeyType.Required)]
      public const string Size = "/Size";

      /// <summary>
      /// (Present only if the file has more than one cross-reference section; must not be an indirect
      /// reference) The byte offset from the beginning of the file to the beginning of the previous
      /// cross-reference section.
      /// </summary>
      [KeyInfo(KeyType.Integer | KeyType.Optional)]
      public const string Prev = "/Prev";

      /// <summary>
      /// (Required; must be an indirect reference) The catalog dictionary for the PDF document
      /// contained in the file.
      /// </summary>
      [KeyInfo(KeyType.Dictionary | KeyType.Required, typeof(PdfCatalog))]
      public const string Root = "/Root";

      /// <summary>
      /// (Required if document is encrypted; PDF 1.1) The document's encryption dictionary.
      /// </summary>
      [KeyInfo(KeyType.Dictionary | KeyType.Optional, typeof(PdfStandardSecurityHandler))]
      public const string Encrypt = "/Encrypt";

      /// <summary>
      /// (Optional; must be an indirect reference) The document's information dictionary.
      /// </summary>
      [KeyInfo(KeyType.Dictionary | KeyType.Optional, typeof(PdfDocumentInformation))]
      public const string Info = "/Info";

      /// <summary>
      /// (Optional, but strongly recommended; PDF 1.1) An array of two strings constituting
      /// a file identifier for the file. Although this entry is optional,
      /// its absence might prevent the file from functioning in some workflows
      /// that depend on files being uniquely identified.
      /// </summary>
      [KeyInfo(KeyType.Array | KeyType.Optional)]
      public const string ID = "/ID";

      /// <summary>
      /// (Optional) The byte offset from the beginning of the file of a cross-reference stream.
      /// </summary>
      [KeyInfo(KeyType.Integer | KeyType.Optional)]
      public const string XRefStm = "/XRefStm";

      /// <summary>
      /// Gets the KeysMeta for these keys.
      /// </summary>
      public static DictionaryMeta Meta
      {
        get
        {
          if (Keys.meta == null)
            Keys.meta = CreateMeta(typeof(Keys));
          return Keys.meta;
        }
      }
      static DictionaryMeta meta;
    }

    /// <summary>
    /// Gets the KeysMeta of this dictionary type.
    /// </summary>
    internal override DictionaryMeta Meta
    {
      get {return Keys.Meta;}
    }
  }
}


text:
package org.jivesoftware.smack.sm.predicates;

import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;

public class ForEveryMessage implements StanzaFilter {

    public static final ForEveryMessage INSTANCE = new ForEveryMessage();

    private ForEveryMessage() {
    }

    @Override
    public boolean accept(Stanza packet) {
        if (packet instanceof Message) {
            return true;
        }
        return false;
    }

}


text:
package com.xxx.market.web.core.plugin.shiro.freemarker;

import freemarker.core.Environment;
import freemarker.log.Logger;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.util.Map;

/**
 * Freemarker tag that renders the tag body only if the current user has not executed a successful authentication
 * attempt during their current session.
 *

 *
The logically opposite tag of this one is the {@link org.apache.shiro.web.tags.AuthenticatedTag}.
 *

 *
Equivalent to {@link org.apache.shiro.web.tags.NotAuthenticatedTag}

 */
public class NotAuthenticatedTag extends SecureTag {
  static final Logger log = Logger.getLogger("NotAuthenticatedTag");

  @Override
  public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException {
    if (getSubject() == null || (!getSubject().isAuthenticated() && !getSubject().isRemembered())) {
      log.debug("Subject does not exist or is not authenticated.  Tag body will be evaluated.");
      renderBody(env, body);
    } else {
      log.debug("Subject exists and is authenticated.  Tag body will not be evaluated.");
    }
  }
}


text:
+++
Talk_date = ""
Talk_start_time = ""
Talk_end_time = ""
Title = "From Zero to Hero: Container Security"
Type = "talk"
Speakers = ["karni-wolf"]
+++


text:
author: "Subutai Ahmad, Alexander Lavin, Scott Purdy, Zuha Agha"
brief: "This paper, which appears in a special issue of Neurocomputing, demonstrates how Numenta's online sequence memory algorithm, Hierarchical Temporal Memory, meets the requirements
necessary for real-time anomaly detection in streaming data. It also presents results using the
Numenta Anomaly Benchmark (NAB), the first open-source
benchmark designed for testing anomaly detection algorithms on streaming data."
category: machine-learning
date: 2017/06/02
hideImage: true
image: ../images/anomaly-detection-image.png
link: http://www.sciencedirect.com/science/article/pii/S0925231217309864
org: "Published in Neurocomputing, June 2017"
sort: c
title: "Unsupervised Real-Time Anomaly Detection for Streaming Data"
type: post
---

| | |
|-|-|
| **Authors** | S. Ahmad, A. Lavin, S. Purdy, and Z. Agha |
| **Journal** | Neurocomputing (2017) |
| **Online** | [Read or Download this Paper][1] |
| **Published** | June 2, 2017 |

Across every industry, we are seeing an increase in the amount of
streaming, time-series data produced by connected real-time data
sources. Deriving value from these streams requires modeling each one in
an unsupervised fashion to detect anomalies in real time. This has
practical and significant value – from using medical sensors to know
when a patient is in distress to uncovering a bottleneck in your IT
infrastructure. Most people agree that detecting real-time anomalies is
important, but it's also difficult to achieve. It requires anomaly
detection systems that process data in real-time as opposed to batches,
learn continuously and are fully automated. This paper demonstrates how
Numenta's online sequence memory algorithm, Hierarchical Temporal Memory
(HTM), meets those requirements. The paper also presents results using
the Numenta Anomaly Benchmark (NAB), the first open-source benchmark
designed for testing anomaly detection algorithms on streaming data.

![Machine temperature readings](../images/anomaly-detection-image.png)
> *This data stream from NAB represents machine temperatures recorded
  over time. Anomalies are marked by a red circle within the pink
  shaded anomaly windows.*

## **Frequently asked questions about this research**

### **Q. What was the purpose of this paper?**

The purpose of this paper is to highlight the importance of anomaly detection
for streaming applications and introduce two contributions within that field.
The first is a novel unsupervised anomaly detection technique using
Hierarchical Temporal Memory (HTM), a theoretical framework for sequence
learning in the cortex. The second is the Numenta Anomaly Benchmark (NAB).
The benchmark, the first of its kind, provides a controlled open-source
environment for testing anomaly detection algorithms on streaming data.
We analyze the characteristics of an ideal detector and articulate how
HTM displays those characteristics. We then analyze the performance of
ten algorithms (including HTM) on NAB. We discuss future challenges
for the emerging field of streaming analytics.

### **Q. What are the key takeaways?**

-   Anomaly detection represents one of the most significant
    applications for machine learning in IoT

-   Because of the unique characteristics of streaming data
    applications, the ideal streaming anomaly detector should meet a set
    of requirements:

    -   Predictions must be made online; they cannot look ahead

    -   Algorithms must learn continuously

    -   Algorithms must run unsupervised and automatically

    -   Algorithms must adapt to dynamic environments

    -   Algorithms should make anomaly detections as early as possible

    -   Algorithms should minimize both false positives and false
        negatives

-   Though HTM was not created specifically for anomaly detection,
    because HTM implementations operate in real-time and work well for
    prediction tasks, this approach can yield good results when applied
    to streaming anomaly detection

-   NAB provides a way to evaluate streaming anomaly detection
    algorithms. It contains a dataset with real-world, labeled data
    streams, a scoring methodology that rewards early detection and an
    open repository that allows anyone to use it.

### **Q. How does this research differ from other studies?**

Anomaly detection has been actively studied for decades. The subject
has generated much interest within the data science and machine learning
communities. While there are many different anomaly detection approaches,
most of them are designed to process data in batches, making them unsuitable
for real-time streaming applications.

In addition, to date there has been no benchmark focused on streaming
applications and the above set of requirements.  We hope NAB will encourage
research that specifically addresses the challenges associated
with streaming data.

### **Q. How were the algorithms evaluated?**

Based on the criteria identified for the ideal anomaly detector,
we selected 10 algorithms to run on NAB, including HTM, Twitter's
Anomaly Detection, Etsy's Skyline, Multinomial Relative Entropy,
EXPoSE, Bayesian Online Changepoint detection, and a simple sliding threshold.
The source code and parameter settings are included in the NAB repository
for each algorithm tested.

### **Q. Can I replicate these results?**

Yes! In keeping with Numenta's [open research
philosophy](http://numenta.com/blog/2014/09/17/increasing-research-transparency/),
we have incorporated the source code and parameter settings for all of
the above algorithms into the [NAB
repository](https://github.com/numenta/NAB). We also welcome questions
and discussion about the paper on the [HTM
Forum](https://discourse.numenta.org/).

### **Q. How does this paper make contributions in machine learning?**

Anomaly detection is one of the most significant, current applications
for machine learning in IoT. Yet streaming data introduce difficult
challenges for machine learning models. Unlike batch models, where the
full dataset is available, streaming models require processing and
learning with each data point. Additionally, sensor streams are often
seen in massive volumes and high velocities, which leaves little room
for human intervention, parameter tweaking or data labeling. This paper
demonstrates how you can use HTM to perform robust anomaly detection on
a variety of data streams. It also allows you to evaluate other machine
learning methods.

For more details on the key properties of HTM and how it compares to
other machine learning models, you can read this [peer-reviewed
paper](http://numenta.com/papers/continuous-online-sequence-learning-with-an-unsupervised-neural-network-model/),
which appears in Neural Computation, November 2016, Volume 28.

### **Q. Where can I find out more?**

The [HTM Forum](https://discourse.numenta.org/) is a great resource for
further questions and discussion on HTM, NAB and other related topics.
The authors of this paper are active participants in the forum.

### **Q. What is next for this research?**

We've identified several areas for future work. NAB is currently limited
to single metric data streams, but the error analysis indicates that the
errors across various algorithms (including HTM) are not always
correlated. Adding real-world multivariate data streams labeled with
anomalies could be valuable and allow for an ensemble-based approach,
which might provide a significant increase in accuracy.

[1]: http://www.sciencedirect.com/science/article/pii/S0925231217309864


text:
int main()
{
    int index, score[SIZE];
    int sum = 0;
    float average;

    printf("Enter %d golf scores: \n", SIZE);
    for (index = 0; index < SIZE; index++)
        scanf("%d", &score[index]);
    printf("The scores read in are as follows:\n");
    for(index = 0; index < SIZE; index++)
        printf("%5d", score[index]);
    printf("\n");
    for (index = 0; index < SIZE; index++)
        sum += score[index];
    average = (float) sum / SIZE;
    printf("Sum of scores = %d, average = %.2f\n", sum, average);
    printf("That is a handicap of %.0f.\n", average - PAR);

    return 0;
}


text:
package org.drools.workbench.services.verifier.webworker.client.testutil;

import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52;
import org.drools.workbench.services.verifier.api.client.configuration.AnalyzerConfiguration;
import org.drools.workbench.services.verifier.api.client.configuration.CheckConfiguration;
import org.drools.workbench.services.verifier.api.client.configuration.RunnerType;
import org.drools.workbench.services.verifier.api.client.index.Index;
import org.drools.workbench.services.verifier.core.main.Analyzer;
import org.drools.workbench.services.verifier.core.main.Reporter;
import org.drools.workbench.services.verifier.plugin.client.api.FactTypes;
import org.drools.workbench.services.verifier.plugin.client.builders.BuildException;
import org.drools.workbench.services.verifier.plugin.client.builders.IndexBuilder;
import org.drools.workbench.services.verifier.plugin.client.builders.ModelMetaDataEnhancer;
import org.drools.workbench.services.verifier.plugin.client.builders.VerifierColumnUtilities;
import org.drools.workbench.services.verifier.webworker.client.DTableUpdateManager;

import static org.mockito.Mockito.mock;

public class DecisionTableAnalyzerBuilder {

    protected GuidedDecisionTable52 model;
    protected Analyzer analyzer;
    private AnalyzerConfiguration configuration;
    private FactTypes factTypes;
    private VerifierColumnUtilities columnUtilities;
    private Index index;

    public DecisionTableAnalyzerBuilder withFieldTypes( final FactTypes factTypes ) {
        this.factTypes = factTypes;
        return this;
    }

    public DecisionTableAnalyzerBuilder withAnalyzer( final Analyzer analyzer ) {
        this.analyzer = analyzer;
        return this;
    }

    public DecisionTableAnalyzerBuilder withModel( final GuidedDecisionTable52 model ) {
        this.model = model;
        return this;
    }

    public Analyzer build() {
        return getInnerBuilder().build();
    }

    protected InnerBuilder getInnerBuilder() {
        return new InnerBuilder( new AnalyzerConfiguration(
                "UUID",
                new DateTimeFormatProviderMock(),
                new UUIDKeyProviderMock(),
                CheckConfiguration.newDefault(),
                RunnerType.GWT ) );
    }

    public UpdateManagerBuilder getUpdateManagerBuilder() {
        return new UpdateManagerBuilder();
    }

    public DecisionTableAnalyzerBuilder withConfiguration( final AnalyzerConfiguration configuration ) {
        this.configuration = configuration;
        return this;
    }

    public DecisionTableAnalyzerBuilder withIndex( final Index index ) {
        this.index = index;
        return this;
    }

    public class CacheBuilder {

        protected Index getIndex() {
            if ( index == null ) {
                try {
                    index = new IndexBuilder( model,
                                              new ModelMetaDataEnhancer( model ).getHeaderMetaData(),
                                              getUtils(),
                                              configuration ).build();
                } catch ( final BuildException buildException ) {
                    buildException.printStackTrace();
                }
            }
            return index;
        }

        protected VerifierColumnUtilities getUtils() {
            if ( columnUtilities == null ) {
                columnUtilities = new VerifierColumnUtilities( model,
                                                               new ModelMetaDataEnhancer( model ).getHeaderMetaData(),
                                                               factTypes );
            }
            return columnUtilities;
        }
    }

    public class UpdateManagerBuilder
            extends CacheBuilder {

        protected DTableUpdateManager updateManager;

        public DTableUpdateManager buildUpdateManager() {
            if ( this.updateManager == null ) {
                this.updateManager = new DTableUpdateManager( getIndex(),
                                                              analyzer,
                                                              configuration );
            }
            return this.updateManager;
        }
    }

    public class InnerBuilder
            extends UpdateManagerBuilder {

        private Reporter analysisReporter;

        public InnerBuilder( final AnalyzerConfiguration configuration ) {
            DecisionTableAnalyzerBuilder.this.configuration = configuration;
        }

        private Analyzer build() {
            analyzer = new Analyzer( getAnalysisReporter(),
                                     getIndex(),
                                     configuration );

            return analyzer;
        }

        protected Reporter getAnalysisReporter() {
            if ( analysisReporter == null ) {
                analysisReporter = mock( Reporter.class );
            }
            return analysisReporter;
        }
    }
}