<commit_before>/*  

    Copyright (C) 2010       <NAME> <<EMAIL>>

*/

#include <iostream>
#include <string>

#include <boost/program_options.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/density.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/variance.hpp>

#include "namespaces.h"
#include "data/Events.h"
#include "exception/Base.h"
#include "Logger.h"

typedef ac::accumulator_set<double, ac::features<ac::tag::mean, ac::tag::variance> > statistics_accumulator;
typedef ac::accumulator_set<double, ac::features<ac::tag::density> > accumulator;
typedef boost::iterator_range<std::vector<std::pair<double, double> >::iterator > histogram; 

pt::time_duration parseTime(const std::string& inputString, bool isEnd=false) {
  std::istringstream iss(inputString);
  pt::time_duration endOffset(pt::seconds(0));

  std::string format;
  if (inputString.size() <= 4) {
    format = "%H%M";
    endOffset = pt::minutes(1);
  } else {
    format = "%H%M%S";
    endOffset = pt::seconds(1);
  }

  // create formatting facet and set format for time_duration type
  pt::time_input_facet *facet = new pt::time_input_facet();
  facet->time_duration_format(format.c_str());

  iss.imbue(std::locale(std::locale::classic(), facet));

  pt::time_duration time;
  iss >> time;

  if (isEnd) 
    return time + endOffset;
  else
    return time;
}

void printEvent(const bo::data::Event& event) {
  std::cout << event << std::endl;
}

void printAllSamplesOfEvent(const bo::data::Event& event) {

  pt::time_facet *timefacet = new pt::time_facet();
  timefacet->format("%Y-%m-%d %H:%M:%S.%f");
  std::locale oldLocale = std::cout.imbue(std::locale(std::locale::classic(), timefacet));

  std::cout << "# " << event << std::endl;

  const bo::data::Waveform& waveform = event.getWaveform();

  unsigned int numberOfChannels = waveform.getNumberOfChannels();
  for (unsigned int sample = 0; sample < waveform.getNumberOfSamples(); sample++) {
    std::cout << waveform.getTime(sample);
    double sum = 0.0;
    for (unsigned int channel = 0; channel < numberOfChannels; channel++) {
      double value = waveform.get(sample, channel);
      sum += value * value;
      std::cout << " " << value;
    }
    if (numberOfChannels > 1)
      std::cout << " " << sqrt(sum);
    std::cout << " " << sample;

    std::cout << std::endl;
  }

  std::cout.imbue(oldLocale);
}

