下面的这个查询用来找出来英国伦敦或它附近的每个机场有多少出边。注意我们先用has('region,GB-ENG)找出来所有在英格兰的机场。如果我们我们不这么做我们可能把把其它国家比如在加拿大的London, Ontario的机场也找出来。
This next query can be used to figure out how many outgoing routes each of the airports classified
as being in (or near) London, England has. Note that we first find all airports in England using
has('region,GB-ENG)'. If we did not do this we would pick up airports in other countries as well such
as London, Ontario, in Canada.
 

 

对上面的内容稍做一些调整。从伦敦出发,中转两次我可以到多少个地方呢,排除又回到伦敦的航班。结果有2000多个地方。注意如何使用aggregate来把这些伦敦的机场保存在一个集合里,可以在查询的后边引用这个集合,这将对找出来哪些航班又回到了伦敦有帮助。

Here is a twist on the above theme. How many places can I get to from London in two hops but not
including flights that end up back in London? It turns out there are over 2,000 places! Notice how
aggregate is used to store the set of London airports as a collection that can be referenced later on
in the query to help with ruling out any flights that would end up back in London.
 

 

我们也可以像这样写前边的查询,不用使用aggreagate步骤。对笔者而言,这个感觉更笨重,有点重复。

We could have written the previous query like this and avoided using aggregate but to me, this feels
more clumsy and somewhat repetitive.
 

 

 

5.1.21. 英格兰的机场之前有多少航线?How many routes are there between airports in England?
我们可以用aggregate步骤相当优雅地找出来位于英格兰的机场之间存在的航线。下面的查询找出来了英格兰的所有的机场,把它们按机场代码排序。然而用一个aggregate步骤收集了这些机场,最后找出来也在去英格兰机场的航线。注意就如写出来的,这个查询找到的是双向的路径,如果它们存在。
We can use an aggregate step to quite elegantly find the routes that exist between airports located
in England. The following query finds all airports in England and orders them by airport code. It
then collects those airports using an aggregate step. Finally the aggregated collection is used to find
routes to airports also within the UK. Note that as written, this query finds routes in both directions
if they exist.

 

 

 运行查询,找出来的路线如下。笔者为节省空间,已将结果分栏保存。
Here are the routes found when the query is run. I arranged the results into columns to save space.
 

 

这个查询用不同的方法可以写成这样。这次用了一个where步骤排除了来前边看到的机场对,所以我们只看到了一个方向的路径。

Here is a different way the query can be written. This time a where step is used to filter out the
previously seen airport pairs so we only get routes in one direction.
 

 

如您所见,这次我们只得到了每个航线对,而不考虑路线的方向。

As you can see this time we only get each airport pair back once regardless of route direction.
 

 

 

5.1.22. 按路线总数,前十位的机场是哪些?What are the top ten airports by route count?
前边我们计算了哪个机场有最多的路线。接下来的三个查询有点类似,但它生成了一个表,从入边、出边,总航线数三个维度前10位的机场。 如前边提到的,因为一些航空公司的航班,出边和放边总是不相同的。举个例子,一些KLM航空公司航班从AMS到非洲的其它机场中转,返回AMS前再飞去另一个机场。结果是它有更多的入边,出边更少。下面的每个例子都用了project步骤来生成一个更可读的格式。
Earlier we calculated which airports have the most routes. These next three queries are of a similar
nature but produce a tables of the top ten airports in terms of incoming, outgoing and overall
routes. As mentioned before, because of the way some airlines route flights, the number of outgoing
and incoming routes to an airport will not always be the same. For example, several KLM Airlines
flights from Amsterdam to airports in Africa continue on to other African airports before returning
to Amsterdam. As a result there are more inbound routes from than out bound routes to these
airports. In each example below the project step is used to generate the results in a easily readable
form.
首先,这个查询找出来有最多出边的机场,按降序排列,找出前10个。
First of all, this query will find the ten airports with the most incoming routes, sorted in descending
order.

 

 

 可以看到FRA和AMS有最多的入边。要记得本书例子中用到的图代表的是某一时间的情况。如果这些查询在后边一个更新版本的航线图上,结果会有些不同。这是因为航线会增加,有时也会去掉一些路线。
So it seems that Frankfurt and Amsterdam are tied for the most incoming routes. It is worth
remembering that the version of the graph used for the examples in the book represents a moment
in time. If these queries are re run at a later date on a newer version of the graph the results will
quite likely be different. This is because airlines regularly add, and in some cases drop, routes.
 

 

现在我们为出边做相同的处理。

Now let’s do the same thing but for outgoing routes.
 

 

这次是FRA的路线最多。它再次重申了笔者前边提到的一点。对于一个机场入边和边的数量不总是一样的。这是取决于航空公司安排航班的情况。有的的航班会在返回这前去其它的目的地,这样就不会总是机场对之间双向的直飞了。笔者作为一名乘客,有时对此感到沮丧。

This time Frankfurt has the most routes. This reinforces a point that I made earlier. The number of
incoming and outgoing routes for a given airport will not always be the same. This is because of the
way airlines route flights. Some flights continue to other destinations before returning so there will
not always be direct flights between airport pairs in both directions. I know as a passenger this is
something that I find frustrating!

 

最后,让我们找出来按机场所有的出边和入边总数排序的前10个机场。

Lastly, let’s find the top ten airports ordered by the total number of incoming and outgoing routes
that they have.
 

 

如我们所料,FRA是总路线最多的机场。顺带提示:在航线这个话题中,图并没有跟踪任意给定的航线运行的频次。这就意味着有最多路线的机场不必是最繁忙的。这是因为许多路线一天当中运行多次。笔者没有在图中包含这些数据。因为对于笔者来说,想要保持同步,它们变化太频繁啦。

As expected, Frankfurt is the airport with the most overall routes. One small side note while on the
topic of airline routes. The graph does not track the frequency at which any given route is operated.
What this means is that the airport with the most routes is not necessarily also the busiest. This is
because many routes are operated multiple times a day. I did not try to include this data in the
graph as it changes too often for me to keep up with.

 

 

posted on 2022-04-27 18:00  bokeyuannicheng0000  阅读(25)  评论(0)    收藏  举报