Skip to content

Commit

Permalink
Export data in csv
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed Nov 28, 2024
1 parent ee68cbc commit df39a72
Show file tree
Hide file tree
Showing 28 changed files with 200 additions and 132 deletions.
4 changes: 4 additions & 0 deletions MMVII/git_help_mpd.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export MMVII_USE_MMV1_IMAGE=1
export MMVII_USE_MMV1_IMAGE=0

=====================================================
git config core.editor vim

git fetch origin
Expand Down
4 changes: 2 additions & 2 deletions MMVII/include/MMVII_2Include_CSV_Serial_Tpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ template <class Type> void FromCSV(std::vector<Type>& aVect,const std::string &
//======================================================================================
template <class Type> void Tpl_AddHeaderReportCSV(cMMVII_Appli & anAppli,const std::string & anId,bool IsMul)
{
anAppli.InitReport(anId,"csv",IsMul,{});
if (anAppli.LevelCall()==0)
anAppli.InitReportCSV(anId,"csv",IsMul,{});
if ((anAppli.LevelCall()==0) || (!IsMul))
{
std::string aNameFile = anAppli.NameFileCSVReport(anId);
cOCSVFile<Type>(aNameFile,true); // true with header
Expand Down
2 changes: 1 addition & 1 deletion MMVII/include/MMVII_Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace MMVII

// extern int The_MMVII_DebugLevel = The_MMVII_DebugLevel_InternalError_medium;
//#define The_MMVII_DebugLevel The_MMVII_DebugLevel_BenchError
// #define The_MMVII_DebugLevel The_MMVII_DebugLevel_InternalError_tiny
#define The_MMVII_DebugLevel The_MMVII_DebugLevel_InternalError_tiny
// #define The_MMVII_DebugLevel The_MMVII_DebugLevel_BenchError
// #define The_MMVII_DebugLevel The_MMVII_DebugLevel_UserError

/** The error handler can be change , so its a function Ptr of type PtrMMVII_Error_Handler,
Expand Down
3 changes: 3 additions & 0 deletions MMVII/include/MMVII_MeasuresIm.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class cMesIm1Pt
std::string mNamePt;
cArray<tREAL4,3> mSigma2; // xx xy yy
};
void AddData(const cAuxAr2007 & anAux,cMesIm1Pt & aGCPMI);

/** class for representing a set of measure in an image*/
class cSetMesPtOf1Im : public cMemCheck
Expand All @@ -96,6 +97,8 @@ class cSetMesPtOf1Im : public cMemCheck
cSetMesPtOf1Im();
static cSetMesPtOf1Im FromFile(const std::string & aNameFile);
void AddMeasure(const cMesIm1Pt &);
/// Add a measure only if name is new, if not test if dist < tol if not ->error
void AddMeasureIfNew(const cMesIm1Pt &,tREAL8 aTol=-1);
void AddData(const cAuxAr2007 & anAux);
void SortMes(); // sort measures in place with NamePt

Expand Down
21 changes: 16 additions & 5 deletions MMVII/include/cMMVII_Appli.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class cTimerSegm
~cTimerSegm();
/// Force to have no show at del, usefull for handling parameter in bench
void SetNoShowAtDel();
double CurBeginTime() const ; ///< Accessor
private :
tTableIndTS mTimers;
tIndTS mLastIndex;
Expand Down Expand Up @@ -395,6 +396,16 @@ enum class eModeCall
eMulSubP
};

struct cAttrReport
{
public :
std::string mPost;
std::string mFile;
std::string mDirRedirect;
bool mIsMul;
bool m2Merge;
};


class cMMVII_Appli : public cMMVII_Ap_NameManip,
public cMMVII_Ap_CPU
Expand Down Expand Up @@ -540,7 +551,7 @@ class cMMVII_Appli : public cMMVII_Ap_NameManip,
virtual void OnCloseReport(int aNbLine,const std::string & anIdent,const std::string & aNameFile) const;

/// Generate a new entry for report "anId", IsMul -> indicate if we are in multi process (for merge at end)
void InitReport(const std::string &anId,const std::string & aPostfix,bool IsMul,const std::vector<std::string> & aHeader={});
void InitReportCSV(const std::string &anId,const std::string & aPostfix,bool IsMul,const std::vector<std::string> & aHeader={});
// void AddTopReport(const std::string &anId,const std::string & VecMsg);


Expand Down Expand Up @@ -734,11 +745,11 @@ class cMMVII_Appli : public cMMVII_Ap_NameManip,
bool mIsInBenchMode; ///< is the command executed for bench (will probably make specific test)

char mCSVSep; ///< separator in csv file, for now hard coded to ","
std::map<std::string,std::string> mMapIdFilesReport; ///< For a given id memorize the post fix, as "csv"
std::map<std::string,std::string> mMapIdPostReport; ///< For a given id , memorize the file (Global of Tmp in sub process)
std::map<std::string,cAttrReport> mMapAttrReport; ///< For a given id memorize the post fix, as "csv"
// std::map<std::string,std::pair<bool,std::string>> mMapIdPostReport; ///< For a given id , memorize IsMul + Post
/// If finally, we want to store finall result is another Dir (when report is used for generating data in csv as export)
std::map<std::string,std::string> mMapIdRedirect;
std::set<std::string> mReport2Merge; ///< Memorize all the report identifier that must be merged
// std::map<std::string,std::string> mMapIdRedirect;
// std::set<std::string> mReport2Merge; ///< Memorize all the report identifier that must be merged
std::string mReportSubDir; ///< In case we want to write in separate subdir (like with GCP)

std::string mPatternInitGMA;
Expand Down
2 changes: 2 additions & 0 deletions MMVII/src/Appli/cMMVII_Ap_CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ cTimerSegm::cTimerSegm(cMMVII_Ap_CPU * anAppli) :
{
}

double cTimerSegm::CurBeginTime() const {return mCurBeginTime;}

void cTimerSegm::SetNoShowAtDel()
{
mShowAtDel = false;
Expand Down
5 changes: 4 additions & 1 deletion MMVII/src/Appli/cMMVII_Appli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,10 @@ void cMMVII_Appli::LogCommandOut(const std::string & aName,bool MainLogFile)
return;
cMMVII_Ofs aOfs(aName,eFileModeOut::AppendText);
// Add id, if several process were throw in // there is a mix and we no longer know which was closed
aOfs.Ofs() << " ending correctly at : " << StrDateCur() << " (Id=" << mPrefixNameAppli << ")\n\n";
aOfs.Ofs() << " ending correctly at : " << StrDateCur()
<< " Time=" << SecFromT0() - TimeSegm().CurBeginTime()
<< " TTT=" << SecFromT0()
<< " (Id=" << mPrefixNameAppli << ")\n\n";
aOfs.Ofs().close();
}

Expand Down
55 changes: 29 additions & 26 deletions MMVII/src/Appli/cMMVII_Appli_MakeReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void cMMVII_Appli::SetReportSubDir(const std::string & aSubDir)
void cMMVII_Appli::SetReportRedir(const std::string &anId,const std::string & aNewDir)
{
CreateDirectories(aNewDir,false);
mMapIdRedirect[anId] = aNewDir;
mMapAttrReport[anId].mDirRedirect = aNewDir;
}


Expand All @@ -38,41 +38,40 @@ std::string cMMVII_Appli::DirSubPReport(const std::string &anId)
}


void cMMVII_Appli::InitReport(const std::string &anId,const std::string &aPost,bool IsMul,const std::vector<std::string> & aHeader)
void cMMVII_Appli::InitReportCSV(const std::string &anId,const std::string &aPost,bool IsMul,const std::vector<std::string> & aHeader)
{
if (IsMul && (LevelCall()==0))
{
mReport2Merge.insert(anId);
}
cAttrReport & anAttr = mMapAttrReport[anId];
anAttr.mIsMul = IsMul;
anAttr.m2Merge = IsMul && (LevelCall()==0);
anAttr.mPost = aPost;

if (LevelCall()==0)
if ((LevelCall()==0) || (!IsMul))
{
CreateDirectories(DirReport(),true);
mMapIdFilesReport[anId] = DirReport()+anId + "." + aPost;
anAttr.mFile = DirReport()+anId + "." + aPost;
if (IsMul)
CreateDirectories(DirSubPReport(anId),true);
}
else if (LevelCall()==1)
{
mMapIdFilesReport[anId] = DirSubPReport(anId) + FileOfPath(UniqueStr(0),false) +"." + aPost;
anAttr.mFile = DirSubPReport(anId) + FileOfPath(UniqueStr(0),false) +"." + aPost;
}
else
return;
mMapIdPostReport[anId] = aPost;

cMMVII_Ofs(mMapIdFilesReport[anId], eFileModeOut::CreateText);
cMMVII_Ofs(anAttr.mFile, eFileModeOut::CreateText);

if (! aHeader.empty())
AddHeaderReportCSV(anId,aHeader);
}

const std::string& cMMVII_Appli::NameFileCSVReport(const std::string & anId) const
{
auto anIt = mMapIdFilesReport.find(anId);
auto anIt = mMapAttrReport.find(anId);

MMVII_INTERNAL_ASSERT_tiny(anIt!=mMapIdPostReport.end(),"NameFileCSVReport for Id=" + anId);
MMVII_INTERNAL_ASSERT_tiny(anIt!=mMapAttrReport.end(),"NameFileCSVReport for Id=" + anId);

return anIt->second;
return anIt->second.mFile;
}

/*
Expand All @@ -87,8 +86,7 @@ void cMMVII_Appli::AddTopReport(const std::string &anId,const std::string & aMs

void cMMVII_Appli::AddOneReport(const std::string &anId,const std::string & aMsg)
{
std::string aName = mMapIdFilesReport[anId];
MMVII_INTERNAL_ASSERT_tiny(aName!="","No file in AddOneMesCSV");
std::string aName = NameFileCSVReport(anId);
cMMVII_Ofs aFile(aName, eFileModeOut::AppendText);

aFile.Ofs() << aMsg;
Expand Down Expand Up @@ -148,24 +146,22 @@ void cMMVII_Appli:: AddStdStatCSV(const std::string &anId,const std::string & a
}



void cMMVII_Appli::DoMergeReport()
{
for (const auto & anIt : mMapIdFilesReport)
for (const auto & [anId,anAttr] : mMapAttrReport)
{
if (BoolFind(mReport2Merge,anIt.first))
if (anAttr.m2Merge)
{
int aNbLines = 0;
// Put aFileGlob in {} to create destruction before OnCloseReport that may generat error
{
cMMVII_Ofs aFileGlob(anIt.second, eFileModeOut::AppendText);
const std::string & anId = anIt.first;
cMMVII_Ofs aFileGlob(anAttr.mFile, eFileModeOut::AppendText);

if (mRMSWasUsed)
{
for (const auto & aNameIm : VectMainSet(0))
{
std::string aNameIn = DirSubPReport(anId) + FileOfPath(aNameIm,false) + "." + mMapIdPostReport[anId];
std::string aNameIn = DirSubPReport(anId) + FileOfPath(aNameIm,false) + "." + anAttr.mPost;
cMMVII_Ifs aIn(aNameIn, eFileModeIn::Text);

std::string aLine;
Expand All @@ -179,16 +175,23 @@ void cMMVII_Appli::DoMergeReport()
RemoveRecurs(DirSubPReport(anId),false,false);

}
OnCloseReport(aNbLines,anIt.first,anIt.second);
OnCloseReport(aNbLines,anId,anAttr.mFile);
}
if (MapBoolFind(mMapIdRedirect,anIt.first) && (LevelCall()==0))
/*
if (MapBoolFind(mMapIdRedirect,anIt.first))
{
StdOut() << "WWftR78::: " << anIt.second << " => " << mMapIdRedirect[anIt.first] + FileOfPath(anIt.second) << "\n";
}
*/
if ( (anAttr.mDirRedirect!="") && ( (LevelCall()==0) || (! anAttr.mIsMul)))
{
std::string aNewFile = mMapIdRedirect[anIt.first] + FileOfPath(anIt.second);
RenameFiles(anIt.second,aNewFile);
std::string aNewFile = anAttr.mDirRedirect + FileOfPath(anAttr.mFile);
RenameFiles(anAttr.mFile,aNewFile);
}
}
}


