<commit_before>
DROP FUNCTION IF EXISTS fn_calc_part_over_whole(cache_job_id int);
CREATE FUNCTION fn_calc_part_over_whole(cache_job_id int)
RETURNS TABLE(id int) AS
$func$
BEGIN

  ----- PART / WHOLE ------
  INSERT INTO _tmp_calc_datapoint
  (indicator_id,location_id,campaign_id,value)

  SELECT DISTINCT
  part.indicator_id as master_id
  ,d_part.location_id
  ,d_part.campaign_id
  ,d_part.value / NULLIF(d_whole.value,0) as value
  FROM calculated_indicator_component part
  INNER JOIN calculated_indicator_component whole
      ON part.indicator_id = whole.indicator_id
      AND whole.calculation = 'WHOLE'
      AND part.calculation = 'PART'
  INNER JOIN _tmp_calc_datapoint d_part
      ON part.indicator_component_id = d_part.indicator_id
  INNER JOIN _tmp_calc_datapoint d_whole
      ON whole.indicator_component_id = d_whole.indicator_id
      AND d_part.campaign_id = d_whole.campaign_id
      AND d_part.location_id = d_whole.location_id;

    RETURN QUERY

  	SELECT ad.id FROM agg_datapoint ad
  	--WHERE dwc.cache_job_id = $1
  	LIMIT 1;

  END
  $func$ LANGUAGE PLPGSQL;
<commit_msg>fix calculation stored proc breaking cache refresh for seed data ( whic is already calculated )<commit_after>
DROP FUNCTION IF EXISTS fn_calc_part_over_whole(cache_job_id int);
CREATE FUNCTION fn_calc_part_over_whole(cache_job_id int)
RETURNS TABLE(id int) AS
$func$
BEGIN

  ----- PART / WHOLE ------
  INSERT INTO _tmp_calc_datapoint
  (indicator_id,location_id,campaign_id,value)

  SELECT DISTINCT
  part.indicator_id as master_id
  ,d_part.location_id
  ,d_part.campaign_id
  ,d_part.value / NULLIF(d_whole.value,0) as value
  FROM calculated_indicator_component part
  INNER JOIN calculated_indicator_component whole
      ON part.indicator_id = whole.indicator_id
      AND whole.calculation = 'WHOLE'
      AND part.calculation = 'PART'
  INNER JOIN _tmp_calc_datapoint d_part
      ON part.indicator_component_id = d_part.indicator_id
  INNER JOIN _tmp_calc_datapoint d_whole
      ON whole.indicator_component_id = d_whole.indicator_id
      AND d_part.campaign_id = d_whole.campaign_id
      AND d_part.location_id = d_whole.location_id
  WHERE NOT EXISTS ( 
      SELECT 1 FROM _tmp_calc_datapoint tcd
      WHERE tcd.campaign_id = d_part.campaign_id
      AND tcd.location_id = d_part.location_id
      AND tcd.indicator_id = part.indicator_id
      );

    RETURN QUERY

  	SELECT ad.id FROM agg_datapoint ad
  	--WHERE dwc.cache_job_id = $1
  	LIMIT 1;

  END
  $func$ LANGUAGE PLPGSQL;

{'fraction_non_alphanumeric': 0.06506986027944112, 'fraction_numerical': 0.0027944111776447107, 'mean_word_length': 3.8471953578336557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2490292', 'n_tokens_mistral': 964, 'n_tokens_neox': 887, 'n_words': 203}