Skip to content

Commit

Permalink
feat(template): Added weeks count to the first graph title (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhbert authored Nov 20, 2024
1 parent 7b821fe commit 95cd65d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
20 changes: 10 additions & 10 deletions cmd/collect/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func getFullHabrViewsCount(limit int, sortType string) []structs.StatsArticle {
var rows []table.Row
var rowStructs []structs.StatsArticle

for i, a := range articles {
for i := 0; i < len(articles); i++ {
var zeroTime time.Time
stats, state := db_service.GetLatestStatsFromArticle(a.ID, zeroTime)
stats, state := db_service.GetLatestStatsFromArticle(articles[i].ID, zeroTime)
var stat structs.StatsArticle
if state {
stat.Id = i
stat.Name = a.Name
stat.Date = a.DateOfPublication
stat.Name = articles[i].Name
stat.Date = articles[i].DateOfPublication
if len(stats) > 1 {
stat.Views = stats[1].Views
stat.Growth = stats[1].Views - stats[0].Views
Expand All @@ -71,13 +71,13 @@ func getFullHabrViewsCount(limit int, sortType string) []structs.StatsArticle {
})
}

for _, st := range rowStructs {
for i := 0; i < len(rowStructs); i++ {
var r table.Row
r = append(r, st.Id)
r = append(r, st.Name)
r = append(r, st.Date.Format("02-Jan-2006"))
r = append(r, st.Views)
r = append(r, getColorForDiff(st.Growth))
r = append(r, rowStructs[i].Id)
r = append(r, rowStructs[i].Name)
r = append(r, rowStructs[i].Date.Format("02-Jan-2006"))
r = append(r, rowStructs[i].Views)
r = append(r, getColorForDiff(rowStructs[i].Growth))

if limit > 0 && len(rows) <= limit {
rows = append(rows, r)
Expand Down
1 change: 1 addition & 0 deletions internal/common/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type TemplateData struct {
Authors []AuthorsTop
AllDates []string
StatsForDiagram []StatsForDiagram
WeeksCount float64
}

type AuthorsTop struct {
Expand Down
6 changes: 4 additions & 2 deletions internal/db_service/habr_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func GetAllDatesOfStats() ([]string, []time.Time) {
return dates, timeDates
}

func GetAllStatsAndDatesForDiagram() []structs.StatsForDiagram {
func GetAllStatsAndDatesForDiagram() ([]structs.StatsForDiagram, float64) {
var statsForDiagram []structs.StatsForDiagram

_, dates := GetAllDatesOfStats()
Expand Down Expand Up @@ -512,5 +512,7 @@ func GetAllStatsAndDatesForDiagram() []structs.StatsForDiagram {
statsForDiagram = append(statsForDiagram, st)
}

return statsForDiagram
weeks := dates[0].Sub(dates[len(dates)-1]).Hours() / 168

return statsForDiagram, weeks
}
2 changes: 1 addition & 1 deletion internal/latex_service/latex.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func getHabrData() structs.TemplateData {
data.AuthorsTopGlobal = data.AuthorsTopGlobal[0:5]
data.Authors = db_service.GetTopOfAuthors(true)
data.AllDates, _ = db_service.GetAllDatesOfStats()
data.StatsForDiagram = db_service.GetAllStatsAndDatesForDiagram()
data.StatsForDiagram, data.WeeksCount = db_service.GetAllStatsAndDatesForDiagram()

csv_service.PrepareCSV("tmp", "articlesCount.csv", data.StatsForDiagram)

Expand Down
2 changes: 1 addition & 1 deletion templates/tex/stats.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
\caption{Все авторы блога}
\end{longtable}
\subsection{Графики изменений}
\subsubsection{График просмотров за последние N недель}
\subsubsection{График просмотров за последние {{ .WeeksCount }} недель}
\begin{tikzpicture}
\begin{axis}[
xlabel={Дата статистики},
Expand Down

0 comments on commit 95cd65d

Please sign in to comment.