int main(int argc, char **argv) {

  std::string file = "";
  std::string mode;
  std::string startTimeString, endTimeString;

  bo::Logger logger("");

  // programm arguments/options
  boost::program_options::options_description desc("program options");
  desc.add_options()
    ("help,h", "show program help")
    ("input-file,i", po::value<std::string>(&file), "file name")
    ("starttime,s", po::value<std::string>(&startTimeString), "start time in HHMM or HHMMSS format")
    ("endtime,e", po::value<std::string>(&endTimeString), "end time in HHMM or HHMMSS format")
    ("mode", po::value<std::string>(&mode)->default_value("plain"), "data mode( plain, statistics, histogram)")
    ("verbose,v", "verbose mode")
    ("long-data,l", "output all samples")
    ("debug", "debug mode")
    ;

  // parse command line options
  po::variables_map vm;
  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
  po::notify(vm); 

  // help output or no 'sql-statement' given
  if (vm.count("help")) {
    std::cout << argv[0] << " [options]" << std::endl << std::endl;
    std::cout << desc << std::endl;
    std::cout << std::endl;

    return 1;
  }

  if (! vm.count("input-file")) {
    std::cerr << "'input-file' missing\n";
    return 5;<commit_msg>fixed default mode value<commit_after>/*  

    Copyright (C) 2010       <NAME> <<EMAIL>>

*/

#include <iostream>
#include <string>

#include <boost/program_options.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/density.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/variance.hpp>

#include "namespaces.h"
#include "data/Events.h"
#include "exception/Base.h"
#include "Logger.h"

typedef ac::accumulator_set<double, ac::features<ac::tag::mean, ac::tag::variance> > statistics_accumulator;
typedef ac::accumulator_set<double, ac::features<ac::tag::density> > accumulator;
typedef boost::iterator_range<std::vector<std::pair<double, double> >::iterator > histogram; 

pt::time_duration parseTime(const std::string& inputString, bool isEnd=false) {
  std::istringstream iss(inputString);
  pt::time_duration endOffset(pt::seconds(0));

  std::string format;
  if (inputString.size() <= 4) {
    format = "%H%M";
    endOffset = pt::minutes(1);
  } else {
    format = "%H%M%S";
    endOffset = pt::seconds(1);
  }

  // create formatting facet and set format for time_duration type
  pt::time_input_facet *facet = new pt::time_input_facet();
  facet->time_duration_format(format.c_str());

  iss.imbue(std::locale(std::locale::classic(), facet));

  pt::time_duration time;
  iss >> time;

  if (isEnd) 
    return time + endOffset;
  else
    return time;
}

void printEvent(const bo::data::Event& event) {
  std::cout << event << std::endl;
}

void printAllSamplesOfEvent(const bo::data::Event& event) {

  pt::time_facet *timefacet = new pt::time_facet();
  timefacet->format("%Y-%m-%d %H:%M:%S.%f");
  std::locale oldLocale = std::cout.imbue(std::locale(std::locale::classic(), timefacet));

  std::cout << "# " << event << std::endl;

  const bo::data::Waveform& waveform = event.getWaveform();

  unsigned int numberOfChannels = waveform.getNumberOfChannels();
  for (unsigned int sample = 0; sample < waveform.getNumberOfSamples(); sample++) {
    std::cout << waveform.getTime(sample);
    double sum = 0.0;
    for (unsigned int channel = 0; channel < numberOfChannels; channel++) {
      double value = waveform.get(sample, channel);
      sum += value * value;
      std::cout << " " << value;
    }
    if (numberOfChannels > 1)
      std::cout << " " << sqrt(sum);
    std::cout << " " << sample;

    std::cout << std::endl;
  }

  std::cout.imbue(oldLocale);
}

int main(int argc, char **argv) {

  std::string file = "";
  std::string mode;
  std::string startTimeString, endTimeString;

  bo::Logger logger("");

  // programm arguments/options
  boost::program_options::options_description desc("program options");
  desc.add_options()
    ("help,h", "show program help")
    ("input-file,i", po::value<std::string>(&file), "file name")
    ("starttime,s", po::value<std::string>(&startTimeString), "start time in HHMM or HHMMSS format")
    ("endtime,e", po::value<std::string>(&endTimeString), "end time in HHMM or HHMMSS format")
    ("mode", po::value<std::string>(&mode)->default_value("default"), "data mode [default, statistics, histogram]")
    ("verbose,v", "verbose mode")
    ("long-data,l", "output all samples")
    ("debug", "debug mode")
    ;

  // parse command line options
  po::variables_map vm;
  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
  po::notify(vm); 

  // help output or no 'sql-statement' given
  if (vm.count("help")) {
    std::cout << argv[0] << " [options]" << std::endl << std::endl;
    std::cout << desc << std::endl;
    std::cout << std::endl;

    return 1;
  }

  if (! vm.count("input-file")) {
    std::cerr << "'input-file' missing\n";
    return 5;
{'fraction_non_alphanumeric': 0.181697788372401, 'fraction_numerical': 0.004237849291484572, 'mean_word_length': 4.6106983655274885, 'pattern_counts': {'":': 0, '<': 137, '<?xml version=': 0, '>': 59, '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': '4523231', 'n_tokens_mistral': 2642, 'n_tokens_neox': 2494, 'n_words': 538}