<commit_before>/**
 * Created by Praveen on 20/10/2015.
 */

import React, { PropTypes, Component } from 'react';
import Collapse from 'rc-collapse';

import * as attributeNames from '../constants/attributeNames';
import * as actionCreators from '../actions/actionCreators';

export default class DevicesDetail extends Component {
    constructor(props) {
        super(props)
    }

    hasDeviceKey(obj) {
        const keyName = '_id';
        return obj.hasOwnProperty(keyName);
    }


    shouldComponentUpdate(nextProps, nextState) {
        const {detailViewDevice} = this.props;
        if(this.hasDeviceKey(detailViewDevice)) {
            let newDetailViewSelectedForDevice = nextProps.detailViewDevice;
            return (detailViewDevice._id !== newDetailViewSelectedForDevice._id);

        } else {
            // No device selected we need to show some informative message
            return true;
        }

    }

    componentDidUpdate() {
        const {detailViewDevice} = this.props;

        if(this.hasDeviceKey(detailViewDevice)) {
            this.drawChart();
        }
    }

    handleMinimizeButtonClick(dispatch, device) {
        console.log('clicked');
        var innerText = $('.back-button-wrapper > i').text();
        console.log(innerText);
        if(innerText === 'chevron_left') {

            if(Foundation.utils.is_small_only()) {
                dispatch(actionCreators.removeDetailViewForDevice(device));

            } else {
                $('.back-button-wrapper > i').text('chevron_right');

                $(".slide").animate({width:'toggle'},100, 'linear', () => {
                    $('.ax-detail-content').removeClass('large-8');
                    $('.ax-detail-content').addClass('large-12');
                });
            }

        } else {
            $('.back-button-wrapper > i').text('chevron_left');

            $(".slide").animate({width:'toggle'},100, 'linear', () => {
                $('.ax-detail-content').removeClass('large-12');
                $('.ax-detail-content').addClass('large-8');
            });

        }
    }

    drawChart() {
        var chartData = [];
        generateChartData();

        function generateChartData() {
            var firstDate = new Date( 2012, 0, 1 );
            firstDate.setDate( firstDate.getDate() - 500 );
            firstDate.setHours( 0, 0, 0, 0 );

            for ( var i = 0; i < 500; i++ ) {
                var newDate = new Date( firstDate );
                newDate.setDate( newDate.getDate() + i );

                var a = Math.round( Math.random() * ( 40 + i ) ) + 100 + i;
                var b = Math.round( Math.random() * 100000000 );

                chartData.push( {
                    date: newDate,
                    value: a,
                    volume: b
                } );
            }
        }

        var chart = AmCharts.makeChart( "chartdiv", {
            type: "stock",
            "theme": "dark",
            dataSets: [ {
                color: "#b0de09",
                fieldMappings: [ {
                    fromField: "value",
                    toField: "value"
                }, {
                    fromField: "volume",
                    toField: "volume"
                } ],
                dataProvider: chartData,
                categoryField: "date"
            } ],


            panels: [ {
                title: "Value",
                percentHeight: 70,

                stockGraphs: [ {
                    id: "g1",
                    valueField: "value"
                } ],

                stockLegend: {
                    valueTextRegular: " ",
                    markerType: "none"
                }
            } ],

            chartScrollbarSettings: {
                graph: "g1"
            },

            chartCursorSettings: {
                valueBalloonsEnabled: true,
                graphBulletSize: 1,
                valueLineBalloonEnabled: true,
                valueLineEnabled: true,
                valueLineAlpha: 0.5
            },

            periodSelector: {
                periods: [ {
                    period: "DD",
                    count: 10,
                    label: "10 days"
                }, {
                    period: "MM",
                    count: 1,
                    label: "1 month"
                }, {
                    period: "YYYY",
                    count: 1,
                    label: "1 year"
                }, {
                    period: "YTD",
                    label: "YTD"
                }, {
                    period: "MAX",
                    label: "MAX"
                } ]
            },

            panelsSettings: {
                usePrefixes: true
            },
            "export": {
                "enabled": true
            }
        } );
    }


    static getHardwareAndSoftwareVersions(attributes) {
        if(attributes) {
            let versionsData = attributes[attributeNames.VERSION];
            if(versionsData) {
                let versionsString = versionsData.value;
                return {
                    hardwareVersion: versionsString.split(',')[1],
                    softwareVersion: versionsString.split(',')[2]
                }
            } else {
                return {
                    hardwareVersion: 'N/A',
                    softwareVersion: 'N/A'<commit_msg>Test mod<commit_after>/**
 * Created by Praveen on 20/10/2015.
 */

import React, { PropTypes, Component } from 'react';
import Collapse from 'rc-collapse';

import * as attributeNames from '../constants/attributeNames';
import * as actionCreators from '../actions/actionCreators';

export default class DevicesDetail extends Component {
    constructor(props) {
        super(props)
    }

    hasDeviceKey(obj) {
        const keyName = '_id';
        return obj.hasOwnProperty(keyName);
    }


    shouldComponentUpdate(nextProps, nextState) {
        const {detailViewDevice} = this.props;
        if(this.hasDeviceKey(detailViewDevice)) {
            let newDetailViewSelectedForDevice = nextProps.detailViewDevice;
            return (detailViewDevice._id !== newDetailViewSelectedForDevice._id);

        } else {
            // No device selected we need to show some informative message
            return true;
        }

    }

    componentDidUpdate() {
        const {detailViewDevice} = this.props;

        if(this.hasDeviceKey(detailViewDevice)) {
            this.drawChart();
        }
    }

    handleMinimizeButtonClick(dispatch, device) {
        console.log('clicked');
        var innerText = $('.back-button-wrapper > i').text();
        console.log(innerText);
        if(innerText === 'chevron_left') {

            if(Foundation.utils.is_small_only()) {
                dispatch(actionCreators.removeDetailViewForDevice(device));

            } else {
                $('.back-button-wrapper > i').text('chevron_right');

                $(".slide").animate({width:'toggle'},100, 'linear', () => {
                    $('.ax-detail-content').removeClass('large-8');
                    $('.ax-detail-content').addClass('large-12');
                });
            }

        } else {
            $('.back-button-wrapper > i').text('chevron_left');

            $(".slide").animate({width:'toggle'},100, 'linear', () => {
                $('.ax-detail-content').removeClass('large-12');
                $('.ax-detail-content').addClass('large-8');
            });

        }
    }

    drawChart() {
        var chartData = [];
        generateChartData();

        function generateChartData() {
            var firstDate = new Date( 2012, 0, 1 );
            firstDate.setDate( firstDate.getDate() - 500 );
            firstDate.setHours( 0, 0, 0, 0 );

            for ( var i = 0; i < 500; i++ ) {
                var newDate = new Date( firstDate );
                newDate.setDate( newDate.getDate() + i );

                var a = Math.round( Math.random() * ( 40 + i ) ) + 100 + i;
                var b = Math.round( Math.random() * 100000000 );

                chartData.push( {
                    date: newDate,
                    value: a,
                    volume: b
                } );
            }
        }

        var chart = AmCharts.makeChart( "chartdiv", {
            type: "stock",
            "theme": "dark",
            dataSets: [ {
                color: "#b0de09",
                fieldMappings: [ {
                    fromField: "value",
                    toField: "value"
                }, {
                    fromField: "volume",
                    toField: "volume"
                } ],
                dataProvider: chartData,
                categoryField: "date"
            } ],


            panels: [ {
                title: "Value",
                percentHeight: 70,

                stockGraphs: [ {
                    id: "g1",
                    valueField: "value"
                } ],

                stockLegend: {
                    valueTextRegular: " ",
                    markerType: "none"
                }
            } ],

            chartScrollbarSettings: {
                graph: "g1"
            },

            chartCursorSettings: {
                valueBalloonsEnabled: true,
                graphBulletSize: 1,
                valueLineBalloonEnabled: true,
                valueLineEnabled: true,
                valueLineAlpha: 0.5
            },

            periodSelector: {
                periods: [ {
                    period: "DD",
                    count: 10,
                    label: "10 days"
                }, {
                    period: "MM",
                    count: 1,
                    label: "1 month"
                }, {
                    period: "YYYY",
                    count: 1,
                    label: "1 year"
                }, {
                    period: "YTD",
                    label: "YTD"
                }, {
                    period: "MAX",
                    label: "MAX"
                } ]
            },

            panelsSettings: {
                usePrefixes: true
            },
            "export": {
                "enabled": true
            }
        } );
    }

    static getHardwareAndSoftwareVersions(attributes) {
        if(attributes) {
            let versionsData = attributes[attributeNames.VERSION];
            if(versionsData) {
                let versionsString = versionsData.value;
                return {
                    hardwareVersion: versionsString.split(',')[1],
                    softwareVersion: versionsString.split(',')[2]
                }
            } else {
                return {
                    hardwareVersion: 'N/A',
                    softwareVersion: 'N/A'
{'fraction_non_alphanumeric': 0.11874768432752872, 'fraction_numerical': 0.013153019636902557, 'mean_word_length': 1.2003260648053802, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5193241', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2631, 'n_words': 526}