mrtomeq / dfqtojson-converter Goto Github PK
View Code? Open in Web Editor NEWDFQ to JSON converter is a free, open source and community-focused parser of Q-DAS ASCII transfer format.
License: MIT License
DFQ to JSON converter is a free, open source and community-focused parser of Q-DAS ASCII transfer format.
License: MIT License
please suggest how to convert local .dfq file using this code
In order to prevent to put 100 dfq-files in the execution folder and get the json results in the same folder, it might be an idea to use a separate source and result folder. If you would like to do that, you might want to look at the method below. The files are put in the [execution folder]/dfq_source and the results are written into [execution folder]/json_result.
static void Main(string[] args)
{
var converter = new DfqConverter();
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
var directory = Path.GetDirectoryName(location);
var directorySource = directory + "\\dfq_source";
var directoryResult = directory + "\\json_result";
var files = Directory.EnumerateFiles(directorySource, "*.dfq");
foreach (var file in files)
{
converter.Convert(file);
string newPath = directoryResult + "\\" + Path.GetFileNameWithoutExtension(file) + ".json";
File.WriteAllText(newPath, converter.GetJson());
}
}
Multiple smaller issues were found at the conversion of *.dfq-files:
I fixed the issues in the code below. You might integrate this solution if you want to.
public void Convert(string dfqFilePath)
{
if (string.IsNullOrEmpty(dfqFilePath))
throw new ArgumentException("dfqFilePath");
Parts = new List<Part>();
Characteristics = new List<Characteristic>();
_currentPart = null;
var dfqFile = File.ReadAllLines(dfqFilePath);
var sectionBlock = new List<List<string>>();
var lineBlock = new List<string>();
Boolean addToLineblock = false;
int counter = 1;
//Create Blocks from file, then process the blocks
for (int i=0; i<dfqFile.Length; i++)
{
String previousLine = "";
String currentLine = dfqFile[i];
String nextLine = "";
if (i>0)
{
previousLine = dfqFile[i - 1];
}
if (i<dfqFile.Length-1)
{
nextLine = dfqFile[i + 1];
}
//Set the separator
//1. Empty lines
//2. K10* to K20 if there is no line break
//Create lineblock
//Console.WriteLine("Create text blocks.");
//=== Special text splitter ===//
//Check if there is a special splitter
Boolean textSplitActiveStart = false;
if (previousLine.StartsWith("K10") && currentLine.StartsWith("K20"))
{
textSplitActiveStart = true;
Console.WriteLine("Special text split start K10*->K20*");
}
//====================================//
//Stop line block
if (string.IsNullOrEmpty(currentLine) || textSplitActiveStart == true || string.IsNullOrEmpty(nextLine))
{
sectionBlock.Add(new List<String>(lineBlock));
lineBlock.Clear();
addToLineblock = false;
Console.WriteLine("End line block at line: " + counter + ">" + currentLine);
}
//Start line block
//Startpart is at start/run, previousline was empty or split K1*/K2 was active
if (string.IsNullOrEmpty(currentLine)==false && (counter==1 || string.IsNullOrEmpty(previousLine)==true || textSplitActiveStart==true))
{
addToLineblock = true;
Console.WriteLine("Start new lineblock at line: " + counter + ">" + currentLine);
}
//Add line if block is open
if (addToLineblock==true)
{
lineBlock.Add(currentLine);
Console.WriteLine("Added line to block. Line: " + counter + ">" + currentLine);
}
counter++;
}
Console.WriteLine("Created " + sectionBlock.Count() + " section blocks.");
Console.WriteLine("Process each section block.");
foreach (var block in sectionBlock)
{
if (block.Count()>0)
{
ProcessBlock(block);
}
}
Console.WriteLine("Conversion finished");
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.