| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $args = trigger.data; |
| 6 | $_Portal = $args._Portal; |
| 7 | $refcons = $args.refcons; |
| 8 | $geto = $args.geto; |
| 9 | $ref = $args.ref; |
| 10 | |
| 11 | $__dada = $refval => |
| 12 | data_feed[[ oracles = $args._Registre, feed_name = $refval, ifnone = false ]]; |
| 13 | |
| 14 | $Lapse = $__dada( 'Lapse' ); |
| 15 | $Origen = $__dada( 'Origen' ); |
| 16 | $cicle_actual = |
| 17 | 1 + floor( ( timestamp - $Origen ) / $__dada( 'Interval' ) ); |
| 18 | }", |
| 19 | "messages": [ |
| 20 | { |
| 21 | "app": "state", |
| 22 | "state": "{ |
| 23 | response[ 'consulta' ] = $refcons; |
| 24 | |
| 25 | |
| 26 | if ( $refcons == 'Dades_Diposit' ) { |
| 27 | response[ 'Ref' ] = $ref; |
| 28 | response[ 'Quantitat dipositada' ] = $__dada( $ref || '_qt' ); |
| 29 | response[ 'Dipositant' ] = $__dada( $ref || '_dipositant' ); |
| 30 | response[ 'Cicle dipòsit' ] = $__dada( $ref || '_cicle' ); |
| 31 | response[ 'Getó dipòsit' ] = $__dada( $ref || '_geto_diposit' ); |
| 32 | response[ 'Data dipòsit' ] = $__dada( $ref || '_data'); |
| 33 | |
| 34 | response[ 'Taxa' ] = $__dada( $ref || '_taxa' ); |
| 35 | response[ 'Qt conversió' ] = $__dada( $ref || '_qt_conversio' ); |
| 36 | response[ 'Cicle conversió' ] = $__dada( $ref || '_cicle_conversio' ); |
| 37 | response[ 'Cicle actual' ] = $cicle_actual; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | if ( $refcons == 'Dades_Contribucio' ) { |
| 42 | response[ 'Ref' ] = $ref; |
| 43 | response[ 'Quantitat' ] = $__dada( $ref || '_qt' ); |
| 44 | response[ 'Contribuidora' ] = $__dada( $ref || '_contribuidora' ); |
| 45 | response[ 'Cicle contribució' ] = $__dada( $ref || '_cicle' ); |
| 46 | response[ 'Escala contribució' ] = $__dada( $ref || '_escala' ); |
| 47 | response[ 'Interval contribució' ] = $__dada( $ref || '_interval' ); |
| 48 | response[ 'Data contribució' ] = $__dada( $ref || '_data'); |
| 49 | $data_escala = $__dada( 'data_escala_actual' ); |
| 50 | response[ "Segons transcorreguts des del darrer salt d'escala" ] = |
| 51 | timestamp - $data_escala; |
| 52 | $geto_contribucio = $__dada( $ref || '_geto' ); |
| 53 | response[ 'Total Contribucions' ] = |
| 54 | $__dada( 'total_contribucions_' || $geto_contribucio ); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | if ( $refcons == 'Dades_Conversio' |
| 59 | OR $refcons == 'Dades_Retribucio' |
| 60 | OR $refcons == 'Dades_Bonificacio' ) { |
| 61 | response[ 'Ref' ] = $ref; |
| 62 | response[ 'Rebedora' ] = $__dada( $ref || '_rebedora' ); |
| 63 | response[ 'Quantitat' ] = $__dada( $ref || '_qt' ); |
| 64 | response[ 'Data' ] = timestamp_to_string( $__dada( $ref || '_data' ), 'date' ); |
| 65 | if ( $refcons == 'Dades_Conversio' ) |
| 66 | response[ 'Unitat' ] = $__dada( $ref || '_unitat' ); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | if ( $refcons == 'Totals' ) { |
| 71 | $total_emissions = $__dada( 'total_emesos_' || $geto ) otherwise 0; |
| 72 | $total_donacions = $__dada( 'total_donacions' ) otherwise 0; |
| 73 | $total_assignacions = $__dada( 'total_assignacions' ) otherwise 0; |
| 74 | $total_activacions = $__dada( 'total_activacions_' || $geto ) otherwise 0; |
| 75 | $total_subscripcions = $__dada( 'total_subscripcions_' || $geto ) otherwise 0; |
| 76 | $total_renovacions = $__dada( 'total_renovacions_' || $geto ) otherwise 0; |
| 77 | $total_transfers = $__dada( 'total_transfers_' || $geto ) otherwise 0; |
| 78 | $total_aportacions = $__dada( 'total_aportacions_' || $geto ) otherwise 0; |
| 79 | $total_diposits = $__dada( 'total_diposits_' || $geto ) otherwise 0; |
| 80 | $total_contribucions = $__dada( 'total_contribucions_' || $geto ) otherwise 0; |
| 81 | $total_convertits = $__dada( 'total_estels_convertits_' || $geto ) otherwise 0; |
| 82 | $total_conversions = $__dada( 'total_conversions_' || $geto ) otherwise 0; |
| 83 | $total_taxes = $__dada( 'total_taxes_' || $geto ) otherwise 0; |
| 84 | $total_retribucions = $__dada( 'total_retribucions_' || $geto ) otherwise 0; |
| 85 | $total_bonificacions = $__dada( 'total_bonificacions_' || $geto ) otherwise 0; |
| 86 | $total_atribucions = $__dada( 'total_atribucions_' || $geto ) otherwise 0; |
| 87 | $volum_escala = |
| 88 | $total_activacions + $total_subscripcions |
| 89 | + $total_renovacions + $total_aportacions |
| 90 | + $total_contribucions; |
| 91 | |
| 92 | response[ 'Getó' ] = $geto; |
| 93 | if ( $geto == $__dada( 'Estels' ) ) { |
| 94 | response[ 'Donacions' ] = $total_donacions; |
| 95 | response[ 'Assignacions' ] = $total_assignacions; |
| 96 | response[ 'Conversions' ] = $total_conversions; |
| 97 | } else { |
| 98 | response[ 'Unitats Emeses' ] = $total_emissions; |
| 99 | response[ 'Estels Convertits' ] = $total_convertits || ' Estels'; |
| 100 | response[ 'Conversions a Estels' ] = $total_conversions || ' Estels'; |
| 101 | response[ 'Atribucions' ] = $total_atribucions; |
| 102 | } |
| 103 | response[ 'Activacions' ] = $total_activacions; |
| 104 | response[ 'Subscripcions' ] = $total_subscripcions; |
| 105 | response[ 'Renovacions' ] = $total_renovacions; |
| 106 | response[ 'Transfers' ] = $total_transfers; |
| 107 | response[ 'Aportacions' ] = $total_aportacions; |
| 108 | response[ 'Diposits' ] = $total_diposits; |
| 109 | response[ 'Contribucions' ] = $total_contribucions; |
| 110 | response[ 'Taxes' ] = $total_taxes; |
| 111 | response[ 'Retribucions' ] = $total_retribucions; |
| 112 | response[ 'Bonificacions' ] = $total_bonificacions; |
| 113 | response[ 'Volum Escala calculat' ] = $volum_escala; |
| 114 | response[ 'Volum Escala registrat' ] = |
| 115 | $__dada( 'volum_escala_' || $geto ) otherwise 0; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | if ( $refcons == 'Cicle_Actual' ) { |
| 120 | $interval = $__dada( 'Interval' ); |
| 121 | $segons_cicle_actual = ( $Origen + ( $cicle_actual * $interval ) ) - timestamp; |
| 122 | $percent_cicle_actual = $segons_cicle_actual / $interval * 100; |
| 123 | response[ 'Cicle actual' ] = $cicle_actual; |
| 124 | response[ 'Data actual' ] = timestamp; |
| 125 | response[ 'Data origen' ] = $Origen; |
| 126 | response[ 'Durada cicles' ] = $interval; |
| 127 | response[ 'Segons restants cicle actual' ] = $segons_cicle_actual; |
| 128 | response[ '% restant del cicle actual' ] = |
| 129 | round( $percent_cicle_actual, 0 ) || ' %'; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | if ( $refcons == 'Escala_Actual' ) { |
| 134 | $escala_actual = $__dada( 'escala_actual_' || $geto ) otherwise 0; |
| 135 | $data_escala = $__dada( 'data_escala_actual_' || $geto ) otherwise 0; |
| 136 | response[ 'Geto' ] = $geto; |
| 137 | response[ 'Escala actual' ] = $escala_actual; |
| 138 | response[ 'Volum Escala actual' ] = $__dada( 'volum_escala_' || $geto ) otherwise 0; |
| 139 | if ( !! $data_escala ) { |
| 140 | response[ "Data del salt d'escala" ] = timestamp_to_string( $data_escala, 'date' ); |
| 141 | response[ 'Data en segons' ] = $data_escala; |
| 142 | response[ 'Segons transcorreguts des de darrer salt escala' ] = timestamp - $data_escala; |
| 143 | } |
| 144 | } |
| 145 | }" |
| 146 | } |
| 147 | ] |
| 148 | } |
| 149 | ] |