Exemplo n.º 1
0
        public async Task UpdateSessionFromSummaryApiAsync(long currentDayMinutes)
        {
            NowTime         nowTime   = SoftwareCoUtil.GetNowTime();
            CodeTimeSummary ctSummary = this.GetCodeTimeSummary();
            long            diff      = ctSummary.activeCodeTimeMinutes < currentDayMinutes ?
                                        currentDayMinutes - ctSummary.activeCodeTimeMinutes : 0;
            PluginDataProject project = await PluginData.GetPluginProject();

            TimeData td = null;

            if (project != null)
            {
                td = await GetTodayTimeDataSummary(project);
            }
            else
            {
                List <TimeData> list = GetTimeDataList();
                if (list != null && list.Count > 0)
                {
                    foreach (TimeData timeData in list)
                    {
                        if (timeData.day.Equals(nowTime.local_day))
                        {
                            td = timeData;
                            break;
                        }
                    }
                }
            }

            if (td == null)
            {
                project            = new PluginDataProject("Unnamed", "Untitled");
                td                 = new TimeData();
                td.day             = nowTime.local_day;
                td.timestamp_local = nowTime.local_now;
                td.timestamp       = nowTime.now;
                td.project         = project;
            }

            long secondsToAdd = diff * 60;

            td.session_seconds += secondsToAdd;
            td.editor_seconds  += secondsToAdd;

            SaveTimeDataSummaryToDisk(td);
        }
Exemplo n.º 2
0
        public CodeTimeSummary GetCodeTimeSummary()
        {
            CodeTimeSummary ctSummary = new CodeTimeSummary();
            NowTime         nowTime   = SoftwareCoUtil.GetNowTime();
            List <TimeData> list      = GetTimeDataList();

            if (list != null && list.Count > 0)
            {
                foreach (TimeData td in list)
                {
                    if (td.day.Equals(nowTime.local_day))
                    {
                        ctSummary.activeCodeTimeMinutes += (td.session_seconds / 60);
                        ctSummary.codeTimeMinutes       += (td.editor_seconds / 60);
                        ctSummary.fileTimeMinutes       += (td.file_seconds / 60);
                    }
                }
            }

            return(ctSummary);
        }
