1 Star 0 Fork 5

Alen_han/UpperCompute

forked from ChinaYasuo/UpperCompute 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
filesystem.cpp 2.46 KB
一键复制 编辑 原始数据 按行查看 历史
dushenda 提交于 2021-01-11 16:41 . v1
#include "filesystem.h"
#include<QDateTime>
#include <QDebug>
#include <QFile>
FileSystem::FileSystem()
{
root_dir = QDir(QDir(QDir::currentPath()).absolutePath()+"/Data");
root_dir.mkpath(root_dir.absolutePath());
}
bool FileSystem::save_file(const QList<double>& pixel, const QList<double>& voltage,const QString& gain, const QString& inter_time, const QString& ids)
{
QDir file_dir = QDir(root_dir.absolutePath()+"/"+get_curr_date_dir()+"/"+ids+"/");
bool mkpath_ok = file_dir.mkpath(file_dir.absolutePath());
if(!mkpath_ok){ return false;qDebug()<<0;}
QDir::setCurrent(file_dir.absolutePath());
QFile file(get_curr_time_fn()+ids+file_ext);
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream out(&file);
out<<"Gain:"+gain<<" IntergerTime:"+inter_time<<endl
<<QString("Pixel")<<QString(",Voltage")<<endl;
for(int i=0;i<pixel.size();++i)
out<<pixel.at(i)<<","<<voltage.at(i)<<endl;
}else {
return false;
}
QDir::setCurrent(root_dir.absolutePath()+"/../");
return true;
}
bool FileSystem::save_file(const QList<double>& pixel, const QList<QList<double>>& voltages,const QString& gain, const QString& inter_time, const QString& ids)
{
QDir file_dir = QDir(root_dir.absolutePath()+"/"+get_curr_date_dir()+"/"+ids);
bool mkpath_ok = file_dir.mkpath(file_dir.absolutePath());
if(!mkpath_ok&&!file_dir.exists()) return false;
QDir::setCurrent(file_dir.absolutePath());
QFile file(get_curr_time_fn()+ids+"_integration"+file_ext);
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream out(&file);
out<<"Gain:"+gain<<" IntergerTime:"+inter_time<<endl;
out<<QString("Pixel");
for(int i=1;i<=voltages.size();++i)
out<<QString(",")<<QString("Vlotage%1").arg(i);
out<<endl;
for(int i=0;i<pixel.size();++i)
{
out<<pixel.at(i);
for(int j=0;j<voltages.size();++j)
out<<","<<voltages.at(j).at(i);
out<<endl;
}
}else {
return false;
}
QDir::setCurrent(root_dir.absolutePath()+"/../");
return true;
}
QString FileSystem::get_curr_date_dir()
{
QDateTime curr_dt = QDateTime::currentDateTime();
return curr_dt.toString("yyyy-MM-dd");
}
QString FileSystem::get_curr_time_fn()//get current dt file name
{
QDateTime curr_dt = QDateTime::currentDateTime();
return curr_dt.toString("hh_mm_ss_");
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/alen_han/upper-compute.git
git@gitee.com:alen_han/upper-compute.git
alen_han
upper-compute
UpperCompute
master

搜索帮助