public GetIndexDataResponse GetIndexData(GetIndexDataRequest request)
        {
            string where = BuildSqlWhere(request);

            string sql = $@"

              Select  AVG(Milliseconds) ART From RequestInfo {where} ;
              Select  COUNT(1) Total From RequestInfo {where} ;
              Select  COUNT(1) Code404 From RequestInfo {where} AND StatusCode = 404 ;
              Select  COUNT(1) Code500 From RequestInfo {where} AND StatusCode = 500 ;
              Select Count(1) From ( Select Distinct Url From RequestInfo ) A;

           ";

            GetIndexDataResponse response = new GetIndexDataResponse();

            using (var result = conn.QueryMultiple(sql))
            {
                response.ART          = (result.ReadFirstOrDefault <string>() ?? "0").ToDouble().ToString("0");
                response.Total        = result.ReadFirstOrDefault <string>();
                response.Code404      = result.ReadFirstOrDefault <string>();
                response.Code500      = result.ReadFirstOrDefault <string>();
                response.APICount     = result.ReadFirst <int>();
                response.ErrorPercent = response.Total.ToInt() == 0 ? "0.00%" :(Convert.ToDouble(response.Code500) / Convert.ToDouble(response.Total)).ToString("0.00%");
            }

            return(response);
        }
Example #2
0
        public GetIndexDataResponse GetIndexData(GetIndexDataRequest request)
        {
            string where = BuildSqlWhere(request);

            // string sql = $@"
            //    Select  AVG(Milliseconds) ART From RequestInfo {where} ;
            //    Select  COUNT(1) Total From RequestInfo {where} ;
            //    Select  COUNT(1) Code404 From RequestInfo {where} AND StatusCode = 404 ;
            //    Select  COUNT(1) Code500 From RequestInfo {where} AND StatusCode = 500 ;
            //   Select Count(1) From ( Select Distinct Url From RequestInfo ) A;
            //";

            GetIndexDataResponse response = new GetIndexDataResponse();

            using (var con = new OracleConnection(connectionString))
            {
                response.ART          = con.QueryFirst <string>($"Select round(AVG(Milliseconds)) ART From RequestInfo {where}");
                response.Total        = con.QueryFirst <string>($"Select  COUNT(1) Total From RequestInfo {where}");
                response.Code404      = con.QueryFirst <string>($"Select  COUNT(1) Code404 From RequestInfo {where} AND StatusCode = 404 ");
                response.Code500      = con.QueryFirst <string>($"Select  COUNT(1) Code500 From RequestInfo {where} AND StatusCode = 500 ");
                response.APICount     = con.QueryFirst <int>($" Select Count(1) From ( Select Distinct Url From RequestInfo ) A");
                response.ErrorPercent = response.Total.ToInt() == 0 ? "0.00%" : (Convert.ToDouble(response.Code500) / Convert.ToDouble(response.Total)).ToString("0.00%");
            }

            return(response);
        }