diff --git a/database/02_test_data.sql b/database/02_test_data.sql index 4ee6c88..23fae45 100644 --- a/database/02_test_data.sql +++ b/database/02_test_data.sql @@ -50,9 +50,7 @@ VALUES (100001, 4), (100001, 2), (100001, 3), (100002, 1); -INSERT INTO work_kind_survey (user_id, score, work_kind_id) -VALUES (100001, 6, 1), - (100002, 7, 2); + INSERT INTO emotion_survey (user_id, emotion_id) VALUES (100001, 1), (100002, 2); diff --git a/database/03_test__survey_data.sql b/database/03_test__survey_data.sql index 6972a4a..d00d742 100644 --- a/database/03_test__survey_data.sql +++ b/database/03_test__survey_data.sql @@ -1,227 +1,237 @@ --- -- DEAR-98 add happiness survey data --- -- User id = 1 --- --- DO $$ --- DECLARE --- start_date DATE := '2024-07-07'; --- end_date DATE := CURRENT_DATE; --- current_date DATE; --- user_id INTEGER := 1; --- num_entries INTEGER; --- i INTEGER; --- scores INTEGER[] := ARRAY[2, 8, 14, 20]; --- score INTEGER; --- BEGIN --- -- Loop through each date in the range --- current_date := start_date; --- WHILE current_date <= end_date LOOP --- -- Randomly decide the number of entries for the current date (0 to 6) --- num_entries := floor(random() * 2)::INTEGER; --- --- RAISE NOTICE 'Date: %, Entries: %', current_date, num_entries; --- --- -- Insert the entries for the current date at the same time --- FOR i IN 1..num_entries LOOP --- score := scores[floor(random() * 4)::INTEGER + 1]; --- INSERT INTO happiness_survey (user_id, submitted, score) --- VALUES (user_id, current_date + interval '12 hours', score); --- END LOOP; --- --- -- Move to the next date --- current_date := current_date + interval '1 day'; --- END LOOP; --- END $$; +-- Happiness Survey Data (User 100002 and User 2) +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-24 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-24 15:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-25 12:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-26 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-27 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-28 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-28 17:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-29 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-30 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-30 18:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-08 17:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-09 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-10 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-11 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-11 15:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-12 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-13 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-14 12:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-14 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-14 17:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-14 17:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-15 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-15 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-16 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-16 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-17 18:00:00.000000 +00:00', 15); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-17 18:00:00.000000 +00:00', 4); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-18 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-18 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-18 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-19 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-19 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 15:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 15:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-21 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-21 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-22 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-22 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-22 12:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-23 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 18:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-23 18:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 18:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-24 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-24 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-24 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-25 12:00:00.000000 +00:00', 4); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-25 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-25 12:00:00.000000 +00:00', 18); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-26 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-26 15:00:00.000000 +00:00', 3); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 15:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 15:00:00.000000 +00:00', 8); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-27 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-27 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-27 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-28 12:00:00.000000 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-06-28 12:00:00.000000 +00:00', 12); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-28 12:00:00.000000 +00:00', 14); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-06-28 12:00:00.000000 +00:00', 6); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-28 12:00:00.000000 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100002, '2024-07-31 19:28:42.118978 +00:00', 1); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:28:42.118978 +00:00', 4); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:28:42.118978 +00:00', 3); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:28:42.118978 +00:00', 2); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:28:42.118978 +00:00', 1); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:28:42.118978 +00:00', 4); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:28:42.118978 +00:00', 5); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:28:42.118978 +00:00', 4); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (2, '2024-07-31 19:34:13.345854 +00:00', 20); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:34:13.345854 +00:00', 17); +INSERT INTO public.happiness_survey (user_id, submitted, score) VALUES (100001, '2024-07-31 19:34:14.468440 +00:00', 8); --- DEAR-98 add happiness survey data +-- Work Kind Survey Data (User 2 and User 100001, 100002) +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 14, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-07-01 12:54:10.518398 +00:00', 5, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-06-01 12:54:10.518398 +00:00', 4, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:10.518398 +00:00', 9, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-06-02 12:54:09.809490 +00:00', 3, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-08-01 12:54:10.518398 +00:00', 9, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-07-01 12:54:09.809490 +00:00', 3, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-05-01 12:54:09.809490 +00:00', 5, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-03-01 12:54:09.809490 +00:00', 8, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-05-01 12:54:09.809490 +00:00', 11, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-08-03 12:54:10.518398 +00:00', 4, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-04-01 12:54:10.518398 +00:00', 12, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-05-01 12:54:10.518398 +00:00', 4, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-08-01 12:54:09.809490 +00:00', 7, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 4, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.809490 +00:00', 3, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-05-01 12:54:09.809490 +00:00', 11, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-08-03 12:54:10.518398 +00:00', 4, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-04-01 12:54:10.518398 +00:00', 12, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-05-01 12:54:10.518398 +00:00', 4, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-08-01 12:54:09.809490 +00:00', 7, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-01 09:30:00 +00:00', 8, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-02 10:00:00 +00:00', 6, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-03 14:45:00 +00:00', 9, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-04 11:30:00 +00:00', 7, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-05 15:20:00 +00:00', 5, 9); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-06 16:10:00 +00:00', 10, 10); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-07 09:00:00 +00:00', 9, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-07-08 09:30:00 +00:00', 8, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-07-09 10:00:00 +00:00', 7, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-07-10 10:30:00 +00:00', 6, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-11 11:00:00 +00:00', 5, 9); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-07-12 11:30:00 +00:00', 10, 10); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-07-13 12:00:00 +00:00', 8, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-07-14 12:30:00 +00:00', 9, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (1, '2024-07-15 13:00:00 +00:00', 6, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-07-16 13:30:00 +00:00', 7, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-07-17 14:00:00 +00:00', 9, 9); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-07-18 14:30:00 +00:00', 8, 10); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-07-01 12:54:10.518000 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-08-03 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-04-01 12:54:10.518398 +00:00', 10, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-05-01 12:54:10.518398 +00:00', 5, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100001, '2024-08-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-04-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-08-03 12:54:10.518398 +00:00', 13, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (100002, '2024-05-01 12:54:10.518398 +00:00', 20, 5); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-01 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-02 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-03 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-04 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-05 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-06 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-07 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-08 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-09 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-10 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-11 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-12 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-13 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-14 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-15 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-16 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-17 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-18 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-19 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-20 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-21 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-22 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-23 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-24 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-25 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-26 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-27 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-28 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-29 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-30 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-03-31 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-01 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-02 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-03 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-04 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-05 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-06 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-07 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-08 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-09 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-10 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-11 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-12 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-13 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-14 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-15 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-16 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-17 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-18 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-18 15:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-19 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-20 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-21 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-22 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-22 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-23 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-24 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-24 18:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-25 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-25 15:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-26 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-27 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-27 16:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-28 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-29 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-30 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-04-30 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-01 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-02 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-03 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-03 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-04 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-05 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-06 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-06 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-07 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-08 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-09 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-09 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-10 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-11 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-12 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-12 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-13 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-14 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-15 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-15 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-16 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-17 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-18 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-18 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-19 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-20 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-21 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-21 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-22 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (1, '2024-05-23 12:00:00', 20); +-- emotions +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-07-31 19:34:07.666594 +00:00', 26); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-07-31 19:34:09.243060 +00:00', 23); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:27.510427 +00:00', 23); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:29.936252 +00:00', 26); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:30.454504 +00:00', 19); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:31.389732 +00:00', 18); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:32.071133 +00:00', 27); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:32.678330 +00:00', 29); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-07-31 19:34:07.666594 +00:00', 26); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-07-03 16:30:30.995000 +00:00', 17); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:27.510427 +00:00', 23); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:29.936252 +00:00', 18); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:30.454504 +00:00', 19); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:30.995367 +00:00', 17); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:31.389732 +00:00', 16); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:32.071133 +00:00', 27); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:32.678330 +00:00', 17); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:33.124167 +00:00', 28); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:27.510427 +00:00', 23); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:29.936252 +00:00', 18); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:30.454504 +00:00', 19); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100001, '2024-08-01 16:30:30.995367 +00:00', 17); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:29.936252 +00:00', 16); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:30.454504 +00:00', 16); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:31.389732 +00:00', 29); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-01 16:30:32.071133 +00:00', 29); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:31.389732 +00:00', 24); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:32.071133 +00:00', 27); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:32.678330 +00:00', 24); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:33.124167 +00:00', 24); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:27.510427 +00:00', 24); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:29.936252 +00:00', 24); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:30.454504 +00:00', 26); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:30.995367 +00:00', 28); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:29.936252 +00:00', 28); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (100002, '2024-08-01 16:30:30.454504 +00:00', 20); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-02 14:58:54.285556 +00:00', 20); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-02 14:58:56.417676 +00:00', 28); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-02 14:58:58.560984 +00:00', 27); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-02 15:02:17.283271 +00:00', 26); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-02 15:02:25.270174 +00:00', 23); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-02 15:02:33.236664 +00:00', 28); +INSERT INTO public.emotion_survey (user_id, submitted, emotion_id) VALUES (2, '2024-08-02 15:02:34.382377 +00:00', 22); ---user id = 100002 -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-24 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-24 15:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-25 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-26 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-27 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-28 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-28 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-29 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-30 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-30 18:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-31 12:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-05-31 15:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-01 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-02 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-02 16:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-03 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-04 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-05 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-05 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-06 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-07 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-08 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-08 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-09 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-10 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-11 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-11 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-12 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-13 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-14 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-14 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-15 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-16 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-17 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-17 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-18 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-19 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-21 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-22 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-24 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-25 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-27 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-28 12:00:00', 20); --- last weeks -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-14 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-14 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-15 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-16 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-17 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-17 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-18 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-19 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-20 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-20 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-21 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-22 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-23 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-23 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-24 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-25 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-26 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-26 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-27 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (2, '2024-06-28 12:00:00', 20); - -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-14 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-14 17:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-15 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-16 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-17 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-17 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-18 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-19 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-20 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-21 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-22 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-23 18:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-24 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-25 12:00:00', 20); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 12:00:00', 2); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-26 15:00:00', 8); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-27 12:00:00', 14); -INSERT INTO happiness_survey (user_id, submitted, score) VALUES (100002, '2024-06-28 12:00:00', 20); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-03 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:10.518398 +00:00', 5, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:10.518398 +00:00', 20, 11); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-04-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 12:34:22.805506 +00:00', 2, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 13:29:35.677432 +00:00', 14, 9); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 13:29:36.276328 +00:00', 8, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:40:12.871626 +00:00', 20, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.809490 +00:00', 3, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.069607 +00:00', 4, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-06-01 12:54:10.518398 +00:00', 4, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-06-02 12:54:09.809490 +00:00', 3, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:40:13.446130 +00:00', 20, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:40:13.625317 +00:00', 20, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:40:14.012145 +00:00', 8, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:58:39.742351 +00:00', 8, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:58:47.457798 +00:00', 2, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 15:02:44.882066 +00:00', 2, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 15:02:45.659849 +00:00', 8, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 15:02:59.511713 +00:00', 8, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 15:03:00.728083 +00:00', 2, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 15:03:18.727770 +00:00', 2, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-07-01 12:54:10.518000 +00:00', 20, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:10.518000 +00:00', 20, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:10.518398 +00:00', 20, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 15, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:10.518398 +00:00', 20, 5); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.809490 +00:00', 3, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:40:13.076227 +00:00', 20, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:28.229059 +00:00', 2, 10); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:28.918953 +00:00', 14, 9); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:29.517146 +00:00', 2, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:30.481056 +00:00', 20, 8); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:30.939850 +00:00', 20, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:31.304414 +00:00', 14, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:32.183953 +00:00', 14, 9); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:32.763149 +00:00', 2, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-02 14:40:13.267407 +00:00', 20, 17); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-05-01 12:54:09.809490 +00:00', 5, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.069607 +00:00', 5, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.809490 +00:00', 15, 6); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 12:54:09.069607 +00:00', 3, 7); +INSERT INTO public.work_kind_survey (user_id, submitted, score, work_kind_id) VALUES (2, '2024-08-01 13:12:31.696380 +00:00', 20, 8); diff --git a/src/main/java/ch/fhnw/deardevbackend/controller/InsightsController.java b/src/main/java/ch/fhnw/deardevbackend/controller/InsightsController.java index 2f7504a..041f32e 100644 --- a/src/main/java/ch/fhnw/deardevbackend/controller/InsightsController.java +++ b/src/main/java/ch/fhnw/deardevbackend/controller/InsightsController.java @@ -1,13 +1,12 @@ package ch.fhnw.deardevbackend.controller; -import ch.fhnw.deardevbackend.dto.*; +import ch.fhnw.deardevbackend.dto.insights.InsightDTO; import ch.fhnw.deardevbackend.services.InsightsService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; + import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; @RestController @@ -17,7 +16,7 @@ public class InsightsController { @Autowired private InsightsService insightsService; - // Overall + @GetMapping("/{userId}/team/{teamId}/sprint/{sprint}") public ResponseEntity getInsightsByTeamAndSprint(@PathVariable Integer userId, @PathVariable Integer teamId, @@ -26,16 +25,4 @@ public ResponseEntity getInsightsByTeamAndSprint(@PathVariable Integ return ResponseEntity.ok(insights); } - // happiness team vs personal - @GetMapping("/happiness/{userId}/team/{teamId}/sprint/{sprint}") - public ResponseEntity> getHappinessInsightsByTeam( - @PathVariable Integer userId, @PathVariable Integer teamId, @PathVariable String sprint) { - try { - List insights = insightsService.getHappinessInsightsByTeam(userId, teamId, sprint); - return ResponseEntity.ok(insights); - } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } - } diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/InsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/InsightDTO.java deleted file mode 100644 index 2179dd6..0000000 --- a/src/main/java/ch/fhnw/deardevbackend/dto/InsightDTO.java +++ /dev/null @@ -1,13 +0,0 @@ -package ch.fhnw.deardevbackend.dto; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -@Data -@AllArgsConstructor -public class InsightDTO { - private List happinessInsights; - private List workKindInsights; -} diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/TeamHappinessInsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/TeamHappinessInsightDTO.java deleted file mode 100644 index 8b484bf..0000000 --- a/src/main/java/ch/fhnw/deardevbackend/dto/TeamHappinessInsightDTO.java +++ /dev/null @@ -1,13 +0,0 @@ -package ch.fhnw.deardevbackend.dto; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -@Data -@AllArgsConstructor -public class TeamHappinessInsightDTO { - private Integer teamId; - private List insights; // todo rename happinessInsights -} diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/TeamWorkKindInsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/TeamWorkKindInsightDTO.java deleted file mode 100644 index c390d5e..0000000 --- a/src/main/java/ch/fhnw/deardevbackend/dto/TeamWorkKindInsightDTO.java +++ /dev/null @@ -1,13 +0,0 @@ -package ch.fhnw.deardevbackend.dto; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.List; - -@Data -@AllArgsConstructor -public class TeamWorkKindInsightDTO { - private Integer teamId; - private List workKindInsights; -} diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/insights/EmotionInsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/insights/EmotionInsightDTO.java new file mode 100644 index 0000000..b263255 --- /dev/null +++ b/src/main/java/ch/fhnw/deardevbackend/dto/insights/EmotionInsightDTO.java @@ -0,0 +1,13 @@ +package ch.fhnw.deardevbackend.dto.insights; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class EmotionInsightDTO { + private Integer emotionId; + private String emotionName; + private Long userCount; + private Long teamCount; +} diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/HappinessInsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/insights/HappinessInsightDTO.java similarity index 56% rename from src/main/java/ch/fhnw/deardevbackend/dto/HappinessInsightDTO.java rename to src/main/java/ch/fhnw/deardevbackend/dto/insights/HappinessInsightDTO.java index 4f7778a..c256eed 100644 --- a/src/main/java/ch/fhnw/deardevbackend/dto/HappinessInsightDTO.java +++ b/src/main/java/ch/fhnw/deardevbackend/dto/insights/HappinessInsightDTO.java @@ -1,4 +1,4 @@ -package ch.fhnw.deardevbackend.dto; +package ch.fhnw.deardevbackend.dto.insights; import lombok.AllArgsConstructor; import lombok.Data; @@ -7,6 +7,6 @@ @AllArgsConstructor public class HappinessInsightDTO { private String day; - private double userAverage; - private double teamAverage; + private Double userAverage; + private Double teamAverage; } diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/insights/InsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/insights/InsightDTO.java new file mode 100644 index 0000000..cb27a32 --- /dev/null +++ b/src/main/java/ch/fhnw/deardevbackend/dto/insights/InsightDTO.java @@ -0,0 +1,17 @@ +package ch.fhnw.deardevbackend.dto.insights; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; + +@Data +@AllArgsConstructor +public class InsightDTO { + private List happinessInsights; + private List workKindInsights; + private List emotionInsights; + private List workKindCountPerDayInsights; + private double userAverageHappiness; + private double teamAverageHappiness; +} diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/insights/WorkKindCountPerDayInsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/insights/WorkKindCountPerDayInsightDTO.java new file mode 100644 index 0000000..7423efd --- /dev/null +++ b/src/main/java/ch/fhnw/deardevbackend/dto/insights/WorkKindCountPerDayInsightDTO.java @@ -0,0 +1,12 @@ +package ch.fhnw.deardevbackend.dto.insights; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class WorkKindCountPerDayInsightDTO { + private Integer workKindCount; + private Double userAverageHappiness; + private Double teamAverageHappiness; +} diff --git a/src/main/java/ch/fhnw/deardevbackend/dto/WorkKindInsightDTO.java b/src/main/java/ch/fhnw/deardevbackend/dto/insights/WorkKindInsightDTO.java similarity index 52% rename from src/main/java/ch/fhnw/deardevbackend/dto/WorkKindInsightDTO.java rename to src/main/java/ch/fhnw/deardevbackend/dto/insights/WorkKindInsightDTO.java index c47edee..96e1895 100644 --- a/src/main/java/ch/fhnw/deardevbackend/dto/WorkKindInsightDTO.java +++ b/src/main/java/ch/fhnw/deardevbackend/dto/insights/WorkKindInsightDTO.java @@ -1,4 +1,4 @@ -package ch.fhnw.deardevbackend.dto; +package ch.fhnw.deardevbackend.dto.insights; import lombok.AllArgsConstructor; import lombok.Data; @@ -6,9 +6,10 @@ @Data @AllArgsConstructor public class WorkKindInsightDTO { - private Integer teamId; private Integer workKindId; private String workKindName; - private Double averageHappiness; - private Long totalCount; + private Double userAverage; + private Long userCount; + private Double teamAverage; + private Long teamCount; } diff --git a/src/main/java/ch/fhnw/deardevbackend/entities/EmotionSurvey.java b/src/main/java/ch/fhnw/deardevbackend/entities/EmotionSurvey.java index e6699d6..83bb2f3 100644 --- a/src/main/java/ch/fhnw/deardevbackend/entities/EmotionSurvey.java +++ b/src/main/java/ch/fhnw/deardevbackend/entities/EmotionSurvey.java @@ -6,6 +6,8 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; + @Entity @NoArgsConstructor @AllArgsConstructor @@ -21,13 +23,8 @@ public class EmotionSurvey { private Integer userId; @Column(name = "submitted", columnDefinition = "TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - private String submitted; + private LocalDateTime submitted; @Column(name = "emotion_id") private Integer emotionId; - - - - - } diff --git a/src/main/java/ch/fhnw/deardevbackend/entities/WorkKindSurvey.java b/src/main/java/ch/fhnw/deardevbackend/entities/WorkKindSurvey.java index c47b874..5119069 100644 --- a/src/main/java/ch/fhnw/deardevbackend/entities/WorkKindSurvey.java +++ b/src/main/java/ch/fhnw/deardevbackend/entities/WorkKindSurvey.java @@ -6,6 +6,8 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; + @Entity @NoArgsConstructor @AllArgsConstructor @@ -21,7 +23,7 @@ public class WorkKindSurvey { private Integer userId; @Column(name = "submitted", columnDefinition = "TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - private String submitted; + private LocalDateTime submitted; @Column(name = "score") private Integer score; diff --git a/src/main/java/ch/fhnw/deardevbackend/mapper/HappinessInsightMapper.java b/src/main/java/ch/fhnw/deardevbackend/mapper/HappinessInsightMapper.java index dbf3c91..a6211c6 100644 --- a/src/main/java/ch/fhnw/deardevbackend/mapper/HappinessInsightMapper.java +++ b/src/main/java/ch/fhnw/deardevbackend/mapper/HappinessInsightMapper.java @@ -2,7 +2,7 @@ -import ch.fhnw.deardevbackend.dto.HappinessInsightDTO; +import ch.fhnw.deardevbackend.dto.insights.HappinessInsightDTO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; diff --git a/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitEmotionSurveyMapper.java b/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitEmotionSurveyMapper.java index a673c5d..6663f02 100644 --- a/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitEmotionSurveyMapper.java +++ b/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitEmotionSurveyMapper.java @@ -11,7 +11,7 @@ public interface SubmitEmotionSurveyMapper { SubmitEmotionSurveyMapper INSTANCE = Mappers.getMapper(SubmitEmotionSurveyMapper.class); - @Mapping(target = "submitted", expression = "java(java.time.OffsetDateTime.now().toString())") + @Mapping(target = "submitted", expression = "java(java.time.LocalDateTime.now())") EmotionSurvey toEmotionSurvey(SubmitEmotionSurveyDTO dto); } diff --git a/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitWorkKindSurveyMapper.java b/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitWorkKindSurveyMapper.java index e0230ee..cded284 100644 --- a/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitWorkKindSurveyMapper.java +++ b/src/main/java/ch/fhnw/deardevbackend/mapper/SubmitWorkKindSurveyMapper.java @@ -12,7 +12,7 @@ public interface SubmitWorkKindSurveyMapper { SubmitWorkKindSurveyMapper INSTANCE = Mappers.getMapper(SubmitWorkKindSurveyMapper.class); - @Mapping(target = "submitted", expression = "java(java.time.OffsetDateTime.now().toString())") + @Mapping(target = "submitted", expression = "java(java.time.LocalDateTime.now())") WorkKindSurvey toWorkKindSurvey(SubmitWorkKindSurveyDTO dto); } diff --git a/src/main/java/ch/fhnw/deardevbackend/mapper/WorkKindInsightMapper.java b/src/main/java/ch/fhnw/deardevbackend/mapper/WorkKindInsightMapper.java index b93d78d..ceb3e6f 100644 --- a/src/main/java/ch/fhnw/deardevbackend/mapper/WorkKindInsightMapper.java +++ b/src/main/java/ch/fhnw/deardevbackend/mapper/WorkKindInsightMapper.java @@ -1,6 +1,6 @@ package ch.fhnw.deardevbackend.mapper; -import ch.fhnw.deardevbackend.dto.WorkKindInsightDTO; +import ch.fhnw.deardevbackend.dto.insights.WorkKindInsightDTO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @@ -9,10 +9,23 @@ public interface WorkKindInsightMapper { WorkKindInsightMapper INSTANCE = Mappers.getMapper(WorkKindInsightMapper.class); - @Mapping(source = "teamId", target = "teamId") @Mapping(source = "workKindId", target = "workKindId") @Mapping(source = "workKindName", target = "workKindName") - @Mapping(source = "averageHappiness", target = "averageHappiness") - @Mapping(source = "totalCount", target = "totalCount") - WorkKindInsightDTO toDTO(Integer teamId, Integer workKindId, String workKindName, Double averageHappiness, Long totalCount); + @Mapping(source = "userAverage", target = "userAverage") + @Mapping(source = "userCount", target = "userCount") + @Mapping(source = "teamAverage", target = "teamAverage") + @Mapping(source = "teamCount", target = "teamCount") + WorkKindInsightDTO toDTO(Integer workKindId, String workKindName, Double userAverage, Long userCount, Double teamAverage, Long teamCount); + + @Mapping(source = "workKindId", target = "workKindId") + @Mapping(source = "workKindName", target = "workKindName") + @Mapping(source = "userAverage", target = "userAverage") + @Mapping(source = "userCount", target = "userCount") + WorkKindInsightDTO toUserDTO(Integer workKindId, String workKindName, Double userAverage, Long userCount); + + @Mapping(source = "workKindId", target = "workKindId") + @Mapping(source = "workKindName", target = "workKindName") + @Mapping(source = "teamAverage", target = "teamAverage") + @Mapping(source = "teamCount", target = "teamCount") + WorkKindInsightDTO toTeamDTO(Integer workKindId, String workKindName, Double teamAverage, Long teamCount); } diff --git a/src/main/java/ch/fhnw/deardevbackend/repositories/InsightsRepository.java b/src/main/java/ch/fhnw/deardevbackend/repositories/InsightsRepository.java index 53b0c5b..f131e59 100644 --- a/src/main/java/ch/fhnw/deardevbackend/repositories/InsightsRepository.java +++ b/src/main/java/ch/fhnw/deardevbackend/repositories/InsightsRepository.java @@ -13,14 +13,7 @@ @Repository public interface InsightsRepository extends JpaRepository { - @Query("SELECT wk.teamId, ws.workKindId, wk.name as workKindName, AVG(ws.score) as averageHappiness, COUNT(ws.workKindId) as totalCount " + - "FROM WorkKindSurvey ws " + - "JOIN WorkKind wk ON ws.workKindId = wk.id " + - "WHERE ws.userId = :userId " + - "GROUP BY wk.teamId, ws.workKindId, wk.name " + - "ORDER BY wk.teamId, ws.workKindId") - List findWorkKindHappinessByUserId(Integer userId); - + // overall happiness - no daterange @Query("SELECT CAST(submitted AS DATE) as day, AVG(score) as average " + "FROM HappinessSurvey " + "WHERE userId IN (SELECT userId FROM TeamMember WHERE teamId = ?1) " + @@ -28,6 +21,7 @@ public interface InsightsRepository extends JpaRepository findTeamDailyAveragesExcludingUser(Integer teamId, Integer userId); + // overall happiness - with daterange @Query("SELECT CAST(h.submitted AS DATE) as day, AVG(h.score) as average " + "FROM HappinessSurvey h " + "WHERE h.userId IN (SELECT tm.userId FROM TeamMember tm WHERE tm.teamId = :teamId) " + @@ -37,4 +31,150 @@ public interface InsightsRepository extends JpaRepository findTeamDailyAveragesExcludingUserAndDateRange(@Param("teamId") Integer teamId, @Param("userId") Integer userId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); + + // work kinds for a user with date range + @Query("SELECT wk.id as workKindId, wk.name as workKindName, " + + "AVG(ws.score) as userAverage, COUNT(ws.workKindId) as userCount " + + "FROM WorkKindSurvey ws " + + "JOIN WorkKind wk ON ws.workKindId = wk.id " + + "WHERE ws.userId = :userId " + + "AND ws.submitted BETWEEN :startDate AND :endDate " + + "GROUP BY wk.id, wk.name " + + "ORDER BY userCount DESC, userAverage DESC") + List findTopWorkKindsByUserAndDateRange(@Param("userId") Integer userId, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate); + + // work kinds for a team with date range (excluding the specific user) + @Query("SELECT wk.id as workKindId, wk.name as workKindName, " + + "AVG(ws.score) as teamAverage, COUNT(ws.workKindId) as teamCount " + + "FROM WorkKindSurvey ws " + + "JOIN WorkKind wk ON ws.workKindId = wk.id " + + "WHERE ws.userId IN (SELECT tm.userId FROM TeamMember tm WHERE tm.teamId = :teamId) " + + "AND ws.userId != :userId " + + "AND ws.submitted BETWEEN :startDate AND :endDate " + + "GROUP BY wk.id, wk.name " + + "ORDER BY teamCount DESC, teamAverage DESC") + List findTopWorkKindsByTeamAndDateRange(@Param("teamId") Integer teamId, + @Param("userId") Integer userId, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate); + + // work kinds for a user without date range + @Query("SELECT wk.id as workKindId, wk.name as workKindName, " + + "AVG(ws.score) as userAverage, COUNT(ws.workKindId) as userCount " + + "FROM WorkKindSurvey ws " + + "JOIN WorkKind wk ON ws.workKindId = wk.id " + + "WHERE ws.userId = :userId " + + "GROUP BY wk.id, wk.name " + + "ORDER BY userCount DESC, userAverage DESC") + List findTopWorkKindsByUser(@Param("userId") Integer userId); + + // work kinds for a team without date range (excluding the specific user) + @Query("SELECT wk.id as workKindId, wk.name as workKindName, " + + "AVG(ws.score) as teamAverage, COUNT(ws.workKindId) as teamCount " + + "FROM WorkKindSurvey ws " + + "JOIN WorkKind wk ON ws.workKindId = wk.id " + + "WHERE ws.userId IN (SELECT tm.userId FROM TeamMember tm WHERE tm.teamId = :teamId) " + + "AND ws.userId != :userId " + + "GROUP BY wk.id, wk.name " + + "ORDER BY teamCount DESC, teamAverage DESC") + List findTopWorkKindsByTeam(@Param("teamId") Integer teamId, @Param("userId") Integer userId); + + + // Fetch most voted emotions for the user with date range + @Query("SELECT e.emotionId, em.name, COUNT(e.emotionId) as userCount " + + "FROM EmotionSurvey e " + + "JOIN Emotion em ON e.emotionId = em.id " + + "WHERE e.userId = :userId " + + "AND e.submitted BETWEEN :startDate AND :endDate " + + "GROUP BY e.emotionId, em.name " + + "ORDER BY userCount DESC") + List findTopEmotionsByUserAndDateRange(@Param("userId") Integer userId, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate); + + // Fetch most voted emotions for the team with date range + @Query("SELECT e.emotionId, em.name, COUNT(e.emotionId) as teamCount " + + "FROM EmotionSurvey e " + + "JOIN Emotion em ON e.emotionId = em.id " + + "WHERE e.userId IN (SELECT tm.userId FROM TeamMember tm WHERE tm.teamId = :teamId) " + + "AND e.userId != :userId " + + "AND e.submitted BETWEEN :startDate AND :endDate " + + "GROUP BY e.emotionId, em.name " + + "ORDER BY teamCount DESC") + List findTopEmotionsByTeamAndDateRange(@Param("teamId") Integer teamId, + @Param("userId") Integer userId, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate); + + // Fetch most voted emotions for the user without date range + @Query("SELECT e.emotionId, em.name, COUNT(e.emotionId) as userCount " + + "FROM EmotionSurvey e " + + "JOIN Emotion em ON e.emotionId = em.id " + + "WHERE e.userId = :userId " + + "GROUP BY e.emotionId, em.name " + + "ORDER BY userCount DESC") + List findTopEmotionsByUser(@Param("userId") Integer userId); + + // Fetch most voted emotions for the team without date range + @Query("SELECT e.emotionId, em.name, COUNT(e.emotionId) as teamCount " + + "FROM EmotionSurvey e " + + "JOIN Emotion em ON e.emotionId = em.id " + + "WHERE e.userId IN (SELECT tm.userId FROM TeamMember tm WHERE tm.teamId = :teamId) " + + "AND e.userId != :userId " + + "GROUP BY e.emotionId, em.name " + + "ORDER BY teamCount DESC") + List findTopEmotionsByTeam(@Param("teamId") Integer teamId, @Param("userId") Integer userId); + + + // Fetch user work kind count and average happiness by day with date range + @Query("SELECT COUNT(DISTINCT wks.workKindId) AS workKindCount, AVG(hs.score) AS userAverageHappiness " + + "FROM WorkKindSurvey wks " + + "JOIN HappinessSurvey hs ON wks.userId = hs.userId " + + "AND CAST(wks.submitted AS DATE) = CAST(hs.submitted AS DATE) " + + "WHERE wks.userId = :userId " + + "AND wks.submitted BETWEEN :startDate AND :endDate " + + "GROUP BY CAST(wks.submitted AS DATE) " + + "ORDER BY workKindCount") + List findUserWorkKindCountAndHappinessByDateRange(@Param("userId") Integer userId, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate); + + // Fetch team work kind count and average happiness by day with date range + @Query("SELECT COUNT(DISTINCT wks.workKindId) AS workKindCount, AVG(hs.score) AS teamAverageHappiness " + + "FROM WorkKindSurvey wks " + + "JOIN HappinessSurvey hs ON wks.userId = hs.userId " + + "AND CAST(wks.submitted AS DATE) = CAST(hs.submitted AS DATE) " + + "WHERE wks.userId IN (SELECT tm.userId FROM TeamMember tm WHERE tm.teamId = :teamId) " + + "AND wks.userId != :userId " + + "AND wks.submitted BETWEEN :startDate AND :endDate " + + "GROUP BY CAST(wks.submitted AS DATE) " + + "ORDER BY workKindCount") + List findTeamWorkKindCountAndHappinessByDateRange(@Param("teamId") Integer teamId, + @Param("userId") Integer userId, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate); + + // Fetch user work kind count and average happiness by day without date range + @Query("SELECT COUNT(DISTINCT wks.workKindId) AS workKindCount, AVG(hs.score) AS userAverageHappiness " + + "FROM WorkKindSurvey wks " + + "JOIN HappinessSurvey hs ON wks.userId = hs.userId " + + "AND CAST(wks.submitted AS DATE) = CAST(hs.submitted AS DATE) " + + "WHERE wks.userId = :userId " + + "GROUP BY CAST(wks.submitted AS DATE) " + + "ORDER BY workKindCount") + List findUserWorkKindCountAndHappiness(@Param("userId") Integer userId); + + // Fetch team work kind count and average happiness by day without date range + @Query("SELECT COUNT(DISTINCT wks.workKindId) AS workKindCount, AVG(hs.score) AS teamAverageHappiness " + + "FROM WorkKindSurvey wks " + + "JOIN HappinessSurvey hs ON wks.userId = hs.userId " + + "AND CAST(wks.submitted AS DATE) = CAST(hs.submitted AS DATE) " + + "WHERE wks.userId IN (SELECT tm.userId FROM TeamMember tm WHERE tm.teamId = :teamId) " + + "AND wks.userId != :userId " + + "GROUP BY CAST(wks.submitted AS DATE) " + + "ORDER BY workKindCount") + List findTeamWorkKindCountAndHappiness(@Param("teamId") Integer teamId, @Param("userId") Integer userId); + } diff --git a/src/main/java/ch/fhnw/deardevbackend/repositories/WorkKindSurveyRepository.java b/src/main/java/ch/fhnw/deardevbackend/repositories/WorkKindSurveyRepository.java index 217ebce..2af30dc 100644 --- a/src/main/java/ch/fhnw/deardevbackend/repositories/WorkKindSurveyRepository.java +++ b/src/main/java/ch/fhnw/deardevbackend/repositories/WorkKindSurveyRepository.java @@ -3,6 +3,7 @@ import ch.fhnw.deardevbackend.entities.WorkKindSurvey; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; @@ -24,4 +25,6 @@ public interface WorkKindSurveyRepository extends JpaRepository findAverageHappinessScoreByWorkKindIdAndUserId(Integer workKindId, Integer userId); + @Query("SELECT COUNT(DISTINCT wk.id) FROM WorkKind wk WHERE wk.teamId = :teamId") + int findDistinctWorkKindCountByTeamId(@Param("teamId") Integer teamId); } diff --git a/src/main/java/ch/fhnw/deardevbackend/services/InsightsService.java b/src/main/java/ch/fhnw/deardevbackend/services/InsightsService.java index 2a6071d..4cec77d 100644 --- a/src/main/java/ch/fhnw/deardevbackend/services/InsightsService.java +++ b/src/main/java/ch/fhnw/deardevbackend/services/InsightsService.java @@ -1,7 +1,7 @@ package ch.fhnw.deardevbackend.services; import ch.fhnw.deardevbackend.annotations.ValidateUserIdParam; -import ch.fhnw.deardevbackend.dto.*; +import ch.fhnw.deardevbackend.dto.insights.*; import ch.fhnw.deardevbackend.mapper.HappinessInsightMapper; import ch.fhnw.deardevbackend.mapper.WorkKindInsightMapper; import ch.fhnw.deardevbackend.repositories.*; @@ -11,9 +11,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import java.time.format.DateTimeFormatter; @@ -22,19 +20,19 @@ public class InsightsService { private final InsightsRepository insightsRepository; private final HappinessSurveyRepository happinessSurveyRepository; - private final TeamMemberRepository teamMemberRepository; + private final WorkKindSurveyRepository workKindSurveyRepository; private final HappinessInsightMapper happinessInsightMapper; private final WorkKindInsightMapper workKindInsightMapper; public InsightsService(InsightsRepository insightsRepository, HappinessSurveyRepository happinessSurveyRepository, - TeamMemberRepository teamMemberRepository, HappinessInsightMapper happinessInsightMapper, - WorkKindInsightMapper workKindInsightMapper) { + WorkKindInsightMapper workKindInsightMapper, + WorkKindSurveyRepository workKindSurveyRepository) { this.insightsRepository = insightsRepository; this.happinessSurveyRepository = happinessSurveyRepository; - this.teamMemberRepository = teamMemberRepository; + this.workKindSurveyRepository = workKindSurveyRepository; this.happinessInsightMapper = happinessInsightMapper; this.workKindInsightMapper = workKindInsightMapper; } @@ -42,13 +40,26 @@ public InsightsService(InsightsRepository insightsRepository, @Transactional(readOnly = true) public InsightDTO getInsightsByTeamAndSprint(@ValidateUserIdParam Integer userId, Integer teamId, String sprint) { List happinessInsights = getHappinessInsightsByTeam(userId, teamId, sprint); - List workKindInsights = getWorkKindInsightsByUserId(userId); + List workKindInsights = getWorkKindInsightsByUserAndTeam(userId, teamId, sprint); + List emotionInsights = getEmotionInsightsByUserAndTeam(userId, teamId, sprint); + List workKindCountPerDayInsights = getWorkKindCountPerDayInsights(userId, teamId, sprint); - return new InsightDTO(happinessInsights, workKindInsights); + + double userAverageHappiness = calculateAverageHappiness(happinessInsights, true); + double teamAverageHappiness = calculateAverageHappiness(happinessInsights, false); + + return new InsightDTO(happinessInsights, workKindInsights, emotionInsights, workKindCountPerDayInsights, userAverageHappiness, teamAverageHappiness); } + + ///// Happiness insights + @Transactional(readOnly = true) public List getHappinessInsightsByTeam(@ValidateUserIdParam Integer userId, Integer teamId, String sprint) { +// todo +// LocalDateTime startDate = getSprintStartDate(sprint); +// LocalDateTime endDate = getSprintEndDate(sprint); + LocalDateTime startDate = null; LocalDateTime endDate = LocalDateTime.now(); @@ -94,33 +105,251 @@ public List getHappinessInsightsByTeam(@ValidateUserIdParam double teamAverage = teamAveragesMap.getOrDefault(day, 0.0); return happinessInsightMapper.toDTO(day, userAverage, teamAverage); }) + .filter(Objects::nonNull) .sorted(Comparator.comparing(h -> LocalDate.parse(h.getDay(), DateTimeFormatter.ISO_DATE))) .collect(Collectors.toList()); } - // todo later asap structure is defined - private WorkKindInsightDTO findMatchingWorkKindInsight(HappinessInsightDTO happinessInsightDTO, List workKindInsights) { - return workKindInsights.stream() - // .filter(workKindInsightDTO -> workKindInsightDTO.getTeamId().equals(happinessInsightDTO.getTeamId())) - .findFirst() - .orElse(null); + private double calculateAverageHappiness(List insights, boolean isUser) { + return insights.stream() + .mapToDouble(insight -> isUser ? insight.getUserAverage() : insight.getTeamAverage()) + .average() + .orElse(0.0); + } + + ///// Workkind insights + + @Transactional(readOnly = true) + public List getWorkKindInsightsByUserAndTeam(@ValidateUserIdParam Integer userId, Integer teamId, String sprint) { + // later todo + // LocalDateTime startDate = getSprintStartDate(sprint); + // LocalDateTime endDate = getSprintEndDate(sprint); + + LocalDateTime startDate = null; + LocalDateTime endDate = LocalDateTime.now(); + + + switch (sprint.toLowerCase()) { + case "current": + startDate = LocalDateTime.now().minusWeeks(3); + break; + case "last": + startDate = LocalDateTime.now().minusWeeks(6); + endDate = LocalDateTime.now().minusWeeks(3); + break; + case "none": + default: + startDate = null; + endDate = null; + break; + } + + + List userWorkKinds; + List teamWorkKinds; + + if (startDate != null) { + userWorkKinds = insightsRepository.findTopWorkKindsByUserAndDateRange(userId, startDate, endDate); + teamWorkKinds = insightsRepository.findTopWorkKindsByTeamAndDateRange(teamId, userId, startDate, endDate); + } else { + userWorkKinds = insightsRepository.findTopWorkKindsByUser(userId); + teamWorkKinds = insightsRepository.findTopWorkKindsByTeam(teamId, userId); + } + + List userWorkKindInsights = userWorkKinds.stream() + .map(workKind -> workKindInsightMapper.toUserDTO( + (Integer) workKind[0], + (String) workKind[1], + (Double) workKind[2], + (Long) workKind[3])) + .collect(Collectors.toList()); + + List teamWorkKindInsights = teamWorkKinds.stream() + .map(workKind -> workKindInsightMapper.toTeamDTO( + (Integer) workKind[0], + (String) workKind[1], + (Double) workKind[2], + (Long) workKind[3])) + .collect(Collectors.toList()); + + // Merge user and team insights into a single list + return mergeUserAndTeamWorkKindInsights(userWorkKindInsights, teamWorkKindInsights); + } + + // Top 5 work kinds by user and team + private List mergeUserAndTeamWorkKindInsights(List userWorkKindInsights, List teamWorkKindInsights) { + Map merged = new HashMap<>(); + + for (WorkKindInsightDTO userInsight : userWorkKindInsights) { + if (userInsight != null) { + merged.put(userInsight.getWorkKindId(), userInsight); + } + } + + for (WorkKindInsightDTO teamInsight : teamWorkKindInsights) { + if (teamInsight != null) { + merged.merge(teamInsight.getWorkKindId(), teamInsight, (userDto, teamDto) -> { + return new WorkKindInsightDTO( + userDto.getWorkKindId(), + userDto.getWorkKindName(), + userDto.getUserAverage() != null ? userDto.getUserAverage() : 0.0, + userDto.getUserCount() != null ? userDto.getUserCount() : 0L, + teamDto.getTeamAverage() != null ? teamDto.getTeamAverage() : 0.0, + teamDto.getTeamCount() != null ? teamDto.getTeamCount() : 0L + ); + }); + } + } + + return merged.values().stream() + .sorted(Comparator.comparingLong((WorkKindInsightDTO dto) -> dto.getUserCount() != null ? dto.getUserCount() : 0L).reversed()) + .limit(5) + .collect(Collectors.toList()); } - // todo remove + ///// Emotion insights + @Transactional(readOnly = true) - public List getWorkKindInsightsByUserId(@ValidateUserIdParam Integer userId) { - List results = insightsRepository.findWorkKindHappinessByUserId(userId); - - return results.stream() - .map(row -> workKindInsightMapper.toDTO( - (Integer) row[0], - (Integer) row[1], - (String) row[2], - (Double) row[3], - (Long) row[4] - )) + public List getEmotionInsightsByUserAndTeam(Integer userId, Integer teamId, String sprint) { + // todo temp + LocalDateTime startDate = null; + LocalDateTime endDate = LocalDateTime.now(); + + switch (sprint.toLowerCase()) { + case "current": + startDate = LocalDateTime.now().minusWeeks(3); + break; + case "last": + startDate = LocalDateTime.now().minusWeeks(6); + endDate = LocalDateTime.now().minusWeeks(3); + break; + case "none": + default: + startDate = null; + endDate = null; + break; + } + + List userEmotions; + List teamEmotions; + + if (startDate != null) { + userEmotions = insightsRepository.findTopEmotionsByUserAndDateRange(userId, startDate, endDate); + teamEmotions = insightsRepository.findTopEmotionsByTeamAndDateRange(teamId, userId, startDate, endDate); + } else { + userEmotions = insightsRepository.findTopEmotionsByUser(userId); + teamEmotions = insightsRepository.findTopEmotionsByTeam(teamId, userId); + } + + List userEmotionInsights = userEmotions.stream() + .map(emotion -> new EmotionInsightDTO( + (Integer) emotion[0], + (String) emotion[1], + (Long) emotion[2], + 0L)) + .collect(Collectors.toList()); + + List teamEmotionInsights = teamEmotions.stream() + .map(emotion -> new EmotionInsightDTO( + (Integer) emotion[0], + (String) emotion[1], + 0L, + (Long) emotion[2])) + .collect(Collectors.toList()); + + return mergeUserAndTeamEmotionInsights(userEmotionInsights, teamEmotionInsights); + } + + private List mergeUserAndTeamEmotionInsights(List userEmotionInsights, List teamEmotionInsights) { + Map merged = new HashMap<>(); + + for (EmotionInsightDTO userInsight : userEmotionInsights) { + merged.put(userInsight.getEmotionId(), userInsight); + } + + for (EmotionInsightDTO teamInsight : teamEmotionInsights) { + merged.merge(teamInsight.getEmotionId(), teamInsight, (userDto, teamDto) -> new EmotionInsightDTO( + userDto.getEmotionId(), + userDto.getEmotionName(), + userDto.getUserCount(), + teamDto.getTeamCount() + )); + } + + return merged.values().stream() + .sorted(Comparator.comparingLong((EmotionInsightDTO dto) -> dto.getUserCount() != null ? dto.getUserCount() : 0L).reversed()) + .limit(10) .collect(Collectors.toList()); } + + ///// Workkind count per day vs. average happiness + + @Transactional(readOnly = true) + public List getWorkKindCountPerDayInsights(Integer userId, Integer teamId, String sprint) { + // todo + LocalDateTime startDate = null; + LocalDateTime endDate = LocalDateTime.now(); + + switch (sprint.toLowerCase()) { + case "current": + startDate = LocalDateTime.now().minusWeeks(3); + break; + case "last": + startDate = LocalDateTime.now().minusWeeks(6); + endDate = LocalDateTime.now().minusWeeks(3); + break; + case "none": + default: + startDate = null; + endDate = null; + break; + } + + List userResults = startDate != null + ? insightsRepository.findUserWorkKindCountAndHappinessByDateRange(userId, startDate, endDate) + : insightsRepository.findUserWorkKindCountAndHappiness(userId); + + List teamResults = startDate != null + ? insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(teamId, userId, startDate, endDate) + : insightsRepository.findTeamWorkKindCountAndHappiness(teamId, userId); + + Map> userHappinessByWorkKindCount = new HashMap<>(); + for (Object[] row : userResults) { + Integer workKindCount = ((Number) row[0]).intValue(); + Double userAverageHappiness = ((Number) row[1]).doubleValue(); + + userHappinessByWorkKindCount.computeIfAbsent(workKindCount, k -> new ArrayList<>()).add(userAverageHappiness); + } + + Map> teamHappinessByWorkKindCount = new HashMap<>(); + for (Object[] row : teamResults) { + Integer workKindCount = ((Number) row[0]).intValue(); + Double teamAverageHappiness = ((Number) row[1]).doubleValue(); + + teamHappinessByWorkKindCount.computeIfAbsent(workKindCount, k -> new ArrayList<>()).add(teamAverageHappiness); + } + + // Calculate averages for each work kind count + List insights = new ArrayList<>(); + int maxWorkKindCount = getMaxWorkKindCountForTeam(teamId); + + for (int i = 1; i <= maxWorkKindCount; i++) { + double userAverageHappiness = userHappinessByWorkKindCount.containsKey(i) ? + userHappinessByWorkKindCount.get(i).stream().mapToDouble(Double::doubleValue).average().orElse(0.0) : 0.0; + + double teamAverageHappiness = teamHappinessByWorkKindCount.containsKey(i) ? + teamHappinessByWorkKindCount.get(i).stream().mapToDouble(Double::doubleValue).average().orElse(0.0) : 0.0; + + insights.add(new WorkKindCountPerDayInsightDTO(i, userAverageHappiness, teamAverageHappiness)); + } + + return insights; + } + + private int getMaxWorkKindCountForTeam(Integer teamId) { + return workKindSurveyRepository.findDistinctWorkKindCountByTeamId(teamId); + } + } diff --git a/src/test/java/ch/fhnw/deardevbackend/services/InsightsServiceTest.java b/src/test/java/ch/fhnw/deardevbackend/services/InsightsServiceTest.java index 4ad0f68..fcffa08 100644 --- a/src/test/java/ch/fhnw/deardevbackend/services/InsightsServiceTest.java +++ b/src/test/java/ch/fhnw/deardevbackend/services/InsightsServiceTest.java @@ -1,16 +1,17 @@ package ch.fhnw.deardevbackend.services; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -import ch.fhnw.deardevbackend.dto.HappinessInsightDTO; -import ch.fhnw.deardevbackend.dto.InsightDTO; -import ch.fhnw.deardevbackend.dto.WorkKindInsightDTO; +import ch.fhnw.deardevbackend.dto.insights.HappinessInsightDTO; +import ch.fhnw.deardevbackend.dto.insights.InsightDTO; +import ch.fhnw.deardevbackend.dto.insights.WorkKindCountPerDayInsightDTO; +import ch.fhnw.deardevbackend.dto.insights.WorkKindInsightDTO; import ch.fhnw.deardevbackend.mapper.HappinessInsightMapper; import ch.fhnw.deardevbackend.mapper.WorkKindInsightMapper; import ch.fhnw.deardevbackend.repositories.InsightsRepository; import ch.fhnw.deardevbackend.repositories.HappinessSurveyRepository; +import ch.fhnw.deardevbackend.repositories.WorkKindSurveyRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -19,6 +20,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.Arrays; +import java.util.Collections; import java.util.List; @ExtendWith(MockitoExtension.class) @@ -33,6 +35,9 @@ public class InsightsServiceTest { @Mock private HappinessSurveyRepository happinessSurveyRepository; + @Mock + private WorkKindSurveyRepository workKindSurveyRepository; + @Mock private HappinessInsightMapper happinessInsightMapper; @@ -43,7 +48,10 @@ public class InsightsServiceTest { private List userAverages; private List teamAverages; - private List workKindHappinessData; + private List userWorkKinds; + private List teamWorkKinds; + private List userWorkKindCountAndHappiness; + private List teamWorkKindCountAndHappiness; private WorkKindInsightDTO workKindInsightDTO1; private WorkKindInsightDTO workKindInsightDTO2; private WorkKindInsightDTO workKindInsightDTO3; @@ -64,21 +72,35 @@ void setUp() { new Object[]{"2024-07-29", 3.0} ); - workKindHappinessData = Arrays.asList( - new Object[]{1, 1, "Development", 4.5, 10L}, - new Object[]{1, 2, "Testing", 3.5, 5L}, - new Object[]{2, 1, "Development", 4.0, 8L}, - new Object[]{2, 2, "Testing", 3.0, 6L} + userWorkKinds = Arrays.asList( + new Object[]{1, "Development", 4.5, 10L}, + new Object[]{2, "Testing", 3.5, 5L} + ); + teamWorkKinds = Arrays.asList( + new Object[]{1, "Development", 4.0, 8L}, + new Object[]{2, "Testing", 3.0, 6L} + ); + + userWorkKindCountAndHappiness = Arrays.asList( + new Object[]{1, 4.0}, + new Object[]{2, 5.0}, + new Object[]{3, 6.0} + ); + teamWorkKindCountAndHappiness = Arrays.asList( + new Object[]{1, 3.0}, + new Object[]{2, 2.5}, + new Object[]{3, 4.0} ); - workKindInsightDTO1 = new WorkKindInsightDTO(1, 1, "Development", 4.5, 10L); - workKindInsightDTO2 = new WorkKindInsightDTO(1, 2, "Testing", 3.5, 5L); - workKindInsightDTO3 = new WorkKindInsightDTO(2, 1, "Development", 4.0, 8L); - workKindInsightDTO4 = new WorkKindInsightDTO(2, 2, "Testing", 3.0, 6L); + workKindInsightDTO1 = new WorkKindInsightDTO(1, "Development", 4.5, 10L, 0.0, 0L); + workKindInsightDTO2 = new WorkKindInsightDTO(2, "Testing", 3.5, 5L, 0.0, 0L); + workKindInsightDTO3 = new WorkKindInsightDTO(1, "Development", 0.0, 0L, 4.0, 8L); + workKindInsightDTO4 = new WorkKindInsightDTO(2, "Testing", 0.0, 0L, 3.0, 6L); } + @Test - void getInsightsByTeamAndSprint_success() { + void getInsightsByTeamAndSprint() { Integer teamId = 1; String sprint = "current"; @@ -88,30 +110,46 @@ void getInsightsByTeamAndSprint_success() { when(happinessInsightMapper.toDTO("2024-07-28", 5.0, 2.0)).thenReturn(new HappinessInsightDTO("2024-07-28", 5.0, 2.0)); when(happinessInsightMapper.toDTO("2024-07-29", 6.0, 3.0)).thenReturn(new HappinessInsightDTO("2024-07-29", 6.0, 3.0)); - when(insightsRepository.findWorkKindHappinessByUserId(userId)).thenReturn(workKindHappinessData); - when(workKindInsightMapper.toDTO(1, 1, "Development", 4.5, 10L)).thenReturn(workKindInsightDTO1); - when(workKindInsightMapper.toDTO(1, 2, "Testing", 3.5, 5L)).thenReturn(workKindInsightDTO2); - when(workKindInsightMapper.toDTO(2, 1, "Development", 4.0, 8L)).thenReturn(workKindInsightDTO3); - when(workKindInsightMapper.toDTO(2, 2, "Testing", 3.0, 6L)).thenReturn(workKindInsightDTO4); + when(insightsRepository.findTopWorkKindsByUserAndDateRange(eq(userId), any(), any())).thenReturn(userWorkKinds); + when(insightsRepository.findTopWorkKindsByTeamAndDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(teamWorkKinds); + when(workKindInsightMapper.toUserDTO(1, "Development", 4.5, 10L)).thenReturn(workKindInsightDTO1); + when(workKindInsightMapper.toUserDTO(2, "Testing", 3.5, 5L)).thenReturn(workKindInsightDTO2); + when(workKindInsightMapper.toTeamDTO(1, "Development", 4.0, 8L)).thenReturn(workKindInsightDTO3); + when(workKindInsightMapper.toTeamDTO(2, "Testing", 3.0, 6L)).thenReturn(workKindInsightDTO4); + + // Mocking for the new method + when(insightsRepository.findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any())).thenReturn(userWorkKindCountAndHappiness); + when(insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(teamWorkKindCountAndHappiness); + when(workKindSurveyRepository.findDistinctWorkKindCountByTeamId(eq(teamId))).thenReturn(3); InsightDTO result = insightsService.getInsightsByTeamAndSprint(userId, teamId, sprint); assertNotNull(result); assertNotNull(result.getHappinessInsights()); assertNotNull(result.getWorkKindInsights()); + assertNotNull(result.getWorkKindCountPerDayInsights()); assertEquals(3, result.getHappinessInsights().size()); - assertEquals(4, result.getWorkKindInsights().size()); + assertEquals(2, result.getWorkKindInsights().size()); + assertEquals(3, result.getWorkKindCountPerDayInsights().size()); verify(happinessSurveyRepository, times(1)).findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any()); verify(insightsRepository, times(1)).findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId), eq(userId), any(), any()); verify(happinessInsightMapper, times(3)).toDTO(anyString(), anyDouble(), anyDouble()); - verify(insightsRepository, times(1)).findWorkKindHappinessByUserId(userId); - verify(workKindInsightMapper, times(4)).toDTO(anyInt(), anyInt(), anyString(), anyDouble(), anyLong()); + verify(insightsRepository, times(1)).findTopWorkKindsByUserAndDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTopWorkKindsByTeamAndDateRange(eq(teamId), eq(userId), any(), any()); + verify(workKindInsightMapper, times(2)).toUserDTO(anyInt(), anyString(), anyDouble(), anyLong()); + verify(workKindInsightMapper, times(2)).toTeamDTO(anyInt(), anyString(), anyDouble(), anyLong()); + + // New verifications + verify(insightsRepository, times(1)).findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any()); + verify(workKindSurveyRepository, times(1)).findDistinctWorkKindCountByTeamId(eq(teamId)); } + @Test - void getHappinessInsightsByTeam_success() { + void getHappinessInsightsByTeam() { Integer teamId = 1; String sprint = "current"; @@ -126,9 +164,9 @@ void getHappinessInsightsByTeam_success() { assertNotNull(result); assertEquals(3, result.size()); - assertEquals("2024-07-27", result.getFirst().getDay()); - assertEquals(5.0, result.getFirst().getUserAverage()); - assertEquals(4.0, result.getFirst().getTeamAverage()); + assertEquals("2024-07-27", result.get(0).getDay()); + assertEquals(5.0, result.get(0).getUserAverage()); + assertEquals(4.0, result.get(0).getTeamAverage()); assertEquals("2024-07-28", result.get(1).getDay()); assertEquals(5.0, result.get(1).getUserAverage()); @@ -144,4 +182,252 @@ void getHappinessInsightsByTeam_success() { } + @Test + void getInsightsByTeamAndSprint_noData() { + Integer teamId = 1; + String sprint = "current"; + + // Mock repository methods to return empty lists + when(happinessSurveyRepository.findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTopWorkKindsByUserAndDateRange(eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTopWorkKindsByTeamAndDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(workKindSurveyRepository.findDistinctWorkKindCountByTeamId(eq(teamId))).thenReturn(0); // Return 0 for no work kinds + + // Execute the service method + InsightDTO result = insightsService.getInsightsByTeamAndSprint(userId, teamId, sprint); + + // Assertions to check for empty results + assertNotNull(result); + assertTrue(result.getHappinessInsights().isEmpty(), "Happiness insights should be empty"); + assertTrue(result.getWorkKindInsights().isEmpty(), "Work kind insights should be empty"); + assertTrue(result.getWorkKindCountPerDayInsights().isEmpty(), "Work kind count per day insights should be empty"); + + // Verify that the repository methods were called + verify(happinessSurveyRepository, times(1)).findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId), eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTopWorkKindsByUserAndDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTopWorkKindsByTeamAndDateRange(eq(teamId), eq(userId), any(), any()); + verify(insightsRepository, times(1)).findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any()); + verify(workKindSurveyRepository, times(1)).findDistinctWorkKindCountByTeamId(eq(teamId)); + } + + @Test + void getInsightsByTeamAndSprint_multipleTeams() { + Integer teamId1 = 1; + Integer teamId2 = 2; + String sprint = "current"; + + List userAveragesTeam1 = Arrays.asList( + new Object[]{"2024-07-27", 5.0}, + new Object[]{"2024-07-28", 5.0}, + new Object[]{"2024-07-29", 6.0} + ); + + List teamAveragesTeam1 = Arrays.asList( + new Object[]{"2024-07-27", 4.0}, + new Object[]{"2024-07-28", 2.0}, + new Object[]{"2024-07-29", 3.0} + ); + + List userAveragesTeam2 = Arrays.asList( + new Object[]{"2024-07-27", 6.0}, + new Object[]{"2024-07-28", 7.0}, + new Object[]{"2024-07-29", 5.5} + ); + + List teamAveragesTeam2 = Arrays.asList( + new Object[]{"2024-07-27", 5.5}, + new Object[]{"2024-07-28", 6.0}, + new Object[]{"2024-07-29", 4.0} + ); + + List userWorkKindCountAndHappinessTeam1 = Arrays.asList( + new Object[]{1, 4.0}, + new Object[]{2, 5.0}, + new Object[]{3, 6.0} + ); + + List teamWorkKindCountAndHappinessTeam1 = Arrays.asList( + new Object[]{1, 3.0}, + new Object[]{2, 2.5}, + new Object[]{3, 4.0} + ); + + List userWorkKindCountAndHappinessTeam2 = Arrays.asList( + new Object[]{1, 5.0}, + new Object[]{2, 6.0}, + new Object[]{3, 7.0} + ); + + List teamWorkKindCountAndHappinessTeam2 = Arrays.asList( + new Object[]{1, 4.5}, + new Object[]{2, 5.0}, + new Object[]{3, 6.0} + ); + + // Setup mocks for team 1 + when(happinessSurveyRepository.findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any())) + .thenReturn(userAveragesTeam1); + when(insightsRepository.findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId1), eq(userId), any(), any())) + .thenReturn(teamAveragesTeam1); + when(happinessInsightMapper.toDTO("2024-07-27", 5.0, 4.0)) + .thenReturn(new HappinessInsightDTO("2024-07-27", 5.0, 4.0)); + when(happinessInsightMapper.toDTO("2024-07-28", 5.0, 2.0)) + .thenReturn(new HappinessInsightDTO("2024-07-28", 5.0, 2.0)); + when(happinessInsightMapper.toDTO("2024-07-29", 6.0, 3.0)) + .thenReturn(new HappinessInsightDTO("2024-07-29", 6.0, 3.0)); + + when(insightsRepository.findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any())).thenReturn(userWorkKindCountAndHappinessTeam1); + when(insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(eq(teamId1), eq(userId), any(), any())).thenReturn(teamWorkKindCountAndHappinessTeam1); + when(workKindSurveyRepository.findDistinctWorkKindCountByTeamId(eq(teamId1))).thenReturn(3); + + // Execute the service method for team 1 + InsightDTO resultTeam1 = insightsService.getInsightsByTeamAndSprint(userId, teamId1, sprint); + + // Verify the results for team 1 + assertNotNull(resultTeam1); + assertEquals(3, resultTeam1.getHappinessInsights().size()); + assertEquals(3, resultTeam1.getWorkKindCountPerDayInsights().size()); + + verify(happinessSurveyRepository, times(1)).findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId1), eq(userId), any(), any()); + verify(happinessInsightMapper, times(3)).toDTO(anyString(), anyDouble(), anyDouble()); + verify(insightsRepository, times(1)).findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamWorkKindCountAndHappinessByDateRange(eq(teamId1), eq(userId), any(), any()); + verify(workKindSurveyRepository, times(1)).findDistinctWorkKindCountByTeamId(eq(teamId1)); + + // Reset mocks for team 2 + reset(happinessSurveyRepository, insightsRepository, happinessInsightMapper, workKindSurveyRepository); + + // Setup mocks for team 2 + when(happinessSurveyRepository.findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any())) + .thenReturn(userAveragesTeam2); + when(insightsRepository.findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId2), eq(userId), any(), any())) + .thenReturn(teamAveragesTeam2); + when(happinessInsightMapper.toDTO("2024-07-27", 6.0, 5.5)) + .thenReturn(new HappinessInsightDTO("2024-07-27", 6.0, 5.5)); + when(happinessInsightMapper.toDTO("2024-07-28", 7.0, 6.0)) + .thenReturn(new HappinessInsightDTO("2024-07-28", 7.0, 6.0)); + when(happinessInsightMapper.toDTO("2024-07-29", 5.5, 4.0)) + .thenReturn(new HappinessInsightDTO("2024-07-29", 5.5, 4.0)); + + when(insightsRepository.findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any())).thenReturn(userWorkKindCountAndHappinessTeam2); + when(insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(eq(teamId2), eq(userId), any(), any())).thenReturn(teamWorkKindCountAndHappinessTeam2); + when(workKindSurveyRepository.findDistinctWorkKindCountByTeamId(eq(teamId2))).thenReturn(3); + + // Execute the service method for team 2 + InsightDTO resultTeam2 = insightsService.getInsightsByTeamAndSprint(userId, teamId2, sprint); + + // Verify the results for team 2 + assertNotNull(resultTeam2); + assertEquals(3, resultTeam2.getHappinessInsights().size()); + assertEquals(3, resultTeam2.getWorkKindCountPerDayInsights().size()); + + verify(happinessSurveyRepository, times(1)).findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId2), eq(userId), any(), any()); + verify(happinessInsightMapper, times(3)).toDTO(anyString(), anyDouble(), anyDouble()); + verify(insightsRepository, times(1)).findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamWorkKindCountAndHappinessByDateRange(eq(teamId2), eq(userId), any(), any()); + verify(workKindSurveyRepository, times(1)).findDistinctWorkKindCountByTeamId(eq(teamId2)); + } + + + @Test + void getInsightsByTeamAndSprint_emptyTeamInsights() { + Integer teamId = 1; + String sprint = "current"; + + // Mock repository methods to return data for the user but empty for the team + when(happinessSurveyRepository.findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any())).thenReturn(userAverages); + when(insightsRepository.findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTopWorkKindsByUserAndDateRange(eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTopWorkKindsByTeamAndDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(workKindSurveyRepository.findDistinctWorkKindCountByTeamId(eq(teamId))).thenReturn(0); + + // Mock happinessInsightMapper to return DTOs for user happiness + when(happinessInsightMapper.toDTO(eq("2024-07-27"), eq(5.0), eq(0.0))).thenReturn(new HappinessInsightDTO("2024-07-27", 5.0, 0.0)); + when(happinessInsightMapper.toDTO(eq("2024-07-28"), eq(5.0), eq(0.0))).thenReturn(new HappinessInsightDTO("2024-07-28", 5.0, 0.0)); + when(happinessInsightMapper.toDTO(eq("2024-07-29"), eq(6.0), eq(0.0))).thenReturn(new HappinessInsightDTO("2024-07-29", 6.0, 0.0)); + + // Execute the service method + InsightDTO result = insightsService.getInsightsByTeamAndSprint(userId, teamId, sprint); + + // Assertions to check for empty results + assertNotNull(result); + assertEquals(3, result.getHappinessInsights().size(), "User happiness insights should not be empty"); + assertTrue(result.getWorkKindInsights().isEmpty(), "Work kind insights should be empty"); + assertTrue(result.getWorkKindCountPerDayInsights().isEmpty(), "Work kind count per day insights should be empty"); + + // Verify that the repository methods were called + verify(happinessSurveyRepository, times(1)).findDailyAveragesByUserIdAndDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamDailyAveragesExcludingUserAndDateRange(eq(teamId), eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTopWorkKindsByUserAndDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTopWorkKindsByTeamAndDateRange(eq(teamId), eq(userId), any(), any()); + verify(insightsRepository, times(1)).findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any()); + verify(workKindSurveyRepository, times(1)).findDistinctWorkKindCountByTeamId(eq(teamId)); + } + + + + @Test + void getWorkKindCountPerDayInsights() { + Integer teamId = 1; + String sprint = "current"; + + when(insightsRepository.findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any())).thenReturn(userWorkKindCountAndHappiness); + when(insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(teamWorkKindCountAndHappiness); + when(workKindSurveyRepository.findDistinctWorkKindCountByTeamId(eq(teamId))).thenReturn(3); + + List result = insightsService.getWorkKindCountPerDayInsights(userId, teamId, sprint); + + assertNotNull(result); + assertEquals(3, result.size()); + + assertEquals(1, result.get(0).getWorkKindCount()); + assertEquals(4.0, result.get(0).getUserAverageHappiness()); + assertEquals(3.0, result.get(0).getTeamAverageHappiness()); + + assertEquals(2, result.get(1).getWorkKindCount()); + assertEquals(5.0, result.get(1).getUserAverageHappiness()); + assertEquals(2.5, result.get(1).getTeamAverageHappiness()); + + assertEquals(3, result.get(2).getWorkKindCount()); + assertEquals(6.0, result.get(2).getUserAverageHappiness()); + assertEquals(4.0, result.get(2).getTeamAverageHappiness()); + + verify(insightsRepository, times(1)).findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any()); + verify(workKindSurveyRepository, times(1)).findDistinctWorkKindCountByTeamId(eq(teamId)); + } + + @Test + void getWorkKindCountPerDayInsights_noData() { + Integer teamId = 1; + String sprint = "current"; + + // Mock repository methods to return empty lists + when(insightsRepository.findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(insightsRepository.findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any())).thenReturn(Collections.emptyList()); + when(workKindSurveyRepository.findDistinctWorkKindCountByTeamId(eq(teamId))).thenReturn(0); + + // Execute the service method + List result = insightsService.getWorkKindCountPerDayInsights(userId, teamId, sprint); + + // Assertions + assertNotNull(result, "Result should not be null"); + assertTrue(result.isEmpty(), "Work kind count per day insights should be empty"); + + // Verify that the repository methods were called + verify(insightsRepository, times(1)).findUserWorkKindCountAndHappinessByDateRange(eq(userId), any(), any()); + verify(insightsRepository, times(1)).findTeamWorkKindCountAndHappinessByDateRange(eq(teamId), eq(userId), any(), any()); + verify(workKindSurveyRepository, times(1)).findDistinctWorkKindCountByTeamId(eq(teamId)); + } + }