Add torrents stats
This commit is contained in:
parent
eb02ff2b46
commit
24d3e0eaee
@ -9,9 +9,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
moviesCountQuery = `SELECT COUNT(*) FROM movies;`
|
moviesCountQuery = `SELECT COUNT(*) FROM movies;`
|
||||||
showsCountQuery = `SELECT COUNT(*) FROM shows;`
|
moviesTorrentsCountByIDQuery = `SELECT COUNT(*) FROM (SELECT DISTINCT(imdb_id) FROM movie_torrents) as TMP;`
|
||||||
episodesCountQuery = `SELECT COUNT(*) FROM episodes;`
|
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
|
// 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")
|
log.Debug("getting stats")
|
||||||
|
|
||||||
stats := struct {
|
stats := struct {
|
||||||
MoviesCount int `json:"movies_count"`
|
MoviesCount int `json:"movies_count"`
|
||||||
ShowsCount int `json:"shows_count"`
|
MoviesTorrentsCount int `json:"movies_torrents_count"`
|
||||||
EpisodesCount int `json:"episodes_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 {
|
for _, s := range []struct {
|
||||||
@ -43,8 +51,12 @@ func GetStatsHandler(env *web.Env, w http.ResponseWriter, r *http.Request) error
|
|||||||
ptr *int
|
ptr *int
|
||||||
}{
|
}{
|
||||||
{moviesCountQuery, &stats.MoviesCount},
|
{moviesCountQuery, &stats.MoviesCount},
|
||||||
|
{moviesTorrentsCountQuery, &stats.MoviesTorrentsCount},
|
||||||
|
{moviesTorrentsCountByIDQuery, &stats.MoviesTorrentsCountByID},
|
||||||
{showsCountQuery, &stats.ShowsCount},
|
{showsCountQuery, &stats.ShowsCount},
|
||||||
{episodesCountQuery, &stats.EpisodesCount},
|
{episodesCountQuery, &stats.EpisodesCount},
|
||||||
|
{episodesTorrentsCountQuery, &stats.EpisodesTorrentsCount},
|
||||||
|
{episodesTorrentsCountByIDQuery, &stats.EpisodesTorrentsCountByID},
|
||||||
} {
|
} {
|
||||||
var err error
|
var err error
|
||||||
*s.ptr, err = GetCount(env.Database, s.query)
|
*s.ptr, err = GetCount(env.Database, s.query)
|
||||||
|
@ -4,9 +4,19 @@ export default function Stats(props) {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2 className="hidden-xs">Stats</h2>
|
<h2 className="hidden-xs">Stats</h2>
|
||||||
<Stat name="Movies" value={props.stats.get("movies_count")} />
|
<Stat
|
||||||
<Stat name="Shows" value={props.stats.get("shows_count")} />
|
name="Movies"
|
||||||
<Stat name="Episodes" value={props.stats.get("episodes_count")} />
|
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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -16,12 +26,29 @@ function Stat(props) {
|
|||||||
<div className="col-xs-4">
|
<div className="col-xs-4">
|
||||||
<div className="panel panel-default">
|
<div className="panel panel-default">
|
||||||
<div className="panel-heading">
|
<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>
|
||||||
<div className="panel-body">
|
<div className="panel-body">
|
||||||
{props.value}
|
<TorrentsStat data={props} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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