<commit_before>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.nanos.pm;

import foam.dao.MapDAO;
import foam.dao.ProxyDAO;
import foam.nanos.NanoService;

public class DAOPMLogger
  extends    ProxyDAO
  implements PMLogger, NanoService
{

  public static final String ServiceName = "pmLogger";

  @Override
  public void log(PM pm) {
    PMInfo pmi = new PMInfo()
            .setClsname(pm.getClassType().getName())
            .setPmname(pm.getName());

    PMInfo dpmi = (PMInfo) getDelegate().find(pmi);
    if ( dpmi == null ) {
      pmi.setMintime(pm.getTime())
              .setMaxtime(pm.getTime())
              .setTotaltime(pm.getTime())
              .setNumoccurrences(1);

      getDelegate().put(pmi);
    } else {
      if ( pm.getTime() < dpmi.getMintime() )
        dpmi.setMintime(pm.getTime());

      if ( pm.getTime() > dpmi.getMaxtime() )
        dpmi.setMaxtime(pm.getTime());

      dpmi.setNumoccurrences(dpmi.getNumoccurrences() + 1);
      dpmi.setTotaltime(dpmi.getTotaltime() + pm.getTime());
      getDelegate().put(dpmi);
    }
  }

  @Override
  public void start() {
    MapDAO dao = new MapDAO();
    dao.setOf(PMInfo.getOwnClassInfo());
    dao.setX(getX());
    setDelegate(dao);
  }
}<commit_msg>DAOPMLogger no longer extends ProxyDAO, but put's it's own MapDAO into context<commit_after>/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.nanos.pm;

import foam.core.ContextAwareSupport;
import foam.dao.MapDAO;
import foam.dao.ProxyDAO;
import foam.nanos.NanoService;

public class DAOPMLogger
  extends ContextAwareSupport
  implements PMLogger, NanoService
{

  public static final String ServiceName = "pmLogger";
  public static final String DAOName = "pmInfoDAO";

  @Override
  public void log(PM pm) {
    PMInfo pmi = new PMInfo()
            .setClsname(pm.getClassType().getName())
            .setPmname(pm.getName());

    MapDAO pmd = (MapDAO) getX().get("pmInfoDAO");

    PMInfo dpmi = (PMInfo) pmd.find(pmi);
    if ( dpmi == null ) {
      pmi.setMintime(pm.getTime())
              .setMaxtime(pm.getTime())
              .setTotaltime(pm.getTime())
              .setNumoccurrences(1);

      pmd.put(pmi);
    } else {
      if ( pm.getTime() < dpmi.getMintime() )
        dpmi.setMintime(pm.getTime());

      if ( pm.getTime() > dpmi.getMaxtime() )
        dpmi.setMaxtime(pm.getTime());

      dpmi.setNumoccurrences(dpmi.getNumoccurrences() + 1);
      dpmi.setTotaltime(dpmi.getTotaltime() + pm.getTime());
      pmd.put(dpmi);
    }
  }

  @Override
  public void start() {
    MapDAO dao = new MapDAO();
    dao.setOf(PMInfo.getOwnClassInfo());
    dao.setX(getX());
    getX().put(DAOName, dao);
  }
}
{'fraction_non_alphanumeric': 0.1422550052687039, 'fraction_numerical': 0.005619950825430277, 'mean_word_length': 2.822818791946309, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4214748', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1040, 'n_words': 186}