Вот метод, который вы можете использовать для получения группы захвата n th для каждого совпадения:
function getMatches(string, regex, index) {
index || (index = 1); // default to the first capturing group
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index]);
}
return matches;
}
// Example :
var myString = 'something format_abc something format_def something format_ghi';
var myRegEx = /(?:^|\s)format_(.*?)(?:\s|$)/g;
// Get an array containing the first capturing group for every match
var matches = getMatches(myString, myRegEx, 1);
// Log results
document.write(matches.length + ' matches found: ' + JSON.stringify(matches))
console.log(matches);
Вот идея.
Постройте каждую трубу в виде 2-го прямоугольника, на котором вы видите дефекты.
необходимо выполнить:
- выяснить, что означает Defect Location
- нужен ли угол?
library(tidyverse)
df <- mydata %>%
#give the pipe an id
mutate( id = 1 ) %>%
group_by( id ) %>%
#give each defect (by pipe) an id
mutate( defect_id = row_number() ) %>%
#not sure what to do woith defect location....
#to get it inside the pipe, i divide by 10... needs looking into!!
mutate( `Defect Location` = `Defect Location` / 10 ) %>%
gather("defect", "x", -Length, -Diameter, -`Defect Angle`, -id, -defect_id, -`Defect Location`)
ggplot( data = df ) +
#draw pipe as a 2D rectangle, height = pi * Diameter
geom_rect( aes( xmin = 0, xmax = Length, ymin = 0, ymax = pi * Diameter ), alpha = 0.1 ) +
#draw start-endpoint and lines with defects
geom_point( aes( x = x, y = `Defect Location`, group = as.character(defect_id) ), color = "red", size = 2 ) +
geom_line( aes( x = x, y = `Defect Location`, group = as.character(defect_id), colour = as.character(defect_id) ), color = "red", size = 2 ) +
#draw each pipe
facet_wrap( ~id, ncol = 1 )