Example #1
0
void  DataBaseServer::ParseParameterStr (const  KKStr&  parameterStr)
{
  VectorKKStr  parameterPairs = parameterStr.Split ("\t");

  VectorKKStr::iterator  idx;
  for  (idx = parameterPairs.begin ();  idx != parameterPairs.end ();  idx++)
  {
    VectorKKStr  fields = (*idx).Split (":=");   // Split by either ':'  or  '='
    if  (fields.size () < 2)
    {
      // Should be two fields;  line must be malformed.
      continue;
    }

    KKStr  parameterName = fields[0].ToUpper ();

    if      ((parameterName == "EMBEDDED")      ||  (parameterName == "EMB")       ||  (parameterName == "E"))   embedded     = fields[1].ToBool ();
    else if ((parameterName == "MYSQLDATADIR")  ||  (parameterName == "MYSQL")     ||  (parameterName == "MDD")) mySqlDataDir = fields[1];
    else if ((parameterName == "DESCRIPTION")   ||  (parameterName == "DESC")      ||  (parameterName == "D"))   description  = fields[1];
    else if ((parameterName == "HOSTNAME")      ||  (parameterName == "HOST")      ||  (parameterName == "H"))   hostName     = fields[1];
    else if ((parameterName == "USERNAME")      ||  (parameterName == "USER")      ||  (parameterName == "U"))   userName     = fields[1];
    else if ((parameterName == "PASSWORD")      ||  (parameterName == "PW")        ||  (parameterName == "P"))   passWord     = fields[1];
    else if ((parameterName == "PORTNUM")       ||  (parameterName == "PN"))                                     portNum      = fields[1].ToUint32 ();
    else if ((parameterName == "DATABASENAME")  ||  (parameterName == "DATABASE")  ||  (parameterName == "DB"))  dataBaseName = fields[1];
  }

  if  (description.EqualIgnoreCase ("Embedded"))
    embedded = true;
}  /* ParseParameterStr */
Example #2
0
void  KKJob::ProcessStatusStr (const KKStr&  statusStr)
{
  log.Level (30) << "KKJob::ProcessStatusStr[" << statusStr << "]" << endl;
  KKStr  fieldName;
  KKStr  fieldValue;

  VectorKKStr fields = statusStr.Split ('\t');
  kkuint32  fieldNum = 0;

  while  (fieldNum < fields.size ())
  {
    fieldName = fields[fieldNum];
    fieldNum++;
    if  (fieldNum < fields.size ())
    {
      fieldValue = fields[fieldNum];
      fieldNum++;
    }
    else
    {
      fieldValue = "";
    }

    fieldName.Upper ();
    fieldValue.TrimLeft ("\n\r\t ");
    fieldValue.TrimRight ("\n\r\t ");

    if  (fieldName.CompareIgnoreCase ("JOBID") == 0)
      jobId = atoi (fieldValue.Str ());

    else  if  (fieldName.CompareIgnoreCase ("PARENTID") == 0)
      parentId = atoi (fieldValue.Str ());

    else  if  (fieldName.CompareIgnoreCase ("STATUS") == 0)
      status = JobStatusFromStr (fieldValue);
   
    else  if  (fieldName.CompareIgnoreCase ("NumProcessors") == 0)
      numProcessors = fieldValue.ToInt ();

    else  if  (fieldName.CompareIgnoreCase ("NumPorcessesAllowed") == 0)
      numPorcessesAllowed = fieldValue.ToInt ();

    else  if  (fieldName.CompareIgnoreCase ("Prerequisites") == 0)
      PrerequisitesFromStr (fieldValue);
      
    else
    {
      ProcessStatusField (fieldName, fieldValue);
    }
  }
}  /* ProcessStatusStr */
Example #3
0
void  KKJob::PrerequisitesFromStr (const KKStr&  s)
{
  prerequisites.clear ();

  if  (s.CompareIgnoreCase ("None") != 0)
  {
    VectorKKStr fields = s.Split (',');
    for  (kkuint32 x = 0;  x < fields.size ();  ++x)
    {
      kkint32 p = fields[x].ToInt ();
      prerequisites.push_back (p);
    }
  }
}  /* PrerequisitesFromStr */
void  InstrumentDataPitchAndRoll::ProcessData (const KKStr&  txt)
{
  VectorKKStr  fields = txt.Split (" \t\n\r");
  if  (fields.size () < 4)
     return;

  float  pitch = -999.99f;
  float  roll  = -999.99f;

  KKStr  fieldName  = "";
  KKStr  fieldValue = "";
  kkuint32 fieldNum   = 0;

  while  (fieldNum < fields.size ())
  {
    fieldName  = fields[fieldNum];
    fieldName.Upper ();
    fieldNum++;

    if  (fieldNum < fields.size ())
    {
      fieldValue = fields[fieldNum];  
      fieldNum++;
    }
    else
    {
      fieldValue = "";
    }

    if  (fieldName == "R")
    {
      roll = fieldValue.ToFloat ();
    }
    else if  (fieldName == "P")
    {
      pitch = fieldValue.ToFloat ();
    }
  } 

  manager->PitchAndRollData (curTextLineStartScanLine, pitch, roll);
}  /* ProcessData */
void  InstrumentDataBatteryMeter::ProcessBatteryData (const KKStr&  txt)
{
  // We will be expecting 5 fields;  
  // <Current battery> <\t> <Bat 0 Voltage>  <\t> .... <\t> <Bat-3 Voltage>
    
  VectorKKStr  fields = txt.Split (',');
  if  (fields.size () < (1 + numOfBatteries))
    return;
      
  // activeBattery is '1' based  that is batteries '1' - '4';  so 
  // batteryLevels[0] = battery level for battery 1.
  kkint32  activeBattery = fields[0].ToInt ();
  if  ((activeBattery < 1)  ||  ((kkuint32)activeBattery > numOfBatteries))
    return;

  kkuint32  x;
  for  (x = 0;  x < numOfBatteries;  x++)
    batteryLevels[x] = fields[x + 1].ToFloat ();

  manager->BatteryData (curTextLineStartScanLine, activeBattery, batteryLevels);
}  /* ProcessBatteryData */
Example #6
0
void   KKJobManager::ProcessJobXmlBlockOfText (const KKStr&  startStr,
                                               istream&      i
                                              )
{
  if  ((startStr.SubStrPart (0, 4) != "<KKJob ")  ||  (startStr.LastChar () != '>'))
  {
    log.Level (-1) << endl 
                   << "KKJobManager::ProcessJobXmlBlockOfText   ***ERROR***   StartStr[" << startStr << "] is not a KKJob String." << endl
                   << endl;
    return;
  }

  KKStr s = startStr.SubStrPart (5);
  s.TrimLeft ();
  s.ChopLastChar ();

  KKStr  jobTypeStr = "";
  kkint32 jobId = -1;


  VectorKKStr  parameters = s.Split (',');
  for  (kkuint32 x = 0;  x < parameters.size ();  ++x)
  {
    KKStr  parameterStr = parameters[x];
    parameterStr.TrimLeft ();
    parameterStr.TrimRight  ();

    KKStr  fieldName = parameterStr.ExtractToken2 ("=");
    fieldName.TrimLeft  ();   fieldName.TrimRight  ();

    KKStr  fieldValue = parameterStr.ExtractToken2 ("=");
    fieldValue.TrimLeft ();   fieldValue.TrimRight ();

    if  (fieldName.CompareIgnoreCase ("JobType") == 0)
      jobTypeStr = fieldValue;

    else if  (fieldName.CompareIgnoreCase ("JobId") == 0)
      jobId = fieldValue.ToInt ();
  }

  
  if  (jobTypeStr.Empty () ||  (jobId < 0))
  {
    log.Level (-1) << endl 
                   << "KKJobManager::ProcessJobXmlBlockOfText   ***ERROR***   StartStr[" << startStr << "]." << endl
                   << "                             JobType and/or JobId were not provided."               << endl
                   << endl;
    return;
  }


  KKJobPtr  j = jobs->LookUpByJobId (jobId);
  if  (j == NULL)
  {
    // We do not have this job in memory yet.  We will have to create it now.
    KKStr  emptyStatusStr = "JobId\t" + StrFormatInt (jobId, "ZZZZ0");
    j = KKJob::CallAppropriateConstructor (this, jobTypeStr, emptyStatusStr);
  }


  j->CompletedJobDataRead (i);
}  /* ProcessJobXmlBlockOfText */
Example #7
0
void  ClassificationBiasMatrix::ReadSimpleConfusionMatrix (istream&           sr,
                                                           MLClassListPtr  fileClasses
                                                          )
{
  //  'classes'     - The class order that the owner of this object is expecting.
  //  'fileClasses' - The order that the classes are stored in the text file.


  if  ((classes == NULL)  ||  (fileClasses == NULL))
  {
    KKStr  errMsg = "ReadSimpleConfusionMatrix   ***ERROR***  The 'Classes'  line was never provided.";
    runLog.Level (-1) << errMsg << endl;
    valid = false;
    throw KKException (errMsg);
  }

  kkint32  classesColIdx = 0;

  char  buff[10240];
  KKStr  l;
  while  (!sr.eof ())
  {
    sr.getline (buff, sizeof (buff));
    l = buff;
    l.TrimLeft ();
    l.TrimRight ();

    if  (l.CompareIgnoreCase ("</SimpleConfusionMatrix>") == 0)
      break;

    KKStr  lineName = l.ExtractToken2 ("\t");

    if  (lineName.CompareIgnoreCase ("DataRow") == 0)
    {
      if  (fileClasses == NULL)
      {
        KKStr  errMsg = "ReadSimpleConfusionMatrix   ***ERROR***  'Classes'  was not provided before 'DataRow'.";
        runLog.Level (-1) << errMsg << endl;
        valid = false;
        throw KKException (errMsg);
      }

      KKStr  className = l.ExtractToken2 ("\t");
      KKStr  data      = l.ExtractToken2 ("\t");

      MLClassPtr  pc = MLClass::CreateNewMLClass (className);
      kkint32  classesIdx     = classes->PtrToIdx (pc);
      kkint32  fileClassesIdx = fileClasses->PtrToIdx (pc);

      if  (classesIdx < 0)
      {
        KKStr  errMsg = "ReadSimpleConfusionMatrix   ***ERROR***  DataRow specifies class[" + className + "] which is not defined by caller";
        runLog.Level (-1) << errMsg << endl;
        valid = false;
        throw KKException (errMsg);
      }

      if  (fileClassesIdx < 0)
      {
        KKStr errMsg = "ReadSimpleConfusionMatrix   ***ERROR***  DataRow specifies class[" + className + "] was not defined in 'Classes' line.";
        runLog.Level (-1) << errMsg << endl;
        valid = false;
        throw KKException (errMsg);
      }

      kkint32  classesRowIdx = classesIdx;

      VectorKKStr  dataFields = data.Split (',');
      if  (dataFields.size () != (kkuint32)numClasses)
      {
        KKStr  errMsg = "ReadSimpleConfusionMatrix   ***ERROR***  DataRow Class[" + className + "]  number[" + StrFormatInt ((kkint32)dataFields.size (), "ZZZ0") + "] of values provided does not match number of Classes.";
        runLog.Level (-1) << errMsg << endl;
        valid = false;
        throw KKException (errMsg);
      }

      for  (kkint32 c = 0;  c < numClasses;  c++)
      {
        pc = fileClasses->IdxToPtr (c);
        classesColIdx = classes->PtrToIdx (pc);

        VectorKKStr   parts = dataFields[c].Split (':');
        if  (parts.size () > 1)
        {
          (*counts)       [classesRowIdx][classesColIdx] = parts[0].ToDouble ();
          (*probabilities)[classesRowIdx][classesColIdx] = parts[1].ToDouble ();
        }
      }
    }
  }
}  /* ReadSimpleConfusionMatrix */