コード例 #1
0
        /// <summary>
        /// TODO: update comments
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public static ContextCategory GetContextCategory(ContextDto dto)
        {
            try
            {
                var processName = dto.Context.ProgramInUse;
                var windowName  = dto.Context.WindowTitle;

                if (string.IsNullOrEmpty(processName) && string.IsNullOrEmpty(windowName))
                {
                    return(ContextCategory.Unknown);
                }

                if (windowName != null)
                {
                    windowName = windowName.ToLower();
                }
                if (processName != null)
                {
                    processName = processName.ToLower();
                }


                // all IDLE, will later manually check with more info to find meetings, breaks, etc.
                if (processName != null && processName.Equals(Dict.Idle.ToLower()))
                {
                    return(ContextCategory.None); //TODO: add logic for <2min idle (reading something)
                }
                // check with planning keywords
                if (IsCategory(ContextCategory.Planning, processName, windowName))
                {
                    // this is needed because "task" could be mapped for the "task manager"
                    return(IsCategory(ContextCategory.Other, processName, windowName)
                        ? ContextCategory.Other
                        : ContextCategory.Planning);
                }
                // if not planning, check with email keywords
                if (IsCategory(ContextCategory.Email, processName, windowName))
                {
                    return(ContextCategory.Email);
                }
                // if editor, might be reading/writing OR coding (if common coding file type extension or the window
                // title has not enough information to accurately map by hand, then map to coding category,
                // else: manual mapping later)
                if (IsEditor(processName, windowName))
                {
                    return((IsCodeFile(windowName))
                        ? ContextCategory.DevCode
                        : ContextCategory.ReadWriteDocument); //ContextCategory.ManualEditor;
                }
                // check with debugging keywords (manual because of manual checking later)
                if (IsCategory(ContextCategory.DevDebug, processName, windowName))
                {
                    return(ContextCategory.DevDebug);
                }
                // check with review keywords (manual because of manual checking later)
                if (IsCategory(ContextCategory.DevReview, processName, windowName))
                {
                    return(ContextCategory.DevReview);
                }
                // check with version control keywords (manual because of manual checking later)
                if (IsCategory(ContextCategory.DevVc, processName, windowName))
                {
                    return(ContextCategory.DevVc);
                }
                // check with coding keywords (there might be more from editors, manual mapping)
                if (IsCategory(ContextCategory.DevCode, processName, windowName))
                {
                    return(ContextCategory.DevCode);
                }
                // check with read/write keywords (there might be more from editors, manual mapping)
                if (IsCategory(ContextCategory.ReadWriteDocument, processName, windowName))
                {
                    return(ContextCategory.ReadWriteDocument);
                }

                // NO automated mapping of formal meetings: will look at self-reported tasks & IDLE times
                // NO automated mapping of in-formal meetings: will look at self-reported tasks & IDLE times


                // check if its a browser (did not yet fit into other categories
                // then it's work related / unrelated web browsing which is manually mapped
                if (IsBrowser(processName))
                {
                    // map according to keywords and websites
                    if (IsWebsiteWorkRelated(windowName))
                    {
                        return(ContextCategory.WorkRelatedBrowsing);
                    }
                    if (IsWebsiteWorkUnrelated(windowName))
                    {
                        return(ContextCategory.WorkUnrelatedBrowsing);
                    }

                    return(ContextCategory.WorkRelatedBrowsing); // default
                }
                // check with instant messaging keywords (subcategory of INFORMAL MEETING)
                if (IsCategory(ContextCategory.InformalMeeting, processName, windowName))
                {
                    return(ContextCategory.InformalMeeting);
                }
                // check with rdp keywords (subcategory of Other)
                if (IsCategory(ContextCategory.OtherRdp, processName, windowName))
                {
                    return(ContextCategory.OtherRdp);
                }
                // check if it's something else (OS related, navigating, etc.)
                if (IsCategory(ContextCategory.Other, processName, windowName))
                {
                    return(ContextCategory.Other);
                }
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
            }

            return(ContextCategory.Unknown); // should never happen!
        }
コード例 #2
0
ファイル: Queries.cs プロジェクト: sealuzh/PersonalAnalytics
        /// <summary>
        /// Saves the timestamp, process name and window title into the database.
        /// 
        /// In case the user doesn't want the window title to be stored (For privacy reasons),
        /// it is obfuscated.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="process"></param>
        internal static void InsertSnapshot(string window, string process)
        {
            if (Shared.Settings.AnonymizeSensitiveData)
            {
                var dto = new ContextDto { Context = new ContextInfos { ProgramInUse = process, WindowTitle = window } };
                window = Dict.Anonymized + " " + ContextMapper.GetContextCategory(dto);  // obfuscate window title
            }

            Database.GetInstance().ExecuteDefaultQuery("INSERT INTO " + Settings.DbTable + " (time, window, process) VALUES (strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime'), " +
                Database.GetInstance().Q(window) + ", " + Database.GetInstance().Q(process) + ")");
        }