public string GetHtml()
        {
            var html = string.Empty;
            var chartQueryPieChartData = new Dictionary <string, long>();
            var chartQueryResultsLocal = Database.GetInstance().GetActivityPieChartData(_date);

            // merge with remote data if necessary
            chartQueryPieChartData = RemoteDataHandler.VisualizeWithRemoteData()
                ? RemoteDataHandler.MergeActivityData(chartQueryResultsLocal, Database.GetInstanceRemote().GetActivityPieChartData(_date))
                : chartQueryResultsLocal;

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

            var chartUrl         = PreparePieChartUrl(chartQueryPieChartData);
            var totalHoursWorked = Database.GetInstance().GetTotalHoursWorked(_date);

            html += VisHelper.ChartTitle("Distribution of the Activity on your Computer");
            html += "<p style='text-align: center;'>Total hours worked on your computer: <strong>" + totalHoursWorked + "</strong>.</p>";

            html += string.IsNullOrEmpty(chartUrl)
                ? VisHelper.NotEnoughData()
                : "<p style='text-align: center;'><img src='" + chartUrl + "'/></p>";

            return(html);
        }
        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);
        }
        private int OnStats(HttpReqResp req)
        {
            try
            {
                var html = string.Empty;
                var date = VisHelper.GetVisualizationDateFromUrlParameters(req);
                //var visType = VisHelper.GetVisualizationTypesFromUrlParameters(req);

                // log request
                Database.GetInstance().LogInfo(string.Format("The participant opened the retrospection/visualization for '{0}'.", date));

                // prepare charts
                var contextTimelineChart = new ContextTimelineChart(date);
                var productivityGauge    = new ProductivityGaugeChart(date);
                var activityPie          = new ActivityPieChart(date);


                // organize & draw charts
                html += "<style type='text/css'>";
                html += "td { border: 3px solid #B0B0B0; }";
                html += "</style>";

                html += "<table cellpadding='20' style='margin-left: auto; margin-right: auto;'>"; // border-color: #F1F1F1;  vertical-align: top; horizontal-align: center;'
                html += "<tr><td style='vertical-align:top;'>" + productivityGauge.GetHtml() + "</td><td style='vertical-align:top;' rowspan='2'>" + contextTimelineChart.GetHtml() + "</td></tr>";
                html += "<tr><td style='vertical-align:top;'>" + activityPie.GetHtml() + "</td></tr>";
                html += "</table>";

                var title = Dict.RetrospectionPageTitle + " for the " + date.Date.ToShortDateString();
                if (RemoteDataHandler.VisualizeWithRemoteData())
                {
                    title += " (visualizing local and remote data)";
                }
                //title += "<a href=\"settings\">" + Settings.SettingsTitle + "</a>";

                html = ((string)_resourceManager.GetObject("personalanalytics_html"))
                       .Replace("{content}", html)
                       //.Replace("{menu}", Menu)
                       .Replace("{title}", title);
                req.Write(html);
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            catch (Exception e)
            {
                req.Write(e.ToString());
                req.SetHeader("Content-Type", "text/html; charset=utf-8");
            }
            return(200);
        }
Esempio n. 4
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);
        }