Add torrents stats
This commit is contained in:
parent
eb02ff2b46
commit
24d3e0eaee
@ -9,9 +9,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
moviesCountQuery = `SELECT COUNT(*) FROM movies;`
|
||||
showsCountQuery = `SELECT COUNT(*) FROM shows;`
|
||||
episodesCountQuery = `SELECT COUNT(*) FROM episodes;`
|
||||
moviesCountQuery = `SELECT COUNT(*) FROM movies;`
|
||||
moviesTorrentsCountByIDQuery = `SELECT COUNT(*) FROM (SELECT DISTINCT(imdb_id) FROM movie_torrents) as TMP;`
|
||||
moviesTorrentsCountQuery = `SELECT COUNT(*) FROM movie_torrents;`
|
||||
showsCountQuery = `SELECT COUNT(*) FROM shows;`
|
||||
episodesCountQuery = `SELECT COUNT(*) FROM episodes;`
|
||||
episodesTorrentsCountByIDQuery = `SELECT COUNT(*) FROM (SELECT DISTINCT(imdb_id) FROM episode_torrents) as TMP;`
|
||||
episodesTorrentsCountQuery = `SELECT COUNT(*) FROM episode_torrents;`
|
||||
)
|
||||
|
||||
// GetCount gets the count from a query
|
||||
@ -33,9 +37,13 @@ func GetStatsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error
|
||||
log.Debug("getting stats")
|
||||
|
||||
stats := struct {
|
||||
MoviesCount int `json:"movies_count"`
|
||||
ShowsCount int `json:"shows_count"`
|
||||
EpisodesCount int `json:"episodes_count"`
|
||||
MoviesCount int `json:"movies_count"`
|
||||
MoviesTorrentsCount int `json:"movies_torrents_count"`
|
||||
MoviesTorrentsCountByID int `json:"movies_torrents_count_by_id"`
|
||||
ShowsCount int `json:"shows_count"`
|
||||
EpisodesCount int `json:"episodes_count"`
|
||||
EpisodesTorrentsCount int `json:"episodes_torrents_count"`
|
||||
EpisodesTorrentsCountByID int `json:"episodes_torrents_count_by_id"`
|
||||
}{}
|
||||
|
||||
for _, s := range []struct {
|
||||
@ -43,8 +51,12 @@ func GetStatsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error
|
||||
ptr *int
|
||||
}{
|
||||
{moviesCountQuery, &stats.MoviesCount},
|
||||
{moviesTorrentsCountQuery, &stats.MoviesTorrentsCount},
|
||||
{moviesTorrentsCountByIDQuery, &stats.MoviesTorrentsCountByID},
|
||||
{showsCountQuery, &stats.ShowsCount},
|
||||
{episodesCountQuery, &stats.EpisodesCount},
|
||||
{episodesTorrentsCountQuery, &stats.EpisodesTorrentsCount},
|
||||
{episodesTorrentsCountByIDQuery, &stats.EpisodesTorrentsCountByID},
|
||||
} {
|
||||
var err error
|
||||
*s.ptr, err = GetCount(env.Database, s.query)
|
||||
|
@ -4,9 +4,19 @@ export default function Stats(props) {
|
||||
return (
|
||||
<div>
|
||||
<h2 className="hidden-xs">Stats</h2>
|
||||
<Stat name="Movies" value={props.stats.get("movies_count")} />
|
||||
<Stat name="Shows" value={props.stats.get("shows_count")} />
|
||||
<Stat name="Episodes" value={props.stats.get("episodes_count")} />
|
||||
<Stat
|
||||
name="Movies"
|
||||
count={props.stats.get("movies_count")}
|
||||
torrentCount={props.stats.get("movies_torrents_count")}
|
||||
torrentCountById={props.stats.get("movies_torrents_count_by_id")}
|
||||
/>
|
||||
<Stat name="Shows" count={props.stats.get("shows_count")} />
|
||||
<Stat
|
||||
name="Episodes"
|
||||
count={props.stats.get("episodes_count")}
|
||||
torrentCount={props.stats.get("episodes_torrents_count")}
|
||||
torrentCountById={props.stats.get("episodes_torrents_count_by_id")}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -16,12 +26,29 @@ function Stat(props) {
|
||||
<div className="col-xs-4">
|
||||
<div className="panel panel-default">
|
||||
<div className="panel-heading">
|
||||
<h3 className="panel-title">{props.name}</h3>
|
||||
<h3 className="panel-title">
|
||||
{props.name}
|
||||
<span className="label label-info pull-right">{props.count}</span>
|
||||
</h3>
|
||||
</div>
|
||||
<div className="panel-body">
|
||||
{props.value}
|
||||
<TorrentsStat data={props} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TorrentsStat(props) {
|
||||
if (props.data.torrentCount === undefined) {
|
||||
return (<span>No torrents</span>);
|
||||
}
|
||||
|
||||
const percentage = Math.floor((props.data.torrentCount * 100) / props.data.count);
|
||||
return (
|
||||
<span>
|
||||
{percentage}% with torrents
|
||||
<small> - {props.data.torrentCount} total</small>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user