Exemplo n.º 3
0
        public async Task UpdateStatusBarWithSummaryDataAsync()
        {
            string MethodName = "UpdateStatusBarWithSummaryDataAsync";

            CodeTimeSummary ctSummary = TimeDataManager.Instance.GetCodeTimeSummary();

            string iconName = "";
            string currentDayMinutesTime = "";

            _sessionSummary = GetSessionSummayData();
            long averageDailyMinutesVal = _sessionSummary.averageDailyMinutes;

            currentDayMinutesTime = SoftwareCoUtil.HumanizeMinutes(ctSummary.activeCodeTimeMinutes);
            // string averageDailyMinutesTime = SoftwareCoUtil.HumanizeMinutes(averageDailyMinutesVal);

            // Code time today:  4 hrs | Avg: 3 hrs 28 min
            iconName = ctSummary.activeCodeTimeMinutes > averageDailyMinutesVal ? "rocket.png" : "cpaw.png";
            // string msg = string.Format("{0}{1}", inFlowIcon, currentDayMinutesTime);

            // it's ok not to await on this
            package.UpdateStatusBarButtonText(currentDayMinutesTime, iconName);
        }
        public async Task RebuildCodeMetricsAsync()
        {
            if (!SoftwareCoPackage.PLUGIN_READY)
            {
                return;
            }
            SessionSummary  summary   = SessionSummaryManager.Instance.GetSessionSummayData();
            CodeTimeSummary ctSummary = TimeDataManager.Instance.GetCodeTimeSummary();

            string editortimeToday = "Today: " + SoftwareCoUtil.HumanizeMinutes(ctSummary.codeTimeMinutes);

            if (Editortime.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(Editortime, "editortime");

                UpdateNodeValue(parentItem, "editortimetodayval", editortimeToday, "rocket.png");
            }
            else
            {
                List <TreeViewItem> editortimeChildren = new List <TreeViewItem>();
                editortimeChildren.Add(BuildMetricNode("editortimetodayval", editortimeToday, "rocket.png"));
                TreeViewItem editorParent = BuildMetricNodes("editortime", "Code time", editortimeChildren);
                Editortime.Items.Add(editorParent);
            }

            string codetimeBoltIcon = ctSummary.activeCodeTimeMinutes > summary.averageDailyMinutes ? "bolt.png" : "bolt-grey.png";
            string codetimeToday    = "Today: " + SoftwareCoUtil.HumanizeMinutes(ctSummary.activeCodeTimeMinutes);
            string codetimeAvg      = "Your average: " + SoftwareCoUtil.HumanizeMinutes(summary.averageDailyMinutes);
            string codetimeGlobal   = "Global average: " + SoftwareCoUtil.HumanizeMinutes(summary.globalAverageDailyMinutes);

            if (Codetime.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(Codetime, "codetime");

                UpdateNodeValue(parentItem, "codetimetodayval", codetimeToday, "rocket.png");
                UpdateNodeValue(parentItem, "codetimeavgval", codetimeAvg, codetimeBoltIcon);
                UpdateNodeValue(parentItem, "codetimeglobalval", codetimeGlobal, "global-grey.png");
            }
            else
            {
                List <TreeViewItem> codetimeChildren = new List <TreeViewItem>();
                codetimeChildren.Add(BuildMetricNode("codetimetodayval", codetimeToday, "rocket.png"));
                codetimeChildren.Add(BuildMetricNode("codetimeavgval", codetimeAvg, codetimeBoltIcon));
                codetimeChildren.Add(BuildMetricNode("codetimeglobalval", codetimeGlobal, "global-grey.png"));
                TreeViewItem codetimeParent = BuildMetricNodes("codetime", "Active code time", codetimeChildren);
                Codetime.Items.Add(codetimeParent);
            }

            string linesaddedBoltIcon = summary.currentDayLinesAdded > summary.averageDailyLinesAdded ? "bolt.png" : "bolt-grey.png";
            string linesaddedToday    = "Today: " + SoftwareCoUtil.FormatNumber(summary.currentDayLinesAdded);
            string linesaddedAvg      = "Your average: " + SoftwareCoUtil.FormatNumber(summary.averageDailyLinesAdded);
            string linesaddedGlobal   = "Global average: " + SoftwareCoUtil.FormatNumber(summary.globalAverageLinesAdded);

            if (Linesadded.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(Linesadded, "linesadded");

                UpdateNodeValue(parentItem, "linesaddedtodayval", linesaddedToday, "rocket.png");
                UpdateNodeValue(parentItem, "linesaddedavgval", linesaddedAvg, linesaddedBoltIcon);
                UpdateNodeValue(parentItem, "linesaddedglobalval", linesaddedGlobal, "global-grey.png");
            }
            else
            {
                List <TreeViewItem> linesaddedChildren = new List <TreeViewItem>();
                linesaddedChildren.Add(BuildMetricNode("linesaddedtodayval", linesaddedToday, "rocket.png"));
                linesaddedChildren.Add(BuildMetricNode("linesaddedavgval", linesaddedAvg, linesaddedBoltIcon));
                linesaddedChildren.Add(BuildMetricNode("linesaddedglobalval", linesaddedGlobal, "global-grey.png"));
                TreeViewItem linesaddedParent = BuildMetricNodes("linesadded", "Lines added", linesaddedChildren);
                Linesadded.Items.Add(linesaddedParent);
            }

            string linesremovedBoltIcon = summary.currentDayLinesRemoved > summary.averageDailyLinesRemoved ? "bolt.png" : "bolt-grey.png";
            string linesremovedToday    = "Today: " + SoftwareCoUtil.FormatNumber(summary.currentDayLinesRemoved);
            string linesremovedAvg      = "Your average: " + SoftwareCoUtil.FormatNumber(summary.averageDailyLinesRemoved);
            string linesremovedGlobal   = "Global average: " + SoftwareCoUtil.FormatNumber(summary.globalAverageLinesRemoved);

            if (Linesremoved.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(Codetime, "linesremoved");

                UpdateNodeValue(parentItem, "linesremovedtodayval", linesremovedToday, "rocket.png");
                UpdateNodeValue(parentItem, "linesremovedavgval", linesremovedAvg, linesremovedBoltIcon);
                UpdateNodeValue(parentItem, "linesremovedglobalval", linesremovedGlobal, "global-grey.png");
            }
            else
            {
                List <TreeViewItem> linesremovedChildren = new List <TreeViewItem>();
                linesremovedChildren.Add(BuildMetricNode("linesremovedtodayval", linesremovedToday, "rocket.png"));
                linesremovedChildren.Add(BuildMetricNode("linesremovedavgval", linesremovedAvg, linesremovedBoltIcon));
                linesremovedChildren.Add(BuildMetricNode("linesremovedglobalval", linesremovedGlobal, "global-grey.png"));
                TreeViewItem linesremovedParent = BuildMetricNodes("linesremoved", "Lines removed", linesremovedChildren);
                Linesremoved.Items.Add(linesremovedParent);
            }

            string keystrokesBoltIcon = summary.currentDayLinesRemoved > summary.averageDailyLinesRemoved ? "bolt.png" : "bolt-grey.png";
            string keystrokesToday    = "Today: " + SoftwareCoUtil.FormatNumber(summary.currentDayKeystrokes);
            string keystrokesAvg      = "Your average: " + SoftwareCoUtil.FormatNumber(summary.averageDailyKeystrokes);
            string keystrokesGlobal   = "Global average: " + SoftwareCoUtil.FormatNumber(summary.globalAverageDailyKeystrokes);

            if (Keystrokes.HasItems)
            {
                // update
                TreeViewItem parentItem = await GetParent(Keystrokes, "keystrokes");

                UpdateNodeValue(parentItem, "keystrokestodayval", keystrokesToday, "rocket.png");
                UpdateNodeValue(parentItem, "keystrokesavgval", keystrokesAvg, keystrokesBoltIcon);
                UpdateNodeValue(parentItem, "keystrokesglobalval", keystrokesGlobal, "global-grey.png");
            }
            else
            {
                List <TreeViewItem> keystrokeChildren = new List <TreeViewItem>();
                keystrokeChildren.Add(BuildMetricNode("keystrokestodayval", keystrokesToday, "rocket.png"));
                keystrokeChildren.Add(BuildMetricNode("keystrokesavgval", keystrokesAvg, keystrokesBoltIcon));
                keystrokeChildren.Add(BuildMetricNode("keystrokesglobalval", keystrokesGlobal, "global-grey.png"));
                TreeViewItem keystrokesParent = BuildMetricNodes("keystrokes", "Keystrokes", keystrokeChildren);
                Keystrokes.Items.Add(keystrokesParent);
            }

            // get the top keystrokes and code time files
            List <FileChangeInfo> topKeystrokeFiles = FileChangeInfoDataManager.Instance.GetTopKeystrokeFiles();

            if (topKeystrokeFiles.Count == 0)
            {
                TopKeystrokeFiles.Visibility = Visibility.Hidden;
            }
            else
            {
                TopKeystrokeFiles.Visibility = Visibility.Visible;
                // add or update

                if (TopKeystrokeFiles.HasItems)
                {
                    /**
                     * TreeViewItem parentItem = await GetParent(TopKeystrokeFiles, "topcodetimefiles");
                     * foreach (FileChangeInfo changeInfo in topKeystrokeFiles)
                     * {
                     *  string keystrokeNumStr = SoftwareCoUtil.FormatNumber(changeInfo.keystrokes);
                     *  string label = changeInfo.name + " | " + keystrokeNumStr;
                     *  UpdateNodeValue(parentItem, "topkeystrokes-" + changeInfo.name, label, "files.png");
                     * }
                     **/
                }
                List <TreeViewItem> topKeystrokeChildren = new List <TreeViewItem>();
                foreach (FileChangeInfo changeInfo in topKeystrokeFiles)
                {
                    string keystrokeNumStr = SoftwareCoUtil.FormatNumber(changeInfo.keystrokes);
                    string label           = changeInfo.name + " | " + keystrokeNumStr;
                    topKeystrokeChildren.Add(BuildMetricNode("topkeystrokes-" + changeInfo.name, label, "files.png"));
                }
                if (topKeystrokesParent == null)
                {
                    topKeystrokesParent = BuildMetricNodes("topkeystrokesfiles", "Top files by keystrokes", topKeystrokeChildren);
                    TopKeystrokeFiles.Items.Add(topKeystrokesParent);
                }
                else
                {
                    topKeystrokesParent.Items.Clear();
                    foreach (TreeViewItem item in topKeystrokeChildren)
                    {
                        topKeystrokesParent.Items.Add(item);
                    }
                }
            }
            List <FileChangeInfo> topCodetimeFiles = FileChangeInfoDataManager.Instance.GetTopCodeTimeFiles();

            if (topCodetimeFiles.Count == 0)
            {
                TopCodeTimeFiles.Visibility = Visibility.Hidden;
            }
            else
            {
                TopCodeTimeFiles.Visibility = Visibility.Visible;
                // add or update

                if (TopCodeTimeFiles.HasItems)
                {
                    /**
                     * TreeViewItem parentItem = await GetParent(TopCodeTimeFiles, "topcodetimefiles");
                     * foreach (FileChangeInfo changeInfo in topCodetimeFiles)
                     * {
                     *  string codetimeMinStr = SoftwareCoUtil.HumanizeMinutes(changeInfo.duration_seconds / 60);
                     *  string label = changeInfo.name + " | " + codetimeMinStr;
                     *  UpdateNodeValue(parentItem, "topcodetime-" + changeInfo.name, label, "files.png");
                     * }
                     **/
                }
                List <TreeViewItem> topCodetimeFilesChildren = new List <TreeViewItem>();
                foreach (FileChangeInfo changeInfo in topCodetimeFiles)
                {
                    string codetimeMinStr = SoftwareCoUtil.HumanizeMinutes(changeInfo.duration_seconds / 60);
                    string label          = changeInfo.name + " | " + codetimeMinStr;
                    topCodetimeFilesChildren.Add(BuildMetricNode("topcodetime-" + changeInfo.name, label, "files.png"));
                }
                if (topCodetimeParent == null)
                {
                    topCodetimeParent = BuildMetricNodes("topcodetimefiles", "Top files by code time", topCodetimeFilesChildren);
                    TopCodeTimeFiles.Items.Add(topCodetimeParent);
                }
                else
                {
                    topCodetimeParent.Items.Clear();
                    foreach (TreeViewItem item in topCodetimeFilesChildren)
                    {
                        topCodetimeParent.Items.Add(item);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private async Task FetchCodeTimeDashboardAsync()
        {
            string summaryContent  = "";
            string summaryInfoFile = FileManager.getSessionSummaryInfoFile();

            bool online = await SoftwareUserSession.IsOnlineAsync();


            HttpResponseMessage resp =
                await SoftwareHttpManager.SendDashboardRequestAsync(HttpMethod.Get, "/dashboard?showMusic=false&showGit=false&showRank=false&showToday=false");

            if (SoftwareHttpManager.IsOk(resp))
            {
                summaryContent += await resp.Content.ReadAsStringAsync();
            }
            else
            {
                summaryContent = NO_DATA;
            }


            if (File.Exists(summaryInfoFile))
            {
                File.SetAttributes(summaryInfoFile, FileAttributes.Normal);
            }

            try
            {
                File.WriteAllText(summaryInfoFile, summaryContent, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
            }

            string dashboardFile    = FileManager.getDashboardFile();
            string dashboardContent = "";
            string suffix           = SoftwareCoUtil.CreateDateSuffix(DateTime.Now);
            string formattedDate    = DateTime.Now.ToString("ddd, MMM ") + suffix + DateTime.Now.ToString(" h:mm tt");

            dashboardContent  = "CODE TIME          " + "(Last updated on " + formattedDate + " )";
            dashboardContent += "\n\n";

            string todayDate  = DateTime.Now.ToString("ddd, MMM ") + suffix;
            string today_date = "Today " + "(" + todayDate + ")";

            dashboardContent += SoftwareCoUtil.getSectionHeader(today_date);

            SessionSummary  _sessionSummary = SessionSummaryManager.Instance.GetSessionSummayData();
            CodeTimeSummary ctSummary       = TimeDataManager.Instance.GetCodeTimeSummary();

            string codeTimeMinutes = SoftwareCoUtil.HumanizeMinutes(ctSummary.codeTimeMinutes);

            dashboardContent += SoftwareCoUtil.getDashboardRow("Code time today", codeTimeMinutes);
            string activeCodeTimeMinutes = SoftwareCoUtil.HumanizeMinutes(ctSummary.activeCodeTimeMinutes);

            dashboardContent += SoftwareCoUtil.getDashboardRow("Active code time today", activeCodeTimeMinutes);
            if (_sessionSummary != null)
            {
                string averageTime = SoftwareCoUtil.HumanizeMinutes(_sessionSummary.averageDailyMinutes);

                String liveshareTime = "";
                //if (_sessionSummary.liveshareMinutes != 0)
                //{
                //    liveshareTime = SoftwareCoUtil.HumanizeMinutes(_sessionSummary.liveshareMinutes);
                //}

                dashboardContent += SoftwareCoUtil.getDashboardRow("90-day avg", averageTime);
                //if (liveshareTime != "0")
                //{
                //    dashboardContent += SoftwareCoUtil.getDashboardRow("Live Share", liveshareTime);
                //}
                dashboardContent += "\n";
            }

            if (FileManager.SessionSummaryInfoFileExists())
            {
                string SummaryData = FileManager.getSessionSummaryInfoFileData();
                dashboardContent += SummaryData;
            }


            if (File.Exists(dashboardFile))
            {
                File.SetAttributes(dashboardFile, FileAttributes.Normal);
            }
            try
            {
                File.WriteAllText(dashboardFile, dashboardContent, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
            }
        }