Add Toggl data to attendances, fix attendance creation for past lectures. Change styling a little.
This commit is contained in:
@@ -12,7 +12,7 @@ class ScrapeTogglJob < ApplicationJob
|
||||
# @param [Course] course
|
||||
def scrape_course(course)
|
||||
toggl_project_id = course.toggl_project
|
||||
lectures = course.lectures.order(:start_time)
|
||||
lectures = course.lectures.order(:start_time).includes(:attendance)
|
||||
|
||||
return if lectures.empty?
|
||||
|
||||
@@ -24,26 +24,30 @@ class ScrapeTogglJob < ApplicationJob
|
||||
end_time: Time.new('2024-01-01')
|
||||
)
|
||||
|
||||
return if entries_data.empty?
|
||||
|
||||
lectures.each do |lecture|
|
||||
return if lecture.attendance.present?
|
||||
|
||||
entries_data.each do |entry|
|
||||
concurrent_time_entry = entry['time_entries'].find do |inner_entry|
|
||||
(Time.new(inner_entry['start']) - lecture.start_time) < 10.minutes
|
||||
(Time.new(inner_entry['start']) - lecture.start_time).abs < 10.minutes
|
||||
end
|
||||
|
||||
if concurrent_time_entry.present?
|
||||
Attendance.create!(
|
||||
lecture:,
|
||||
associated_toggl_entry: concurrent_time_entry['id'],
|
||||
kind: :concurrent
|
||||
kind: :concurrent,
|
||||
toggl_data: entry
|
||||
)
|
||||
elsif entry['description'] == lecture.nice_title
|
||||
elsif entry['description'] == lecture.title
|
||||
# If the title matches but it wasn't concurrent, then it was a catchup
|
||||
Attendance.create!(
|
||||
lecture:,
|
||||
associated_toggl_entry: entry['time_entries'][0]['id'],
|
||||
kind: :catchup
|
||||
kind: :catchup,
|
||||
toggl_data: entry
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user