Fixing days to next free slot

templates/queries-index-mysql.tpl.html,
templates/queries-index-sqlite.tpl.html: Enhanced the query that finds
    the next free slot (query_next_available_episode). Also made it
    compute the days to the slot from the current day. The query returns
    data for calling Date::Calc to compute the number of days, but this
    calculation is no longer necessary. Next release will remove this.

templates/content-index.tpl.html: The number of days to the next free
    slot is reported here. The original Date::Calc computation which did
    this is no longer needed and has been removed since the query
    (query_next_available_episode) does it.
This commit is contained in:
Dave Morriss 2023-10-10 17:55:44 +01:00
parent faac8c202e
commit 366729a827
3 changed files with 102 additions and 74 deletions

View File

@ -26,17 +26,15 @@
<hr> <hr>
<article> <article>
<header> <header>
<h3>Welcome to HPR the Community Podcast</h3> <h3>Welcome to HPR, the Community Podcast</h3>
</header> </header>
<!--% days_till_next_episode = 0 %--> <!--% days_till_next_episode = 0 %-->
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH next_available_episode_result IN DBI.query(query_next_available_episode) <!--% FOREACH next_available_episode_result IN DBI.query(query_next_available_episode) %-->
%--> <!--% days_till_next_episode = next_available_episode_result.delta_days %-->
<!--% END %-->
<!--% USE date %--> <!--% USE date %-->
<!--% calc = date.calc %--> <!--% calc = date.calc %-->
<!--% days_till_next_episode = calc.Delta_Days(date.format(date.now, '%Y'),date.format(date.now, '%m'),date.format(date.now, '%d'),next_available_episode_result.last_year,next_available_episode_result.last_month,next_available_episode_result.last_day) %-->
<!--% END %-->
<!--% USE date %-->
<!--% delta = date.calc.N_Delta_YMD(2005,9,19, date.format(date.now, '%Y'),date.format(date.now, '%m'),date.format(date.now, '%d')) %--> <!--% delta = date.calc.N_Delta_YMD(2005,9,19, date.format(date.now, '%Y'),date.format(date.now, '%m'),date.format(date.now, '%d')) %-->
<p>We started producing shows as <a href="<!--% absolute_path(baseurl) %-->eps/index.html#twat_episodes"><em>Today with a Techie</em></a> on 2005-09-19, <!--% delta.0 %--> years, <!--% delta.1 %--> months, <!--% delta.2 %--> days ago. our shows are produced by <a href="<!--% absolute_path(baseurl) %-->correspondents/index.html">listeners</a> like you and can be on any <a href="<!--% absolute_path(baseurl) %-->eps/index.html">topic</a> that <strong>"are of interest to <a href="https://en.wikipedia.org/wiki/hacker_(hobbyist)">hackers</a>"</strong>. If you listen to HPR then please consider contributing one show a year. if you <a href="<!--% absolute_url(baseurl) %-->about.html#so_you_want_to_record_a_podcast">record</a> your show now it could be <a href="<!--% hub_baseurl %-->calendar.php">released</a> in <strong><!--% days_till_next_episode %--></strong> days.</p> <p>We started producing shows as <a href="<!--% absolute_path(baseurl) %-->eps/index.html#twat_episodes"><em>Today with a Techie</em></a> on 2005-09-19, <!--% delta.0 %--> years, <!--% delta.1 %--> months, <!--% delta.2 %--> days ago. our shows are produced by <a href="<!--% absolute_path(baseurl) %-->correspondents/index.html">listeners</a> like you and can be on any <a href="<!--% absolute_path(baseurl) %-->eps/index.html">topic</a> that <strong>"are of interest to <a href="https://en.wikipedia.org/wiki/hacker_(hobbyist)">hackers</a>"</strong>. If you listen to HPR then please consider contributing one show a year. if you <a href="<!--% absolute_url(baseurl) %-->about.html#so_you_want_to_record_a_podcast">record</a> your show now it could be <a href="<!--% hub_baseurl %-->calendar.php">released</a> in <strong><!--% days_till_next_episode %--></strong> days.</p>
</article> </article>
@ -54,7 +52,7 @@
<h3><!--% latest_episodes.summary%--></h3> <h3><!--% latest_episodes.summary%--></h3>
<p class="meta"$><!--% show_avatar(latest_episodes.hostid, latest_episodes.host, host_cnt) %--> <p class="meta"$><!--% show_avatar(latest_episodes.hostid, latest_episodes.host, host_cnt) %-->
Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(latest_episodes.hostid) %-->.html"><!--% latest_episodes.host %--></a> on <!--% latest_episodes.date %--> is flagged as <!--% display_explicit(latest_episodes.explicit) %--> and released under a <!--% latest_episodes.license %--> license. <br> Hosted by <a href="<!--% absolute_path(baseurl) %-->correspondents/<!--% zero_pad_left(latest_episodes.hostid) %-->.html"><!--% latest_episodes.host %--></a> on <!--% latest_episodes.date %--> is flagged as <!--% display_explicit(latest_episodes.explicit) %--> and released under a <!--% latest_episodes.license %--> license. <br>
<!--% display_tags(latest_episodes.tags) %--> <!--% display_tags(latest_episodes.tags) %-->
<span><!--% show_series(latest_episodes.series, latest_episodes.seriesid) %--></span> <span><!--% show_series(latest_episodes.series, latest_episodes.seriesid) %--></span>
<span><label>Comments: </label><!--% display_comments_tally(latest_episodes.id, latest_episodes.eps_tally) %--></span><br> <span><label>Comments: </label><!--% display_comments_tally(latest_episodes.id, latest_episodes.eps_tally) %--></span><br>
<!--% listen_now(latest_episodes, "hpr", baseurl, media_baseurl) %--> <!--% listen_now(latest_episodes, "hpr", baseurl, media_baseurl) %-->
@ -72,7 +70,7 @@
<hr> <hr>
<h1>Previous five weeks</h1> <h1>Previous five weeks</h1>
</header> </header>
<!--% FOREACH last_5_weeks_episodes IN DBI.query(query_last_5_weeks_episodes) <!--% FOREACH last_5_weeks_episodes IN DBI.query(query_last_5_weeks_episodes)
%--> %-->
<!--% show_summary(last_5_weeks_episodes) %--> <!--% show_summary(last_5_weeks_episodes) %-->
<p class="listen-in"><!--% display_listen_in(last_5_weeks_episodes.id) %--></p> <p class="listen-in"><!--% display_listen_in(last_5_weeks_episodes.id) %--></p>

