I've been gathering information using api calls from my jira. Information gathered is saved in a body file and it has the following content:
No tickets:
{"startAt":0,"maxResults":50,"total":0,"issues":[]}{"startAt":0,"maxResults":50,"total":0,"issues":[]}
One Ticket:
{"expand":"names,schema","startAt":0,"maxResults":50,"total":1,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields","id":"456881","self":"https://myjira...com","key":"TICKET-1111","fields":{"summary":"[TICKET] New Test jira","created":"2018-12-17T01:47:09.000-0800"}}]}{"expand":"names,schema","startAt":0,"maxResults":50,"total":1,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields","id":"456881","self":"https://myjira...com","key":"TICKET-1111","fields":{"summary":"[TICKET] New Test jira","created":"2018-12-17T01:47:09.000-0800"}}]}
Two Tickets:
{expand:schema,names,startAt:0,maxResults:50,total:2,issues:[{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:456881,self:https://myjira...com,key:TICKET-1111,fields:{summary:[TICKET] New Test jira,created:2018-12-17T01:47:09.000-0800}},{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:320281,self:https://myjira...com,key:TICKET-2222,fields:{summary:[TICKET] Test jira,created:2016-03-18T07:58:52.000-0700}}]}{expand:schema,names,startAt:0,maxResults:50,total:2,issues:[{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:456881,self:https://myjira...com,key:TICKET-1111,fields:{summary:[TICKET] New Test jira,created:2018-12-17T01:47:09.000-0800}},{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:320281,self:https://myjira...com,key:TICKET-2222,fields:{summary:[TICKET] Test jira,created:2016-03-18T07:58:52.000-0700}}]}
etc..
Using this code I've been able to gather total open tickets:
std::ifstream t("BodyOpenIssues.out");
std::string BodyString((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
// Removing Quotes
BodyString.erase(std::remove(BodyString.begin(), BodyString.end(), '"'), BodyString.end());
int Result = 0;
unsigned first = BodyString.find("total:");
unsigned last = BodyString.find(",issues");
std::string TotalOpenIssues = BodyString.substr(first + 6, last - (first + 6));
Result = std::stoi(TotalOpenIssues);
return Result;
Using a second function I'm trying to get the keys based on total open tickets.
if (GetOpenIssuesNumber() > 0)
{
std::ifstream t("BodyOpenIssues.out");
std::string BodyString((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
// Removing Quotes
BodyString.erase(std::remove(BodyString.begin(), BodyString.end(), '"'), BodyString.end());
unsigned first = BodyString.find("key:TICKET-");
unsigned last = BodyString.find(",fields");
std::string TotalOpenIssues = BodyString.substr(first + 11, last - (first + 11));
String^ Result = gcnew String(TotalOpenIssues.c_str());
return "TICKET-" + Result;
}
else
{
return "No open issues found";
}
What I mean is:
If Total is 1 to search from the beginning and find the first key TICKET-1111.
If Total is 2 to search from the beginning and get the first key TICKET-1111 then to continue from there and to find the next key TICKET-2222.
And based on that total to find that many keys in that string.
I got lost from all the casting between the types as ifstream reads the file and I save the result in std::string. After the find I save the result in System::String to use it in my Label.. I've been researching and found out that I can use char array but I can't make it dynamic based on BodyString.length().
If more information is required please let me know.
Any suggestions are really appreciated! Thank you in advance!
I went for nlohmann json library. It has everything I need. Thank you Walnut!
These are formatted as JSON. You should use a JSON library for C++ and parse the files with that. Using search/replace is unnecessary complicated and you will likely run into corner cases you haven't considered sooner or later (do you really want the code to randomly miss tickets, etc.?). Also String^ is not C++. Are you writing C++/CLI instead of C++? If so, please tag c++-cli instead of c++. – walnut
I have a field to validate repeated questions. I must convert special characters into normal letters using a method, and then I use a method to skip spaces and other characters to validate if the new text is equal to the existing questions. In my local everything is working fine, but in a Production instance, it skips characters 1, f, x and b. My project in Production is mounted in Linux.
My two methods are:
replaceSpecialCharacters(output){
return output = output.replace(/á|é|í|ó|ú|ñ|ä|ë|ï|ö|ü|à|è|ì|ò|ù/ig,function (str,offset,s) {
var str = str=="á"?"a":str=="é"?"e":str=="í"?"i":str=="ó"?"o":str=="ú"?"u":str=="ñ"?"n":str;
str = str=="Á"?"A":str=="É"?"E":str=="Í"?"I":str=="Ó"?"O":str=="Ú"?"U":str=="Ñ"?"N":str;
str = str=="à"?"a":str=="è"?"e":str=="ì"?"i":str=="ò"?"o":str=="ù"?"u":str;
str = str=="À"?"A":str=="È"?"E":str=="Ì"?"I":str=="Ò"?"O":str=="Ù"?"U":str;
str = str=="ä"?"a":str=="ë"?"e":str=="ï"?"i":str=="ö"?"o":str=="ü"?"u":str;
str = str=="Ä"?"A":str=="Ë"?"E":str=="Ï"?"I":str=="Ö"?"O":str=="Ü"?"U":str;
return (str);
});
}
validateRepeatedQuestion(question): void {
var questionToCheck = this.replaceSpecialCharacters(question).replace(/[(\s)+(\¿)+(\?)+(\¡)+(\!)+(\")+(\')+]/g, "");
this.setState({isRepeated: false});
for (let i = 0; i < this.props.allQuestions.length; i++) {
var questionFromArray = this.replaceSpecialCharacters(this.props.allQuestions[i].text).replace(/[(\s)+(\¿)+(\?)+(\¡)+(\!)+(\")+(\')+]/g, "");
if(this.props.allQuestions[i].position != this.props.question.position){
if(questionFromArray.toLocaleLowerCase() == questionToCheck.toLocaleLowerCase()){
this.setState({isRepeated: true});
}
}
}
}
If I have a question like "How old are you?" and I try to add a question like "How old are you?1111" I expect the validation to take the new question as different, but the actual output says that the question is repeated, even if I'm adding numbers 1. It must be different.
I have written the code to check the query string
Logic::if query string is "?" should remove all the characters from the query string and print the vailid URL.
char str[] = "http://john.org/test.mp4?iufjdlwle";
char *pch;
pch = strtok(str,"?");
printf("%s\n",pch);
Output::
bash-3.2$ ./querystring
http://john.com/test.mp4
But i have to check one more case
Need to get the URL only if there is any extensions present before query string?
if No extensions are present before the query string,need to skip.
I have tried this way,
continuation of the code
char *final;
final = pch+(strlen(pch)-3);
printf("%s\n",final);
if(strcasecmp(p,"mp4"))
printf("falure case\n");
else
printf("Success case\n");
It will work for .mp4 extension alone.
Incase if i'm getting *.mpeg or *.m3u8 or *.flv as an extensions,it will fail.
Can someone guide me how to solve this problem and make it working?
A query string is what starts after a question mark ?, fine.
You should try to define what an extension is. For me, it is what can happen after a dot (.) in the last component of the url, where the components are delimited with slashes (/)
So you should do:
first remove the possible query string including the initial ?
then locate the last /
then locate the last . that occurs after the last /
If you find one, it is the starting point of the extension.
So assuming pch contains the url without any query string, you can do:
char * ix = strrchr(pch, '/');
if (ix == NULL) {
// an URL without / is rather weird, better report and abort
...
}
ix = strrchr(ix, '.');
if (ix == NULL) {
// no extension here: ignore the url
...
}
else {
// found an URL containing an extension: process it
// ix+1 points to the extension
...
}
My purpose is to parse text files and store information in respective tables.
I have to parse around 100 folders having more that 8000 files and whole size approximately 20GB.
When I tried to store whole file contents in a string, memory out exception was thrown.
That is
using (StreamReader objStream = new StreamReader(filename))
{
string fileDetails = objStream.ReadToEnd();
}
Hence I tried one logic like
using (StreamReader objStream = new StreamReader(filename))
{
// Getting total number of lines in a file
int fileLineCount = File.ReadLines(filename).Count();
if (fileLineCount < 90000)
{
fileDetails = objStream.ReadToEnd();
fileDetails = fileDetails.Replace(Environment.NewLine, "\n");
string[] fileInfo = fileDetails.ToString().Split('\n');
//call respective method for parsing and insertion
}
else
{
while ((firstLine = objStream.ReadLine()) != null)
{
lineCount++;
fileDetails = (fileDetails != string.Empty) ? string.Concat(fileDetails, "\n", firstLine)
: string.Concat(firstLine);
if (lineCount == 90000)
{
fileDetails = fileDetails.Replace(Environment.NewLine, "\n");
string[] fileInfo = fileDetails.ToString().Split('\n');
lineCount = 0;
//call respective method for parsing and insertion
}
}
//when content is 90057, to parse 57
if (lineCount < 90000 )
{
string[] fileInfo = fileDetails.ToString().Split('\n');
lineCount = 0;
//call respective method for parsing and insertion
}
}
}
Here 90,000 is the bulk size which is safe to process without giving out of memory exception for my case.
Still the process is taking more than 2 days for completion. I observed this is because of reading line by line.
Is there any better approach to handle this ?
Thanks in Advance :)
You can use a profiler to detect what sucks your performance. In this case it's obvious: disk access and string concatenation.
Do not read a file more than once. Let's take a look at your code. First of all, the line int fileLineCount = File.ReadLines(filename).Count(); means you read the whole file and discard what you've read. That's bad. Throw away your if (fileLineCount < 90000) and keep only else.
It almost doesn't matter if you read line-by-line in consecutive order or the whole file because reading is buffered in any case.
Avoid string concatenation, especially for long strings.
fileDetails = fileDetails.Replace(Environment.NewLine, "\n");
string[] fileInfo = fileDetails.ToString().Split('\n');
It's really bad. You read the file line-by-line, why do you do this replacement/split? File.ReadLines() gives you a collection of all lines. Just pass it to your parsing routine.
If you'll do this properly I expect significant speedup. It can be optimized further by reading files in a separate thread while processing them in the main. But this is another story.
As we know, assert continues the execution but verify stops the execution the moment the script fails.
e.g suppose two string abc, abd xyz
i want to verify the two strings. How to verify them without using Assert.assertEquals(expected, actual);
Can anyone please guide me for the same?
You can verify the 2 strings by creating a method and using if else to compare them.
In your example instead of assert this can be done
public void compareMethod()
{
string expected = "abc";
string actual = "xyz";
if(expected == actual)
{
//do steps required
}
else
{
}
}
If you have already stored strings and want to verifyText using Selenium WebDriver then the following code will surely help..
if("expected String".equals("actual string"))
{
System.out.println("String matches ");
}
else
{
System.out.println("String does not match ");
}
Try this