<commit_before>#include <stdlib.h>

#include "metric.h"


static float _compute_metrics_interval(monikor_metric_t *a, monikor_metric_t *b) {
  float duration;

  duration = 1000000 * (b->clock.tv_sec - a->clock.tv_sec)
    + (b->clock.tv_usec - a->clock.tv_usec);
  return duration / 1000000.0;
}

static void _compute_float_delta(monikor_metric_t *a, monikor_metric_t *b, monikor_metric_t *res) {
  res->type = MONIKOR_FLOAT;
  res->value._float = b->value._float - a->value._float;
  if (a->flags & MONIKOR_METRIC_TIMEDELTA) {
    res->value._float /= _compute_metrics_interval(a, b);
  }
}

static void _compute_int_delta(monikor_metric_t *a, monikor_metric_t *b, monikor_metric_t *res) {
  if (a->flags & MONIKOR_METRIC_TIMEDELTA) {
    res->type = MONIKOR_FLOAT;
    res->value._float = (float)(b->value._int - a->value._int) / _compute_metrics_interval(a, b);
  } else {
    res->type = MONIKOR_INTEGER;
    res->value._int = b->value._int - a->value._int;
  }
}

monikor_metric_t *monikor_metric_compute_delta(monikor_metric_t *a, monikor_metric_t *b) {
  monikor_metric_t *result;

  if (!(result = monikor_metric_clone(a)))
    return NULL;
  result->flags &= ~(MONIKOR_METRIC_DELTA | MONIKOR_METRIC_TIMEDELTA);
  switch (a->type) {<commit_msg>handle timedelta counters reset<commit_after>#include <stdlib.h>

#include "metric.h"


static float _compute_metrics_interval(monikor_metric_t *a, monikor_metric_t *b) {
  float duration;

  duration = 1000000 * (b->clock.tv_sec - a->clock.tv_sec)
    + (b->clock.tv_usec - a->clock.tv_usec);
  return duration / 1000000.0;
}

static void _compute_float_delta(monikor_metric_t *a, monikor_metric_t *b, monikor_metric_t *res) {
  res->type = MONIKOR_FLOAT;
  res->value._float = b->value._float - a->value._float;
  if (a->flags & MONIKOR_METRIC_TIMEDELTA) {
    if (b->value._int < a->value._int)
      res->value._float = 0.0;
    else
      res->value._float /= _compute_metrics_interval(a, b);
  }
}

static void _compute_int_delta(monikor_metric_t *a, monikor_metric_t *b, monikor_metric_t *res) {
  if (a->flags & MONIKOR_METRIC_TIMEDELTA) {
    res->type = MONIKOR_FLOAT;
    if (b->value._int < a->value._int)
      res->value._float = 0.0;
    else
      res->value._float = (float)(b->value._int - a->value._int) / _compute_metrics_interval(a, b);
  } else {
    res->type = MONIKOR_INTEGER;
    if (b->value._int < a->value._int)
      res->value._int = 0;
    else
      res->value._int = b->value._int - a->value._int;
  }
}

monikor_metric_t *monikor_metric_compute_delta(monikor_metric_t *a, monikor_metric_t *b) {
  monikor_metric_t *result;

  if (!(result = monikor_metric_clone(a)))
    return NULL;
  result->flags &= ~(MONIKOR_METRIC_DELTA | MONIKOR_METRIC_TIMEDELTA);
  switch (a->type) {
{'fraction_non_alphanumeric': 0.14259862468331524, 'fraction_numerical': 0.012667390517553384, 'mean_word_length': 4.043795620437956, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 56, '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': '919190', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1109, 'n_words': 183}