<commit_before>#include "eventsmanager.h"

#include <QDebug>

EventsManager::EventsManager()
{
  last_event = 0;
  last_magnification = 1;
}


void EventsManager::clear()
{
  events_container.clear();
  last_magnification = 1;
  last_event = 0;
}


void EventsManager::newEventArrived(Event e)
{
  QList<Event>::iterator i = events_container[e.getCaller()].begin();
  while (i != events_container[e.getCaller()].end() && (*i).getStart() < e.getStart())
    ++i;
  events_container[e.getCaller()].insert(i, e);
  if (e.getStart() > last_event)
    last_event = e.getStart();
}


unsigned long EventsManager::countCallers()
{
  return events_container.count();
}


QList<Event> * EventsManager::getCallerEventsList(unsigned long caller)
{
  unsigned long c = 0;
  QMap <QString, QList<Event>>::iterator i = events_container.begin();
  while (c <= caller && i != events_container.end()) {
    ++i;
    ++c;
  }
  return &(*i);
}


QMap <QString, QList<Event>> * EventsManager::getCallers()
{
  return &events_container;
}


qreal EventsManager::magnify(qreal start, qreal end, qreal width)
{
  qreal new_center;
  qreal size = end - start;
  qreal last_event_magnified = last_event * last_magnification;
  qreal fraction;
  qreal normalized = size / last_event_magnified;

  new_center = (start + end) / 2 / last_magnification;

  if (size > 0)
    fraction = 1 / normalized;
  else
    fraction = -normalized;

  last_magnification = fraction;
<commit_msg>Improved zooming<commit_after>#include "eventsmanager.h"

#include <QDebug>

EventsManager::EventsManager()
{
  last_event = 0;
  last_magnification = 1;
}


void EventsManager::clear()
{
  events_container.clear();
  last_magnification = 1;
  last_event = 0;
}


void EventsManager::newEventArrived(Event e)
{
  QList<Event>::iterator i = events_container[e.getCaller()].begin();
  while (i != events_container[e.getCaller()].end() && (*i).getStart() < e.getStart())
    ++i;
  events_container[e.getCaller()].insert(i, e);
  if (e.getStart() > last_event)
    last_event = e.getStart();
}


unsigned long EventsManager::countCallers()
{
  return events_container.count();
}


QList<Event> * EventsManager::getCallerEventsList(unsigned long caller)
{
  unsigned long c = 0;
  QMap <QString, QList<Event>>::iterator i = events_container.begin();
  while (c <= caller && i != events_container.end()) {
    ++i;
    ++c;
  }
  return &(*i);
}


QMap <QString, QList<Event>> * EventsManager::getCallers()
{
  return &events_container;
}


qreal EventsManager::magnify(qreal start, qreal end, qreal width)
{
  qreal new_center;
  qreal fraction;
  qreal size = end - start;
  qreal magnification = width / size;

  new_center = (start + end) / 2 / last_magnification;

  if (size > 0)
    fraction = magnification;
  else
    fraction = -last_magnification / magnification;

  last_magnification = fraction;

{'fraction_non_alphanumeric': 0.1452064380685794, 'fraction_numerical': 0.005248425472358292, 'mean_word_length': 4.435361216730038, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6053382', 'n_tokens_mistral': 1034, 'n_tokens_neox': 982, 'n_words': 211}