public string GetHtml()
        {
            var html = String.Empty;
            var productivityGaugeData = new List <ProductivityTimeDto>();

            // fetch data sets
            var productivityGaugeDataLocal = Database.GetInstance().GetUserProductivityData(_date, false);

            // merge with remote data if necessary
            productivityGaugeData = RemoteDataHandler.VisualizeWithRemoteData()
                ? RemoteDataHandler.MergeProductivityData(productivityGaugeDataLocal, Database.GetInstanceRemote().GetUserProductivityData(_date, false))
                : productivityGaugeDataLocal;

            html += VisHelper.ChartTitle("Your Perceived Productivity");

            if (productivityGaugeData.Count == 0)
            {
                html += VisHelper.NotEnoughData(Dict.NotEnoughDataMiniSurvey);
                return(html);
            }

            // Calculate Productivityvalue
            var productivityValue = CalculateWeightedProductivityValue(productivityGaugeData);

            /////////////////////
            // Some strings for the attributes
            /////////////////////
            const string gaugeChartName = "gaugeChartName";
            const int    height         = 100;

            /////////////////////
            // CSS
            /////////////////////
            html += "<style type='text/css'>";
            html += ".c3-gauge-value { fill: white; visibility:hidden; }"; // hack to hide the gauge value
            html += "</style>";

            /////////////////////
            // HTML
            /////////////////////
            //html += "<p style='text-align: center;'>Average productivity based on your manual selection in the mini-surveys<br />(1 = very unproductive, 7 = very productive).</p>";
            html += "<div id='" + gaugeChartName + "' align='center'></div>";

            /////////////////////
            // JS
            /////////////////////

            var          productivityValueString = Math.Round(productivityValue, 1).ToString().Replace(',', '.');
            var          data       = "columns: [ ['PerceivedProductivity', " + productivityValueString + "] ], type: 'gauge'";
            const string gauge      = " label : { show: false }, min: 1, max: 7, width: 36";
            const string color      = "pattern: ['#FF0000', '#F97600', '#F6C600', '#60B044'], threshold: { unit: 'value', max: 7, values: [1, 2, 4, 6] }";
            var          size       = "height: " + height;
            var          parameters = " bindto: '#" + gaugeChartName + "', data: { " + data + " }, gauge: { " + gauge + " }, color: { " + color + " }, size: { " + size + " }";

            html += "<script type='text/javascript'>";
            html += "var " + gaugeChartName + " = c3.generate({ " + parameters + " });";
            html += "</script>";

            return(html);
        }
Esempio n. 2
0
        private string CreateProdTasksLineGraph()
        {
            var html = string.Empty;

            // fetch data sets
            var productivityDataSet    = new List <ProductivityTimeDto>();
            var tasksWorkedOnDataSet   = new List <TasksWorkedOnTimeDto>();
            var tasksWorkedOnDataLocal = Database.GetInstance().GetTasksWorkedOnData(_date);
            var productivityDataLocal  = Database.GetInstance().GetUserProductivityData(_date, true);

            // merge with remote data if necessary
            tasksWorkedOnDataSet = RemoteDataHandler.VisualizeWithRemoteData()
                ? RemoteDataHandler.MergeTasksData(tasksWorkedOnDataLocal, Database.GetInstanceRemote().GetTasksWorkedOnData(_date))
                : tasksWorkedOnDataLocal;

            productivityDataSet = RemoteDataHandler.VisualizeWithRemoteData()
                ? RemoteDataHandler.MergeProductivityData(productivityDataLocal, Database.GetInstanceRemote().GetUserProductivityData(_date, false))
                : productivityDataLocal;

            if (tasksWorkedOnDataSet == null || tasksWorkedOnDataSet.Count <= 1 ||
                productivityDataSet == null || productivityDataSet.Count <= 1)
            {
                html += VisHelper.NotEnoughData(Dict.NotEnoughDataMiniSurvey);
                return(html);
            }

            /////////////////////
            // Some strings for the attributes
            /////////////////////
            const string prodTasksLineGraph = "prodTasksLineGraph";
            const int    width  = 730; //780;
            const int    height = 130;

            /////////////////////
            // CSS
            /////////////////////
            html += "<style type='text/css'>";
            html += ".c3-line { stroke-width: 2px; }";
            //html += ".c3-axis-y-label { color: #007acc; fill: #007acc; font-size: 1.4em; }"; // left axis label color
            //html += ".c3-axis-y2-label { fill: 'gray'; font-size: 1.4em; }"; // right axis label color
            html += "</style>";

            /////////////////////
            // HTML
            /////////////////////
            html += "<div id='" + prodTasksLineGraph + "' align='right'></div>";

            /////////////////////
            // JS
            /////////////////////
            var ticks    = CalculateLineChartAxisTicks(_date);
            var timeAxis = tasksWorkedOnDataSet.Aggregate("", (current, a) => current + (a.Time + ", ")).Trim().TrimEnd(',');
            var productivityFormattedData = productivityDataSet.Aggregate("", (current, p) => current + (p.UserProductvity + ", ")).Trim().TrimEnd(',');
            var tasksFormattedData        = tasksWorkedOnDataSet.Aggregate("", (current, t) => current + (t.TasksWorkedOn + ", ")).Trim().TrimEnd(',');

            const string colors  = "'Number_Of_Activities_In_Session': '#007acc', 'Perceived_Productivity': 'gray'";
            var          data    = "x: 'timeAxis', columns: [['timeAxis', " + timeAxis + "], ['Number_Of_Activities_In_Session',  " + tasksFormattedData + " ], ['Perceived_Productivity', " + productivityFormattedData + " ] ], type: 'spline', colors: { " + colors + " } , axes: { 'PerceivedProductivity': 'y', 'NumberOfTasksWorkedOn': 'y2' }";
            var          size    = "width: " + width + ", height: " + height;
            const string tooltip = "show: false"; //(tasksWorkedOnDataSet.Count > 4) ? " show: false " : " show: true "; // only hide if there are more than 4 elements
            const string legend  = "show: true";  // can only be shown on the right side, and bottom (not left) ... :(
            const string point   = "show: false";

            //var axis = "x: { localtime: true, type: 'timeseries', tick: { values: [ " + ticks + "],  format: function(x) { return pad2(x.getHours()) + ':' + pad2(x.getMinutes()); }}  }, y: { max: 7, min: 1, label: { text: 'Perceived Productivity', position: 'outer-right' } }, y2: { show: true, min: 0, label: { text: 'Number of tasks worked on', position: 'outer-right' } }";
            var axis       = "x: { localtime: true, type: 'timeseries', tick: { values: [ " + ticks + "], format: function(x) { return formatDate(x.getHours()); }}  }, y: { show: false, max: 7, min: 1 }, y2: { show: false, min: 0 }";
            var parameters = " bindto: '#" + prodTasksLineGraph + "', data: { " + data + " }, legend: { " + legend + " }, axis: { " + axis + " } , size: { " + size + " }, tooltip: { " + tooltip + " }, point: { " + point + " } ";

            html += "<script type='text/javascript'>";
            html += "var formatDate = function(hours) { var suffix = 'AM'; if (hours >= 12) { suffix = 'PM'; hours = hours - 12; } if (hours == 0) { hours = 12; } if (hours < 10) return '0' + hours + ' ' + suffix; else return hours + ' ' + suffix; };";
            html += "var " + prodTasksLineGraph + " = c3.generate({ " + parameters + " });"; // return x.getHours() + ':' + x.getMinutes();
            html += "</script>";

            return(html);
        }