You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_dashbord.go 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. package repo
  2. import (
  3. "encoding/csv"
  4. "fmt"
  5. "io/ioutil"
  6. "net/http"
  7. "net/url"
  8. "os"
  9. "path"
  10. "strconv"
  11. "time"
  12. "code.gitea.io/gitea/models"
  13. "code.gitea.io/gitea/modules/log"
  14. "code.gitea.io/gitea/modules/context"
  15. "code.gitea.io/gitea/modules/setting"
  16. )
  17. const DEFAULT_PAGE_SIZE = 10
  18. const DATE_FORMAT = "2006-01-02"
  19. type ProjectsPeriodData struct {
  20. RecordBeginTime string `json:"recordBeginTime"`
  21. LastUpdatedTime string `json:"lastUpdatedTime"`
  22. PageSize int `json:"pageSize"`
  23. TotalPage int `json:"totalPage"`
  24. TotalCount int64 `json:"totalCount"`
  25. PageRecords []*models.RepoStatistic `json:"pageRecords"`
  26. }
  27. type UserInfo struct {
  28. User string `json:"user"`
  29. Mode int `json:"mode"`
  30. PR int64 `json:"pr"`
  31. Commit int `json:"commit"`
  32. }
  33. type ProjectLatestData struct {
  34. RecordBeginTime string `json:"recordBeginTime"`
  35. LastUpdatedTime string `json:"lastUpdatedTime"`
  36. CreatTime string `json:"creatTime"`
  37. OpenI float64 `json:"openi"`
  38. Comment int64 `json:"comment"`
  39. View int64 `json:"view"`
  40. Download int64 `json:"download"`
  41. IssueClosedRatio float32 `json:"issueClosedRatio"`
  42. Impact float64 `json:"impact"`
  43. Completeness float64 `json:"completeness"`
  44. Liveness float64 `json:"liveness"`
  45. ProjectHealth float64 `json:"projectHealth"`
  46. TeamHealth float64 `json:"teamHealth"`
  47. Growth float64 `json:"growth"`
  48. Description string `json:"description"`
  49. Top10 []UserInfo `json:"top10"`
  50. }
  51. func RestoreForkNumber(ctx *context.Context) {
  52. repos, err := models.GetAllRepositories()
  53. if err != nil {
  54. log.Error("GetAllRepositories failed: %v", err.Error())
  55. return
  56. }
  57. for _, repo := range repos {
  58. models.RestoreRepoStatFork(int64(repo.NumForks), repo.ID)
  59. }
  60. ctx.JSON(http.StatusOK, struct{}{})
  61. }
  62. func GetAllProjectsPeriodStatistics(ctx *context.Context) {
  63. recordBeginTime, err := getRecordBeginTime()
  64. if err != nil {
  65. log.Error("Can not get record begin time", err)
  66. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
  67. return
  68. }
  69. beginTime, endTime, err := getTimePeroid(ctx, recordBeginTime)
  70. if err != nil {
  71. log.Error("Parameter is wrong", err)
  72. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.parameter_is_wrong"))
  73. return
  74. }
  75. q := ctx.QueryTrim("q")
  76. page := ctx.QueryInt("page")
  77. if page <= 0 {
  78. page = 1
  79. }
  80. pageSize := ctx.QueryInt("pagesize")
  81. if pageSize <= 0 {
  82. pageSize = DEFAULT_PAGE_SIZE
  83. }
  84. orderBy := getOrderBy(ctx)
  85. latestUpdatedTime, latestDate, err := models.GetRepoStatLastUpdatedTime()
  86. if err != nil {
  87. log.Error("Can not query the last updated time.", err)
  88. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.last_update_time_error"))
  89. return
  90. }
  91. countSql := generateCountSql(beginTime, endTime, latestDate, q)
  92. total, err := models.CountRepoStatByRawSql(countSql)
  93. if err != nil {
  94. log.Error("Can not query total count.", err)
  95. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error"))
  96. return
  97. }
  98. sql := generateSqlByType(ctx, beginTime, endTime, latestDate, q, orderBy, page, pageSize)
  99. projectsPeriodData := ProjectsPeriodData{
  100. RecordBeginTime: recordBeginTime.Format(DATE_FORMAT),
  101. PageSize: pageSize,
  102. TotalPage: getTotalPage(total, pageSize),
  103. TotalCount: total,
  104. LastUpdatedTime: latestUpdatedTime,
  105. PageRecords: models.GetRepoStatisticByRawSql(sql),
  106. }
  107. ctx.JSON(http.StatusOK, projectsPeriodData)
  108. }
  109. func generateSqlByType(ctx *context.Context, beginTime time.Time, endTime time.Time, latestDate string, q string, orderBy string, page int, pageSize int) string {
  110. sql := ""
  111. if ctx.QueryTrim("type") == "all" {
  112. sql = generateTypeAllSql(beginTime, endTime, latestDate, q, orderBy, page, pageSize)
  113. } else {
  114. sql = generatePageSql(beginTime, endTime, latestDate, q, orderBy, page, pageSize)
  115. }
  116. return sql
  117. }
  118. func ServeAllProjectsPeriodStatisticsFile(ctx *context.Context) {
  119. recordBeginTime, err := getRecordBeginTime()
  120. if err != nil {
  121. log.Error("Can not get record begin time", err)
  122. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
  123. return
  124. }
  125. beginTime, endTime, err := getTimePeroid(ctx, recordBeginTime)
  126. if err != nil {
  127. log.Error("Parameter is wrong", err)
  128. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.parameter_is_wrong"))
  129. return
  130. }
  131. q := ctx.QueryTrim("q")
  132. page := ctx.QueryInt("page")
  133. if page <= 0 {
  134. page = 1
  135. }
  136. pageSize := 1000
  137. orderBy := getOrderBy(ctx)
  138. _, latestDate, err := models.GetRepoStatLastUpdatedTime()
  139. if err != nil {
  140. log.Error("Can not query the last updated time.", err)
  141. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.last_update_time_error"))
  142. return
  143. }
  144. countSql := generateCountSql(beginTime, endTime, latestDate, q)
  145. total, err := models.CountRepoStatByRawSql(countSql)
  146. if err != nil {
  147. log.Error("Can not query total count.", err)
  148. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error"))
  149. return
  150. }
  151. fileName, frontName := getFileName(ctx, beginTime, endTime)
  152. if err := os.MkdirAll(setting.RadarMap.Path, os.ModePerm); err != nil {
  153. ctx.Error(http.StatusBadRequest, fmt.Errorf("Failed to create dir %s: %v", setting.AvatarUploadPath, err).Error())
  154. }
  155. totalPage := getTotalPage(total, pageSize)
  156. f, e := os.Create(fileName)
  157. defer f.Close()
  158. if e != nil {
  159. log.Warn("Failed to create file", e)
  160. }
  161. writer := csv.NewWriter(f)
  162. writer.Write(allProjectsPeroidHeader(ctx))
  163. for i := 0; i <= totalPage; i++ {
  164. pageRecords := models.GetRepoStatisticByRawSql(generateSqlByType(ctx, beginTime, endTime, latestDate, q, orderBy, i+1, pageSize))
  165. for _, record := range pageRecords {
  166. e = writer.Write(allProjectsPeroidValues(record, ctx))
  167. if e != nil {
  168. log.Warn("Failed to write record", e)
  169. }
  170. }
  171. writer.Flush()
  172. }
  173. ctx.ServeFile(fileName, url.QueryEscape(frontName))
  174. }
  175. func getFileName(ctx *context.Context, beginTime time.Time, endTime time.Time) (string, string) {
  176. baseName := setting.RadarMap.Path + "/项目分析_"
  177. if ctx.QueryTrim("q") != "" {
  178. baseName = baseName + ctx.QueryTrim("q") + "_"
  179. }
  180. if ctx.QueryTrim("type") == "all" {
  181. baseName = baseName + "所有"
  182. } else {
  183. baseName = baseName + beginTime.AddDate(0, 0, -1).Format(DATE_FORMAT) + "_" + endTime.AddDate(0, 0, -1).Format(DATE_FORMAT)
  184. }
  185. frontName := baseName + ".csv"
  186. localName := baseName + "_" + strconv.FormatInt(time.Now().Unix(), 10) + ".csv"
  187. return localName, path.Base(frontName)
  188. }
  189. func ClearUnusedStatisticsFile() {
  190. fileInfos, err := ioutil.ReadDir(setting.RadarMap.Path)
  191. if err != nil {
  192. log.Warn("can not read dir: "+setting.RadarMap.Path, err)
  193. return
  194. }
  195. for _, fileInfo := range fileInfos {
  196. if !fileInfo.IsDir() && fileInfo.ModTime().Before(time.Now().AddDate(0, 0, -1)) {
  197. os.Remove(path.Join(setting.RadarMap.Path, fileInfo.Name()))
  198. }
  199. }
  200. }
  201. func allProjectsPeroidHeader(ctx *context.Context) []string {
  202. return []string{ctx.Tr("admin.repos.id"), ctx.Tr("admin.repos.projectName"), ctx.Tr("admin.repos.isPrivate"), ctx.Tr("admin.repos.openi"), ctx.Tr("admin.repos.visit"), ctx.Tr("admin.repos.download"), ctx.Tr("admin.repos.pr"), ctx.Tr("admin.repos.commit"),
  203. ctx.Tr("admin.repos.watches"), ctx.Tr("admin.repos.stars"), ctx.Tr("admin.repos.forks"), ctx.Tr("admin.repos.issues"), ctx.Tr("admin.repos.closedIssues"), ctx.Tr("admin.repos.contributor")}
  204. }
  205. func allProjectsPeroidValues(rs *models.RepoStatistic, ctx *context.Context) []string {
  206. return []string{strconv.FormatInt(rs.RepoID, 10), rs.Name, getIsPrivateDisplay(rs.IsPrivate, ctx), strconv.FormatFloat(rs.RadarTotal, 'f', 2, 64),
  207. strconv.FormatInt(rs.NumVisits, 10), strconv.FormatInt(rs.NumDownloads, 10), strconv.FormatInt(rs.NumPulls, 10), strconv.FormatInt(rs.NumCommits, 10),
  208. strconv.FormatInt(rs.NumWatches, 10), strconv.FormatInt(rs.NumStars, 10), strconv.FormatInt(rs.NumForks, 10), strconv.FormatInt(rs.NumIssues, 10),
  209. strconv.FormatInt(rs.NumClosedIssues, 10), strconv.FormatInt(rs.NumContributor, 10),
  210. }
  211. }
  212. func getIsPrivateDisplay(private bool, ctx *context.Context) string {
  213. if private {
  214. return ctx.Tr("admin.repos.yes")
  215. } else {
  216. return ctx.Tr("admin.repos.no")
  217. }
  218. }
  219. func GetProjectLatestStatistics(ctx *context.Context) {
  220. repoId := ctx.Params(":id")
  221. recordBeginTime, err := getRecordBeginTime()
  222. if err != nil {
  223. log.Error("Can not get record begin time", err)
  224. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
  225. return
  226. }
  227. latestUpdatedTime, latestDate, err := models.GetRepoStatLastUpdatedTime(repoId)
  228. repoIdInt, _ := strconv.ParseInt(repoId, 10, 64)
  229. repoStat, err := models.GetRepoStatisticByDateAndRepoId(latestDate, repoIdInt)
  230. if err != nil {
  231. log.Error("Can not get the repo statistics "+repoId, err)
  232. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.get_repo_stat_error"))
  233. return
  234. }
  235. repository, err := models.GetRepositoryByID(repoIdInt)
  236. if err != nil {
  237. log.Error("Can not get the repo info "+repoId, err)
  238. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.get_repo_info_error"))
  239. return
  240. }
  241. projectLatestData := ProjectLatestData{
  242. RecordBeginTime: recordBeginTime.Format(DATE_FORMAT),
  243. CreatTime: time.Unix(int64(repository.CreatedUnix), 0).Format(DATE_FORMAT),
  244. LastUpdatedTime: latestUpdatedTime,
  245. OpenI: repoStat.RadarTotal,
  246. Comment: repoStat.NumComments,
  247. View: repoStat.NumVisits,
  248. Download: repoStat.NumDownloads,
  249. IssueClosedRatio: repoStat.IssueFixedRate,
  250. Impact: repoStat.Impact,
  251. Completeness: repoStat.Completeness,
  252. Liveness: repoStat.Liveness,
  253. ProjectHealth: repoStat.ProjectHealth,
  254. TeamHealth: repoStat.TeamHealth,
  255. Growth: repoStat.Growth,
  256. Description: repository.Description,
  257. }
  258. contributors, err := models.GetTop10Contributor(repository.RepoPath())
  259. if err != nil {
  260. log.Error("can not get contributors", err)
  261. }
  262. users := make([]UserInfo, 0)
  263. for _, contributor := range contributors {
  264. mode := repository.GetCollaboratorMode(contributor.UserId)
  265. if mode == -1 {
  266. if contributor.IsAdmin {
  267. mode = int(models.AccessModeAdmin)
  268. }
  269. if contributor.UserId == repository.OwnerID {
  270. mode = int(models.AccessModeOwner)
  271. }
  272. }
  273. pr := models.GetPullCountByUserAndRepoId(repoIdInt, contributor.UserId)
  274. userInfo := UserInfo{
  275. User: contributor.Committer,
  276. Commit: contributor.CommitCnt,
  277. Mode: mode,
  278. PR: pr,
  279. }
  280. users = append(users, userInfo)
  281. }
  282. projectLatestData.Top10 = users
  283. ctx.JSON(http.StatusOK, projectLatestData)
  284. }
  285. func GetProjectPeriodStatistics(ctx *context.Context) {
  286. repoId := ctx.Params(":id")
  287. recordBeginTime, err := getRecordBeginTime()
  288. if err != nil {
  289. log.Error("Can not get record begin time", err)
  290. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
  291. return
  292. }
  293. repoIdInt, _ := strconv.ParseInt(repoId, 10, 64)
  294. if err != nil {
  295. log.Error("Can not get record begin time", err)
  296. ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
  297. return
  298. }
  299. beginTime, endTime, err := getTimePeroid(ctx, recordBeginTime)
  300. isOpenI := ctx.QueryBool("openi")
  301. var repositorys []*models.RepoStatistic
  302. if isOpenI {
  303. repositorys = models.GetRepoStatisticByRawSql(generateRadarSql(beginTime, endTime, repoIdInt))
  304. } else {
  305. repositorys = models.GetRepoStatisticByRawSql(generateTargetSql(beginTime, endTime, repoIdInt))
  306. }
  307. ctx.JSON(http.StatusOK, repositorys)
  308. }
  309. func generateRadarSql(beginTime time.Time, endTime time.Time, repoId int64) string {
  310. sql := "SELECT date, impact, completeness, liveness, project_health, team_health, growth, radar_total FROM repo_statistic" +
  311. " where repo_id=" + strconv.FormatInt(repoId, 10) + " and created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
  312. " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10)
  313. return sql
  314. }
  315. func generateTargetSql(beginTime time.Time, endTime time.Time, repoId int64) string {
  316. sql := "SELECT date, num_visits,num_downloads,num_commits FROM repo_statistic" +
  317. " where repo_id=" + strconv.FormatInt(repoId, 10) + " and created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
  318. " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10)
  319. return sql
  320. }
  321. func generateCountSql(beginTime time.Time, endTime time.Time, latestDate string, q string) string {
  322. countSql := "SELECT count(*) FROM " +
  323. "(SELECT repo_id FROM repo_statistic where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
  324. " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + " group by repo_id) A," +
  325. "(SELECT repo_id,name,is_private,radar_total from public.repo_statistic where date='" + latestDate + "') B" +
  326. " where A.repo_id=B.repo_id"
  327. if q != "" {
  328. countSql = countSql + " and B.name like '%" + q + "%'"
  329. }
  330. return countSql
  331. }
  332. func generateTypeAllSql(beginTime time.Time, endTime time.Time, latestDate string, q string, orderBy string, page int, pageSize int) string {
  333. 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 " +
  334. "(SELECT repo_id,sum(num_visits) as num_visits " +
  335. " FROM repo_statistic where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
  336. " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + " group by repo_id) A," +
  337. "(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" +
  338. " where A.repo_id=B.repo_id"
  339. if q != "" {
  340. sql = sql + " and name like '%" + q + "%'"
  341. }
  342. sql = sql + " order by " + orderBy + " desc,repo_id" + " limit " + strconv.Itoa(pageSize) + " offset " + strconv.Itoa((page-1)*pageSize)
  343. return sql
  344. }
  345. func generatePageSql(beginTime time.Time, endTime time.Time, latestDate string, q string, orderBy string, page int, pageSize int) string {
  346. 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 " +
  347. "(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 " +
  348. " FROM repo_statistic where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
  349. " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + " group by repo_id) A," +
  350. "(SELECT repo_id,name,is_private,radar_total from public.repo_statistic where date='" + latestDate + "') B" +
  351. " where A.repo_id=B.repo_id"
  352. if q != "" {
  353. sql = sql + " and B.name like '%" + q + "%'"
  354. }
  355. sql = sql + " order by " + orderBy + " desc,A.repo_id" + " limit " + strconv.Itoa(pageSize) + " offset " + strconv.Itoa((page-1)*pageSize)
  356. return sql
  357. }
  358. func getOrderBy(ctx *context.Context) string {
  359. orderBy := ""
  360. switch ctx.Query("sort") {
  361. case "openi":
  362. orderBy = "B.radar_total"
  363. case "view":
  364. orderBy = "A.num_visits"
  365. case "download":
  366. orderBy = "A.num_downloads"
  367. case "pr":
  368. orderBy = "A.num_pulls"
  369. case "commit":
  370. orderBy = "A.num_commits"
  371. case "watch":
  372. orderBy = "A.num_watches"
  373. case "star":
  374. orderBy = "A.num_stars"
  375. case "fork":
  376. orderBy = "A.num_forks"
  377. case "issue":
  378. orderBy = "A.num_issues"
  379. case "issue_closed":
  380. orderBy = "A.num_closed_issues"
  381. case "contributor":
  382. orderBy = "A.num_contributor"
  383. default:
  384. orderBy = "B.radar_total"
  385. }
  386. return orderBy
  387. }
  388. func getTimePeroid(ctx *context.Context, recordBeginTime time.Time) (time.Time, time.Time, error) {
  389. queryType := ctx.QueryTrim("type")
  390. now := time.Now()
  391. recordBeginTimeTemp := recordBeginTime.AddDate(0, 0, 1)
  392. beginTimeStr := ctx.QueryTrim("beginTime")
  393. endTimeStr := ctx.QueryTrim("endTime")
  394. var beginTime time.Time
  395. var endTime time.Time
  396. var err error
  397. if queryType != "" {
  398. if queryType == "all" {
  399. beginTime = recordBeginTimeTemp
  400. endTime = now
  401. } else if queryType == "yesterday" {
  402. endTime = now
  403. beginTime = time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, now.Location())
  404. } else if queryType == "current_week" {
  405. beginTime = now.AddDate(0, 0, -int(time.Now().Weekday())+1)
  406. beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
  407. endTime = now
  408. } else if queryType == "current_month" {
  409. endTime = now
  410. beginTime = time.Date(endTime.Year(), endTime.Month(), 2, 0, 0, 0, 0, now.Location())
  411. } else if queryType == "monthly" {
  412. endTime = now
  413. beginTime = now.AddDate(0, -1, 1)
  414. beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
  415. } else if queryType == "current_year" {
  416. endTime = now
  417. beginTime = time.Date(endTime.Year(), 1, 2, 0, 0, 0, 0, now.Location())
  418. } else if queryType == "last_month" {
  419. lastMonthTime := now.AddDate(0, -1, 0)
  420. beginTime = time.Date(lastMonthTime.Year(), lastMonthTime.Month(), 2, 0, 0, 0, 0, now.Location())
  421. endTime = time.Date(now.Year(), now.Month(), 2, 0, 0, 0, 0, now.Location())
  422. } else {
  423. return now, now, fmt.Errorf("The value of type parameter is wrong.")
  424. }
  425. } else {
  426. if beginTimeStr == "" || endTimeStr == "" {
  427. //如果查询类型和开始时间结束时间都未设置,按queryType=all处理
  428. beginTime = recordBeginTimeTemp
  429. endTime = now
  430. } else {
  431. beginTime, err = time.Parse("2006-01-02", beginTimeStr)
  432. if err != nil {
  433. return now, now, err
  434. }
  435. endTime, err = time.Parse("2006-01-02", endTimeStr)
  436. if err != nil {
  437. return now, now, err
  438. }
  439. beginTime = beginTime.AddDate(0, 0, 1)
  440. endTime = endTime.AddDate(0, 0, 1)
  441. }
  442. }
  443. if beginTime.Before(recordBeginTimeTemp) {
  444. beginTime = recordBeginTimeTemp
  445. }
  446. return beginTime, endTime, nil
  447. }
  448. func getRecordBeginTime() (time.Time, error) {
  449. return time.Parse(DATE_FORMAT, setting.RadarMap.RecordBeginTime)
  450. }
  451. func getTotalPage(total int64, pageSize int) int {
  452. another := 0
  453. if int(total)%pageSize != 0 {
  454. another = 1
  455. }
  456. return int(total)/pageSize + another
  457. }