示例#1
0
            /// <summary>
            /// 统计月度所有项目时间段情况(散点图)
            /// </summary>
            /// <param name="userId"></param>
            /// <param name="year"></param>
            /// <param name="month"></param>
            /// <returns></returns>
            public static List <Tuple <string, List <Tuple <DateTime, double> > > > BubbleReport(int year, int month)
            {
                List <Tuple <string, List <Tuple <DateTime, double> > > > rs = null;
                DateTime monthStart = new DateTime(year, month, 1);
                DateTime monthEnd   = monthStart.AddMonths(1);

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.BeginDate >= monthStart && x.BeginDate < monthEnd, null))
                    {
                        var heartbeats = db.Do <WakaTimeDatas>().Where(x => x.BeginDate >= monthStart && x.BeginDate < monthEnd).OrderByDescending(x => x.Duration).Take(1000).ToList();
                        if (ListTool.HasElements(heartbeats))
                        {
                            rs = new List <Tuple <string, List <Tuple <DateTime, double> > > >();
                            heartbeats.ForEach(x =>
                            {
                                if (!rs.Any(y => y.Item1 == x.Project))
                                {
                                    rs.Add(new Tuple <string, List <Tuple <DateTime, double> > >(x.Project, new List <Tuple <DateTime, double> >()));
                                }
                                else
                                {
                                    var item = rs.FirstOrDefault(y => y.Item1 == x.Project);
                                    if (item != null)
                                    {
                                        item.Item2.Add(new Tuple <DateTime, double>(x.BeginDate, x.Duration));
                                    }
                                }
                            });
                        }
                    }
                }
                return(rs);
            }
示例#2
0
            /// <summary>
            /// 统计最近七天编程语言使用占用情况
            /// </summary>
            /// <param name="userId"></param>
            /// <returns></returns>
            public static List <Tuple <string, double> > LanguageCount()
            {
                DateTime today                    = DateTime.Now;
                DateTime sevenDaysAgo             = new DateTime(today.AddDays(-6).Year, today.AddDays(-6).Month, today.AddDays(-6).Day, 0, 0, 0);
                List <Tuple <string, double> > rs = null;

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.ID != null, null))
                    {
                        var languageGroup = db.Do <WakaTimeDatas>().Where(x => x.Language != null && x.BeginDate >= sevenDaysAgo).GroupBy(x => x.Language).
                                            Select(x => new
                        {
                            Language = x.Max(e => e.Language),
                            Duration = x.Sum(y => y.Duration),
                        }).OrderByDescending(x => x.Duration).Take(MAX_LANGUAGE).ToList();

                        if (ListTool.HasElements(languageGroup))
                        {
                            rs = new List <Tuple <string, double> >();
                            languageGroup.ForEach(x =>
                            {
                                Tuple <string, double> rec = new Tuple <string, double>(x.Language, x.Duration);
                                rs.Add(rec);
                            });
                        }
                    }
                }
                return(rs);
            }
示例#3
0
        public static int GetDatas(string apiKey, DateTime date)
        {
            int count                          = 0;
            var durations                      = GetDurations(apiKey, date);
            var heartbeats                     = GetHeartbeats(apiKey, date);
            List <WakaTimeDatas> datas         = AssembleHeartbeats(durations, heartbeats);
            List <WakaTimeDatas> notExistDatas = new List <WakaTimeDatas>();

            if (ListTool.HasElements(datas))
            {
                using (Muse db = new Muse())
                {
                    foreach (var data in datas)
                    {
                        if (!db.Any <WakaTimeDatas>(x => x.ID == data.ID, null))
                        {
                            if (!notExistDatas.Any(x => x.ID == data.ID))
                            {
                                notExistDatas.Add(data);
                            }
                        }
                    }
                    if (ListTool.HasElements(notExistDatas))
                    {
                        count = db.Adds(notExistDatas);
                    }
                }
            }
            return(count);
        }
