Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-35400: Serve AuxTel movies from RubinTV #82

Merged
merged 13 commits into from
Jul 6, 2022
Merged
66 changes: 44 additions & 22 deletions src/rubintv/handlers/external/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,19 @@ async def get_recent_table(request: web.Request) -> web.Response:
else:
bucket = request.config_dict["rubintv/gcs_bucket"]
events = get_most_recent_day_events(bucket, camera)
channels = camera.channels
the_date = events[0].cleanDate()
the_date = events[0].date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bugs me a little that you need two versions of the date especially since you turn it into a string anyway in the second line of the function on line 315.

My preference would be to only pass around the cleaned string or the object version and deal with manipulation of the thing in the function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ugyballoons I'll let you deal with this one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take your point. Date passing across the app is unnecessarily tangled. I think there are 5 representations of any single date in use across model, controller and view. There are two versions of date strings and there should only be one.


metadata_json = get_metadata_json(
bucket.name, camera.slug, the_date, logger
)
metadata_json = get_metadata_json(bucket, camera, the_date, logger)
per_day = get_per_day_channels(bucket, camera, the_date, logger)

page = get_formatted_page(
"cameras/camera.jinja",
title=title,
camera=camera,
channels=channels,
date=the_date,
date=the_date.strftime("%Y-%m-%d"),
events=events,
metadata=metadata_json,
per_day=per_day,
)

logger.info("get_recent_table", duration=timer.seconds)
Expand Down Expand Up @@ -192,16 +190,16 @@ async def update_todays_table(request: web.Request) -> web.Response:
)
events = flatten_events_dict_into_list(camera, events_dict)

metadata_json = get_metadata_json(
bucket.name, camera.slug, date_str, logger
)
metadata_json = get_metadata_json(bucket, camera, the_date, logger)
per_day = get_per_day_channels(bucket, camera, the_date, logger)

page = get_formatted_page(
"cameras/data-table-header.jinja",
camera=camera,
date=the_date,
events=events,
metadata=metadata_json,
per_day=per_day,
)

logger.info("update_todays_table", duration=timer.seconds)
Expand Down Expand Up @@ -235,9 +233,8 @@ async def get_historical(request: web.Request) -> web.Response:
smrd_dict = historical.get_events_for_date(camera, smrd)
smrd_events = flatten_events_dict_into_list(camera, smrd_dict)

metadata_json = get_metadata_json(
bucket.name, camera.slug, smrd.strftime("%Y-%m-%d"), logger
)
metadata_json = get_metadata_json(bucket, camera, smrd, logger)
per_day = get_per_day_channels(bucket, camera, smrd, logger)

page = get_formatted_page(
"cameras/historical.jinja",
Expand All @@ -249,6 +246,7 @@ async def get_historical(request: web.Request) -> web.Response:
date=smrd,
events=smrd_events,
metadata=metadata_json,
per_day=per_day,
)

logger.info("get_historical", duration=timer.seconds)
Expand All @@ -271,25 +269,52 @@ async def get_historical_day_data(request: web.Request) -> web.Response:
day_dict = historical.get_events_for_date(camera, the_date)
day_events = flatten_events_dict_into_list(camera, day_dict)

metadata_json = get_metadata_json(
bucket.name, camera.slug, date_str, logger
)
per_day = get_per_day_channels(bucket, camera, the_date, logger)
metadata_json = get_metadata_json(bucket, camera, the_date, logger)

page = get_formatted_page(
"cameras/data-table-header-with-day-channels.jinja",
"cameras/historical-update.jinja",
camera=camera,
date=the_date,
events=day_events,
metadata=metadata_json,
per_day=per_day,
)
return web.Response(text=page, content_type="text/html")


def get_per_day_channels(
bucket: Bucket, camera: Camera, the_date: date, logger: Any
) -> dict[str, str]:
per_day_channels = {}
if movie_url := get_movie_url(bucket, camera, the_date, logger):
per_day_channels["movie"] = movie_url
return per_day_channels


def get_movie_url(
bucket: Bucket, camera: Camera, a_date: date, logger: Any
) -> str:
prefix = camera.per_day_channels["movie"].prefix
date_str = a_date.strftime("%Y%m%d")
url = f"https://storage.googleapis.com/{bucket.name}/"
url += f"{prefix}/dayObs_{date_str}.mp4"
try:
res = requests.head(url)
if res.status_code != 200:
url = ""
except requests.exceptions.RequestException as e:
logger.error(f"Error retrieving movie from {url} with error {e}")
url = ""
return url


