Track associated toggl entry id for uniqueness, show stats for time spent in different parts of the lecture flow.
This commit is contained in:
@@ -28,30 +28,62 @@ class ScrapeTogglJob < ApplicationJob
|
||||
|
||||
return if entries_data.empty?
|
||||
|
||||
lectures.each do |lecture|
|
||||
next if lecture.attendance.present?
|
||||
entries_data.each do |entry|
|
||||
entry_title = entry['description']
|
||||
|
||||
entries_data.each do |entry|
|
||||
concurrent_time_entry = entry['time_entries'].find do |inner_entry|
|
||||
if (lecture = lectures.find_by(title: entry_title))
|
||||
is_concurrent = entry['time_entries'].any? do |inner_entry|
|
||||
(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 = if is_concurrent
|
||||
:concurrent
|
||||
else
|
||||
:catchup
|
||||
end
|
||||
|
||||
lecture.tracked_time_entries.create!(
|
||||
toggl_data: entry,
|
||||
associated_toggl_entry_id: entry['time_entries'][0]['id'],
|
||||
|
||||
# TODO: What should happen if the time entry is materially before the lecture?
|
||||
kind:
|
||||
) and next
|
||||
end
|
||||
|
||||
concurrent_unlabeled = entry['time_entries'].any? do |inner_entry|
|
||||
lecture = lectures.find do |lecture|
|
||||
(Time.new(inner_entry['start']) - lecture.start_time).abs < 10.minutes
|
||||
end
|
||||
|
||||
if lecture.present?
|
||||
lecture.tracked_time_entries.create!(
|
||||
kind: :concurrent,
|
||||
toggl_data: entry
|
||||
)
|
||||
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,
|
||||
toggl_data: entry
|
||||
toggl_data: entry,
|
||||
associated_toggl_entry_id: inner_entry['id']
|
||||
)
|
||||
end
|
||||
|
||||
lecture.present?
|
||||
end
|
||||
|
||||
next if concurrent_unlabeled
|
||||
|
||||
preparation_regex = /^(.+): ?(?:Prep|Preparation)?$/
|
||||
review_regex = /^(.+): ?(?:Review|Recap)/
|
||||
|
||||
if (lecture_title_match = entry_title.match(preparation_regex)) and (lecture = lectures.find_by(title: lecture_title_match[1]))
|
||||
lecture.tracked_time_entries.create!(
|
||||
kind: :preparation,
|
||||
toggl_data: entry,
|
||||
associated_toggl_entry_id: entry['time_entries'][0]['id'],
|
||||
)
|
||||
elsif (lecture_title_match = entry_title.match(review_regex)) and (lecture = lectures.find_by(title: lecture_title_match[1]))
|
||||
lecture.tracked_time_entries.create!(
|
||||
kind: :review,
|
||||
toggl_data: entry,
|
||||
associated_toggl_entry_id: entry['time_entries'][0]['id'],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user