<commit_before>/* global Ember, hebeutils, _ */
import DefaultStory from 'hebe-dash/components/stories/story-types/default-story/component';

// hebe-dash/components/stories/complete/story-types/default-story/component

export default DefaultStory.extend({
    // Story settings (including default values)
    // Uncomment any setting you need to change, delete any you don't need
    storyConfig: {
        title: '', // (Provide a story title)
        subTitle: '', // (Provide a story subtitle)
        // author: '', (Provide the author of the story)
        
        // description: '', (Provide a longer description of the story)
        // license: '', (Define which license applies to usage of the story)
        // dataSourceUrl: '', (Where did the data come from?)
        // feedbackEmail: '', (Provide an email users can contact about this story)
        
        // color: 'white', (Set the story colour)
        // width: '2', (Set the width of the story. If your story contains a slider, you must define the width, even if it is the same as the default.)
        // height: '2', (Set the height of the story)
        // headerImage: '', (Provide an image to show in the story header instead of the title and subtitle)
        
        // slider: false, (Add a horizontal slider to the story)
        scroll: false, // (Should the story vertically scroll its content?)
        viewOnly: true
    },

    periodContacts: 0,
    period: '',

    currentYear: '2015',
    previousYear: '2014',
    currentYearContacts: 12000,
    previousYearContacts: 15000,
    threshold: 2000,
    ragRatingColour: 'yw-green', // yw-green for below, yw-amber for same or above
    ragRatingText: '',
    ragRatingPercentage: '',
    topContacts: [],
    years: [],
    onInsertElement: function () {
        // this.set('loaded', true);
        this.get('ywData');
        // this.queryData();
        // this.updateRagTile();
        this.get('years');
    }.on('didInsertElement'),

    queryData: function () {
        var _this = this;

        var appSettings = this.get('appSettings');
        var ywFilter = appSettings.canvasSettings.ywFilter;
        var ywData = ywFilter.data;


        if (!Ember.isEmpty(ywData)) {
            var primaryNeeds = appSettings.groupSortCount(ywData,'need',4);
            _this.set('primaryNeeds', primaryNeeds);

            var count = this.get('ywData.length');
            this.set('periodContacts', count);

            var dateString = 'from ' + moment(ywFilter.startDate).format('Do MMM YY') + ' to ' + moment(ywFilter.endDate).format('Do MMM YY')
            this.set('period', dateString);
            
            if (count < this.get('threshold')) {
                // alert('Lower contacts');
                this.set('ragRatingColour', 'yw-green');
            } else {
                // alert('Higher contacts');
                this.set('ragRatingColour', 'yw-amber');
            }

            setTimeout(function () {
                _this.set('loaded', true);
            });
        }
    }.observes('appSettings.canvasSettings.ywFilter.data'),

    updateRagTile: function () {
        if (this.get('currentYearContacts') < this.get('previousYearContacts')) {
            var percentage = Math.round((100 - ((this.get('currentYearContacts') / this.get('previousYearContacts')) * 100)));

            this.set('ragRatingColour', 'yw-green');
            this.set('ragRatingPercentage', percentage);
            this.set('ragRatingText', 'down on last year');

        } else {<commit_msg>Corrected issue with count not showing in tile.<commit_after>/* global Ember, hebeutils, _ */
import DefaultStory from 'hebe-dash/components/stories/story-types/default-story/component';

// hebe-dash/components/stories/complete/story-types/default-story/component

export default DefaultStory.extend({
    // Story settings (including default values)
    // Uncomment any setting you need to change, delete any you don't need
    storyConfig: {
        title: '', // (Provide a story title)
        subTitle: '', // (Provide a story subtitle)
        // author: '', (Provide the author of the story)
        
        // description: '', (Provide a longer description of the story)
        // license: '', (Define which license applies to usage of the story)
        // dataSourceUrl: '', (Where did the data come from?)
        // feedbackEmail: '', (Provide an email users can contact about this story)
        
        // color: 'white', (Set the story colour)
        // width: '2', (Set the width of the story. If your story contains a slider, you must define the width, even if it is the same as the default.)
        // height: '2', (Set the height of the story)
        // headerImage: '', (Provide an image to show in the story header instead of the title and subtitle)
        
        // slider: false, (Add a horizontal slider to the story)
        scroll: false, // (Should the story vertically scroll its content?)
        viewOnly: true
    },

    periodContacts: 0,
    period: '',

    currentYear: '2015',
    previousYear: '2014',
    currentYearContacts: 12000,
    previousYearContacts: 15000,
    threshold: 2000,
    ragRatingColour: 'yw-green', // yw-green for below, yw-amber for same or above
    ragRatingText: '',
    ragRatingPercentage: '',
    topContacts: [],
    years: [],
    onInsertElement: function () {
        // this.set('loaded', true);
        this.get('ywData');
        // this.queryData();
        // this.updateRagTile();
        this.get('years');
    }.on('didInsertElement'),

    queryData: function () {
        var _this = this;

        var appSettings = this.get('appSettings');
        var ywFilter = appSettings.canvasSettings.ywFilter;
        var ywData = ywFilter.data;


        if (!Ember.isEmpty(ywData)) {
            var primaryNeeds = appSettings.groupSortCount(ywData,'need',4);
            _this.set('primaryNeeds', primaryNeeds);

            var count = ywData.length;
            this.set('periodContacts', count);

            var dateString = 'from ' + moment(ywFilter.startDate).format('Do MMM YY') + ' to ' + moment(ywFilter.endDate).format('Do MMM YY')
            this.set('period', dateString);
            
            if (count < this.get('threshold')) {
                // alert('Lower contacts');
                this.set('ragRatingColour', 'yw-green');
            } else {
                // alert('Higher contacts');
                this.set('ragRatingColour', 'yw-amber');
            }

            setTimeout(function () {
                _this.set('loaded', true);
            });
        }
    }.observes('appSettings.canvasSettings.ywFilter.data'),

    updateRagTile: function () {
        if (this.get('currentYearContacts') < this.get('previousYearContacts')) {
            var percentage = Math.round((100 - ((this.get('currentYearContacts') / this.get('previousYearContacts')) * 100)));

            this.set('ragRatingColour', 'yw-green');
            this.set('ragRatingPercentage', percentage);
            this.set('ragRatingText', 'down on last year');

        } else {
{'fraction_non_alphanumeric': 0.13226621735467564, 'fraction_numerical': 0.008986239820275204, 'mean_word_length': 2.3130232558139534, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3019698', 'n_tokens_mistral': 2074, 'n_tokens_neox': 1952, 'n_words': 549}