Click here to Skip to main content
15,905,316 members

Comments by Member 13475664 (Top 16 by date)

Member 13475664 19-Dec-17 11:20am View    
by using example in this link i did
https://stackoverflow.com/questions/31834306/best-algorithm-to-group-data-by-similarity-same-id
but it used to always create new group, if the same ID data is sent it was not sent to that group of ID
Member 13475664 19-Dec-17 10:04am View    
actually i used
std::vector<std::vector<mydata> > GroupByIDs(const std::vector<mydata>& data)
{
std::vector<std::vector<mydata> > groups;

decltype(data.end()) upper;

for(auto lower = data.begin(); lower != data.end(); lower = upper)
{
// get the upper position of all elements with the same ID
upper = std::upper_bound(data.begin(), data.end(), *lower);

// add those elements as a group to the output vector
groups.emplace_back(lower, upper);
}

return groups;
}

but it went on creating new groups it was not storing into the group which was already created if the same ID is sent to this function
Member 13475664 16-Dec-17 14:02pm View    
i found the solution by comparing length of the string, i am finally able to avoid the unwanted lines.
Member 13475664 16-Dec-17 11:30am View    
Deleted
the overall code

start:

while (std::getline(file, line))
{
std::istringstream iss(line);

std::size_t space = line.find(" ", 0);
if (!isspace(line[0]))
{
iss.clear();
}
else
{
int i;
for (i = 0; i <= 12; i++)
{
if (isalpha(line[i]))
{
iss.clear();
goto start;
}
}

iss >> data.time >> data.state >> data.ID >> data.status >> data.type >> data.byte_lent >> data.message_1 >> data.message_2 >> data.message_3 >> data.message_4 >> data.message_5 >> data.message_6;
iss >> data.message_7 >> data.message_8 >> data.type1 >> data.type2 >> data.type3 >> data.type4 >> data.type5 >> data.type6 >> data.type7 >> data.type8 >> data.type9;
Member 13475664 16-Dec-17 6:30am View    
Deleted
the code represent the reading of a file, where i need to extract only the lines that has information other lines must be ignored
the text is actually in the following manner
date Fri Sep 1 02:11:40.195 pm 2017
base hex timestamps absolute
internal events logged
// version 9.0.0
Begin Triggerblock Fri Sep 1 02:11:40.195 pm 2017
0.000000 Start of measurement
0.002893 1 201 Rx d 8 06 0D 00 B0 89 00 0D E7 Length = 227925 BitCount = 118 ID = 513
0.003133 1 280 Rx d 8 1B 0C 7C F1 E8 75 39 67 Length = 221910 BitCount = 115 ID = 640
0.006981 Status:chip status error active
0.006981 Status:chip status error active
0.007123 1 244 Rx d 8 7B 01 00 08 80 80 C0 00 Length = 233925 BitCount = 121 ID = 580
0.007148 2 B2 Rx d 8 C0 13 9A 13 D8 13 C0 13 Length = 221910 BitCount = 115 ID = 178
0.007359 1 246 Rx d 8 55 01 00 49 50 B6 7A 89 Length = 217925 BitCount = 113 ID = 582
0.007394 2 86 Rx d 8 62 00 2A 20 01 84 02 00 Length = 225925 BitCount = 117 ID = 134

i need to ignore those lines that has sentences and read only the lines that have information and store those values in a class.