From e52e09cfd59985fa827d1a9b15cb93890eac5230 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 14:40:48 +0800 Subject: [PATCH 01/18] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/models.go | 1 + models/user_login_log.go | 31 +++++++++++++++++++++++++++++++ routers/user/auth.go | 14 ++++++++------ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 models/user_login_log.go diff --git a/models/models.go b/models/models.go index 0cdcee4fd..696d0949b 100755 --- a/models/models.go +++ b/models/models.go @@ -139,6 +139,7 @@ func init() { new(RepoStatistic), new(SummaryStatistic), new(UserBusinessAnalysis), + new(UserLoginLog), ) gonicNames := []string{"SSL", "UID"} diff --git a/models/user_login_log.go b/models/user_login_log.go new file mode 100644 index 000000000..849e9af0b --- /dev/null +++ b/models/user_login_log.go @@ -0,0 +1,31 @@ +package models + +import ( + "fmt" + "time" + "net/http" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/timeutil" +) + +type UserLoginLog struct { + ID int64 `xorm:"pk autoincr"` + uid int64 `xorm:"NOT NULL"` + ipAddr string `xorm:"default NULL"` + CreatedUnix timeutil.TimeStamp `xorm:"created"` +} + +func SaveLoginInfoToDb(r *http.Request,u User){ + + + +} + + +func getIP(r *http.Request) string {     + forwarded := r.Header.Get("X-FORWARDED-FOR")     + if forwarded != "" {         + return forwarded     + }     + return r.RemoteAddr +} \ No newline at end of file diff --git a/routers/user/auth.go b/routers/user/auth.go index 13e338565..749386e07 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -215,6 +215,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { } return } + log.Info("Go this 1.") // If this user is enrolled in 2FA, we can't sign the user in just yet. // Instead, redirect them to the 2FA authentication page. _, err = models.GetTwoFactorByUID(u.ID) @@ -226,7 +227,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { } return } - + log.Info("Go this 2.") // User needs to use 2FA, save data and redirect to 2FA page. if err := ctx.Session.Set("twofaUid", u.ID); err != nil { ctx.ServerError("UserSignIn: Unable to set twofaUid in session", err) @@ -240,13 +241,14 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { ctx.ServerError("UserSignIn: Unable to save session", err) return } - + log.Info("Go this 3.") regs, err := models.GetU2FRegistrationsByUID(u.ID) if err == nil && len(regs) > 0 { ctx.Redirect(setting.AppSubURL + "/user/u2f") return } - + log.Info("Go this 4.") + models.SaveLoginInfoToDb(ctx.Req.Request, u) ctx.Redirect(setting.AppSubURL + "/user/two_factor") } @@ -1168,8 +1170,8 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo log.Trace("Account created: %s", u.Name, ctx.Data["MsgID"]) err := models.AddEmailAddress(&models.EmailAddress{ - UID: u.ID, - Email: form.Email, + UID: u.ID, + Email: form.Email, IsActivated: !setting.Service.RegisterEmailConfirm, }) @@ -1267,7 +1269,7 @@ func Activate(ctx *context.Context) { } email, err := models.GetEmailAddressByIDAndEmail(user.ID, user.Email) - if err != nil || email == nil{ + if err != nil || email == nil { log.Error("GetEmailAddressByIDAndEmail failed", ctx.Data["MsgID"]) } else { if err := email.Activate(); err != nil { From f3b530b24923aab2a951198ee12e1e0c8505256d Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:05:06 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_login_log.go | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/models/user_login_log.go b/models/user_login_log.go index 849e9af0b..288f8e051 100644 --- a/models/user_login_log.go +++ b/models/user_login_log.go @@ -1,31 +1,34 @@ package models import ( - "fmt" - "time" "net/http" - "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/timeutil" ) type UserLoginLog struct { - ID int64 `xorm:"pk autoincr"` - uid int64 `xorm:"NOT NULL"` - ipAddr string `xorm:"default NULL"` - CreatedUnix timeutil.TimeStamp `xorm:"created"` + ID int64 `xorm:"pk autoincr"` + uid int64 `xorm:"NOT NULL"` + ipAddr string `xorm:"default NULL"` + CreatedUnix timeutil.TimeStamp `xorm:"created"` } -func SaveLoginInfoToDb(r *http.Request,u User){ +func SaveLoginInfoToDb(r *http.Request, u *User) { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() - + var dateRecord UserLoginLog -} + dateRecord.uid = u.ID + dateRecord.ipAddr = getIP(r) + statictisSess.Insert(&dateRecord) +} -func getIP(r *http.Request) string {     - forwarded := r.Header.Get("X-FORWARDED-FOR")     - if forwarded != "" {         - return forwarded     - }     +func getIP(r *http.Request) string { + forwarded := r.Header.Get("X-FORWARDED-FOR") + if forwarded != "" { + return forwarded + } return r.RemoteAddr -} \ No newline at end of file +} From bac11fc65363543ec9f3bc839256b586de535b67 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:11:58 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/user/auth.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/user/auth.go b/routers/user/auth.go index 749386e07..d9811bd83 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -225,6 +225,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { } else { ctx.ServerError("UserSignIn", err) } + log.Info("Go this 1-1.") return } log.Info("Go this 2.") From c1b3feaed871f529cfa062d85a4e8acc68f4c606 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:15:06 +0800 Subject: [PATCH 04/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/user/auth.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/routers/user/auth.go b/routers/user/auth.go index d9811bd83..44c5ad97d 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -215,7 +215,7 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { } return } - log.Info("Go this 1.") + models.SaveLoginInfoToDb(ctx.Req.Request, u) // If this user is enrolled in 2FA, we can't sign the user in just yet. // Instead, redirect them to the 2FA authentication page. _, err = models.GetTwoFactorByUID(u.ID) @@ -225,10 +225,8 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { } else { ctx.ServerError("UserSignIn", err) } - log.Info("Go this 1-1.") return } - log.Info("Go this 2.") // User needs to use 2FA, save data and redirect to 2FA page. if err := ctx.Session.Set("twofaUid", u.ID); err != nil { ctx.ServerError("UserSignIn: Unable to set twofaUid in session", err) @@ -242,14 +240,12 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { ctx.ServerError("UserSignIn: Unable to save session", err) return } - log.Info("Go this 3.") regs, err := models.GetU2FRegistrationsByUID(u.ID) if err == nil && len(regs) > 0 { ctx.Redirect(setting.AppSubURL + "/user/u2f") return } - log.Info("Go this 4.") - models.SaveLoginInfoToDb(ctx.Req.Request, u) + ctx.Redirect(setting.AppSubURL + "/user/two_factor") } From 6c56ed5a03864d50dd6de1d934bc6a65bb8618cb Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:19:40 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_login_log.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/user_login_log.go b/models/user_login_log.go index 288f8e051..4a4c5c58c 100644 --- a/models/user_login_log.go +++ b/models/user_login_log.go @@ -1,8 +1,10 @@ package models import ( + "fmt" "net/http" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" ) @@ -21,6 +23,8 @@ func SaveLoginInfoToDb(r *http.Request, u *User) { dateRecord.uid = u.ID dateRecord.ipAddr = getIP(r) + log.Info("uid=" + fmt.Sprint(dateRecord.uid)) + log.Info("ip=" + dateRecord.ipAddr) statictisSess.Insert(&dateRecord) } From f453c288df56c4459ff4be53ebf3efe07a705190 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:23:20 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_login_log.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/models/user_login_log.go b/models/user_login_log.go index 4a4c5c58c..75f43847f 100644 --- a/models/user_login_log.go +++ b/models/user_login_log.go @@ -10,8 +10,8 @@ import ( type UserLoginLog struct { ID int64 `xorm:"pk autoincr"` - uid int64 `xorm:"NOT NULL"` - ipAddr string `xorm:"default NULL"` + UId int64 `xorm:"NOT NULL"` + IpAddr string `xorm:"default NULL"` CreatedUnix timeutil.TimeStamp `xorm:"created"` } @@ -21,10 +21,10 @@ func SaveLoginInfoToDb(r *http.Request, u *User) { var dateRecord UserLoginLog - dateRecord.uid = u.ID - dateRecord.ipAddr = getIP(r) - log.Info("uid=" + fmt.Sprint(dateRecord.uid)) - log.Info("ip=" + dateRecord.ipAddr) + dateRecord.UId = u.ID + dateRecord.IpAddr = getIP(r) + log.Info("uid=" + fmt.Sprint(dateRecord.UId)) + log.Info("ip=" + dateRecord.IpAddr) statictisSess.Insert(&dateRecord) } From 225a68b995b1236d1d23ee0196632b883dc93553 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:31:20 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_login_log.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/user_login_log.go b/models/user_login_log.go index 75f43847f..46260efda 100644 --- a/models/user_login_log.go +++ b/models/user_login_log.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "fmt" "net/http" @@ -30,9 +31,12 @@ func SaveLoginInfoToDb(r *http.Request, u *User) { } func getIP(r *http.Request) string { + headerjson, _ := json.Marshal(r.Header) + log.Info("json=" + string(headerjson)) forwarded := r.Header.Get("X-FORWARDED-FOR") if forwarded != "" { return forwarded } + return r.RemoteAddr } From 762f2e3117f3c79b6a21d12570f79efee1c44252 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:38:15 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_login_log.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/user_login_log.go b/models/user_login_log.go index 46260efda..fb6be9948 100644 --- a/models/user_login_log.go +++ b/models/user_login_log.go @@ -32,7 +32,11 @@ func SaveLoginInfoToDb(r *http.Request, u *User) { func getIP(r *http.Request) string { headerjson, _ := json.Marshal(r.Header) - log.Info("json=" + string(headerjson)) + log.Info("header json=" + string(headerjson)) + + reqjson, _ := json.Marshal(r) + log.Info("request json=" + string(reqjson)) + forwarded := r.Header.Get("X-FORWARDED-FOR") if forwarded != "" { return forwarded From 32d199a6c8d2fdee1e1633fd15044663457abc2e Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:43:36 +0800 Subject: [PATCH 09/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_login_log.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/user_login_log.go b/models/user_login_log.go index fb6be9948..299cd48af 100644 --- a/models/user_login_log.go +++ b/models/user_login_log.go @@ -34,8 +34,8 @@ func getIP(r *http.Request) string { headerjson, _ := json.Marshal(r.Header) log.Info("header json=" + string(headerjson)) - reqjson, _ := json.Marshal(r) - log.Info("request json=" + string(reqjson)) + trailerjson, _ := json.Marshal(r.Trailer) + log.Info("trailerjson=" + string(trailerjson)) forwarded := r.Header.Get("X-FORWARDED-FOR") if forwarded != "" { From d739407e0d22e08ea0c4c5092f49672231b7f78c Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 26 Oct 2021 15:59:46 +0800 Subject: [PATCH 10/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 25 +++++++++++++++++++++++++ models/user_login_log.go | 12 ------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 8b7691677..406cc36f1 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -153,6 +153,7 @@ func CountData(wikiCountMap map[string]int) { CommitDatasetSizeMap := queryDatasetSize(start_unix, end_unix) SolveIssueCountMap := querySolveIssue(start_unix, end_unix) CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) + LoginCountMap := queryLoginCount(start_unix, end_unix) for i, userRecord := range userList { var dateRecord UserBusinessAnalysis @@ -235,6 +236,12 @@ func CountData(wikiCountMap map[string]int) { dateRecord.CreateRepoCount = CreateRepoCountMap[dateRecord.ID] } + if _, ok := LoginCountMap[dateRecord.ID]; !ok { + dateRecord.LoginCount = 0 + } else { + dateRecord.LoginCount = LoginCountMap[dateRecord.ID] + } + dateRecord.CommitModelCount = 0 statictisSess := xStatistic.NewSession() @@ -421,6 +428,24 @@ func queryUserCreateRepo(start_unix int64, end_unix int64) map[int64]int { return resultMap } +func queryLoginCount(start_unix int64, end_unix int64) map[int64]int { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + statictisSess.Select("id,u_id").Table("user_login_log").Where("created_unix>=" + fmt.Sprint(start_unix) + " and created_unix<=" + fmt.Sprint(end_unix)) + userLoginLogList := make([]*UserLoginLog, 0) + statictisSess.Find(&userLoginLogList) + resultMap := make(map[int64]int) + log.Info("query user login size=" + fmt.Sprint(len(userLoginLogList))) + for _, loginRecord := range userLoginLogList { + if _, ok := resultMap[loginRecord.UId]; !ok { + resultMap[loginRecord.UId] = 1 + } else { + resultMap[loginRecord.UId] += 1 + } + } + return resultMap +} + func subMonth(t1, t2 time.Time) (month int) { y1 := t1.Year() y2 := t2.Year() diff --git a/models/user_login_log.go b/models/user_login_log.go index 299cd48af..4a499d527 100644 --- a/models/user_login_log.go +++ b/models/user_login_log.go @@ -1,11 +1,8 @@ package models import ( - "encoding/json" - "fmt" "net/http" - "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" ) @@ -24,23 +21,14 @@ func SaveLoginInfoToDb(r *http.Request, u *User) { dateRecord.UId = u.ID dateRecord.IpAddr = getIP(r) - log.Info("uid=" + fmt.Sprint(dateRecord.UId)) - log.Info("ip=" + dateRecord.IpAddr) statictisSess.Insert(&dateRecord) } func getIP(r *http.Request) string { - headerjson, _ := json.Marshal(r.Header) - log.Info("header json=" + string(headerjson)) - - trailerjson, _ := json.Marshal(r.Trailer) - log.Info("trailerjson=" + string(trailerjson)) - forwarded := r.Header.Get("X-FORWARDED-FOR") if forwarded != "" { return forwarded } - return r.RemoteAddr } From 100795a7153a6adaba4c8720f5f7b22ad102c0cb Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 27 Oct 2021 10:59:37 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9Bug#617?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- public/self/labelTaskPage.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/self/labelTaskPage.js b/public/self/labelTaskPage.js index 03acd6df1..a7b252b4f 100644 --- a/public/self/labelTaskPage.js +++ b/public/self/labelTaskPage.js @@ -41,7 +41,7 @@ function setDataSetTask(){ //dislpayUser(); getLabelPropertyTask(); displayLabelPropertyTask(); - + dataset_sele_Change(""); $(".ui.dataset.modal").modal("show"); } @@ -132,6 +132,7 @@ function setPredictTask(){ get_model_list(); displayModelTask(); + dataset_auto_sele_Change(""); $(".ui.predict.modal").modal("show"); } From f7f3b76efa5ea1967ac47dafd29712f77cce375e Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 27 Oct 2021 11:08:50 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82=E4=BF=AE=E6=94=B9#617?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- public/self/labelTaskPage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/self/labelTaskPage.js b/public/self/labelTaskPage.js index a7b252b4f..a68dfaadc 100644 --- a/public/self/labelTaskPage.js +++ b/public/self/labelTaskPage.js @@ -198,13 +198,13 @@ function sele_export_Change(sele){ function dataset_sele_Change(sele){ var dataset_listName = $('#dataset_list option:selected').text(); console.log("select dataset_list =" + dataset_listName); - $("#datasetlabeltaskname").attr({value:dataset_listName+"-人工标注"}); + $("#datasetlabeltaskname").val(dataset_listName+"-人工标注"); } function dataset_auto_sele_Change(sele){ var dataset_listName = $('#dataset_list_auto option:selected').text(); console.log("select dataset_list_auto =" + dataset_listName); - $("#autolabeltaskname").attr({value:dataset_listName+"-自动标注"}); + $("#autolabeltaskname").val(dataset_listName+"-自动标注"); } From 5b2c866e05ea27c435d1287987e5047deb1950bc Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 28 Oct 2021 10:38:36 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/private/tool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/private/tool.go b/routers/private/tool.go index a7a7bee9d..dcab8668e 100755 --- a/routers/private/tool.go +++ b/routers/private/tool.go @@ -41,4 +41,5 @@ func UpdateAllRepoCommitCnt(ctx *macaron.Context) { func RepoStatisticManually(ctx *macaron.Context) { date := ctx.Query("date") repo.RepoStatisticDaily(date) + repo.SummaryStatisticDaily(date) } From 08bf463e998c9620763e82a3dd200dbdc8992ae5 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 28 Oct 2021 11:33:59 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 31 +++++++++++++++++++++++++------ routers/private/tool.go | 1 + routers/repo/user_data_analysis.go | 28 ++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 406cc36f1..6f6abb1ff 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -114,7 +114,7 @@ func QueryUserStaticData(startTime int64, endTime int64) []*UserBusinessAnalysis return userBusinessAnalysisReturnList } -func CountData(wikiCountMap map[string]int) { +func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime time.Time) { log.Info("start to count other user info data") sess := x.NewSession() defer sess.Close() @@ -125,12 +125,12 @@ func CountData(wikiCountMap map[string]int) { currentTimeNow := time.Now() log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) - yesterday := currentTimeNow.AddDate(0, 0, -1) - startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) + //yesterday := currentTimeNow.AddDate(0, 0, -1) + //startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) start_unix := startTime.Unix() log.Info("DB query time:" + startTime.Format("2006-01-02 15:04:05")) - endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) + //endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) end_unix := endTime.Unix() CountDate := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 1, 0, 0, currentTimeNow.Location()) @@ -155,11 +155,17 @@ func CountData(wikiCountMap map[string]int) { CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) LoginCountMap := queryLoginCount(start_unix, end_unix) + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + for i, userRecord := range userList { var dateRecord UserBusinessAnalysis dateRecord.ID = userRecord.ID log.Info("i=" + fmt.Sprint(i) + " userName=" + userRecord.Name) dateRecord.CountDate = CountDate.Unix() + + statictisSess.Delete(&dateRecord) + dateRecord.Email = userRecord.Email dateRecord.RegistDate = userRecord.CreatedUnix dateRecord.Name = userRecord.Name @@ -244,13 +250,26 @@ func CountData(wikiCountMap map[string]int) { dateRecord.CommitModelCount = 0 - statictisSess := xStatistic.NewSession() - defer statictisSess.Close() statictisSess.Insert(&dateRecord) } } +func CountData(wikiCountMap map[string]int) { + + currentTimeNow := time.Now() + log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) + + yesterday := currentTimeNow.AddDate(0, 0, -1) + startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) + + log.Info("DB query time:" + startTime.Format("2006-01-02 15:04:05")) + + endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) + + CounDataByDate(wikiCountMap, startTime, endTime) +} + func querySolveIssue(start_unix int64, end_unix int64) map[int64]int { //select issue_assignees.* from issue_assignees,issue where issue.is_closed=true and issue.id=issue_assignees.issue_id sess := x.NewSession() diff --git a/routers/private/tool.go b/routers/private/tool.go index dcab8668e..b93f17090 100755 --- a/routers/private/tool.go +++ b/routers/private/tool.go @@ -42,4 +42,5 @@ func RepoStatisticManually(ctx *macaron.Context) { date := ctx.Query("date") repo.RepoStatisticDaily(date) repo.SummaryStatisticDaily(date) + repo.TimingCountDataByDate(date) } diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 3260780ac..7dc7af321 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -8,16 +8,17 @@ import ( "code.gitea.io/gitea/modules/log" ) -func TimingCountData() { +func TimingCountDataByDate(date string) { + + t, _ := time.Parse("2006-01-02", date) + startTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) + + endTime := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, t.Location()) + //query wiki data log.Info("start to time count data") wikiMap := make(map[string]int) - currentTimeNow := time.Now() - log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) - - yesterday := currentTimeNow.AddDate(0, 0, -1) - repoList, err := models.GetAllRepositories() if err != nil { log.Error("query repo error.") @@ -29,7 +30,7 @@ func TimingCountData() { time, err := git.GetLatestCommitTime(wikiPath) if err == nil { log.Info("last commit time:" + time.Format("2006-01-02 15:04:05") + " wikiPath=" + wikiPath) - if time.After(yesterday) { + if time.After(startTime) { wikiRepo, _, err := FindWikiRepoCommitByWikiPath(wikiPath) if err != nil { log.Error("wiki not exist. wikiPath=" + wikiPath) @@ -55,5 +56,16 @@ func TimingCountData() { } } //other user info data - models.CountData(wikiMap) + models.CounDataByDate(wikiMap, startTime, endTime) + +} + +func TimingCountData() { + + log.Info("start to time count data") + currentTimeNow := time.Now() + log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) + startTime := currentTimeNow.AddDate(0, 0, -1).Format("2006-01-02") + + TimingCountDataByDate(startTime) } From d47b14737babc8c3abd03c5447f7b87970d88f43 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 28 Oct 2021 15:13:43 +0800 Subject: [PATCH 15/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 6f6abb1ff..bb6726a2c 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -255,21 +255,6 @@ func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime ti } -func CountData(wikiCountMap map[string]int) { - - currentTimeNow := time.Now() - log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) - - yesterday := currentTimeNow.AddDate(0, 0, -1) - startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) - - log.Info("DB query time:" + startTime.Format("2006-01-02 15:04:05")) - - endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) - - CounDataByDate(wikiCountMap, startTime, endTime) -} - func querySolveIssue(start_unix int64, end_unix int64) map[int64]int { //select issue_assignees.* from issue_assignees,issue where issue.is_closed=true and issue.id=issue_assignees.issue_id sess := x.NewSession() From f6c89586fadcd89a8a437e909a55e029a525d89b Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 28 Oct 2021 15:55:45 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E8=80=85=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E4=B8=8E=E4=BB=A3=E7=A0=81=E4=B8=BB=E9=A1=B5=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E8=B4=A1=E7=8C=AE=E8=80=85=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/repo_activity_custom.go | 106 ++++++++++++++++++++++++++++++++++++++- modules/git/repo_stats_custom.go | 59 ++-------------------- 2 files changed, 108 insertions(+), 57 deletions(-) diff --git a/models/repo_activity_custom.go b/models/repo_activity_custom.go index f6cbf0331..9cb7e4a09 100644 --- a/models/repo_activity_custom.go +++ b/models/repo_activity_custom.go @@ -1,13 +1,115 @@ package models -import "code.gitea.io/gitea/modules/git" +import ( + "fmt" + "strings" + "time" + + "code.gitea.io/gitea/modules/git" +) func GetRepoKPIStats(repo *Repository) (*git.RepoKPIStats, error) { wikiPath := "" if repo.HasWiki() { wikiPath = repo.WikiPath() } - return git.GetRepoKPIStats(repo.RepoPath(), wikiPath) + return getRepoKPIStats(repo.RepoPath(), wikiPath) +} + +func getRepoKPIStats(repoPath string, wikiPath string) (*git.RepoKPIStats, error) { + stats := &git.RepoKPIStats{} + + contributors, err := git.GetContributors(repoPath) + if err != nil { + return nil, err + } + timeUntil := time.Now() + fourMonthAgo := timeUntil.AddDate(0, -4, 0) + recentlyContributors, err := git.GetContributorsDetail(repoPath, fourMonthAgo) + newContributersDict := make(map[string]struct{}) + if err != nil { + return nil, err + } + + if contributors != nil { + contributorDistinctDict := make(map[string]int, 0) + keyContributorsDict := make(map[string]struct{}, 0) + + for _, contributor := range contributors { + if strings.Compare(contributor.Email, "") == 0 { + continue + } + + user, err := GetUserByActivateEmail(contributor.Email) + if err == nil { + value, ok := contributorDistinctDict[user.Email] + if !ok { + contributorDistinctDict[user.Email] = contributor.CommitCnt + } else { + contributorDistinctDict[user.Email] = value + contributor.CommitCnt + } + setKeyContributerDict(contributorDistinctDict, user.Email, keyContributorsDict) + + } else { + value, ok := contributorDistinctDict[contributor.Email] + if !ok { + contributorDistinctDict[contributor.Email] = contributor.CommitCnt + } else { + contributorDistinctDict[contributor.Email] = value + contributor.CommitCnt + } + setKeyContributerDict(contributorDistinctDict, contributor.Email, keyContributorsDict) + } + + } + + if recentlyContributors != nil { + for _, recentlyContributor := range recentlyContributors { + + user, err := GetUserByActivateEmail(recentlyContributor.Email) + var ok bool + if err == nil { + _, ok = contributorDistinctDict[user.Email] + } else { + _, ok = contributorDistinctDict[recentlyContributor.Email] + } + + if !ok { + stats.ContributorsAdded++ + newContributersDict[recentlyContributor.Email] = struct{}{} + } + + } + } + + stats.Contributors = int64(len(contributorDistinctDict)) + stats.KeyContributors = int64(len(keyContributorsDict)) + + } + + err = git.SetDevelopAge(repoPath, stats) + if err != nil { + return nil, fmt.Errorf("FillFromGit: %v", err) + } + err = git.SetRepoKPIStats(repoPath, fourMonthAgo, stats, newContributersDict) + + if err != nil { + return nil, fmt.Errorf("FillFromGit: %v", err) + } + + git.SetWikiPages(wikiPath, stats) + return stats, nil + +} + +func setKeyContributerDict(contributorDistinctDict map[string]int, email string, keyContributorsDict map[string]struct{}) { + if contributorDistinctDict[email] >= 3 { + _, ok := keyContributorsDict[email] + if !ok { + keyContributorsDict[email] = struct{}{} + + } + + } } func GetAllUserKPIStats() (map[string]*git.UserKPIStats, error) { diff --git a/modules/git/repo_stats_custom.go b/modules/git/repo_stats_custom.go index f7556d5c2..5d99bd8af 100644 --- a/modules/git/repo_stats_custom.go +++ b/modules/git/repo_stats_custom.go @@ -35,58 +35,7 @@ type UserKPITypeStats struct { isNewContributor bool //是否是4个月内的新增贡献者 } -func GetRepoKPIStats(repoPath string, wikiPath string) (*RepoKPIStats, error) { - stats := &RepoKPIStats{} - - contributors, err := GetContributors(repoPath) - if err != nil { - return nil, err - } - timeUntil := time.Now() - fourMonthAgo := timeUntil.AddDate(0, -4, 0) - recentlyContributors, err := getContributors(repoPath, fourMonthAgo) - newContributersDict := make(map[string]struct{}) - if err != nil { - return nil, err - } - - if contributors != nil { - stats.Contributors = int64(len(contributors)) - for _, contributor := range contributors { - if contributor.CommitCnt >= 3 { - stats.KeyContributors++ - } - - if recentlyContributors != nil { - for _, recentlyContributor := range recentlyContributors { - if recentlyContributor.Email == contributor.Email && recentlyContributor.CommitCnt == contributor.CommitCnt { - stats.ContributorsAdded++ - newContributersDict[recentlyContributor.Email] = struct{}{} - } - - } - } - - } - - } - - err = setDevelopAge(repoPath, stats) - if err != nil { - return nil, fmt.Errorf("FillFromGit: %v", err) - } - err = setRepoKPIStats(repoPath, fourMonthAgo, stats, newContributersDict) - - if err != nil { - return nil, fmt.Errorf("FillFromGit: %v", err) - } - - setWikiPages(wikiPath, stats) - return stats, nil - -} - -func setDevelopAge(repoPath string, stats *RepoKPIStats) error { +func SetDevelopAge(repoPath string, stats *RepoKPIStats) error { args := []string{"log", "--no-merges", "--branches=*", "--format=%cd", "--date=short"} stdout, err := NewCommand(args...).RunInDirBytes(repoPath) if err != nil { @@ -173,7 +122,7 @@ func GetUserKPIStats(repoPath string) (map[string]*UserKPIStats, error) { } -func setRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, newContributers map[string]struct{}) error { +func SetRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, newContributers map[string]struct{}) error { since := fromTime.Format(time.RFC3339) args := []string{"log", "--numstat", "--no-merges", "--branches=*", "--pretty=format:---%n%h%n%an%n%ae%n", "--date=iso", fmt.Sprintf("--since='%s'", since)} @@ -259,7 +208,7 @@ func setRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, n } -func getContributors(repoPath string, fromTime time.Time) ([]Contributor, error) { +func GetContributorsDetail(repoPath string, fromTime time.Time) ([]Contributor, error) { since := fromTime.Format(time.RFC3339) cmd := NewCommand("shortlog", "-sne", "--all", fmt.Sprintf("--since='%s'", since)) stdout, err := cmd.RunInDir(repoPath) @@ -289,7 +238,7 @@ func getContributors(repoPath string, fromTime time.Time) ([]Contributor, error) return nil, nil } -func setWikiPages(wikiPath string, stats *RepoKPIStats) { +func SetWikiPages(wikiPath string, stats *RepoKPIStats) { wikiPages := 0 if wikiPath == "" { From 70eac24667300c7dd0e1b4aba03a89854f493c76 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 28 Oct 2021 16:18:50 +0800 Subject: [PATCH 17/18] show pic --- routers/repo/attachment.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 59f297a49..bb48c640b 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -278,7 +278,21 @@ func GetAttachment(ctx *context.Context) { ctx.ServerError("Update", err) return } - http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) + if dataSet != nil { + http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently) + } else { + fr, err := storage.Attachments.Open(attach.RelativePath()) + if err != nil { + ctx.ServerError("Open", err) + return + } + defer fr.Close() + if err = ServeData(ctx, attach.Name, fr); err != nil { + ctx.ServerError("ServeData", err) + return + } + } + } else { fr, err := storage.Attachments.Open(attach.RelativePath()) if err != nil { From 77e4b87bfe890d3612ab8c7168e43ac2ff1da2d3 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 28 Oct 2021 16:44:53 +0800 Subject: [PATCH 18/18] =?UTF-8?q?=E6=B5=8F=E8=A7=88=E9=87=8F=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E8=AE=A1=E7=AE=97=E4=BB=A5K=E4=B8=BA=E5=8D=95?= =?UTF-8?q?=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/normalization/normalization.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/normalization/normalization.go b/modules/normalization/normalization.go index f651cb5f1..c2b545f90 100644 --- a/modules/normalization/normalization.go +++ b/modules/normalization/normalization.go @@ -34,7 +34,7 @@ func GetImpactInitValue(watch int64, star int64, fork int64, download int64, com setting.RadarMap.ImpactFork*float64(fork) + setting.RadarMap.ImpactCodeDownload*float64(download)*0.001 + setting.RadarMap.ImpactComments*float64(comments) + - setting.RadarMap.ImpactBrowser*float64(browser) + setting.RadarMap.ImpactBrowser*float64(browser)*0.001 }