Skip to content

Commit

Permalink
feat(template): Added a section with the number of entries in the dat…
Browse files Browse the repository at this point in the history
…abase and a detailed list of dates.
  • Loading branch information
Zhbert authored Oct 25, 2024
1 parent 3a0205e commit ca6fdc3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 23 deletions.
1 change: 1 addition & 0 deletions internal/common/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type TemplateData struct {
AuthorsCount int
AuthorsTopGlobal []AuthorsTop
Authors []AuthorsTop
AllDates []string
}

type AuthorsTop struct {
Expand Down
23 changes: 23 additions & 0 deletions internal/db_service/habr_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,26 @@ func GetCountOfStats() int64 {
}
return count
}

func GetAllDatesOfStats() []string {
var dates []string

var stats []domain.HabrStats

db, err := gorm.Open(sqlite.Open("colligendis.db"),
&gorm.Config{Logger: logger.Default.LogMode(getLogger())})
if err != nil {
log.Fatal("Error opening db!")
} else {
db.
Group("date_of_stats").
Order("date_of_stats DESC").
Find(&stats)

for _, stat := range stats {
dates = append(dates, stat.DateOfStats.Format("January 2, 2006"))
}
}

return dates
}
1 change: 1 addition & 0 deletions internal/latex_service/latex.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func getHabrData() structs.TemplateData {
data.AuthorsTopGlobal = db_service.GetTopOfAuthors(false)
data.AuthorsTopGlobal = data.AuthorsTopGlobal[0:5]
data.Authors = db_service.GetTopOfAuthors(true)
data.AllDates = db_service.GetAllDatesOfStats()

return data
}
Expand Down
55 changes: 32 additions & 23 deletions templates/tex/stats.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,36 @@
\caption{Топ-5 авторов за все время}
\end{threeparttable}
\end{table}
\subsection{Статистика глобальная}
\subsubsection{Все статьи в блоге}
Отсортировано по количеству просмотров за неделю.
\begin{longtable}{|p{0.60\textwidth}|*{3}{p{0.10\textwidth}|}}
\hline
\textbf{Название статьи} & \textbf{Дата публикации} & \textbf{Общее кол-во просмотров} & \textbf{Кол-во просмотров за неделю} \\ \hline
\hline \endfirsthead
{{ range .AllArticlesGlobal }}
{{ .Name }} & {{ .Date.Format "2006-01-02" }} & {{ .Views }} & {{ .Growth }} \\ \hline
{{ end }}
\caption{Все статьи в блоге}
\end{longtable}
\subsubsection{Все авторы блога}
Отсортированы по имени.
\begin{longtable}{|p{0.65\textwidth}|p{0.25\textwidth}|}
\hline
\textbf{Имя автора} & \textbf{Количество статей} \\ \hline
\hline \endfirsthead
{{ range .Authors }}
{{ .Name }} & {{ .ArticlesCount }} \\ \hline
{{ end }}
\caption{Все авторы блога}
\end{longtable}
\subsection{Статистика глобальная}
\subsubsection{Все статьи в блоге}
Отсортировано по количеству просмотров за неделю.
\begin{longtable}{|p{0.60\textwidth}|*{3}{p{0.10\textwidth}|}}
\hline
\textbf{Название статьи} & \textbf{Дата публикации} & \textbf{Общее кол-во просмотров} & \textbf{Кол-во просмотров за неделю} \\ \hline
\hline \endfirsthead
{{ range .AllArticlesGlobal }}
{{ .Name }} & {{ .Date.Format "2006-01-02" }} & {{ .Views }} & {{ .Growth }} \\ \hline
{{ end }}
\caption{Все статьи в блоге}
\end{longtable}
\subsubsection{Все авторы блога}
Отсортированы по имени.
\begin{longtable}{|p{0.65\textwidth}|p{0.25\textwidth}|}
\hline
\textbf{Имя автора} & \textbf{Количество статей} \\ \hline
\hline \endfirsthead
{{ range .Authors }}
{{ .Name }} & {{ .ArticlesCount }} \\ \hline
{{ end }}
\caption{Все авторы блога}
\end{longtable}
\section{Системная информация}
\subsection{Хабр}
Всего записей статистики в базе данных: {{ .StatsInBaseCount }}:
\begin{itemize}
\setlength{\itemsep}{-2mm}
{{ range .AllDates }}
\item {{ . }}
{{ end }}
\end{itemize}
\end{document}

0 comments on commit ca6fdc3

Please sign in to comment.