hierarchy

Laravel flatten and pluck from multidimensional collection

我的未来我决定 提交于 2021-02-19 02:00:14
问题 I have to retrieve just an array of id from the given collection, something like [10,54,61,21,etc] . I've tried flatten , pluck , but nothing seems to work apart from a foreach which is something I would like to remove at this step. // Model class Children extends Eloquent { public function directChildrens(){ return $this->hasMany('App\Children','father_id','id')->select('id','father_id'); } public function childrens(){ return $this->directChildrens()->with('childrens'); } } // Controller

How to use Opencv contours to describe line points in a unidirectional way

▼魔方 西西 提交于 2021-02-18 06:40:22
问题 I am using opencvs findContour to find the points to describe an image made up of lines (not polygons) as such: cv::findContours(src, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); . 回答1: If I understand correctly, the "cv2.connectedComponents" method gives what you are looking for. It assigns a label for each point in your image, the label is the same if points are connected. By doing this assignment there is no duplication happening. So, if your lines are one pixel wide

Building a tree using nested unordered lists

时光怂恿深爱的人放手 提交于 2021-02-11 15:49:59
问题 How can I build this HTML code: <ul class="tree"> <li>Animals <ul> <li>Birds</li> <li>Mammals <ul> <li>Elephant</li> <li>Mouse</li> </ul> </li> <li>Reptiles</li> </ul> </li> <li>Plants <ul> <li>Flowers <ul> <li>Rose</li> <li>Tulip</li> </ul> </li> <li>Trees</li> </ul> </li> </ul> From this structure: CREATE TABLE `categories` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `position` INT(11) DEFAULT NULL, `parent_id` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `parent_id_fk` (`parent_id`),

For each employee in employee table, find number of direct and indirect bosses in hierarchy

☆樱花仙子☆ 提交于 2021-02-08 06:09:24
问题 I am given an employee table which looks something like this: Queries to create sample input. CREATE TABLE employee( empId INTEGER, empName VARCHAR(20), mgrId INTEGER, salary DECIMAL(12,2) ); INSERT INTO employee VALUES (1, 'A', 2, 100), (2, 'B', 4, 150), (3, 'C', 4, 165), (4, 'D', 7, 200), (5, 'E', 6, 210), (6, 'F', 7, 250), (7, 'G', 7, 300), (8, 'H', 6, 170); Link to SQL Fiddle: http://sqlfiddle.com/#!9/cd4be8 This sample data results in this hierarchy. Each employee has a direct boss. Also

For each employee in employee table, find number of direct and indirect bosses in hierarchy

99封情书 提交于 2021-02-08 06:04:04
问题 I am given an employee table which looks something like this: Queries to create sample input. CREATE TABLE employee( empId INTEGER, empName VARCHAR(20), mgrId INTEGER, salary DECIMAL(12,2) ); INSERT INTO employee VALUES (1, 'A', 2, 100), (2, 'B', 4, 150), (3, 'C', 4, 165), (4, 'D', 7, 200), (5, 'E', 6, 210), (6, 'F', 7, 250), (7, 'G', 7, 300), (8, 'H', 6, 170); Link to SQL Fiddle: http://sqlfiddle.com/#!9/cd4be8 This sample data results in this hierarchy. Each employee has a direct boss. Also

Count depth of a hierarchy of classes

大兔子大兔子 提交于 2021-02-07 11:11:15
问题 I've seen a lot of different examples of how to do this and am well aware that I could write out a loop that iterates my entire tree of classes to find the maximum depth, but I cannot help but think there has to be a simpler way. Basically I have two classes that I developed to host all my applications settings, SettingGroup which is exactly what it sounds like, basically a folder, and Setting which is the setting itself and the configurations that allow the application to know what the

Retrieving full hierarchy sorted by a column under PostgreSQL's Ltree module

随声附和 提交于 2021-02-06 09:12:35
问题 I'm using PostgreSQL's Ltree module for storing hierarchical data. I'm looking to retrieve the full hierarchy sorted by a particular column. Consider the following table: votes | path | ... -------+-------+----- 1 | 1 | ... 2 | 1.1 | ... 4 | 1.2 | ... 1 | 1.2.1 | ... 3 | 2 | ... 1 | 2.1 | ... 2 | 2.1.1 | ... 4 | 2.1.2 | ... ... | ... | ... In my current implementation, I'd query the database with SELECT * FROM comments ORDER BY path , which would return the whole tree: Node 1 -- Node 1.1 --

Retrieving full hierarchy sorted by a column under PostgreSQL's Ltree module

余生颓废 提交于 2021-02-06 09:12:34
问题 I'm using PostgreSQL's Ltree module for storing hierarchical data. I'm looking to retrieve the full hierarchy sorted by a particular column. Consider the following table: votes | path | ... -------+-------+----- 1 | 1 | ... 2 | 1.1 | ... 4 | 1.2 | ... 1 | 1.2.1 | ... 3 | 2 | ... 1 | 2.1 | ... 2 | 2.1.1 | ... 4 | 2.1.2 | ... ... | ... | ... In my current implementation, I'd query the database with SELECT * FROM comments ORDER BY path , which would return the whole tree: Node 1 -- Node 1.1 --

Retrieving full hierarchy sorted by a column under PostgreSQL's Ltree module

你。 提交于 2021-02-06 09:09:33
问题 I'm using PostgreSQL's Ltree module for storing hierarchical data. I'm looking to retrieve the full hierarchy sorted by a particular column. Consider the following table: votes | path | ... -------+-------+----- 1 | 1 | ... 2 | 1.1 | ... 4 | 1.2 | ... 1 | 1.2.1 | ... 3 | 2 | ... 1 | 2.1 | ... 2 | 2.1.1 | ... 4 | 2.1.2 | ... ... | ... | ... In my current implementation, I'd query the database with SELECT * FROM comments ORDER BY path , which would return the whole tree: Node 1 -- Node 1.1 --

Retrieving full hierarchy sorted by a column under PostgreSQL's Ltree module

℡╲_俬逩灬. 提交于 2021-02-06 09:07:25
问题 I'm using PostgreSQL's Ltree module for storing hierarchical data. I'm looking to retrieve the full hierarchy sorted by a particular column. Consider the following table: votes | path | ... -------+-------+----- 1 | 1 | ... 2 | 1.1 | ... 4 | 1.2 | ... 1 | 1.2.1 | ... 3 | 2 | ... 1 | 2.1 | ... 2 | 2.1.1 | ... 4 | 2.1.2 | ... ... | ... | ... In my current implementation, I'd query the database with SELECT * FROM comments ORDER BY path , which would return the whole tree: Node 1 -- Node 1.1 --