File: BasicLog.cpp

package info (click to toggle)
dasher 4.11%2Bgit20130508.adc653-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 40,248 kB
  • ctags: 5,158
  • sloc: xml: 185,479; cpp: 32,301; sh: 11,207; makefile: 828; ansic: 483
file content (86 lines) | stat: -rw-r--r-- 1,962 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "BasicLog.h"

#include "DasherInterfaceBase.h"

#include <cmath>
#include <fstream>
#include <iostream>

#ifdef _WIN32
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif

using namespace Dasher;

CBasicLog::CBasicLog(CSettingsUser *pCreateFrom, CDasherInterfaceBase *pIntf)
: CUserLogBase(pIntf), CSettingsUser(pCreateFrom) {
  m_iSymbolCount = 0;
  m_bStarted = false;
}

CBasicLog::~CBasicLog() {
  EndTrial();
}

void CBasicLog::StartWriting() {
  if(!m_bStarted) {
    StartTrial();
    m_bStarted = true;
  }
}

void CBasicLog::StopWriting(float dNats) {
  m_dBits += dNats / log(2.0);
}

void CBasicLog::AddSymbols(Dasher::VECTOR_SYMBOL_PROB* pVectorNewSymbolProbs, eUserLogEventType iEvent) {
  m_iSymbolCount += pVectorNewSymbolProbs->size();
}

void CBasicLog::DeleteSymbols(int iNumToDelete, eUserLogEventType iEvent) {
  m_iSymbolCount -= iNumToDelete;
}

void CBasicLog::NewTrial() {
  EndTrial();
}

void CBasicLog::KeyDown(int iId, int iType, int iEffect) {
  ++m_iKeyCount;
}

void CBasicLog::StartTrial() {
  m_iSymbolCount = 0;
  m_iKeyCount = 0;
  m_dBits = 0.0;
  m_strStartDate = GetDateStamp();
  m_iInitialRate = GetLongParameter(LP_MAX_BITRATE);
}

void CBasicLog::EndTrial() {
  if(!m_bStarted)
    return;

  std::string strFileName(CFileLogger::GetFullFilenamePath("dasher_basic.log"));

  std::ofstream oFile;
  oFile.open(strFileName.c_str(), ios::out | ios::app);

  oFile << "\"" << m_strStartDate << "\":\"" << GetDateStamp() << "\":" << m_iSymbolCount << ":" << m_dBits << ":" << m_iKeyCount << ":" << m_iInitialRate / 100.0 << ":" << GetLongParameter(LP_MAX_BITRATE) / 100.0 << ":\"" << GetStringParameter(SP_INPUT_FILTER) << "\":\"" << GetStringParameter(SP_ALPHABET_ID) << "\"" << std::endl;

  oFile.close();

  m_bStarted = false;
}

std::string CBasicLog::GetDateStamp() {
  char* szTimeLine = NULL;
  time_t t;

  t = time(NULL);
  szTimeLine = ctime(&t);

  return std::string(szTimeLine).substr(0, 24);
}