示例#4
0
            /// <summary>
            /// 获取所有年份
            /// </summary>
            /// <returns></returns>
            public static List<int> AllYears()
            {
                List<int> years = new List<int>();
                using (Muse db = new Muse())
                {
                    if (db.Any<WakaTimeDatas>(x => x.ID != null, null))
                    {
                        var data = db.Do<WakaTimeDatas>().
                              GroupBy(x => new { x.BeginDate.Year }).
                              Select(x => new
                              {
                                  Date = x.Max(y => y.BeginDate),
                              }).OrderByDescending(x => x.Date).ToList();

                        if (ListTool.HasElements(data))
                        {
                            data.ForEach(x =>
                            {
                                years.Add(x.Date.Year);
                            });
                        }
                    }
                }
                int year = DateTime.Now.Year;
                if (!years.Contains(year)) years.Add(year);
                return years;
            }
示例#5
0
            /// <summary>
            /// 统计所有编程语言使用占用情况
            /// </summary>
            /// <param name="userId"></param>
            /// <returns></returns>
            public static List <Tuple <string, double> > LanguageCount()
            {
                List <Tuple <string, double> > rs = null;

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.ID != null, null))
                    {
                        var languageGroup = db.Do <WakaTimeDatas>().Where(x => x.Language != null).GroupBy(x => x.Language).
                                            Select(x => new
                        {
                            Language = x.Max(e => e.Language),
                            Duration = x.Sum(y => y.Duration),
                        }).OrderByDescending(x => x.Duration).Take(MAX_LANGUAGE).ToList();

                        if (ListTool.HasElements(languageGroup))
                        {
                            rs = new List <Tuple <string, double> >();
                            languageGroup.ForEach(x =>
                            {
                                Tuple <string, double> rec = new Tuple <string, double>(x.Language, x.Duration);
                                rs.Add(rec);
                            });
                        }
                    }
                }
                return(rs);
            }
示例#6
0
        private void GetFileToDatabase()
        {
            var drives = FileQueryEngine.GetReadyNtfsDrives().OrderBy(x => x.Name);

            if (ListTool.HasElements(drives))
            {
                foreach (var drive in drives)
                {
                    NewFileCount = 0;
                    //if (!drive.Name.Contains("J")) continue;//测试只读取D盘
                    //if (drive.Name.Contains("D")) continue;//测试时跳过D盘
                    //if (drive.Name.Contains("F")) continue;//测试时跳过F盘

                    using (var db = new Muse())
                    {
                        //检测磁盘是否格式化,如果格式化则清空USN记录
                        DateTime dt1 = DriveTool.GetLastFormatTime(drive.Name);
                        var      ds  = db.Get <UsnDrives>(x => x.Name == drive.Name, null);
                        if ((ds == null) || (ds != null && ds.LastFormatTime != dt1.ToString()))
                        {
                            var deleteSql = db.Context.Database.ExecuteSqlCommand("DELETE FROM usnfiles WHERE drive = @p0;", drive.Name);

                            if (ds == null)
                            {
                                db.Add(new UsnDrives()
                                {
                                    Name = drive.Name, LastFormatTime = dt1.ToString()
                                });
                            }
                            else
                            {
                                ds.LastFormatTime = dt1.ToString();
                                db.Update(ds, true);
                            }
                        }

                        //查询上次读取到的位置(最后一条记录)
                        ulong filenumber = 0;
                        long  usn        = 0;
                        if (db.Any <UsnFiles>(x => x.Drive == drive.Name, null))
                        {
                            int      lastId  = db.Do <UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Id);
                            UsnFiles lastRec = db.Get <UsnFiles>(x => x.Id == lastId, null);

                            usn        = lastRec.Usn;
                            filenumber = NumberStringTool.ToUlong(lastRec.Number);

                            //usn = db.Do<UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Usn);
                            //string filenumberstr = db.Do<UsnFiles>().Where(x => x.Drive == drive.Name).Max(x => x.Number);
                            //filenumber = NumberStringTool.ToUlong(filenumberstr);
                        }
                        //从上次FileNumber记录开始读取
                        var usnOperator = new UsnOperator(drive);
                        usnOperator.GetEntries(usn, filenumber, GetFileToDatabaseEvent, 1000);
                    }
                }
            }
        }
        public static void Start()
        {
            if (IsStart)
            {
                return;
            }
            IsStart = true;

            Task.Factory.StartNew(() =>
            {
                //设置退出条件
                while (!Token.IsCancellationRequested)
                {
                    //队列中存在元素
                    if (Queue.Any())
                    {
                        //循环进行操作
                        for (int i = 0; i < Queue.Count; i++)
                        {
                            try
                            {
                                if (Queue.TryDequeue(out string file))
                                {
                                    R.Log.v("💗💗💗 准备处理文件:" + file);
                                    var pic = PictureReorganize.CreateModel(file);
                                    if (pic != null)
                                    {
                                        R.Log.v("图片信息读取成功");
                                        using (Muse db = new Muse("pictures"))
                                        {
                                            if (db.Any <Pictures>(x => x.MD5 == pic.MD5 && x.SHA1 == pic.SHA1, null))
                                            {
                                                R.Log.v("图片已入库,不需要在重复保存了,即将删除");
                                                FileTool.Delete(file);
                                            }
                                            else
                                            {
                                                R.Log.v("图片未入库,准备入库并分类保存");
                                                db.Add(pic);
                                                pic = PictureReorganize.AddLocationInfo(file, pic);
                                                pic = PictureReorganize.AddContentInfo(file, pic);
                                                PictureReorganize.ReorganizePicture(file, R.Paths.Pictures, pic);
                                            }
                                        }
                                    }
                                }
                            }
                            catch { }
                        }
                    }
                    Sleep.S(Interval);
                }
            });
        }
示例#8
0
            /// <summary>
            /// 获取编程总时长
            /// </summary>
            /// <returns></returns>
            public static double Career()
            {
                double career = 0;

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.ID != null, null))
                    {
                        career = db.Do <WakaTimeDatas>().Sum(x => x.Duration);
                    }
                }
                return(career);
            }
示例#9
0
        /// <summary>
        /// 定时处理要备份的文件任务
        /// </summary>
        private void BackupFileTask()
        {
            while (IsStart)
            {
                if (ListTool.HasElements(BackupFiles))
                {
                    //获取要备份的文件列表并复制样本
                    List <string> temp;
                    lock (BackupFiles)
                    {
                        temp        = BackupFiles;
                        BackupFiles = new List <string>();
                    }

                    using (var db = new Muse())
                    {
                        foreach (var t in temp)
                        {
                            //要备份的文件存在
                            if (File.Exists(t))
                            {
                                //文件属于要备份的文件目录
                                string      filepath = DirTool.GetFilePath(t);
                                BackupPaths path     = Paths.FirstOrDefault(x => filepath.Contains(x.Path));
                                if (path != null)
                                {
                                    //文件的MD5码以前没有备份过
                                    string md5    = FileTool.GetMD5(t);
                                    bool   isback = db.Any <BackupFiles>(x => x.FullPath == t && x.Md5 == md5, null);
                                    if (!isback)
                                    {
                                        string pathname  = path.Path;                                                                           //备份文件夹路径
                                        string pathalias = path.Alias;                                                                          //备份文件夹别名
                                        string pathfile  = t.Substring(pathname.Length, t.Length - pathname.Length);                            //截取备份文件子目录(相对备份文件夹)
                                        string fileext   = "." + DateTimeConvert.CompactString(DateTime.Now) + Path.GetExtension(t);            //设置后缀
                                        string fullpath  = DirTool.Combine(R.Settings.FileBackup.FileManBackup, pathalias, pathfile + fileext); //组合路径

                                        //删除冗余
                                        DeleteExcess(t);
                                        //备份文件
                                        BackupFile(t, fullpath, md5);
                                        _FileCount++;
                                    }
                                }
                            }
                        }
                    }
                }
                Thread.Sleep(R.Settings.FileBackup.BACK_UP_INTERVAL);
            }
        }
示例#10
0
            /// <summary>
            /// 统计月总时长
            /// </summary>
            /// <returns></returns>
            public static double Career(int year, int month)
            {
                double career = 0;

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.BeginDate.Year == year && x.BeginDate.Month == month, null))
                    {
                        career = db.Do <WakaTimeDatas>().Where(x => x.BeginDate.Year == year &&
                                                               x.BeginDate.Month == month).Sum(x => x.Duration);
                    }
                }
                return(career);
            }
示例#11
0
            /// <summary>
            /// 获取最近七天时长
            /// </summary>
            public static double Career()
            {
                double   career       = 0;
                DateTime today        = DateTime.Now;
                DateTime sevenDaysAgo = new DateTime(today.AddDays(-6).Year, today.AddDays(-6).Month, today.AddDays(-6).Day, 0, 0, 0);

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.BeginDate >= sevenDaysAgo, null))
                    {
                        career = db.Do <WakaTimeDatas>().Where(x => x.BeginDate >= sevenDaysAgo).Sum(x => x.Duration);
                    }
                }
                return(career);
            }
示例#12
0
            public static List<Tuple<DateTime, double>> MonthlyColumn(int year)
            {
                List<Tuple<DateTime, double>> rs = null;
                DateTime date = new DateTime(year, 1, 1);
                using (Muse db = new Muse())
                {
                    if (db.Any<WakaTimeDatas>(x => x.BeginDate.Year == date.Year, null))
                    {
                        var data = db.Do<WakaTimeDatas>().
                                    Where(x => x.BeginDate.Year == date.Year).
                                    GroupBy(x => new { x.BeginDate.Year, x.BeginDate.Month }).
                                    Select(x => new
                                    {
                                        Date = x.Max(y => y.BeginDate),
                                        Duration = x.Sum(y => y.Duration),
                                    }).OrderByDescending(x => x.Duration).ToList();

                        //整理数据库数据
                        if (ListTool.HasElements(data))
                        {
                            rs = new List<Tuple<DateTime, double>>();
                            data.ForEach(x =>
                            {
                                rs.Add(new Tuple<DateTime, double>(x.Date, x.Duration));
                            });
                        }
                        //补充缺失数据
                        if (ListTool.HasElements(rs))
                        {
                            for (int i = 0; i < 12; i++)
                            {
                                var dt = date.AddMonths(i);
                                if (!rs.Any(x => x.Item1.Year == dt.Year && x.Item1.Month == dt.Month))
                                {
                                    rs.Add(new Tuple<DateTime, double>(dt, 0));
                                }
                            }
                        }
                    }
                }
                return rs;
            }
示例#13
0
            /// <summary>
            /// 统计月度所有项目报表(堆叠柱状图)
            /// </summary>
            /// <param name="userId"></param>
            /// <param name="year"></param>
            /// <param name="month"></param>
            /// <returns></returns>
            public static List <Tuple <string, List <Tuple <DateTime, double> > > > Report(int year, int month)
            {
                List <Tuple <string, List <Tuple <DateTime, double> > > > rs = null;
                DateTime monthStart = new DateTime(year, month, 1);
                DateTime monthEnd   = monthStart.AddMonths(1);
                int      totalDays  = (int)(monthEnd - monthStart).TotalDays;

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.BeginDate >= monthStart && x.BeginDate < monthEnd, null))
                    {
                        var monthCount = db.Do <WakaTimeDatas>().
                                         Where(x => x.BeginDate >= monthStart && x.BeginDate < monthEnd).
                                         GroupBy(x => new { x.BeginDate.Year, x.BeginDate.Month, x.BeginDate.Day, x.Project }).
                                         Select(x => new
                        {
                            Date     = x.Max(y => y.BeginDate),
                            Project  = x.Max(y => y.Project),
                            Duration = x.Sum(y => y.Duration),
                        }).OrderByDescending(x => x.Duration).ToList();

                        //整理数据库数据
                        if (ListTool.HasElements(monthCount))
                        {
                            rs = new List <Tuple <string, List <Tuple <DateTime, double> > > >();
                            monthCount.ForEach(x =>
                            {
                                if (!rs.Any(y => y.Item1 == x.Project))
                                {
                                    var rec = new List <Tuple <DateTime, double> >();
                                    rec.Add(new Tuple <DateTime, double>(x.Date, x.Duration));
                                    rs.Add(new Tuple <string, List <Tuple <DateTime, double> > >(x.Project, rec));
                                }
                                else
                                {
                                    var item = rs.FirstOrDefault(y => y.Item1 == x.Project);
                                    if (item != null)
                                    {
                                        item.Item2.Add(new Tuple <DateTime, double>(x.Date, x.Duration));
                                    }
                                }
                            });
                        }
                        //补充缺失数据
                        if (ListTool.HasElements(rs))
                        {
                            foreach (var project in rs)
                            {
                                if (ListTool.HasElements(project.Item2))
                                {
                                    for (int i = 0; i < totalDays; i++)
                                    {
                                        var dt = new DateTime(monthStart.AddDays(i).Year, monthStart.AddDays(i).Month, monthStart.AddDays(i).Day, 0, 0, 0);
                                        if (!project.Item2.Any(x => x.Item1.Year == dt.Year && x.Item1.Month == dt.Month && x.Item1.Day == dt.Day))
                                        {
                                            project.Item2.Add(new Tuple <DateTime, double>(dt, 0));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return(rs);
            }
示例#14
0
            /// <summary>
            /// 获取最近七天信息
            /// </summary>
            public static List <Tuple <string, List <Tuple <DateTime, double> > > > Report()
            {
                List <Tuple <string, List <Tuple <DateTime, double> > > > rs = null;
                DateTime today        = DateTime.Now;
                DateTime sevenDaysAgo = new DateTime(today.AddDays(-6).Year, today.AddDays(-6).Month, today.AddDays(-6).Day, 0, 0, 0);

                using (Muse db = new Muse())
                {
                    if (db.Any <WakaTimeDatas>(x => x.BeginDate >= sevenDaysAgo, null))
                    {
                        //查询数据库
                        var weekCount = db.Do <WakaTimeDatas>().
                                        Where(x => x.BeginDate >= sevenDaysAgo).
                                        GroupBy(x => new { x.BeginDate.Year, x.BeginDate.Month, x.BeginDate.Day, x.Project }).
                                        Select(x => new
                        {
                            Date     = x.Max(y => y.BeginDate),
                            Project  = x.Max(y => y.Project),
                            Duration = x.Sum(y => y.Duration),
                        }).OrderByDescending(x => x.Date).ToList();
                        //整理数据库数据
                        if (ListTool.HasElements(weekCount))
                        {
                            rs = new List <Tuple <string, List <Tuple <DateTime, double> > > >();
                            weekCount.ForEach(x =>
                            {
                                if (!rs.Any(y => y.Item1 == x.Project))
                                {
                                    var rec = new List <Tuple <DateTime, double> >();
                                    rec.Add(new Tuple <DateTime, double>(x.Date, x.Duration));
                                    rs.Add(new Tuple <string, List <Tuple <DateTime, double> > >(x.Project, rec));
                                }
                                else
                                {
                                    var item = rs.FirstOrDefault(y => y.Item1 == x.Project);
                                    if (item != null)
                                    {
                                        item.Item2.Add(new Tuple <DateTime, double>(x.Date, x.Duration));
                                    }
                                }
                            });
                        }
                        //补充缺失数据
                        if (ListTool.HasElements(rs))
                        {
                            foreach (var project in rs)
                            {
                                if (ListTool.HasElements(project.Item2))
                                {
                                    for (int i = 0; i < 7; i++)
                                    {
                                        var dt = new DateTime(today.AddDays(-i).Year, today.AddDays(-i).Month, today.AddDays(-i).Day, 0, 0, 0);
                                        if (!project.Item2.Any(x => x.Item1.Year == dt.Year && x.Item1.Month == dt.Month && x.Item1.Day == dt.Day))
                                        {
                                            project.Item2.Add(new Tuple <DateTime, double>(dt, 0));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return(rs);
            }