select enrollment_term_id ,count(enrollment_term_id) as count from canvas.courses group by enrollment_term_id order by enrollment_term_id desc;


select id, name, sis_source_id from canvas.enrollment_terms order by sis_source_id ;


select c.id, c.workflow_state, c.sis_source_id, c.course_code, c.enrollment_term_id, t.name from canvas.courses c 
join canvas.enrollment_terms t on c.enrollment_term_id=t.id
order by c.sis_source_id, c.course_code;


SELECT * FROM information_schema.tables;


INSERT INTO canvas.schedule (canvascourse, crn, code, units, teacher, start,"end", type, loc, site, partofday, cap, act, sem) 
VALUES (9651, '40724', 'SPAN 1A', '5.000', 'David G  Perez', '1-27', '5-22', 'in-person', 'HU 105', 'Gilroy', 'Midday', 30, 26, '202030');




--
--
-- users in sp24 and number of each type of course taking
--
--

-- one student
select u.sortable_name, c.course_code, s.units, s.type, s.start
from canvas.users u 
join canvas.enrollments e on u.id=e.user_id
join canvas.courses c on e.course_id=c.id
join canvas.schedule s on c.id=s.canvascourse
where s.sem='202430' and e.workflow_state='active' and e.type='StudentEnrollment' -- and u.sortable_name='Zendejas, Grace'
order by u.sortable_name, s.start, c.course_code ;



-- num courses
select u.sortable_name, 
   sum(CASE WHEN s.type = 'in-person' THEN 1 ELSE 0 end) AS inperson,
   sum(CASE WHEN s.type = 'hybrid' THEN 1 ELSE 0 end) AS hybrid,
   sum(CASE WHEN s.type = 'online' THEN 1 ELSE 0 end) AS online,
   sum(CASE WHEN s.type = 'online live' THEN 1 ELSE 0 end) AS onlinelive,
   count(*) as total
from canvas.users u 
join canvas.enrollments e on u.id=e.user_id
join canvas.courses c on e.course_id=c.id
join canvas.schedule s on c.id=s.canvascourse
where s.sem='202430' and e.workflow_state='active' and e.type='StudentEnrollment'
group by u.sortable_name
order by total desc, online desc, onlinelive desc, hybrid desc;




-- num units
select u.sortable_name, p.sis_user_id,
   sum(CASE WHEN s.type = 'in-person' THEN s.units::FLOAT ELSE 0 end) AS inperson,
   sum(CASE WHEN s.type = 'hybrid' THEN s.units::FLOAT ELSE 0 end) AS hybrid,
   sum(CASE WHEN s.type = 'online' THEN s.units::FLOAT ELSE 0 end) AS online,
   sum(CASE WHEN s.type = 'online live' THEN s.units::FLOAT ELSE 0 end) AS onlinelive,
   sum(s.units::FLOAT) as total
from canvas.users u 
join canvas.enrollments e on u.id=e.user_id
join canvas.courses c on e.course_id=c.id
join canvas.schedule s on c.id=s.canvascourse
join canvas.pseudonyms p on u.id=p.user_id 
where s.sem='202430' and e.workflow_state='active' and e.type='StudentEnrollment'
group by u.sortable_name, p.sis_user_id 
order by total desc, online desc, onlinelive desc, hybrid desc;

-- only units
select 
   sum(s.units::FLOAT) as total
from canvas.users u 
join canvas.enrollments e on u.id=e.user_id
join canvas.courses c on e.course_id=c.id
join canvas.schedule s on c.id=s.canvascourse
join canvas.pseudonyms p on u.id=p.user_id 
where s.sem='202430' and e.workflow_state='active' and e.type='StudentEnrollment'
group by u.sortable_name
order by total desc;




-- each class

select u.sortable_name, c.course_code, s.type, s.units::FLOAT
from canvas.users u 
join canvas.enrollments e on u.id=e.user_id
join canvas.courses c on e.course_id=c.id
join canvas.schedule s on c.id=s.canvascourse
where s.sem='202430' and e.workflow_state='active' and e.type='StudentEnrollment'
order by u.sortable_name, c.course_code;