| @@ -62,7 +62,7 @@ type UserBusinessAnalysis struct { | |||
| Name string `xorm:"NOT NULL"` | |||
| } | |||
| func CountData(wikiCountMap map[int64]int) { | |||
| func CountData(wikiCountMap map[string]int) { | |||
| log.Info("start to count data") | |||
| sess := x.NewSession() | |||
| defer sess.Close() | |||
| @@ -93,6 +93,7 @@ func CountData(wikiCountMap map[int64]int) { | |||
| StarRepoCountMap := queryStar(start_unix, end_unix) | |||
| WatchedCountMap := queryFollow(start_unix, end_unix) | |||
| CommitDatasetSizeMap := queryDatasetSize(start_unix, end_unix) | |||
| SolveIssueCountMap := querySolveIssue(start_unix, end_unix) | |||
| for i, userRecord := range userList { | |||
| var dateRecord UserBusinessAnalysis | |||
| @@ -151,6 +152,18 @@ func CountData(wikiCountMap map[int64]int) { | |||
| dateRecord.CommitDatasetSize = CommitDatasetSizeMap[dateRecord.ID] | |||
| } | |||
| if _, ok := SolveIssueCountMap[dateRecord.ID]; !ok { | |||
| dateRecord.SolveIssueCount = 0 | |||
| } else { | |||
| dateRecord.SolveIssueCount = SolveIssueCountMap[dateRecord.ID] | |||
| } | |||
| if _, ok := wikiCountMap[dateRecord.Name]; !ok { | |||
| dateRecord.EncyclopediasCount = 0 | |||
| } else { | |||
| dateRecord.EncyclopediasCount = wikiCountMap[dateRecord.Name] | |||
| } | |||
| dateRecord.CommitModelCount = 0 | |||
| sess.Insert(&dateRecord) | |||
| @@ -52,6 +52,25 @@ func (repo *Repository) GetAllCommitsCount() (int64, error) { | |||
| return AllCommitsCount(repo.Path) | |||
| } | |||
| func (repo *Repository) ParsePrettyFormatLogToList(logs []byte) (*list.List, error) { | |||
| l := list.New() | |||
| if len(logs) == 0 { | |||
| return l, nil | |||
| } | |||
| parts := bytes.Split(logs, []byte{'\n'}) | |||
| for _, commitID := range parts { | |||
| commit, err := repo.GetCommit(string(commitID)) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| l.PushBack(commit) | |||
| } | |||
| return l, nil | |||
| } | |||
| func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { | |||
| l := list.New() | |||
| if len(logs) == 0 { | |||
| @@ -441,7 +460,7 @@ type Contributor struct { | |||
| Email string | |||
| } | |||
| func GetContributors(repoPath string) ([]Contributor, error){ | |||
| func GetContributors(repoPath string) ([]Contributor, error) { | |||
| cmd := NewCommand("shortlog", "-sne", "--all") | |||
| stdout, err := cmd.RunInDir(repoPath) | |||
| if err != nil { | |||
| @@ -458,9 +477,9 @@ func GetContributors(repoPath string) ([]Contributor, error){ | |||
| } | |||
| number := oneCount[0:strings.Index(oneCount, "\t")] | |||
| commitCnt, _ := strconv.Atoi(number) | |||
| committer := oneCount[strings.Index(oneCount, "\t")+1:strings.LastIndex(oneCount, " ")] | |||
| committer := oneCount[strings.Index(oneCount, "\t")+1 : strings.LastIndex(oneCount, " ")] | |||
| committer = strings.Trim(committer, " ") | |||
| email := oneCount[strings.Index(oneCount, "<")+1:strings.Index(oneCount, ">")] | |||
| email := oneCount[strings.Index(oneCount, "<")+1 : strings.Index(oneCount, ">")] | |||
| contributorsInfo[i] = Contributor{ | |||
| commitCnt, committer, email, | |||
| } | |||
| @@ -206,6 +206,15 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) { | |||
| return commits.Front().Value.(*Commit), nil | |||
| } | |||
| func (repo *Repository) GetCommitByPathAndDays(relpath string, days int) (*list.List, error) { | |||
| stdout, err := NewCommand("log", "-1", prettyLogFormat, "--", relpath, "--since="+fmt.Sprint(days)+".days").RunInDirBytes(repo.Path) | |||
| if err != nil { | |||
| return nil, err | |||
| } | |||
| return repo.parsePrettyFormatLogToList(stdout) | |||
| } | |||
| // CommitsRangeSize the default commits range size | |||
| var CommitsRangeSize = 50 | |||
| @@ -1,71 +1,48 @@ | |||
| package repo | |||
| import ( | |||
| "encoding/json" | |||
| "time" | |||
| "code.gitea.io/gitea/models" | |||
| "code.gitea.io/gitea/modules/git" | |||
| "code.gitea.io/gitea/modules/log" | |||
| wiki_service "code.gitea.io/gitea/services/wiki" | |||
| ) | |||
| func TimeingCountData() { | |||
| //query wiki data | |||
| log.Info("start to time count data") | |||
| wikiMap := make(map[int64]int) | |||
| wikiMap := make(map[string]int) | |||
| repoList := models.QueryAllRepo() | |||
| currentTimeNow := time.Now() | |||
| log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) | |||
| yesterday := currentTimeNow.AddDate(0, 0, -1) | |||
| repoList := models.QueryAllRepo() | |||
| log.Info("start to query wiki data") | |||
| for _, repoRecord := range repoList { | |||
| wikiPath := models.WikiPath(repoRecord.OwnerName, repoRecord.Name) | |||
| wikiRepo, commit, err := FindWikiRepoCommitByWikiPath(wikiPath) | |||
| if err != nil { | |||
| log.Error("wiki not exist. wikiPath=" + wikiPath) | |||
| } else { | |||
| log.Info("wiki exist, wikiPath=" + wikiPath) | |||
| lastCommit, _ := wikiRepo.GetBranchCommit("master") | |||
| lastCommitObj, err := json.Marshal(lastCommit) | |||
| if err != nil { | |||
| log.Error("convert to json error.") | |||
| } else { | |||
| log.Info("json=" + string(lastCommitObj)) | |||
| } | |||
| entries, err := commit.ListEntries() | |||
| if err != nil { | |||
| if wikiRepo != nil { | |||
| wikiRepo.Close() | |||
| } | |||
| } else { | |||
| pages := make([]PageMeta, 0, len(entries)) | |||
| for _, entry := range entries { | |||
| if !entry.IsRegular() { | |||
| continue | |||
| } | |||
| wikiName, err := wiki_service.FilenameToName(entry.Name()) | |||
| if err != nil { | |||
| if wikiRepo != nil { | |||
| wikiRepo.Close() | |||
| 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) { | |||
| wikiRepo, _, err := FindWikiRepoCommitByWikiPath(wikiPath) | |||
| if err != nil { | |||
| log.Error("wiki not exist. wikiPath=" + wikiPath) | |||
| } else { | |||
| log.Info("wiki exist, wikiPath=" + wikiPath) | |||
| list, _ := wikiRepo.GetCommitByPathAndDays(wikiPath, 1) | |||
| for logEntry := list.Front(); logEntry != nil; logEntry = logEntry.Next() { | |||
| commit := logEntry.Value.(*git.Commit) | |||
| log.Info("commit msg=" + commit.CommitMessage + " time=" + commit.Committer.When.Format("2006-01-02 15:04:05")) | |||
| if _, ok := wikiMap[commit.Committer.Name]; !ok { | |||
| wikiMap[commit.Committer.Name] = 0 | |||
| } else { | |||
| wikiMap[commit.Committer.Name] += 1 | |||
| } | |||
| continue | |||
| } else if wikiName == "_Sidebar" || wikiName == "_Footer" { | |||
| continue | |||
| } | |||
| jsonObj, err := json.Marshal(entry) | |||
| if err != nil { | |||
| log.Error("convert to json error.") | |||
| } else { | |||
| log.Info("json=" + string(jsonObj)) | |||
| } | |||
| log.Info("wikiName=" + wikiName + " SubURL=" + wiki_service.NameToSubURL(wikiName)) | |||
| pages = append(pages, PageMeta{ | |||
| Name: wikiName, | |||
| SubURL: wiki_service.NameToSubURL(wikiName), | |||
| }) | |||
| } | |||
| } | |||
| } | |||
| } | |||