Skip to content

Added endpoint /api/uptime/ for posting and getting uptime days from …#35

Merged
jnation3406 merged 11 commits intomainfrom
feature/uptime_api
May 9, 2026
Merged

Added endpoint /api/uptime/ for posting and getting uptime days from …#35
jnation3406 merged 11 commits intomainfrom
feature/uptime_api

Conversation

@jnation3406
Copy link
Copy Markdown
Member

…downtime database. It uses rise set and the semester bounds to take in a list of full or partial days and create or remove downtimes from them.

This API is intended for AEON use cases, to take in uptime "nights" in the format they prefer and calculate and create downtimes from that. It is a stepping stone to providing a full calendar UI to manage their instruments available nights.

Jon added 2 commits April 13, 2026 23:35
…downtime database. It uses rise set and the semester bounds to take in a list of full or partial days and create or remove downtimes from them.
Copy link
Copy Markdown
Contributor

@jashan-lco jashan-lco left a comment

Choose a reason for hiding this comment

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

Looks good for what I think it's trying to do. API feels very convoluted and designed for a very specific use case.

I still don't understand why we can't just have CRUD Uptime resources with simple start/end times and then do merging/complement logic with downtimes in a view at runtime or in the scheduler.

Comment thread pyproject.toml
Comment thread schedule/uptime.py
"""
Modifies existing downtimes based on input uptimes on resources.

Takes output of UptimesSerializer and calculates the exact uptime windows using rise_set, then merges
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider annotating the type annotation as such: list[UptimesSerializer]. Maybe one day type hints will work for Django.

Comment thread schedule/serializers.py
Comment thread downtime/urls.py Outdated

urlpatterns = [
re_path(r'^$', DowntimeListView.as_view(), name='web-downtime-list'),
re_path(r'^api/uptime/', UptimeView.as_view(), name='uptime'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as below, uptime-groups?

Comment thread schedule/uptime.py
Comment thread schedule/uptime.py Outdated
Comment thread schedule/uptime.py
telescope_info = configdb.get_telescope_info(uptime_group['site'], uptime_group['enclosure'],
uptime_group['telescope'], uptime_group['instrument_type'])
rise_set_site = {
'latitude': Angle(degrees=telescope_info['latitude']),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens when this information is incorrect in configdb or changed? What's the process of getting a consistent view? Submit another request? Will that get rid of the downtime blocks created by the previous request or will those be "merged" into the new set?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm... On the one hand those values rarely change, but you are right that it is possible to change the hour angles associated with the telescope, which would vary its nighttime intervals. Again, these change very very rarely or not at all for most telescopes, but in the case that they did change within a semester with existing downtimes from this method, and then someone called this method again to delete one of those downtimes, then if the ha limit was grown (so the night interval was smaller), then it would leave a sliver of "uptime" outside the now current ha limit. In practice though this sliver shouldn't cause any problems downstream in our system since the new ha limits would prohibit scheduling or accepting new requests in those slivers of time, regardless of the lack of downtime there.

TLDR this could lead to slightly inconsistent uptimes/downtimes but I don't think it would break anything.

@jnation3406
Copy link
Copy Markdown
Member Author

Looks good for what I think it's trying to do. API feels very convoluted and designed for a very specific use case.

I still don't understand why we can't just have CRUD Uptime resources with simple start/end times and then do merging/complement logic with downtimes in a view at runtime or in the scheduler.

Yeah, I agree this is totally specialized for the AEON workflow, and for merging "uptime" definitions into our existing Downtime model. I thought a bit about creating a complement Uptime model, and then whenever someone requests Downtimes it merges both, but that felt like it would complicate the existing usage just to support this AEON use case so I thought it would be better to just shoe horn their use case into the existing Downtime model.

There are some questions I had if we had both Downtime and Uptime models, like what do we do if they have competing views of the world defined for the same resource, i.e. downtime in one but uptime in another for the same time period? And also with a simple Uptime model that defines start/end intervals of uptime, we are still left with the problem of AEON only knowing the fraction of the day they want, and not specific start / end of night times for scheduling.

@jashan-lco
Copy link
Copy Markdown
Contributor

what do we do if they have competing views of the world defined for the same resource, i.e. downtime in one but uptime in another for the same time period?

Downtime takes precedence seems like the most conservative and safest option to me.

@jnation3406
Copy link
Copy Markdown
Member Author

what do we do if they have competing views of the world defined for the same resource, i.e. downtime in one but uptime in another for the same time period?

Downtime takes precedence seems like the most conservative and safest option to me.

When we are combining uptime + downtime, that means we are first taking the complement of uptime to get downtime, then combining downtime (from uptime) + downtime (from downtime). So what does downtime taking precedence mean in that case? I.e. if we have 1 day of uptime in the semester, then the rest of the semester is "downtime". But then if we also define a period of short downtimes surrounding a few days in the semester, that implies the time in between them is uptime. But if we combine the downtimes and uptime to get a total downtime, we would be left with only the uptime day. The only sensible thing I can think of is just having some restriction like for a resource and semester you can only define 1+ uptimes or 1+ downtimes but not both. But then the definition of using downtime or uptime for that resource and semester is based on what we create first for it which I don't like either.

@jnation3406 jnation3406 merged commit 44951f4 into main May 9, 2026
12 checks passed
@jnation3406 jnation3406 deleted the feature/uptime_api branch May 9, 2026 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants