|
|
@@ -207,6 +207,71 @@ func ServeAllProjectsPeriodStatisticsFile(ctx *context.Context) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func ServeAllProjectsOpenIStatisticsFile(ctx *context.Context) { |
|
|
|
|
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 0 { |
|
|
|
page = 1 |
|
|
|
} |
|
|
|
pageSize := 1000 |
|
|
|
|
|
|
|
_, latestDate, err := models.GetRepoStatLastUpdatedTime() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query the last updated time.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.last_update_time_error")) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
date := ctx.QueryTrim("date") |
|
|
|
if date == "" { |
|
|
|
date = latestDate |
|
|
|
} |
|
|
|
|
|
|
|
countSql := generateOpenICountSql(date) |
|
|
|
total, err := models.CountRepoStatByRawSql(countSql) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query total count.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error")) |
|
|
|
return |
|
|
|
} |
|
|
|
var projectAnalysis = ctx.Tr("repo.repo_stat_inspect") |
|
|
|
fileName := "项目分析_OPENI_" + date + ".xlsx" |
|
|
|
|
|
|
|
totalPage := getTotalPage(total, pageSize) |
|
|
|
|
|
|
|
f := excelize.NewFile() |
|
|
|
|
|
|
|
index := f.NewSheet(projectAnalysis) |
|
|
|
f.DeleteSheet("Sheet1") |
|
|
|
|
|
|
|
for k, v := range allProjectsOpenIHeader() { |
|
|
|
f.SetCellValue(projectAnalysis, k, v) |
|
|
|
} |
|
|
|
|
|
|
|
var row = 2 |
|
|
|
for i := 0; i <= totalPage; i++ { |
|
|
|
|
|
|
|
pageRecords := models.GetRepoStatisticByRawSql(generateTypeAllOpenISql(date, i+1, pageSize)) |
|
|
|
for _, record := range pageRecords { |
|
|
|
|
|
|
|
for k, v := range allProjectsOpenIValues(row, record, ctx) { |
|
|
|
f.SetCellValue(projectAnalysis, k, v) |
|
|
|
} |
|
|
|
row++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
f.SetActiveSheet(index) |
|
|
|
|
|
|
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(fileName)) |
|
|
|
ctx.Resp.Header().Set("Content-Type", "application/octet-stream") |
|
|
|
|
|
|
|
f.WriteTo(ctx.Resp) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func getFileName(ctx *context.Context, beginTime time.Time, endTime time.Time, projectAnalysis string) string { |
|
|
|
baseName := projectAnalysis + "_" |
|
|
|
|
|
|
@@ -237,6 +302,32 @@ func allProjectsPeroidValues(row int, rs *models.RepoStatistic, ctx *context.Con |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func allProjectsOpenIHeader() map[string]string { |
|
|
|
|
|
|
|
return map[string]string{"A1": "ID", "B1": "项目名称", "C1": "拥有者", "D1": "是否私有", "E1": "OpenI指数", |
|
|
|
"F1": "影响力", "G1": "成熟度", "H1": "活跃度", "I1": "项目健康度", "J1": "团队健康度", "K1": "项目发展趋势", |
|
|
|
"L1": "关注数", "M1": "点赞数", "N1": "派生数", "O1": "代码下载量", "P1": "评论数", "Q1": "浏览量", "R1": "已解决任务数", "S1": "版本发布数量", "T1": "有效开发年龄", |
|
|
|
"U1": "数据集", "V1": "模型数", "W1": "百科页面数量", "X1": "提交数", "Y1": "任务数", "Z1": "PR数", "AA1": "版本发布数量", "AB1": "任务完成比例", "AC1": "贡献者数", "AD1": "关键贡献者数", |
|
|
|
"AE1": "新人增长量", "AF1": "代码规模增长量", "AG1": "任务增长量", "AH1": "新人增长量", "AI1": "提交增长量", "AJ1": "评论增长量", |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func allProjectsOpenIValues(row int, rs *models.RepoStatistic, ctx *context.Context) map[string]string { |
|
|
|
|
|
|
|
return map[string]string{getCellName("A", row): strconv.FormatInt(rs.RepoID, 10), getCellName("B", row): rs.Name, getCellName("C", row): rs.OwnerName, getCellName("D", row): getIsPrivateDisplay(rs.IsPrivate, ctx), getCellName("E", row): strconv.FormatFloat(rs.RadarTotal, 'f', 2, 64), |
|
|
|
getCellName("F", row): strconv.FormatFloat(rs.Impact, 'f', 2, 64), getCellName("G", row): strconv.FormatFloat(rs.Completeness, 'f', 2, 64), getCellName("H", row): strconv.FormatFloat(rs.Liveness, 'f', 2, 64), getCellName("I", row): strconv.FormatFloat(rs.ProjectHealth, 'f', 2, 64), getCellName("J", row): strconv.FormatFloat(rs.TeamHealth, 'f', 2, 64), getCellName("K", row): strconv.FormatFloat(rs.Growth, 'f', 2, 64), |
|
|
|
getCellName("L", row): strconv.FormatInt(rs.NumWatches, 10), getCellName("M", row): strconv.FormatInt(rs.NumStars, 10), getCellName("N", row): strconv.FormatInt(rs.NumForks, 10), getCellName("O", row): strconv.FormatInt(rs.NumDownloads, 10), |
|
|
|
|
|
|
|
getCellName("P", row): strconv.FormatInt(rs.NumComments, 10), getCellName("Q", row): strconv.FormatInt(rs.NumVisits, 10), getCellName("R", row): strconv.FormatInt(rs.NumClosedIssues, 10), getCellName("S", row): strconv.FormatInt(rs.NumVersions, 10), |
|
|
|
getCellName("T", row): strconv.FormatInt(rs.NumDevMonths, 10), getCellName("U", row): strconv.FormatInt(rs.DatasetSize, 10), getCellName("V", row): strconv.FormatInt(rs.NumModels, 10), getCellName("W", row): strconv.FormatInt(rs.NumWikiViews, 10), |
|
|
|
getCellName("X", row): strconv.FormatInt(rs.NumCommits, 10), getCellName("Y", row): strconv.FormatInt(rs.NumIssues, 10), getCellName("Z", row): strconv.FormatInt(rs.NumPulls, 10), getCellName("AA", row): strconv.FormatInt(rs.NumVersions, 10), |
|
|
|
getCellName("AB", row): strconv.FormatFloat(float64(rs.IssueFixedRate), 'f', 2, 64), getCellName("AC", row): strconv.FormatInt(rs.NumContributor, 10), getCellName("AD", row): strconv.FormatInt(rs.NumKeyContributor, 10), getCellName("AE", row): strconv.FormatInt(rs.NumContributorsGrowth, 10), |
|
|
|
getCellName("AF", row): strconv.FormatInt(rs.NumCommitLinesGrowth, 10), getCellName("AG", row): strconv.FormatInt(rs.NumIssuesGrowth, 10), getCellName("AH", row): strconv.FormatInt(rs.NumContributorsGrowth, 10), getCellName("AI", row): strconv.FormatInt(rs.NumCommitsGrowth, 10), getCellName("AJ", row): strconv.FormatInt(rs.NumCommentsGrowth, 10), |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func getCellName(col string, row int) string { |
|
|
|
return col + strconv.Itoa(row) |
|
|
|
} |
|
|
@@ -381,6 +472,13 @@ func generateCountSql(beginTime time.Time, endTime time.Time, latestDate string, |
|
|
|
return countSql |
|
|
|
} |
|
|
|
|
|
|
|
func generateOpenICountSql(latestDate string) string { |
|
|
|
countSql := "SELECT count(*) FROM " + |
|
|
|
"public.repo_statistic where date='" + latestDate + "'" |
|
|
|
|
|
|
|
return countSql |
|
|
|
} |
|
|
|
|
|
|
|
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,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 " + |
|
|
@@ -396,6 +494,14 @@ func generateTypeAllSql(beginTime time.Time, endTime time.Time, latestDate strin |
|
|
|
return sql |
|
|
|
} |
|
|
|
|
|
|
|
func generateTypeAllOpenISql(latestDate string, page int, pageSize int) string { |
|
|
|
sql := "SELECT id, repo_id, date, num_watches, num_stars, num_forks, num_downloads, num_comments, num_visits, num_closed_issues, num_versions, num_dev_months, repo_size, dataset_size, num_models, num_wiki_views, num_commits, num_issues, num_pulls, issue_fixed_rate, num_contributor, num_key_contributor, num_contributors_growth, num_commits_growth, num_commit_lines_growth, num_issues_growth, num_comments_growth, impact, completeness, liveness, project_health, team_health, growth, radar_total, name, is_private, owner_name FROM " + |
|
|
|
" public.repo_statistic where date='" + latestDate + "'" |
|
|
|
|
|
|
|
sql = sql + " order by radar_total desc,repo_id" + " limit " + strconv.Itoa(pageSize) + " offset " + strconv.Itoa((page-1)*pageSize) |
|
|
|
return sql |
|
|
|
} |
|
|
|
|
|
|
|
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,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 " + |
|
|
|