<commit_before>DROP FUNCTION IF EXISTS profile_scops_exec_times(exp_ids uuid[]);
CREATE OR REPLACE FUNCTION public.profile_scops_exec_times(exp_ids uuid[])
  RETURNS TABLE(project character varying, execTime_us DOUBLE PRECISION) AS
$BODY$
BEGIN
  RETURN QUERY
        SELECT sub.project, sub.execTime_us FROM (
          SELECT
              run.project_name AS project,
              run.run_group,
              SUM(metrics.value * 1000000) AS execTime_us
          FROM run, metrics
          WHERE run.id = metrics.run_id and
                run.experiment_group = ANY (exp_ids) and
                metrics.name = 'time.real_s'
          GROUP BY
                run.project_name, run.run_group
        ) AS sub;
END
$BODY$
  LANGUAGE plpgsql;

DROP FUNCTION IF EXISTS profile_scops_valid_regions(exp_ids UUID[]);
CREATE OR REPLACE FUNCTION profile_scops_valid_regions(exp_ids UUID[])
    RETURNS
    TABLE(run_id INTEGER,
          duration NUMERIC,
      id NUMERIC,
      name VARCHAR,
      events BIGINT)
AS $BODY$
BEGIN
  RETURN QUERY
    SELECT
        regions.run_id,
        regions.duration,
        regions.id,
        regions.name,
        regions.events
    FROM
        run, regions, metrics
    WHERE
        run.id = regions.run_id and
        run.id = metrics.run_id and
        metrics.name = 'time.real_s' and
        metrics.value * 1000000 >= regions.duration and
        run.experiment_group = ANY (exp_ids);
END
$BODY$ language plpgsql;

DROP FUNCTION IF EXISTS profile_scops_count_invalid_regions(exp_ids UUID[]);
CREATE OR REPLACE FUNCTION profile_scops_count_invalid_regions(exp_ids UUID[])
    RETURNS INTEGER
AS $BODY$
BEGIN
  RETURN
    (SELECT
        count(*) AS num_invalid
    FROM
        run, regions, metrics
    WHERE
        run.id = regions.run_id and
        run.id = metrics.run_id and
        metrics.name = 'time.real_s' and
        metrics.value * 1000000 < regions.duration and
        run.experiment_group = ANY (exp_ids));
END
$BODY$ language plpgsql;

DROP FUNCTION IF EXISTS profile_scops_ratio_valid_regions(exp_ids UUID[]);
CREATE OR REPLACE FUNCTION profile_scops_ratio_valid_regions(exp_ids UUID[])
    RETURNS INTEGER
AS $BODY$
BEGIN
  RETURN
    (SELECT 100*(1-(
                SELECT *
                FROM profile_scops_count_invalid_regions(exp_ids)
            )::DOUBLE PRECISION / (
                SELECT count(*)
                FROM profile_scops_valid_regions(exp_ids)
            )
        ) AS usefulRatio<commit_msg>ProfileScopDetection: Precise the result of ratio_valid_regions query<commit_after>DROP FUNCTION IF EXISTS profile_scops_exec_times(exp_ids uuid[]);
CREATE OR REPLACE FUNCTION public.profile_scops_exec_times(exp_ids uuid[])
  RETURNS TABLE(project character varying, execTime_us DOUBLE PRECISION) AS
$BODY$
BEGIN
  RETURN QUERY
        SELECT sub.project, sub.execTime_us FROM (
          SELECT
              run.project_name AS project,
              run.run_group,
              SUM(metrics.value * 1000000) AS execTime_us
          FROM run, metrics
          WHERE run.id = metrics.run_id and
                run.experiment_group = ANY (exp_ids) and
                metrics.name = 'time.real_s'
          GROUP BY
                run.project_name, run.run_group
        ) AS sub;
END
$BODY$
  LANGUAGE plpgsql;

DROP FUNCTION IF EXISTS profile_scops_valid_regions(exp_ids UUID[]);
CREATE OR REPLACE FUNCTION profile_scops_valid_regions(exp_ids UUID[])
    RETURNS
    TABLE(run_id INTEGER,
          duration NUMERIC,
      id NUMERIC,
      name VARCHAR,
      events BIGINT)
AS $BODY$
BEGIN
  RETURN QUERY
    SELECT
        regions.run_id,
        regions.duration,
        regions.id,
        regions.name,
        regions.events
    FROM
        run, regions, metrics
    WHERE
        run.id = regions.run_id and
        run.id = metrics.run_id and
        metrics.name = 'time.real_s' and
        metrics.value * 1000000 >= regions.duration and
        run.experiment_group = ANY (exp_ids);
END
$BODY$ language plpgsql;

DROP FUNCTION IF EXISTS profile_scops_count_invalid_regions(exp_ids UUID[]);
CREATE OR REPLACE FUNCTION profile_scops_count_invalid_regions(exp_ids UUID[])
    RETURNS DOUBLE PRECISION
AS $BODY$
BEGIN
  RETURN
    (SELECT
        count(*) AS num_invalid
    FROM
        run, regions, metrics
    WHERE
        run.id = regions.run_id and
        run.id = metrics.run_id and
        metrics.name = 'time.real_s' and
        metrics.value * 1000000 < regions.duration and
        run.experiment_group = ANY (exp_ids));
END
$BODY$ language plpgsql;

DROP FUNCTION IF EXISTS profile_scops_ratio_valid_regions(exp_ids UUID[]);
CREATE OR REPLACE FUNCTION profile_scops_ratio_valid_regions(exp_ids UUID[])
    RETURNS DOUBLE PRECISION
AS $BODY$
BEGIN
  RETURN
    (SELECT 100*(1-(
                SELECT *
                FROM profile_scops_count_invalid_regions(exp_ids)
            )::DOUBLE PRECISION / (
                SELECT count(*)
                FROM profile_scops_valid_regions(exp_ids)
            )
        )
{'fraction_non_alphanumeric': 0.06968433591423466, 'fraction_numerical': 0.009926543577526306, 'mean_word_length': 2.434219495569189, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '128408', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1557, 'n_words': 399}