def get_metadata_json(
bucket_name: str, camera_slug: str, date_str: str, logger: Any
bucket: Bucket, camera: Camera, a_date: date, logger: Any
) -> str:
date_str = a_date.strftime("%Y%m%d")
metadata_json = "{}"
metadata_url = get_metadata_url(bucket_name, camera_slug, date_str)
metadata_url = get_metadata_url(bucket.name, camera.slug, date_str)
try:
metadata_res = requests.get(metadata_url)
if metadata_res.status_code == 200:
Expand All @@ -300,9 +325,6 @@ def get_metadata_json(


def get_metadata_url(bucket_name: str, camera_slug: str, date_str: str) -> str:
# reformat the date string from YYYY-m-d to YYYYmmdd
date_str = "".join([f"{int(x):02}" for x in date_str.split("-")])

url = f"https://storage.googleapis.com/{bucket_name}/"
url += f"{camera_slug}_metadata/dayObs_{date_str}.json"
return url
Expand Down
2 changes: 1 addition & 1 deletion src/rubintv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __post_init__(self) -> None:
simplename="rolling",
),
"movie": Channel(
name="Tonight's Movie", prefix="auxtel_movie", simplename="movie"
name="Tonight's Movie", prefix="auxtel_movies", simplename="movie"
),
}

Expand Down
1 change: 1 addition & 0 deletions src/rubintv/static/images/movie.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/rubintv/static/js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { createTableControlUI, applySelected, loadMetadata } from './modules/tab
'filter',
'disperser',
'airmass',
'time_begin_tai'
'time_begin_tai',
'Seeing'
]

let meta = loadMetadata()
Expand Down
4 changes: 3 additions & 1 deletion src/rubintv/static/js/modules/table-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const checkboxMapping = {
time_begin_tai: 'TAI',
filter: 'Filter',
disperser: 'Disperser',
airmass: 'Airmass'
airmass: 'Airmass',
focus_z: 'Focus-Z',
Seeing: 'DIMM Seeing'
}

export function loadMetadata () {
Expand Down
3 changes: 2 additions & 1 deletion src/rubintv/static/js/refresh-daytable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { createTableControlUI, applySelected, loadMetadata } from './modules/tab
'filter',
'disperser',
'airmass',
'time_begin_tai'
'time_begin_tai',
'Seeing'
]

let meta = loadMetadata()
Expand Down
5 changes: 5 additions & 0 deletions src/rubintv/static/stylesheets/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rubintv/static/stylesheets/main.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/rubintv/static/stylesheets/main.sass
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ a
.button.historical
background-color: #262534
color: #fff
.button.movie
background-color: #83daee
text-align: center

html
font-family: "Rubik", sans-serif
Expand Down
35 changes: 18 additions & 17 deletions src/rubintv/templates/cameras/camera.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@
<nav id="per-image-menu" class="channel-menu" role="navigation">
<h3>Per Image Channels: Current</h3>
<ul class="channels flr">
{% for channel in channels %}
{% if channels[channel].label %}
{% for channel in camera.channels %}
{% if camera.channels[channel].label %}
<li class="channel">
<a class="button button-large {{channel}}"
href="/rubintv/{{ camera.slug }}/{{channel}}_current" target="_blank">
<span>{{ channels[channel].name }}</span>
<span>{{ camera.channels[channel].name }}</span>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</nav>

{% if camera.per_day_channels | length %}
<nav id="per-night-menu" class="channel-menu" role="navigation">
<h3>Per Night Channels</h3>
<ul class="channels flr">
{% for pn_channel in camera.per_day_channels.values() %}
<li class="channel">
<a class="button button-small" href="#">
{{ pn_channel.name }}
</a>
</li>
{% endfor %}
</ul>
</nav>
{% if per_day | length %}
<nav id="per-night-menu" class="channel-menu" role="navigation">
<h3>Per Night Channels</h3>
<ul class="channels flr">
{% for pd_channel_name in per_day %}
<li class="channel">
<a class="button button-large {{ pd_channel_name }}"
href="{{ per_day[pd_channel_name] }}">
<img src="/rubintv/static/images/{{ pd_channel_name }}.svg">
Tonight's Movie
</a>
</li>
{% endfor %}
</ul>
</nav>
{% endif %}
</div>

Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions src/rubintv/templates/cameras/historical-update.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% include "cameras/per-day-channels.jinja" %}
{% include "cameras/data-table-header.jinja" %}
3 changes: 2 additions & 1 deletion src/rubintv/templates/cameras/historical.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{% include "cameras/calendar.jinja" %}
</section>
<section class="channel-day-data">
{% include "cameras/data-table-header-with-day-channels.jinja" %}
{% include "cameras/per-day-channels.jinja" %}
{% include "cameras/data-table-header.jinja" %}
</section>
{% endblock content %}
{% block footer_scripts %}
Expand Down
16 changes: 16 additions & 0 deletions src/rubintv/templates/cameras/per-day-channels.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% if per_day | length %}
<nav id="per-night-menu" class="channel-menu" role="navigation">
<h3>Per Night Channels</h3>
<ul class="channels flr">
{% for pd_channel_name in per_day %}
<li class="channel">
<a class="button button-large {{ pd_channel_name }}"
href="{{ per_day[pd_channel_name] }}">
<img src="/rubintv/static/images/{{ pd_channel_name }}.svg">
Movie for {{ date }}
</a>
</li>
{% endfor %}
</ul>
</nav>
{% endif %}