| @@ -12,6 +12,7 @@ type RepoStatistic struct { | |||||
| ID int64 `xorm:"pk autoincr" json:"-"` | ID int64 `xorm:"pk autoincr" json:"-"` | ||||
| RepoID int64 `xorm:"unique(s) NOT NULL" json:"repo_id"` | RepoID int64 `xorm:"unique(s) NOT NULL" json:"repo_id"` | ||||
| Name string `xorm:"INDEX" json:"name"` | Name string `xorm:"INDEX" json:"name"` | ||||
| OwnerName string `json:"ownerName"` | |||||
| IsPrivate bool `json:"isPrivate"` | IsPrivate bool `json:"isPrivate"` | ||||
| Date string `xorm:"unique(s) NOT NULL" json:"date"` | Date string `xorm:"unique(s) NOT NULL" json:"date"` | ||||
| NumWatches int64 `xorm:"NOT NULL DEFAULT 0" json:"watch"` | NumWatches int64 `xorm:"NOT NULL DEFAULT 0" json:"watch"` | ||||
| @@ -73,6 +73,8 @@ type UserBusinessAnalysis struct { | |||||
| //user | //user | ||||
| Name string `xorm:"NOT NULL"` | Name string `xorm:"NOT NULL"` | ||||
| DataDate string `xorm:"NULL"` | |||||
| } | } | ||||
| type UserBusinessAnalysisQueryOptions struct { | type UserBusinessAnalysisQueryOptions struct { | ||||
| @@ -263,7 +265,7 @@ func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime ti | |||||
| end_unix := endTime.Unix() | end_unix := endTime.Unix() | ||||
| CountDate := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 1, 0, 0, currentTimeNow.Location()) | CountDate := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 1, 0, 0, currentTimeNow.Location()) | ||||
| DataDate := startTime.Format("2006-01-02") | |||||
| CodeMergeCountMap := queryPullRequest(start_unix, end_unix) | CodeMergeCountMap := queryPullRequest(start_unix, end_unix) | ||||
| CommitCountMap := queryAction(start_unix, end_unix, 5) | CommitCountMap := queryAction(start_unix, end_unix, 5) | ||||
| IssueCountMap := queryAction(start_unix, end_unix, 10) | IssueCountMap := queryAction(start_unix, end_unix, 10) | ||||
| @@ -300,6 +302,7 @@ func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime ti | |||||
| dateRecord.RegistDate = userRecord.CreatedUnix | dateRecord.RegistDate = userRecord.CreatedUnix | ||||
| dateRecord.Name = userRecord.Name | dateRecord.Name = userRecord.Name | ||||
| dateRecord.GiteaAgeMonth = subMonth(currentTimeNow, userRecord.CreatedUnix.AsTime()) | dateRecord.GiteaAgeMonth = subMonth(currentTimeNow, userRecord.CreatedUnix.AsTime()) | ||||
| dateRecord.DataDate = DataDate | |||||
| if _, ok := CodeMergeCountMap[dateRecord.ID]; !ok { | if _, ok := CodeMergeCountMap[dateRecord.ID]; !ok { | ||||
| dateRecord.CodeMergeCount = 0 | dateRecord.CodeMergeCount = 0 | ||||
| } else { | } else { | ||||
| @@ -522,10 +525,10 @@ func queryFollow(start_unix int64, end_unix int64) map[int64]int { | |||||
| resultMap := make(map[int64]int) | resultMap := make(map[int64]int) | ||||
| log.Info("query Follow size=" + fmt.Sprint(len(followList))) | log.Info("query Follow size=" + fmt.Sprint(len(followList))) | ||||
| for _, followRecord := range followList { | for _, followRecord := range followList { | ||||
| if _, ok := resultMap[followRecord.UserID]; !ok { | |||||
| resultMap[followRecord.UserID] = 1 | |||||
| if _, ok := resultMap[followRecord.FollowID]; !ok { | |||||
| resultMap[followRecord.FollowID] = 1 | |||||
| } else { | } else { | ||||
| resultMap[followRecord.UserID] += 1 | |||||
| resultMap[followRecord.FollowID] += 1 | |||||
| } | } | ||||
| } | } | ||||
| return resultMap | return resultMap | ||||
| @@ -243,13 +243,20 @@ func allProjectsPeroidHeader(ctx *context.Context) []string { | |||||
| } | } | ||||
| func allProjectsPeroidValues(rs *models.RepoStatistic, ctx *context.Context) []string { | func allProjectsPeroidValues(rs *models.RepoStatistic, ctx *context.Context) []string { | ||||
| return []string{strconv.FormatInt(rs.RepoID, 10), rs.Name, getIsPrivateDisplay(rs.IsPrivate, ctx), strconv.FormatFloat(rs.RadarTotal, 'f', 2, 64), | |||||
| return []string{strconv.FormatInt(rs.RepoID, 10), constructDistinctName(rs), getIsPrivateDisplay(rs.IsPrivate, ctx), strconv.FormatFloat(rs.RadarTotal, 'f', 2, 64), | |||||
| strconv.FormatInt(rs.NumVisits, 10), strconv.FormatInt(rs.NumDownloads, 10), strconv.FormatInt(rs.NumPulls, 10), strconv.FormatInt(rs.NumCommits, 10), | strconv.FormatInt(rs.NumVisits, 10), strconv.FormatInt(rs.NumDownloads, 10), strconv.FormatInt(rs.NumPulls, 10), strconv.FormatInt(rs.NumCommits, 10), | ||||
| strconv.FormatInt(rs.NumWatches, 10), strconv.FormatInt(rs.NumStars, 10), strconv.FormatInt(rs.NumForks, 10), strconv.FormatInt(rs.NumIssues, 10), | strconv.FormatInt(rs.NumWatches, 10), strconv.FormatInt(rs.NumStars, 10), strconv.FormatInt(rs.NumForks, 10), strconv.FormatInt(rs.NumIssues, 10), | ||||
| strconv.FormatInt(rs.NumClosedIssues, 10), strconv.FormatInt(rs.NumContributor, 10), | strconv.FormatInt(rs.NumClosedIssues, 10), strconv.FormatInt(rs.NumContributor, 10), | ||||
| } | } | ||||
| } | } | ||||
| func constructDistinctName(rs *models.RepoStatistic) string { | |||||
| if rs.OwnerName == "" { | |||||
| return rs.Name | |||||
| } | |||||
| return rs.OwnerName + "/" + rs.Name | |||||
| } | |||||
| func getIsPrivateDisplay(private bool, ctx *context.Context) string { | func getIsPrivateDisplay(private bool, ctx *context.Context) string { | ||||
| if private { | if private { | ||||
| return ctx.Tr("admin.repos.yes") | return ctx.Tr("admin.repos.yes") | ||||
| @@ -390,11 +397,11 @@ func generateCountSql(beginTime time.Time, endTime time.Time, latestDate string, | |||||
| } | } | ||||
| func generateTypeAllSql(beginTime time.Time, endTime time.Time, latestDate string, q string, orderBy string, page int, pageSize int) string { | func generateTypeAllSql(beginTime time.Time, endTime time.Time, latestDate string, q string, orderBy string, page int, pageSize int) string { | ||||
| sql := "SELECT A.repo_id,name,is_private,radar_total,num_watches,num_visits,num_downloads,num_pulls,num_commits,num_stars,num_forks,num_issues,num_closed_issues,num_contributor FROM " + | |||||
| sql := "SELECT A.repo_id,name,owner_name,is_private,radar_total,num_watches,num_visits,num_downloads,num_pulls,num_commits,num_stars,num_forks,num_issues,num_closed_issues,num_contributor FROM " + | |||||
| "(SELECT repo_id,sum(num_visits) as num_visits " + | "(SELECT repo_id,sum(num_visits) as num_visits " + | ||||
| " FROM repo_statistic where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | " FROM repo_statistic where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | ||||
| " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + " group by repo_id) A," + | " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + " group by repo_id) A," + | ||||
| "(SELECT repo_id,name,is_private,radar_total,num_watches,num_downloads,num_pulls,num_commits,num_stars,num_forks,num_issues,num_closed_issues,num_contributor from public.repo_statistic where date='" + latestDate + "') B" + | |||||
| "(SELECT repo_id,name,owner_name,is_private,radar_total,num_watches,num_downloads,num_pulls,num_commits,num_stars,num_forks,num_issues,num_closed_issues,num_contributor from public.repo_statistic where date='" + latestDate + "') B" + | |||||
| " where A.repo_id=B.repo_id" | " where A.repo_id=B.repo_id" | ||||
| if q != "" { | if q != "" { | ||||
| @@ -406,11 +413,11 @@ func generateTypeAllSql(beginTime time.Time, endTime time.Time, latestDate strin | |||||
| func generatePageSql(beginTime time.Time, endTime time.Time, latestDate string, q string, orderBy string, page int, pageSize int) string { | func generatePageSql(beginTime time.Time, endTime time.Time, latestDate string, q string, orderBy string, page int, pageSize int) string { | ||||
| sql := "SELECT A.repo_id,name,is_private,radar_total,num_watches,num_visits,num_downloads,num_pulls,num_commits,num_stars,num_forks,num_issues,num_closed_issues,num_contributor FROM " + | |||||
| sql := "SELECT A.repo_id,name,owner_name,is_private,radar_total,num_watches,num_visits,num_downloads,num_pulls,num_commits,num_stars,num_forks,num_issues,num_closed_issues,num_contributor FROM " + | |||||
| "(SELECT repo_id,sum(num_watches_added) as num_watches,sum(num_visits) as num_visits, sum(num_downloads_added) as num_downloads,sum(num_pulls_added) as num_pulls,sum(num_commits_added) as num_commits,sum(num_stars_added) as num_stars,sum(num_forks_added) num_forks,sum(num_issues_added) as num_issues,sum(num_closed_issues_added) as num_closed_issues,sum(num_contributor_added) as num_contributor " + | "(SELECT repo_id,sum(num_watches_added) as num_watches,sum(num_visits) as num_visits, sum(num_downloads_added) as num_downloads,sum(num_pulls_added) as num_pulls,sum(num_commits_added) as num_commits,sum(num_stars_added) as num_stars,sum(num_forks_added) num_forks,sum(num_issues_added) as num_issues,sum(num_closed_issues_added) as num_closed_issues,sum(num_contributor_added) as num_contributor " + | ||||
| " FROM repo_statistic where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | " FROM repo_statistic where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + | ||||
| " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + " group by repo_id) A," + | " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + " group by repo_id) A," + | ||||
| "(SELECT repo_id,name,is_private,radar_total from public.repo_statistic where date='" + latestDate + "') B" + | |||||
| "(SELECT repo_id,name,owner_name,is_private,radar_total from public.repo_statistic where date='" + latestDate + "') B" + | |||||
| " where A.repo_id=B.repo_id" | " where A.repo_id=B.repo_id" | ||||
| if q != "" { | if q != "" { | ||||
| sql = sql + " and B.name like '%" + q + "%'" | sql = sql + " and B.name like '%" + q + "%'" | ||||
| @@ -470,7 +477,7 @@ func getTimePeroid(ctx *context.Context, recordBeginTime time.Time) (time.Time, | |||||
| beginTime = time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, now.Location()) | beginTime = time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, now.Location()) | ||||
| } else if queryType == "current_week" { | } else if queryType == "current_week" { | ||||
| beginTime = now.AddDate(0, 0, -int(time.Now().Weekday())+1) | |||||
| beginTime = now.AddDate(0, 0, -int(time.Now().Weekday())+2) //begin from monday | |||||
| beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location()) | beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location()) | ||||
| endTime = now | endTime = now | ||||
| } else if queryType == "current_month" { | } else if queryType == "current_month" { | ||||
| @@ -61,6 +61,8 @@ func RepoStatisticDaily(date string) { | |||||
| var issueFixedRate float32 | var issueFixedRate float32 | ||||
| if repo.NumIssues != 0 { | if repo.NumIssues != 0 { | ||||
| issueFixedRate = float32(repo.NumClosedIssues) / float32(repo.NumIssues) | issueFixedRate = float32(repo.NumClosedIssues) / float32(repo.NumIssues) | ||||
| } else { | |||||
| issueFixedRate = 1.0 | |||||
| } | } | ||||
| var numVersions int64 | var numVersions int64 | ||||
| @@ -89,13 +91,15 @@ func RepoStatisticDaily(date string) { | |||||
| } | } | ||||
| repoStat := models.RepoStatistic{ | repoStat := models.RepoStatistic{ | ||||
| RepoID: repo.ID, | |||||
| Date: date, | |||||
| Name: repo.Name, | |||||
| IsPrivate: repo.IsPrivate, | |||||
| NumWatches: int64(repo.NumWatches), | |||||
| NumStars: int64(repo.NumStars), | |||||
| NumForks: int64(repo.NumForks), | |||||
| RepoID: repo.ID, | |||||
| Date: date, | |||||
| Name: repo.Name, | |||||
| IsPrivate: repo.IsPrivate, | |||||
| OwnerName: repo.OwnerName, | |||||
| NumWatches: int64(repo.NumWatches), | |||||
| NumStars: int64(repo.NumStars), | |||||
| NumForks: int64(repo.NumForks), | |||||
| NumDownloads: repo.CloneCnt, | NumDownloads: repo.CloneCnt, | ||||
| NumComments: numComments, | NumComments: numComments, | ||||
| NumVisits: int64(numVisits), | NumVisits: int64(numVisits), | ||||
| @@ -18,6 +18,7 @@ func QueryUserStaticData(ctx *context.Context) { | |||||
| log.Info("startDate=" + startDate + " endDate=" + endDate) | log.Info("startDate=" + startDate + " endDate=" + endDate) | ||||
| startTime, _ := time.Parse("2006-01-02", startDate) | startTime, _ := time.Parse("2006-01-02", startDate) | ||||
| endTime, _ := time.Parse("2006-01-02", endDate) | endTime, _ := time.Parse("2006-01-02", endDate) | ||||
| endTime = endTime.AddDate(0, 0, 1) | |||||
| log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) | log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) | ||||
| ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix())) | ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix())) | ||||
| } | } | ||||
| @@ -38,6 +39,7 @@ func QueryUserStaticDataPage(ctx *context.Context) { | |||||
| log.Info("startDate=" + startDate + " endDate=" + endDate + " userName=" + userName + " page=" + fmt.Sprint(page)) | log.Info("startDate=" + startDate + " endDate=" + endDate + " userName=" + userName + " page=" + fmt.Sprint(page)) | ||||
| startTime, _ := time.Parse("2006-01-02", startDate) | startTime, _ := time.Parse("2006-01-02", startDate) | ||||
| endTime, _ := time.Parse("2006-01-02", endDate) | endTime, _ := time.Parse("2006-01-02", endDate) | ||||
| endTime = endTime.AddDate(0, 0, 1) | |||||
| log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) | log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) | ||||
| pageOpts := &models.UserBusinessAnalysisQueryOptions{ | pageOpts := &models.UserBusinessAnalysisQueryOptions{ | ||||
| @@ -792,8 +792,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| }, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef()) | }, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef()) | ||||
| m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action) | m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action) | ||||
| m.Get("/tool/query_user_static", repo.QueryUserStaticData) | |||||
| m.Get("/tool/query_user_static_page", repo.QueryUserStaticDataPage) | |||||
| m.Get("/tool/query_user_static", adminReq, repo.QueryUserStaticData) | |||||
| m.Get("/tool/query_user_static_page", adminReq, repo.QueryUserStaticDataPage) | |||||
| // Grouping for those endpoints not requiring authentication | // Grouping for those endpoints not requiring authentication | ||||
| m.Group("/:username/:reponame", func() { | m.Group("/:username/:reponame", func() { | ||||
| m.Get("/contributors", repo.Contributors) | m.Get("/contributors", repo.Contributors) | ||||