Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Flight Delay Big Data Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s2875462
Flight Delay Big Data Project
Commits
46f2740c
Commit
46f2740c
authored
3 years ago
by
a.b.wahlgren@student.utwente.nl
Browse files
Options
Downloads
Patches
Plain Diff
Beginning to gather proportion of delay averages
parent
f846dfdf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
avg_delays.py
+26
-0
26 additions, 0 deletions
avg_delays.py
canc_threshold.py
+45
-0
45 additions, 0 deletions
canc_threshold.py
with
71 additions
and
0 deletions
avg_delays.py
+
26
−
0
View file @
46f2740c
...
@@ -30,3 +30,29 @@ df_w = df.select(col("WeatherDelay")).where(col("WeatherDelay") > 0)
...
@@ -30,3 +30,29 @@ df_w = df.select(col("WeatherDelay")).where(col("WeatherDelay") > 0)
sum_w
=
df_w
.
rdd
.
map
(
lambda
x
:
(
1
,
x
[
0
])).
reduceByKey
(
lambda
x
,
y
:
int
(
x
)
+
int
(
y
)).
collect
()[
0
][
1
]
sum_w
=
df_w
.
rdd
.
map
(
lambda
x
:
(
1
,
x
[
0
])).
reduceByKey
(
lambda
x
,
y
:
int
(
x
)
+
int
(
y
)).
collect
()[
0
][
1
]
avg_w
=
sum_w
/
df_w
.
count
()
avg_w
=
sum_w
/
df_w
.
count
()
print
(
"
The average delay caused by weather conditions is
"
+
str
(
avg_w
)
+
"
minutes.
"
)
print
(
"
The average delay caused by weather conditions is
"
+
str
(
avg_w
)
+
"
minutes.
"
)
'''
--- Average Arrival Delay ---
'''
df_arr
=
df
.
select
(
col
(
"
ArrDelay
"
)).
where
(
col
(
"
ArrDelay
"
)
>
0
)
sum_arr
=
df_arr
.
rdd
.
map
(
lambda
x
:
(
1
,
x
[
0
])).
reduceByKey
(
lambda
x
,
y
:
int
(
x
)
+
int
(
y
)).
collect
()[
0
][
1
]
avg_arr
=
sum_arr
/
df_arr
.
count
()
print
(
"
The average arrival delay is
"
+
str
(
avg_arr
)
+
"
minutes.
"
)
'''
--- Average Departure Delay ---
'''
df_dep
=
df
.
select
(
col
(
"
DepDelay
"
)).
where
(
col
(
"
DepDelay
"
)
>
0
)
sum_dep
=
df_dep
.
rdd
.
map
(
lambda
x
:
(
1
,
x
[
0
])).
reduceByKey
(
lambda
x
,
y
:
int
(
x
)
+
int
(
y
)).
collect
()[
0
][
1
]
avg_dep
=
sum_dep
/
df_dep
.
count
()
print
(
"
The average departure delay is
"
+
str
(
avg_dep
)
+
"
minutes.
"
)
'''
--- Average Carrier Delay ---
'''
df_car
=
df
.
select
(
col
(
"
CarrierDelay
"
)).
where
(
col
(
"
CarrierDelay
"
)
>
0
)
sum_car
=
df_arr
.
rdd
.
map
(
lambda
x
:
(
1
,
x
[
0
])).
reduceByKey
(
lambda
x
,
y
:
int
(
x
)
+
int
(
y
)).
collect
()[
0
][
1
]
avg_car
=
sum_car
/
df_car
.
count
()
print
(
"
The average carrier delay caused is
"
+
str
(
avg_car
)
+
"
minutes.
"
)
This diff is collapsed.
Click to expand it.
canc_threshold.py
0 → 100644
+
45
−
0
View file @
46f2740c
from
pyspark.sql
import
SparkSession
from
pyspark.sql.functions
import
col
,
max
as
pmax
spark
=
SparkSession
.
builder
.
getOrCreate
()
df
=
spark
.
read
.
csv
(
"
/user/s2875462/airline.csv.shuffle
"
,
header
=
"
true
"
)
'''
QUESTION: Is there a certain threshold where the total delay causes flights to be canceled?
Local run:
Cluster run:
Approach:
1. Get all flights which are cancelled and have been delayed
2. Sort them on department delay
3. Look for patterns
Output:
'''
df2
=
df
.
select
(
col
(
"
DepDelay
"
),
col
(
"
Cancelled
"
))
\
.
where
(
col
(
"
DepDelay
"
)
>=
0
)
\
.
sort
(
col
(
"
DepDelay
"
))
tot
=
df2
.
count
()
df3
=
df2
.
limit
(
tot
//
4
).
select
(
pmax
(
"
DepDelay
"
).
alias
(
"
max
"
))
df3
.
show
()
df4
=
df2
.
limit
(
2
*
tot
//
4
).
select
(
pmax
(
"
DepDelay
"
).
alias
(
"
max
"
))
df4
.
show
()
df5
=
df2
.
limit
(
3
*
tot
//
4
).
select
(
pmax
(
"
DepDelay
"
).
alias
(
"
max
"
))
df5
.
show
()
df6
=
df2
.
select
(
pmax
(
"
DepDelay
"
).
alias
(
"
max
"
))
df6
.
show
()
# .where((col("Cancelled") == 1) & (col("DepDelay") > 0))
df2
.
show
(
10
)
print
(
df2
.
count
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment