跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

提交记录
修改Core/Servicers/Instances/WebData.cs+41 −0看文件
@@ -5,12 +5,16 @@ using Core.Models.Data;
55using Core.Models.Db;
66using Core.Models.WebPage;
77using Core.Servicers.Interfaces;
8新增:using CsvHelper;
89using Newtonsoft.Json;
10新增:using Npoi.Mapper;
911using NPOI.SS.Formula.Functions;
1012using Org.BouncyCastle.Security;
1113using System;
1214using System.Collections.Generic;
1315using System.Diagnostics;
16新增:using System.Globalization;
17新增:using System.IO;
1418using System.Linq;
1519using System.Linq.Expressions;
1620
@@ -791,5 +795,42 @@ namespace Core.Servicers.Instances
791795 db.Database.ExecuteSqlCommand("update WebSiteModels set Duration = 0 where ID = " + siteId_);
792796 }
793797 }
798新增:
799新增: public void Export(string dir_, DateTime start_, DateTime end_)
800新增: {
801新增: start_ = new DateTime(start_.Year, start_.Month, 1, 0, 0, 0);
802新增: end_ = new DateTime(end_.Year, end_.Month, DateTime.DaysInMonth(end_.Year, end_.Month), 23, 59, 59);
803新增:
804新增: using (var db = _database.GetReaderContext())
805新增: {
806新增: var webSiteData = db.WebBrowserLogs.Where(m => m.LogTime >= start_ && m.LogTime <= end_)
807新增: .ToList()
808新增: .Select(m => new
809新增: {
810新增: 时间 = m.LogTime,
811新增: 标题 = m.Url.Title,
812新增: 网址 = m.Url.Url,
813新增: 时长 = m.Duration,
814新增: });
815新增:
816新增:
817新增: var mapper = new Mapper();
818新增: mapper.Put(webSiteData, "浏览记录");
819新增:
820新增: string name = $"Tai网页统计数据({start_.ToString("yyyy年MM月")}-{end_.ToString("yyyy年MM月")})";
821新增: if (start_.Year == end_.Year && start_.Month == end_.Month)
822新增: {
823新增: name = $"Tai网页统计数据({start_.ToString("yyyy年MM月")})";
824新增: }
825新增: mapper.Save(Path.Combine(dir_, $"{name}.xlsx"));
826新增:
827新增: // 导出csv
828新增: using (var writer = new StreamWriter(Path.Combine(dir_, $"{name}.csv"), false, System.Text.Encoding.UTF8))
829新增: using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
830新增: {
831新增: csv.WriteRecords(webSiteData);
832新增: }
833新增: }
834新增: }
794835 }
795836}
文件末尾没有换行
修改Core/Servicers/Interfaces/IWebData.cs+7 −0看文件
@@ -161,5 +161,12 @@ namespace Core.Servicers.Interfaces
161161 /// </summary>
162162 /// <param name="siteId_">站点ID</param>
163163 void Clear(int siteId_);
164新增: /// <summary>
165新增: /// 导出数据
166新增: /// </summary>
167新增: /// <param name="dir_">导出目录</param>
168新增: /// <param name="start_">开始时间</param>
169新增: /// <param name="end_">结束时间</param>
170新增: void Export(string dir_, DateTime start_, DateTime end_);
164171 }
165172}
修改UI/ViewModels/SettingPageVM.cs+2 −0看文件
@@ -1,6 +1,7 @@
11using Core.Librarys;
22using Core.Models.Config;
33using Core.Models.Config.Link;
4新增:using Core.Servicers.Instances;
45using Core.Servicers.Interfaces;
56using System;
67using System.Collections.Generic;
@@ -193,6 +194,7 @@ namespace UI.ViewModels
193194 if (dialog.ShowDialog() == DialogResult.OK)
194195 {
195196 data.ExportToExcel(dialog.SelectedPath, ExportDataStartMonthDate, ExportDataEndMonthDate);
197新增: _webData.Export(dialog.SelectedPath, ExportDataStartMonthDate, ExportDataEndMonthDate);
196198 mainVM.Toast("导出数据完成", Controls.Window.ToastType.Success);
197199 }
198200 }