pigreco / COVID-19_ITA

QGIS project for the visualization of COVID-19 data through an atlas with dynamic graphs - regions (https://github.com/pcm-dpc/COVID-19)
https://pigrecoinfinito.com/
Creative Commons Attribution 4.0 International
14 stars 4 forks source link

etichetta su regione: totale e incremento #1

Closed pigreco closed 4 years ago

pigreco commented 4 years ago

Espressione da usare:

 relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva") 
 [ array_find(array_sort( 
 relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="data"),true ) ,
 ( format_date( now() - to_interval  ( '1 day' ), 'yyyy-MM-dd'  ) ) )] 
 || ' ( +' || 
  ( to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva") 
 [ array_find(array_sort( 
 relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="data"),true ) ,
 ( format_date( now() - to_interval  ( '1 day' ), 'yyyy-MM-dd'  ) ) )] ) 
  - 
 to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva") 
[array_find(array_sort( 
 relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:= substr( "data",1,10 ) ),true )
 , ( format_date( now() - to_interval  ( '2 day' ), 'yyyy-MM-dd'  ) ) ) ] )  ) 
 || ' ) '

per ottenere:

image

pigreco commented 4 years ago

L'espressione di sopra non è sempre utilizzabile a causa dell'utilizzo della funzione now(), una prima soluzione è questa:

 relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva")  [-1] 
 || ' ( +' || 
  ( to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva")  [-1] ) 
  - 
 to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva") [-2 ] ) ) 
 || ' ) '
pigreco commented 4 years ago

correggere errore:

image

pigreco commented 4 years ago

prima soluzione:

 relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva")  [-1] 
 || ' ( ' ||
if ( ( to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva")  [-1] ) 
  - 
 to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva") [-2 ] ) ) > 0, '+', '' ) 
 ||  
  ( to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva")  [-1] ) 
  - 
 to_int( relation_aggregate( 
 relation:='rel',
 aggregate:='array_agg',
 expression:="terapia_intensiva") [-2 ] ) ) 
 || ' ) '

image