StatisticheUtils.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.core.statistiche.utils;

  21. import org.openspcoop2.core.constants.CostantiDB;
  22. import org.openspcoop2.core.statistiche.model.StatisticaModel;
  23. import org.openspcoop2.generic_project.beans.FunctionField;
  24. import org.openspcoop2.generic_project.beans.IField;
  25. import org.openspcoop2.generic_project.exception.ExpressionException;
  26. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  27. import org.openspcoop2.generic_project.expression.IExpression;
  28. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;

  29. /**    
  30.  * StatisticheUtils
  31.  *
  32.  * @author Poli Andrea (poli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class StatisticheUtils {

  37.     public static void selezionaRecordValidi(IExpression expr, StatisticaModel model) throws ExpressionNotImplementedException, ExpressionException{
  38.         expr.greaterEquals(model.STATO_RECORD, CostantiDB.STATISTICHE_STATO_RECORD_VALIDO);
  39.     }
  40.    
  41.     public static FunctionField calcolaMedia(ISQLFieldConverter fieldConverter, IField latenza, IField numeroRichieste, String alias) throws ExpressionException{
  42.         // (SUM(latenza_servizio*richieste))/SUM(richieste)
  43.         String columnLatenza = fieldConverter.toColumn(latenza, false);
  44.         String columnRichieste = fieldConverter.toColumn(numeroRichieste, false);
  45.         String  sbFunctionValue = getSqlCalcolaMedia(columnLatenza, columnRichieste);
  46.         Class<?> functionValueType = Long.class;
  47.        
  48.         return new FunctionField(sbFunctionValue.toString(),functionValueType,"","",alias);
  49.     }
  50.    
  51.     public static String getSqlCalcolaMedia(String columnLatenza, String columnRichieste) {
  52.         StringBuilder sbFunctionValue = new StringBuilder("(");
  53.         sbFunctionValue.append("SUM(").append(columnLatenza).append("*").append(columnRichieste).append(")");
  54.         sbFunctionValue.append("/");
  55.         sbFunctionValue.append("SUM(").append(columnRichieste).append(")");
  56.         sbFunctionValue.append(")");
  57.         return sbFunctionValue.toString();
  58.     }
  59. }