Time Estimation Cleanup (#1301)

* Moved the calculation for time to read to the backend. Tweaked some logic around showing est time to complete.

* Added debug logging to help pinpoint a duplicate issue in Kavita.

* More combination logic is error checked in a special way for Robbie to reproduce an issue.

* Migrated chapter detail card to use backend for time calculation. Ensure we take all chapters into account for volume time calcs

* Tweaked messaging for some critical logs to include file

* Ensure pages count uses comma separated number

* Moved Hangfire annotations to interface level. Adjusted word count service to always recalculate when user requests via analyze series files.
This commit is contained in:
Joseph Milazzo 2022-05-29 09:50:59 -05:00 committed by GitHub
parent 85b4ad0c58
commit 8e69b6cfc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 161 additions and 62 deletions

View file

@ -628,6 +628,66 @@ namespace API.Controllers
return await _readerService.GetPrevChapterIdAsync(seriesId, volumeId, currentChapterId, userId);
}
/// <summary>
/// Given word count, page count, and if the entity is an epub file, this will return the read time.
/// </summary>
/// <param name="wordCount"></param>
/// <param name="pageCount"></param>
/// <param name="isEpub"></param>
/// <returns>Will always assume no progress as it's not privy</returns>
[HttpGet("manual-read-time")]
public ActionResult<HourEstimateRangeDto> GetManualReadTime(int wordCount, int pageCount, bool isEpub)
{
if (isEpub)
{
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((wordCount / ReaderService.MinWordsPerHour)),
MaxHours = (int) Math.Round((wordCount / ReaderService.MaxWordsPerHour)),
AvgHours = (int) Math.Round((wordCount / ReaderService.AvgWordsPerHour)),
HasProgress = false
});
}
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((pageCount / ReaderService.MinPagesPerMinute / 60F)),
MaxHours = (int) Math.Round((pageCount / ReaderService.MaxPagesPerMinute / 60F)),
AvgHours = (int) Math.Round((pageCount / ReaderService.AvgPagesPerMinute / 60F)),
HasProgress = false
});
}
[HttpGet("read-time")]
public async Task<ActionResult<HourEstimateRangeDto>> GetReadTime(int seriesId)
{
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);
var progress = (await _unitOfWork.AppUserProgressRepository.GetUserProgressForSeriesAsync(seriesId, userId)).ToList();
if (series.Format == MangaFormat.Epub)
{
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((series.WordCount / ReaderService.MinWordsPerHour)),
MaxHours = (int) Math.Round((series.WordCount / ReaderService.MaxWordsPerHour)),
AvgHours = (int) Math.Round((series.WordCount / ReaderService.AvgWordsPerHour)),
HasProgress = progress.Any()
});
}
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((series.Pages / ReaderService.MinPagesPerMinute / 60F)),
MaxHours = (int) Math.Round((series.Pages / ReaderService.MaxPagesPerMinute / 60F)),
AvgHours = (int) Math.Round((series.Pages / ReaderService.AvgPagesPerMinute / 60F)),
HasProgress = progress.Any()
});
}
/// <summary>
/// For the current user, returns an estimate on how long it would take to finish reading the series.
/// </summary>