View File

@ -1,58 +1,73 @@
<!--% query_next_available_episode = ' <!--% query_next_available_episode = '
WITH next_id AS ( WITH next_id AS (
SELECT id, id + 1 AS \'id_next\', date as \'last_date\' SELECT id, id + 1 AS id_next, date as last_date
FROM eps FROM eps
WHERE eps.date > NOW() WHERE eps.date > NOW()
) ),
SELECT free_slot AS (
MIN(next_id.id_next) AS \'next_id\', SELECT
DATE_FORMAT(DATE_ADD(MIN(last_date), INTERVAL 1 DAY), \'%Y\') AS \'last_year\', last_date AS prev_date,
DATE_FORMAT(DATE_ADD(MIN(last_date), INTERVAL 1 DAY), \'%d\') AS \'last_day\', CASE
DATE_FORMAT(DATE_ADD(MIN(last_date), INTERVAL 1 DAY), \'%m\') AS \'last_month\' WHEN DAYOFWEEK(last_date) = 6
FROM next_id THEN 3
LEFT JOIN eps ON next_id.id_next = eps.id ELSE 1
WHERE eps.id IS NULL END AS date_offset,
next_id.id_next AS empty_slot
FROM next_id
LEFT JOIN eps ON next_id.id_next = eps.id
WHERE eps.id IS NULL
ORDER BY next_id.id
LIMIT 1
)
SELECT
empty_slot AS next_id,
ADDDATE(prev_date,date_offset) AS next_date,
YEAR(ADDDATE(prev_date,date_offset)) AS last_year,
MONTH(ADDDATE(prev_date,date_offset)) AS last_month,
DAY(ADDDATE(prev_date,date_offset)) AS last_day,
DATEDIFF(ADDDATE(prev_date,date_offset),NOW()) AS delta_days
FROM free_slot
' '
%--> %-->
<!--% query_latest_episodes = ' <!--% query_latest_episodes = '
WITH comment_tallies AS ( WITH comment_tallies AS (
SELECT SELECT
eps_id, eps_id,
COUNT(eps_id) AS eps_tally COUNT(eps_id) AS eps_tally
FROM comments FROM comments
GROUP BY eps_id GROUP BY eps_id
) )
SELECT SELECT
eps.id, eps.id,
eps.explicit, eps.explicit,
eps.date, eps.license, eps.duration, eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags, eps.title, eps.summary, eps.tags,
eps.notes, eps.notes,
hosts.local_image, hosts.local_image,
hosts.hostid, hosts.hostid,
hosts.host, hosts.email, hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid, miniseries.name AS series, miniseries.id AS seriesid,
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.date <= UTC_DATE() WHERE eps.date <= UTC_DATE()
ORDER BY eps.id DESC ORDER BY eps.id DESC
LIMIT 10 LIMIT 10
' '
%--> %-->
<!--% query_last_5_weeks_episodes = ' <!--% query_last_5_weeks_episodes = '
SELECT SELECT
eps.id, eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit , CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.title, eps.summary, eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags, eps.duration, eps.notes, eps.tags,
hosts.hostid, hosts.hostid,
hosts.host, hosts.email, hosts.local_image, hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid miniseries.name AS series, miniseries.id AS seriesid
FROM eps FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date <= UTC_DATE() WHERE eps.date <= UTC_DATE()
ORDER BY eps.id DESC ORDER BY eps.id DESC

View File

@ -1,58 +1,73 @@
<!--% query_next_available_episode = ' <!--% query_next_available_episode = '
WITH next_id AS ( WITH next_id AS (
SELECT id, id + 1 AS \'id_next\', date as \'last_date\' SELECT id, id + 1 AS id_next, date as last_date
FROM eps FROM eps
WHERE eps.date > date(\'now\') WHERE eps.date > date(\'now\')
) ),
SELECT free_slot AS (
MIN(next_id.id_next) AS \'next_id\', SELECT
strftime(\'%Y\', DATE (MIN (last_date), \'+1 Days\')) AS \'last_year\', last_date AS prev_date,
strftime(\'%d\', DATE (MIN (last_date), \'+1 Days\')) AS \'last_day\', CASE
strftime(\'%m\', DATE (MIN (last_date), \'+1 Days\')) AS \'last_month\' WHEN strftime(\'%w\',last_date) = \'5\'
FROM next_id THEN \'+3 days\'
LEFT JOIN eps ON next_id.id_next = eps.id ELSE \'+1 days\'
WHERE eps.id IS NULL END AS date_offset,
next_id.id_next AS empty_slot
FROM next_id
LEFT JOIN eps ON next_id.id_next = eps.id
WHERE eps.id IS NULL
ORDER BY next_id.id
LIMIT 1
)
SELECT
empty_slot AS next_id,
DATE (prev_date, date_offset) AS next_date,
strftime(\'%Y\', DATE (prev_date, date_offset)) AS last_year,
strftime(\'%m\', DATE (prev_date, date_offset)) AS last_month,
strftime(\'%d\', DATE (prev_date, date_offset)) AS last_day,
printf(\'%i\',abs(julianday(DATE (prev_date, date_offset)) - julianday(\'now\') + 1)) AS delta_days
FROM free_slot
' '
%--> %-->
<!--% query_latest_episodes = ' <!--% query_latest_episodes = '
WITH comment_tallies AS ( WITH comment_tallies AS (
SELECT SELECT
eps_id, eps_id,
COUNT(eps_id) AS eps_tally COUNT(eps_id) AS eps_tally
FROM comments FROM comments
GROUP BY eps_id GROUP BY eps_id
) )
SELECT SELECT
eps.id, eps.id,
eps.explicit, eps.explicit,
eps.date, eps.license, eps.duration, eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags, eps.title, eps.summary, eps.tags,
eps.notes, eps.notes,
hosts.local_image, hosts.local_image,
hosts.hostid, hosts.hostid,
hosts.host, hosts.email, hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid, miniseries.name AS series, miniseries.id AS seriesid,
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.date <= date(\'now\') WHERE eps.date <= date(\'now\')
ORDER BY eps.id + 0 DESC ORDER BY eps.id + 0 DESC
LIMIT 10 LIMIT 10
' '
%--> %-->
<!--% query_last_5_weeks_episodes = ' <!--% query_last_5_weeks_episodes = '
SELECT SELECT
eps.id, eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit , CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.title, eps.summary, eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags, eps.duration, eps.notes, eps.tags,
hosts.hostid, hosts.hostid,
hosts.host, hosts.email, hosts.local_image, hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid miniseries.name AS series, miniseries.id AS seriesid
FROM eps FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date <= date(\'now\') WHERE eps.date <= date(\'now\')
ORDER BY eps.id + 0 DESC ORDER BY eps.id + 0 DESC