diff --git a/ddbb scripts/recommender_popularity_detailed.sql b/ddbb scripts/recommender_popularity_detailed.sql new file mode 100644 index 0000000000000000000000000000000000000000..05f2fd144d66bfc33bab093502964977a0424d6b --- /dev/null +++ b/ddbb scripts/recommender_popularity_detailed.sql @@ -0,0 +1,100 @@ +-- Created on: 16/01/2023 +-- @author: Andoni Aranguren Ubierna +-- Adaptations: 02/2023 @author: Sergio Campos + +drop procedure `recommender_popularity_detailed`; +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `recommender_popularity_detailed`(IN kpi INT, IN action INT) +BEGIN + IF ((kpi is null) and (action is NULL)) THEN + SELECT t_p_list.plan_id,p.action_id, p.action_name, p.lat, p.lon, + -- This lines are so we can get the list of kpis vvvvvvvvvv + GROUP_CONCAT(distinct t_p_list.plan_id) as plan_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_id) as kpi_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_name) as kpi_name_list, + GROUP_CONCAT(t_p_list.absolute) as kpi_absolute_list, + GROUP_CONCAT(t_p_list.relative) as kpi_relative_list, + GROUP_CONCAT(t_p_list.geographical) as kpi_geographical_list, + -- This lines are so we can get the list of kpis ^^^^^^^^^^ + p.popularity as popularity, p.category as category + FROM action p + -- This lines are so we can get the list of kpis vvvvvvvvvv + INNER JOIN chosen_action t_list ON t_list.action_id = p.action_id + INNER JOIN kpi_action_plan_detail t_p_list ON t_list.plan_id = t_p_list.plan_id + INNER JOIN action a ON a.action_id = t_p_list.action_id + -- This lines are so we can get the list of kpis ^^^^^^^^^^ + GROUP BY p.action_id + ORDER BY popularity DESC + LIMIT 100; + + ELSEIF (not(kpi is null)) THEN + SELECT t_p_list.plan_id,p.action_id, p.action_name, p.lat, p.lon, + -- This lines are so we can get the list of kpis vvvvvvvvvv + GROUP_CONCAT(distinct t_p_list.plan_id) as plan_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_id) as kpi_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_name) as kpi_name_list, + GROUP_CONCAT(t_p_list.absolute) as kpi_absolute_list, + GROUP_CONCAT(t_p_list.relative) as kpi_relative_list, + GROUP_CONCAT(t_p_list.geographical) as kpi_geographical_list, + -- This lines are so we can get the list of kpis ^^^^^^^^^^ + p.popularity as popularity, p.category as category + FROM action p + -- This lines are so we can get the list of kpis vvvvvvvvvv + INNER JOIN chosen_action t_list ON t_list.action_id = p.action_id + INNER JOIN kpi_action_plan_detail t_p_list ON t_list.plan_id = t_p_list.plan_id + INNER JOIN action a ON a.action_id = t_p_list.action_id + -- This lines are so we can get the list of kpis ^^^^^^^^^^ + WHERE t_p_list.kpi_id = kpi + GROUP BY p.action_id + ORDER BY popularity DESC + LIMIT 100; + + ELSEIF (not(action is NULL)) THEN + SELECT t_p_list.plan_id, p.action_id, p.action_name, p.lat, p.lon, + -- This lines are so we can get the list of kpis vvvvvvvvvv + GROUP_CONCAT(distinct t_p_list.plan_id) as plan_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_id) as kpi_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_name) as kpi_name_list, + GROUP_CONCAT(t_p_list.absolute) as kpi_absolute_list, + GROUP_CONCAT(t_p_list.relative) as kpi_relative_list, + GROUP_CONCAT(t_p_list.geographical) as kpi_geographical_list, + -- This lines are so we can get the list of kpis ^^^^^^^^^^ + p.popularity as popularity, p.category as category + FROM action p + -- This lines are so we can get the list of kpis vvvvvvvvvv + INNER JOIN chosen_action t_list ON t_list.action_id = p.action_id + INNER JOIN kpi_action_plan_detail t_p_list ON t_list.plan_id = t_p_list.plan_id + INNER JOIN action a ON a.action_id = t_p_list.action_id + -- This lines are so we can get the list of kpis ^^^^^^^^^^ + WHERE t_list.action_id = action + GROUP BY p.action_id + ORDER BY popularity DESC + LIMIT 100; + + ELSE + SELECT t_p_list.plan_id, p.action_id, p.action_name, p.lat, p.lon, + -- This lines are so we can get the list of kpis vvvvvvvvvv + GROUP_CONCAT(distinct t_p_list.plan_id) as plan_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_id) as kpi_id_list, + GROUP_CONCAT(distinct t_p_list.kpi_name) as kpi_name_list, + GROUP_CONCAT(t_p_list.absolute) as kpi_absolute_list, + GROUP_CONCAT(t_p_list.relative) as kpi_relative_list, + GROUP_CONCAT(t_p_list.geographical) as kpi_geographical_list, + -- This lines are so we can get the list of kpis ^^^^^^^^^^ + p.popularity as popularity, p.category as category + FROM action p + -- This lines are so we can get the list of kpis vvvvvvvvvv + INNER JOIN chosen_action t_list ON t_list.action_id = p.action_id + INNER JOIN kpi_action_plan_detail t_p_list ON t_list.plan_id = t_p_list.plan_id + INNER JOIN action a ON a.action_id = t_p_list.action_id + WHERE t_list.action_id = action AND t_p_list.kpi_id = kpi + GROUP BY p.action_id + ORDER BY popularity DESC + LIMIT 100; + + + + END IF; +END$$ +DELIMITER ; +