Exemple #1
0
        /// <summary>
        /// Return vo for user, adding if necessary
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>

        static UserDataVo UserData(
            string userId)
        {
            object o = UserDataHash[userId];

            if (o != null)
            {
                return((UserDataVo)o);
            }

            UserDataVo vo = new UserDataVo();

            vo.Userid = userId;

            UserDataHash.Add(userId, vo);
            return(vo);
        }
Exemple #2
0
        /// <summary>
        /// Commandline command to analyse usage data
        /// </summary>
        /// <param name="commandLine"></param>
        /// <returns></returns>

        public static string AnalyzeUsageData(
            string commandArgs)
        {
            string      currentUserid = "";
            DateTime    startTime = DateTime.MinValue, finishTime;
            int         count, pass, n, rowCount = 0;
            int         i1, i2;
            string      txt, rec, buf;
            string      sql, sqlmsg, stmt, table;
            int         objid, curobj, emp_id;
            int         noMatchingBegin = 0;
            DbCommandMx drd;

            Lex lex = new Lex();

            lex.OpenString(commandArgs);
            string startDate  = lex.Get();
            string endDate    = lex.Get();
            string startDate2 = DateTimeMx.Normalize(startDate);
            string endDate2   = DateTimeMx.Normalize(endDate);

            if (startDate2 == null || endDate2 == null)
            {
                throw new Exception("Syntax: Analyze Usage Data <start_date> <end_date>");
            }

            startDate2 = "to_date('" + startDate2 + "','YYYYMMDD')";
            endDate2   = "to_date('" + endDate2 + " 235959','YYYYMMDD HH24MISS')";

            string where = "where crt_dt between " + startDate2 + " and " + endDate2;

            string arg = lex.Get();

            if (Lex.Eq(arg, "DumpUsageData"))
            {
                return(DumpUsageData(where));
            }

            // Init data

            TableData       = new Hashtable();       // number of times each table accessed
            CommandData     = new Hashtable();       // number of times each command accessed
            TransactionData = new Hashtable();       // count for each transaction type
            UserDataHash    = new Hashtable();       // info on each user, site, department

            // Process usage log records. Find the users for the time period,
            // how many times each user accessed app and the average
            // session time in minutes for each user

            string orderBy = "order by ownr_id, crt_dt";

            drd = UsageDao.Select(where, orderBy);

            UserObject beginUo = new UserObject();

            while (true)
            {
                UserObject uo = UsageDao.Read(drd);
                if (uo == null)
                {
                    drd.Dispose();
                    if (rowCount > 0)
                    {
                        break;
                    }
                    throw new Exception("No data found for specified for time period");
                }

                if (uo.Owner == null || uo.Owner.Trim().Length == 0)
                {
                    continue;                     // skip if owner not specified
                }
                if (rowCount % 1000 == 0)
                {
                    UAL.Progress.Show("Analyzing Usage Data, rows: " + rowCount + " ...", UmlautMobius.String, false);
                }

                rowCount++;

                string eventName = uo.Description;
                string eventData = uo.Content;

                // Increment count on event type

                object o = TransactionData[eventName];
                if (o == null)
                {
                    TransactionData.Add(eventName, 0);
                    count = 0;
                }
                else
                {
                    count = (int)o;
                }
                TransactionData[eventName] = count + 1;

                // Beginning of session?

                if (Lex.Eq(eventName, "Begin"))
                {
                    beginUo       = uo;
                    currentUserid = uo.Owner;
                    startTime     = uo.UpdateDateTime;
                    UserData(currentUserid).Count++;
                }

                else if (Lex.Eq(eventName, "SSS") ||
                         eventName.ToLower().StartsWith("strsrch sss"))
                {
                    UserData(uo.Owner).SsCount++;
                }

                else if (Lex.Eq(eventName, "MSimilar") ||
                         eventName.ToLower().StartsWith("strsrch msimilar"))
                {
                    UserData(uo.Owner).SimCount++;
                }

                else if (eventName.StartsWith("QueryGrid"))                 // get QueryGridAnd, Complex & Or
                {
                    UserData(uo.Owner).QueryCount++;
                }

                else if (Lex.Eq(eventName, "TableStats") && uo.Content != null)
                {
                    string[] sa = uo.Content.Split('\n');
                    for (i1 = 0; i1 < sa.Length; i1++)
                    {
                        if (sa[i1] == null || sa[i1] == "" || sa[i1] == "")
                        {
                            continue;
                        }
                        string[] sa2 = sa[i1].Split('\t');                         // split into table name & count
                        if (sa2.Length != 2)
                        {
                            continue;
                        }
                        o = TableData[sa2[0]];                         // lookup table
                        if (o == null)
                        {
                            TableData.Add(sa2[0], null);
                            count = 0;
                        }
                        else
                        {
                            count = (int)o;
                        }
                        TableData[sa2[0]] = count + Int32.Parse(sa2[1]);
                    }
                }

                else if (Lex.Eq(eventName, "CommandStats") && uo.Content != null)
                {
                    string[] sa = uo.Content.Split('\n');
                    for (i1 = 0; i1 < sa.Length; i1++)
                    {
                        if (sa[i1] == null || sa[i1] == "" || sa[i1] == "")
                        {
                            continue;
                        }
                        string[] sa2 = sa[i1].Split('\t');                         // split into table name & count
                        if (sa2.Length != 2)
                        {
                            continue;
                        }
                        o = CommandData[sa2[0]];                         // lookup table
                        if (o == null)
                        {
                            CommandData.Add(sa2[0], null);
                            count = 0;
                        }
                        else
                        {
                            count = (int)o;
                        }
                        CommandData[sa2[0]] = count + Int32.Parse(sa2[1]);
                    }
                }

                else if (Lex.Eq(eventName, "End"))
                {
                    if (uo.Owner == currentUserid)                     // same user?
                    {
                        UserData(currentUserid).Ended++;

                        TimeSpan elapsed = uo.UpdateDateTime.Subtract(startTime);
                        UserData(currentUserid).TotalTime += elapsed.Minutes;
                    }
                    else
                    {
                        noMatchingBegin++;
                    }

                    currentUserid = "";
                }
            }             // end of main loop

            // Calculate totals

            UserDataVo totalVo = UserData("=Total=");

            foreach (UserDataVo vo in UserDataHash.Values)
            {
                if (vo.Userid == totalVo.Userid)
                {
                    continue;
                }

                totalVo.Users++;
                totalVo.Count      += vo.Count;
                totalVo.Ended      += vo.Ended;
                totalVo.SsCount    += vo.SsCount;
                totalVo.SimCount   += vo.SimCount;
                totalVo.QueryCount += vo.QueryCount;
                totalVo.TotalTime  += vo.TotalTime;
            }

            // Calculate site totals


            foreach (UserDataVo vo in UserDataHash.Values)
            {
                if (vo.Users > 0)
                {
                    continue;                               // just individuals
                }
                if (vo.Site == "")
                {
                    continue;                                // ignore if no site info
                }
                totalVo.Users++;
                totalVo.Count      += vo.Count;
                totalVo.Ended      += vo.Ended;
                totalVo.SsCount    += vo.SsCount;
                totalVo.SimCount   += vo.SimCount;
                totalVo.QueryCount += vo.QueryCount;
                totalVo.TotalTime  += vo.TotalTime;
            }

            // Order user data by descending usage count

            ArrayList UserDataList = new ArrayList(UserDataHash.Values);

            UserDataVo ud1, ud2;

            for (i1 = 1; i1 < UserDataList.Count; i1++)
            {
                ud1 = (UserDataVo)UserDataList[i1];
                for (i2 = i1 - 1; i2 >= 0; i2--)
                {
                    ud2 = (UserDataVo)UserDataList[i2];
                    if (ud1.Count < ud2.Count)
                    {
                        break;
                    }
                    UserDataList[i2 + 1] = UserDataList[i2];
                }
                UserDataList[i2 + 1] = ud1;
            }

            // Output user info

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Mobius Usage Statistics for " + startDate + " through " + endDate);
            sb.AppendLine("");

            string format, s;

            object[] args;

            format = "{0,-38} {1,5} {2,4} {3,7} {4,4} {5,4}";
            args   = new object[] { "User", "Uses", "Time", "Queries", "SSS", "Sim" };
            s      = String.Format(format, args);
            sb.AppendLine(s);

            args = new object[] { "--------------------------------------", "-----", "----", "-------", "----", "----" };
            s    = String.Format(format, args);
            sb.AppendLine(s);

            for (pass = 1; pass <= 2; pass++)             // do summary values first, then users
            {
                for (int ui = 0; ui < UserDataList.Count; ui++)
                {
                    UserDataVo vo = (UserDataVo)UserDataList[ui];
                    if (pass == 1 && vo.Users == 0)
                    {
                        continue;                                                 // skip users on first past
                    }
                    else if (pass == 2 && vo.Users > 0)
                    {
                        continue;                                                     // skip totals on 2nd pass
                    }
                    if (vo.Ended == 0)
                    {
                        vo.AverageTime = 0;
                    }
                    else
                    {
                        vo.AverageTime = vo.TotalTime / vo.Ended; // avg. Time (min) for properly ended sessions
                    }
                    if (vo.Users > 0)                             // summary
                    {
                        txt = vo.Userid + " (" + vo.Users.ToString() + " users)";
                    }

                    else
                    {                     // single user
                        try
                        {
                            UserInfo sui = Security.GetUserInfo(vo.Userid);
                            txt  = sui.LastName + ", " + sui.FirstName;
                            txt += " (" + vo.Userid + ")";
                        }
                        catch (Exception ex) { txt = vo.Userid; }

                        if (vo.Site != "")
                        {
                            txt += " (" + vo.Site + ")";
                        }
                    }

                    args = new object[] { txt, vo.Count, vo.AverageTime, vo.QueryCount, vo.SsCount, vo.SimCount };
                    s    = String.Format(format, args);
                    sb.AppendLine(s);
                }
            }

            // Output table usage stats

            sb.AppendLine("");
            format = "{0,-18} {1,8}";
            s      = String.Format(format, "MetaTable", "Accesses");
            sb.AppendLine(s);
            s = String.Format(format, "------------------", "--------");
            sb.AppendLine(s);

            ArrayList al = new ArrayList();

            foreach (string key in TableData.Keys)
            {
                s = String.Format(format, key, TableData[key]);
                al.Add(s);
            }
            al.Sort();
            foreach (string s2 in al)
            {
                sb.AppendLine(s2);
            }

            // Output command usage stats

            sb.AppendLine("");
            format = "{0,-18} {1,8}";
            s      = String.Format(format, "Command", "Accesses");
            sb.AppendLine(s);
            s = String.Format(format, "------------------", "--------");
            sb.AppendLine(s);

            al = new ArrayList();
            foreach (string key in CommandData.Keys)
            {
                s = String.Format(format, key, CommandData[key]);
                al.Add(s);
            }
            al.Sort();
            foreach (string s2 in al)
            {
                sb.AppendLine(s2);
            }

            // Output transaction counts

            sb.AppendLine("");
            format = "{0,-18} {1,8}";
            s      = String.Format(format, "Transaction", "Count");
            sb.AppendLine(s);
            s = String.Format(format, "------------------", "--------");
            sb.AppendLine(s);

            al = new ArrayList();
            foreach (string key in TransactionData.Keys)
            {
                s = String.Format(format, key, TransactionData[key]);
                al.Add(s);
            }
            al.Sort();
            foreach (string s2 in al)
            {
                sb.AppendLine(s2);
            }

            return(sb.ToString());
        }