This commit is contained in:
ducklet 2021-08-04 17:30:17 +02:00
parent ff4f8fa246
commit fb059ae5d1
6 changed files with 24 additions and 22 deletions

View file

@ -25,9 +25,7 @@
</span> </span>
</p> </p>
<div class="control"> <div class="control">
<a class="button is-info" <a class="button is-info" :disabled="!active"> Search </a>
:disabled="!active"
> Search </a>
</div> </div>
</div> </div>

View file

@ -29,8 +29,18 @@
<span class="mediatype">{{ item.media_type }}</span> <span class="mediatype">{{ item.media_type }}</span>
</td> </td>
<td> <td>
<span class="score imdb-score tag is-large" :title="`IMDb rating (1-10) / ${item.imdb_votes} votes`">{{ imdb_rating(item.imdb_score) }}</span> <span
<span class="score tag is-info is-large" :title="`User rating (1-10) / ${item.user_scores.length} votes / σ = ${imdb_stdev(item.user_scores)}`">{{ avg_imdb_rating(item.user_scores) }}</span> class="score imdb-score tag is-large"
:title="`IMDb rating (1-10) / ${item.imdb_votes} votes`"
>{{ imdb_rating(item.imdb_score) }}</span
>
<span
class="score tag is-info is-large"
:title="`User rating (1-10) / ${
item.user_scores.length
} votes / σ = ${imdb_stdev(item.user_scores)}`"
>{{ avg_imdb_rating(item.user_scores) }}</span
>
</td> </td>
<td> <td>
<span>{{ duration(item.runtime) }}</span> <span>{{ duration(item.runtime) }}</span>
@ -46,7 +56,6 @@
import { defineComponent } from "vue" import { defineComponent } from "vue"
import { mean, pstdev } from "../utils.ts" import { mean, pstdev } from "../utils.ts"
function avg_imdb_rating(scores) { function avg_imdb_rating(scores) {
return imdb_rating(scores.length === 0 ? null : mean(scores)) return imdb_rating(scores.length === 0 ? null : mean(scores))
} }
@ -125,6 +134,5 @@ export default defineComponent({
background-color: rgb(245, 197, 24); background-color: rgb(245, 197, 24);
} }
.user-score { .user-score {
} }
</style> </style>

View file

@ -25,11 +25,7 @@
</span> </span>
</p> </p>
<p class="control"> <p class="control">
<button <button class="button is-primary is-small" :disabled="!active" @click="login">
class="button is-primary is-small"
:disabled="!active"
@click="login"
>
Login Login
</button> </button>
</p> </p>

View file

@ -10,7 +10,7 @@ export function mean(nums) {
return sum(nums) / nums.length return sum(nums) / nums.length
} }
export function pstdev(nums, mu=null) { export function pstdev(nums, mu = null) {
if (mu === null) { if (mu === null) {
mu = mean(nums) mu = mean(nums)
} }

View file

@ -566,11 +566,11 @@ async def find_movies(
query = f""" query = f"""
SELECT {','.join(sql_fields(Movie))} SELECT {','.join(sql_fields(Movie))}
FROM {Movie._table} FROM {Movie._table}
WHERE {(' AND '.join(conditions)) if conditions else '1=1'} WHERE {(' AND '.join(conditions)) if conditions else '1=1'}
ORDER BY ORDER BY
length({Movie._table}.title) ASC, length({Movie._table}.title) ASC,
{Movie._table}.imdb_score DESC, {Movie._table}.imdb_score DESC,
{Movie._table}.release_year DESC {Movie._table}.release_year DESC
LIMIT :skip_rows, :limit_rows LIMIT :skip_rows, :limit_rows
""" """
rows = await shared_connection().fetch_all(bindparams(query, values)) rows = await shared_connection().fetch_all(bindparams(query, values))

View file

@ -319,9 +319,6 @@ async def add_movie(request):
not_implemented() not_implemented()
import_lock = asyncio.Lock()
@route("/movies/_reload_imdb", methods=["GET"]) @route("/movies/_reload_imdb", methods=["GET"])
@requires(["authenticated", "admin"]) @requires(["authenticated", "admin"])
async def progress_for_load_imdb_movies(request): async def progress_for_load_imdb_movies(request):
@ -352,11 +349,14 @@ async def progress_for_load_imdb_movies(request):
return JSONResponse(resp) return JSONResponse(resp)
_import_lock = asyncio.Lock()
@route("/movies/_reload_imdb", methods=["POST"]) @route("/movies/_reload_imdb", methods=["POST"])
@requires(["authenticated", "admin"]) @requires(["authenticated", "admin"])
async def load_imdb_movies(request): async def load_imdb_movies(request):
async with import_lock: async with _import_lock:
progress = await db.get_import_progress() progress = await db.get_import_progress()
if progress and not progress.stopped: if progress and not progress.stopped:
return JSONResponse( return JSONResponse(