Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - API+APP - Posibilidad de crear tramos #254

Open
wants to merge 33 commits into
base: reporting
Choose a base branch
from
Open

Conversation

jortilles
Copy link
Collaborator

@jortilles jortilles commented Nov 19, 2024

Descripción del Cambio

Se añade la posibilidad poder definir rangos de valores sobre un campo numérico. El campo se convierte en un campo de texto. Los rangos se pueden editar.

Issue(s) resuelto(s)

Pruebas a realizar para validar el cambio

Realizar un panel con un campo numérico y definir rangos.

@jortilles jortilles self-assigned this Nov 19, 2024
@juanSTIC juanSTIC added enhancement New feature or request SinergiaDA documentation Improvements or additions to documentation labels Nov 22, 2024
Copy link
Collaborator

@PaulaaSTIC PaulaaSTIC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. En la imagen 1 se muestra el resumen de los tramos, mientras que en la imagen 2, al ejecutarse, cambia la simbología. En el resultado final (imagen 2) deberían aparecer los tramos especificados en la imagen 1.
  2. No se puede modificar ni eliminar el rango implementado. Una vez aplicado, sería necesario quitar el campo y volver a añadirlo.

1-
image
2-
image

@jortilles
Copy link
Collaborator Author

@ronaldchavezjortilles falta revisar la ordenacion

@jortilles jortilles requested a review from PaulaaSTIC December 19, 2024 12:10
@jortilles
Copy link
Collaborator Author

Ya se han resuelto los casos encontrados. Ya se puede volver a validar

Copy link
Collaborator

@PaulaaSTIC PaulaaSTIC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SELECT   CASE 
	WHEN sda_stic_payment_commitments.amount < 12 THEN '< 12' 
	WHEN sda_stic_payment_commitments.amount >= 12 AND sda_stic_payment_commitments.amount <= 14 THEN ' 12 - 14' 
	WHEN sda_stic_payment_commitments.amount >= 15 AND sda_stic_payment_commitments.amount <= 17 THEN ' 15 - 17' 
	WHEN sda_stic_payment_commitments.amount >= 18 THEN '>= 18' 
END  as `Importe`  
FROM sda_stic_payment_commitments 
group by  CASE 
	WHEN sda_stic_payment_commitments.amount < 12 THEN '< 12' 
	WHEN sda_stic_payment_commitments.amount >= 12 AND sda_stic_payment_commitments.amount <= 14 THEN ' 12 - 14' 
	WHEN sda_stic_payment_commitments.amount >= 15 AND sda_stic_payment_commitments.amount <= 17 THEN ' 15 - 17' 
	WHEN sda_stic_payment_commitments.amount >= 18 THEN '>= 18' 
END  
order by CASE 
	WHEN sda_stic_payment_commitments.amount < 12 THEN 1 
	WHEN sda_stic_payment_commitments.amount >= 12 AND sda_stic_payment_commitments.amount <= 14 THEN 2 
	WHEN sda_stic_payment_commitments.amount >= 15 AND sda_stic_payment_commitments.amount <= 17 THEN 3 
	WHEN sda_stic_payment_commitments.amount >= 18 THEN  4 
END **No**

Al ejecutar la SQL el No que se escribe después del último END genera un error de SQL, Error quering database

Copy link
Collaborator

@PaulaaSTIC PaulaaSTIC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No permite usar un rango con números negativos, -11:2:5 no deja insertar el -

@jortilles
Copy link
Collaborator Author

Los numeros negativos van en rojo

Copy link
Collaborator

@juanSTIC juanSTIC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error en la ordenación de los tramos
Aunque en la imagen que aparece al diseñar el tramo se muestra correctamente, en la consulta no aparecen ordenadas, a pesar de que el campo esté ordenado (en este caso por importe):
image

image

Copy link
Collaborator

@PaulaaSTIC PaulaaSTIC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si creamos un tramo y el campo tiene una agregación pero no hay valores asociados, el tramo debe mostrarse con un valor de 0. Esto debe suceder únicamente si existe una agregación.

image

image

La consulta que se está ejecutando actualmente es la siguiente:

SELECT   CASE
	WHEN sda_contacts.stic_age_c < 2 THEN '< 2'
	WHEN sda_contacts.stic_age_c >= 2 AND sda_contacts.stic_age_c <= 3 THEN ' 2 - 3'
	WHEN sda_contacts.stic_age_c >= 4 AND sda_contacts.stic_age_c <= 5 THEN ' 4 - 5'
	WHEN sda_contacts.stic_age_c >= 6 AND sda_contacts.stic_age_c <= 6 THEN ' 6 - 6'
	WHEN sda_contacts.stic_age_c >= 7 AND sda_contacts.stic_age_c <= 7 THEN ' 7 - 7'
	WHEN sda_contacts.stic_age_c >= 8 AND sda_contacts.stic_age_c <= 9 THEN ' 8 - 9'
	WHEN sda_contacts.stic_age_c >= 10 THEN '>= 10'
