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

Use course_date_range logic for GraphQL course start date (#1430) #1431

Merged

Conversation

ssciolla
Copy link
Contributor

This PR aims to resolve #1430.

@ssciolla ssciolla added 🪳 bug Something isn't working ⚙️ backend labels Sep 12, 2022
@jonespm
Copy link
Member

jonespm commented Sep 12, 2022

This is how I was thinking of changing it. I'd might just remove the course_date_range method completely and update the only 2 places in views.py that use this to call these directly instead.

I also think we should have these fields a different name than get_date_start on the model. I'm not sure what I'd call it. It's really also doing a resolve_date_start, so that actually seems like a better name for the model. Maybe date_start_using_term? Maybe that's too wordy.

if self.date_start is not None:
start = self.date_start
elif self.term is not None and self.term.date_start is not None:
start = self.term.date_start
else:
logger.info(f"No date_start value was found for course {self.name} ({self.canvas_id}) or term; setting to current date and time")
start = datetime.now(pytz.UTC)
return start

def determine_date_end(self, start: Union[datetime, None] = None) -> datetime:
Copy link
Contributor Author

@ssciolla ssciolla Sep 12, 2022

Choose a reason for hiding this comment

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

Maybe passing the start here is too fancy, but maybe it keeps things more consistent and saves a query in some circumstances.

Scenarios to consider:

  • No course dates, no term dates, current time and two weeks from now; better synchronized but probably only by milliseconds, which is basically irrelevant.
  • No date end, no term dates, but a course start date. Query for course doesn't need to be re-made when getting the course start?

These may not matter much anyway, since I tried accessing a course without a term (which I manually deleted), and it said that course data was still being processed.

Copy link
Contributor

@pushyamig pushyamig Sep 13, 2022

Choose a reason for hiding this comment

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

I was able to test these scenarios and I was able to get correct result.

In case of no end date, Things were fine as well. I don't think Assignment planning relies on end date. But resource access view does and in that case the bar was showing 2 weeks only. The behavior is same from before. All this change was doing is name change of the function.

@ssciolla ssciolla marked this pull request as ready for review September 12, 2022 21:24
@pushyamig
Copy link
Contributor

I am reviewing it now.

@pushyamig
Copy link
Contributor

I am running into some setup issues, so I have a delay in reviewing. But I don't see those issues as part of this PR.

"setting to two weeks past start date."
)
date_start = start if start else self.determine_date_start()
end = date_start + timedelta(weeks=2)
Copy link
Contributor

Choose a reason for hiding this comment

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

I felt the assignment of the end date could be done with date_end variable if you like as it is done for date_start just for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I made it a bit more consistent. I was just trying to use a different name than the start parameter. 1dc178a

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@pushyamig
Copy link
Contributor

One think I noticed is when api/v1/courses/12344/info/ made during the loading for the course view, when course doesn't have start and end date the value returned is null. But the current week and total weeks value calculations is based on the determine_start_date and determine_end_date .

It is a moot point but I feel we could populate that course start and end date in response (since we are calculating it based on our ideas and AP/RA view use that value as well )for clarity purposes. But this is nothing related to this issue

Copy link
Contributor

@pushyamig pushyamig left a comment

Choose a reason for hiding this comment

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

I see this change as an improvement and working as expected. I have some comment but are optional

Copy link
Member

@zqian zqian left a comment

Choose a reason for hiding this comment

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

The date lookup logic looks good to me. Test was a success.

@ssciolla
Copy link
Contributor Author

ssciolla commented Sep 13, 2022

One think I noticed is when api/v1/courses/12344/info/ made during the loading for the course view, when course doesn't have start and end date the value returned is null. But the current week and total weeks value calculations is based on the determine_start_date and determine_end_date .

It is a moot point but I feel we could populate that course start and end date in response (since we are calculating it based on our ideas and AP/RA view use that value as well )for clarity purposes. But this is nothing related to this issue

Thanks for noting this @pushyamig. I think it would be worth examining that view again to make sure we're returning consistent data that is actually used. I don't see us using these course dates or the term really from that particular endpoint in the frontend. Maybe we did at some point. I think for now we should be okay.

I've created a separate issue to look into this later: #1433

@ssciolla ssciolla merged commit 9fa492d into tl-its-umich-edu:master Sep 13, 2022
jonespm pushed a commit to jonespm/student-dashboard-django that referenced this pull request Sep 20, 2022
…mich-edu#1430) (tl-its-umich-edu#1431)

* Add first draft of fix for GraphQL course start date

* Rename methods; fix determine_date_end; tidy up

* Use determine_date_start in views

* Remove course_date_range

* Reorganize imports

* Change some variable names

* Move import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ backend 🪳 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assignment Planning week numbers are not calculated correctly for courses using Term dates
4 participants