Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(template): Added a section with the number of entries in the database and a detailed list of dates. #28

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}