// By default nothing to do
void cMMVII_Appli::OnCloseReport(int aNbLine,const std::string & anIdent,const std::string & aNameFile) const
{
Expand Down
14 changes: 13 additions & 1 deletion MMVII/src/CodedTarget/cCheckBoardTargetExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,9 @@ void cAppliCheckBoardTargetExtract::DoExport()
if (aCdtM.Code())
{
std::string aCode = aCdtM.Code()->Name() ;
aSetM.AddMeasure(cMesIm1Pt(aCdtM.mC0,aCode,1.0));
cMesIm1Pt aMesIm(aCdtM.mC0,aCode,1.0);
aSetM.AddMeasure(aMesIm);
Tpl_AddOneObjReportCSV(*this,mIdExportCSV,aMesIm);
}
}

Expand All @@ -567,6 +569,14 @@ void cAppliCheckBoardTargetExtract::DoExport()

void cAppliCheckBoardTargetExtract::DoOneImage()
{
mIdExportCSV = "CheckBoardCodedTarget-" + mNameIm;
// Create a report with header computed from type
Tpl_AddHeaderReportCSV<cMesIm1Pt>(*this,mIdExportCSV,false);
// Redirect the reports on folder of result
SetReportRedir(mIdExportCSV,mPhProj.DPPointsMeasures().FullDirOut());



mInterpol = new cTabulatedDiffInterpolator(cSinCApodInterpolator(5.0,5.0));

mSpecif = cFullSpecifTarget::CreateFromFile(mNameSpecif);
Expand Down Expand Up @@ -707,6 +717,8 @@ int cAppliCheckBoardTargetExtract::Exe()
{
mPhProj.FinishInit();



if (RunMultiSet(0,0))
{
return ResultMultiSet();
Expand Down
1 change: 1 addition & 0 deletions MMVII/src/CodedTarget/cCheckBoardTargetExtract.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class cAppliCheckBoardTargetExtract : public cMMVII_Appli
tREAL8 mCurScale; /// Memorize the current value of the scale
bool mMainScale; /// Is it the first/main scale
cDiffInterpolator1D * mInterpol;
std::string mIdExportCSV; /// Identifier for handling result as CSV-files
};


Expand Down
27 changes: 21 additions & 6 deletions MMVII/src/CodedTarget/cCircTargetExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ class cAppliExtractCircTarget : public cMMVII_Appli,

tREAL8 mStepRefineGrad;
cDiffInterpolator1D * mInterpol;
std::string mIdExportCSV;
};


Expand Down Expand Up @@ -847,8 +848,14 @@ void cAppliExtractCircTarget::DoExport()
if (anEE->mCardDetect==1)
{
std::string aCode = anEE->mWithCode ? anEE->mEncode.Name() : (MMVII_NONE +"_" + ToStr(aCptUnCoded,mSpec->NbBits()));
aSetM.AddMeasure(cMesIm1Pt(anEE->mPt,aCode,1.0));
mVSavE.push_back(cSaveExtrEllipe(*anEE,aCode));
cMesIm1Pt aMesIm(anEE->mPt,aCode,1.0);
aSetM.AddMeasure(aMesIm);
Tpl_AddOneObjReportCSV(*this,mIdExportCSV,aMesIm);

cSaveExtrEllipe anESave(*anEE,aCode);

mVSavE.push_back(anESave);


if (! anEE->mWithCode) aCptUnCoded++;
}
Expand All @@ -861,6 +868,8 @@ void cAppliExtractCircTarget::DoExport()
SaveInFile(mVSavE,cSaveExtrEllipe::NameFile(mPhProj,aSetM,false));
}



void cAppliExtractCircTarget::MakeImageSeed()
{
cRGBImage aImVisu= cRGBImage::FromFile(mNameIm,CurBoxIn());
Expand Down Expand Up @@ -1047,6 +1056,12 @@ void cAppliExtractCircTarget::TestOnSimul()

int cAppliExtractCircTarget::ExeOnParsedBox()
{
mIdExportCSV = "CircCodedTarget" + mNameIm;
// Create a report with header computed from type
Tpl_AddHeaderReportCSV<cMesIm1Pt>(*this,mIdExportCSV,false);
// Redirect the reports on folder of result
SetReportRedir(mIdExportCSV,mPhProj.DPPointsMeasures().FullDirOut());

mInterpol = new cTabulatedDiffInterpolator(cSinCApodInterpolator(5.0,5.0));

mPBWT.mDistMinMaxLoc = mPBWT.mMinDiam * mRatioDMML;
Expand Down Expand Up @@ -1200,17 +1215,17 @@ int cAppliExtractCircTarget::Exe()
}

mReportMutipleDetec = "MultipleTarget";
InitReport(mReportMutipleDetec,"csv",true,{"Image","Target","Mult","x","y"});
InitReportCSV(mReportMutipleDetec,"csv",true,{"Image","Target","Mult","x","y"});


if (mDoReportSimul)
{
mReportSimulDet = "SimulDetails" ;
mReportSimulGlob = "SimulGlob" ;
InitReport(mReportSimulDet,"csv",true);
InitReport(mReportSimulGlob,"csv",true);
InitReportCSV(mReportSimulDet,"csv",true);
InitReportCSV(mReportSimulGlob,"csv",true);
}
mNbMaxMulTargetTot = mNbMaxMT_Init + mNbMaxMT_PerIm * VectMainSet(0).size() ;
StdOut() << "mNbMaxMulTargetTotmNbMaxMulTargetTotmNbMaxMulTargetTotmNbMaxMulTargetTotmNbMaxMulTargetTotmNbMaxMulTargetTot " << mNbMaxMulTargetTot << "\n";


if (RunMultiSet(0,0)) // If a pattern was used, run in // by a recall to itself 0->Param 0->Set
Expand Down
2 changes: 1 addition & 1 deletion MMVII/src/CodedTarget/cCompleteUncodeTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ int cAppliCompletUncodedTarget::Exe()
mPhProj.FinishInit();

mNameReportEllipse = "EllipsesDim";
InitReport(mNameReportEllipse,"csv",true);
InitReportCSV(mNameReportEllipse,"csv",true);


AddHeaderReportCSV(mNameReportEllipse,{"Image","Pt","Ray","Ratio"});
Expand Down
4 changes: 2 additions & 2 deletions MMVII/src/CodedTarget/cDistCorrectCirgTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ int cAppliCorrecDistCircTarget::Exe()
mPostfixReport = "_Ori-"+ mPhProj.DPOrient().DirIn() + "_Mes-"+ mPhProj.DPPointsMeasures().DirIn() ;
mReportDetail = "Detail-" +mPostfixReport;
mReportIm = "ByImage-" +mPostfixReport;
InitReport(mReportDetail,"csv",true);
InitReport(mReportIm,"csv",true);
InitReportCSV(mReportDetail,"csv",true);
InitReportCSV(mReportIm,"csv",true);


mSaveMeasure = mPhProj.DPPointsMeasures().DirOutIsInit();
Expand Down
Loading

0 comments on commit df39a72

Please sign in to comment.