END  as `Edad`, cast( count( distinct `sda_contacts`.`first_name`) as decimal(32,0) ) as `Nombre`
FROM sda_contacts
where  (`sda_contacts`.`stic_age_c`  between
                      2 and 10 )
group by  CASE
	WHEN sda_contacts.stic_age_c < 2 THEN '< 2'
	WHEN sda_contacts.stic_age_c >= 2 AND sda_contacts.stic_age_c <= 3 THEN ' 2 - 3'
	WHEN sda_contacts.stic_age_c >= 4 AND sda_contacts.stic_age_c <= 5 THEN ' 4 - 5'
	WHEN sda_contacts.stic_age_c >= 6 AND sda_contacts.stic_age_c <= 6 THEN ' 6 - 6'
	WHEN sda_contacts.stic_age_c >= 7 AND sda_contacts.stic_age_c <= 7 THEN ' 7 - 7'
	WHEN sda_contacts.stic_age_c >= 8 AND sda_contacts.stic_age_c <= 9 THEN ' 8 - 9'
	WHEN sda_contacts.stic_age_c >= 10 THEN '>= 10'
END
Nuevo

Para solucionar el problema y asegurarnos de que se muestren todos los tramos con un valor de 0 si no hay datos, realizamos el siguiente cambio:

WITH ranges AS (
    SELECT ' < 2' as `range`
    UNION SELECT ' 2 - 3'
    UNION SELECT ' 4 - 5'
    UNION SELECT ' 6 - 6'
    UNION SELECT ' 7 - 7'
    UNION SELECT ' 8 - 9'
    UNION SELECT '>= 10'
)
SELECT
    r.range as 'Edad',
    COALESCE(t.Nombre, 0) as 'Nombre'
FROM ranges r
LEFT JOIN (
    SELECT
        CASE
            WHEN stic_age_c < 2 THEN '< 2'
            WHEN stic_age_c >= 2 AND stic_age_c <= 3 THEN ' 2 - 3'
            WHEN stic_age_c >= 4 AND stic_age_c <= 5 THEN ' 4 - 5'
            WHEN stic_age_c >= 6 AND stic_age_c <= 6 THEN ' 6 - 6'
            WHEN stic_age_c >= 7 AND stic_age_c <= 7 THEN ' 7 - 7'
            WHEN stic_age_c >= 8 AND stic_age_c <= 9 THEN ' 8 - 9'
            WHEN stic_age_c >= 10 THEN '>= 10'
        END as Edad,
        cast(count(distinct first_name) as decimal(32,0)) as Nombre
    FROM sda_contacts
    WHERE stic_age_c BETWEEN 2 AND 10
    GROUP BY
        CASE
            WHEN stic_age_c < 2 THEN '< 2'
            WHEN stic_age_c >= 2 AND stic_age_c <= 3 THEN ' 2 - 3'
            WHEN stic_age_c >= 4 AND stic_age_c <= 5 THEN ' 4 - 5'
            WHEN stic_age_c >= 6 AND stic_age_c <= 6 THEN ' 6 - 6'
            WHEN stic_age_c >= 7 AND stic_age_c <= 7 THEN ' 7 - 7'
            WHEN stic_age_c >= 8 AND stic_age_c <= 9 THEN ' 8 - 9'
            WHEN stic_age_c >= 10 THEN '>= 10'
        END
) t ON r.range = t.Edad
ORDER BY
    CASE
        WHEN r.range = '< 2' THEN 1
        WHEN r.range = ' 2 - 3' THEN 2
        WHEN r.range = ' 4 - 5' THEN 3
        WHEN r.range = ' 6 - 6' THEN 4
        WHEN r.range = ' 7 - 7' THEN 5
        WHEN r.range = ' 8 - 9' THEN 6
        WHEN r.range = '>= 10' THEN 7
    END;

Esta consulta utiliza un WITH para definir los rangos de forma explícita y realiza un LEFT JOIN con la tabla de datos reales, asegurando que los tramos sin datos se muestren con un valor de 0.
El resultado es:
image
Para las pruebas, se ha utilizado el campo Edad (sin agregación) con un filtro entre 2 y 10, junto con el campo Nombre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request SinergiaDA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants