Airlines provide air transport services for traveling passengers and freight. Airlines utilize aircraft to supply these services and may form partnerships or alliances with other airlines for codeshare agreements, in which they both offer and operate the same flight. Airlines may be scheduled or charter operators.
These software components cover functions across Air Traffic Control, Airport, Reservation Systems, Customs, GDS, Tourism areas.
Popular New Releases in Airlines
respa
0.12.1
spatial_access
v1.0.2
MSFS2020-Real-Time-Weather
Version 0.2
swot_simulator
Unsmoothed products
hotel-booking
SQL procedures and C# functions are ready!
Popular Libraries in Airlines
by jpatokal php
1108
Website for storing flight information, rendering paths on a zoomable world map and calculating statistics, with plenty of free airline, airport and route data.
by carsonluuu java
46 MIT
Taxi Dispatch Simulator ✅
by City-of-Helsinki python
42 MIT
Resource reservation and management app and API
by milankl python
34 GPL-3.0
Travel carbon footprint of AGU Fall Meeting 2019 in San Francisco, USA
by harismuneer java
33 MIT
✈️ An enterprise level Flight Booking System for Turkish Airlines (web-application) based on the Model View Controller (MVC) Architecture made using Java Servlets, Java Server Pages (JSPs). Moreover authentication and authorization for users is implemented. The web-application is also secured against SQL Injection and Cross-Site Scripting attacks.
by khanhnamle1994 python
31
Travel Time Optimization via Ant Colony and Genetic Evolution
by thegenuinegourav java
31 MIT
An Android App that will unleash Vistara Airport Experience.
by GeoDaCenter python
28
by X-Plane python
24 MIT
Python tools for manipulating X-Plane's apt.dat files & interfacing with the X-Plane Scenery Gateway API
Trending New libraries in Airlines
by epranka javascript
22
Top of descent path calculator. Let's calculate your descent!
by svp318 python
15 GPL-3.0
A work in progress to update a custom Microsoft Flight Simulator 2020 weather preset with the current conditions of a given airport.
by ghulamghousdev csharp
11
Airline Reservation System is an online Airline Ticket Reservation Application built using Windows Forms, C#, MS SQL Server.
by Candidemile javascript
10
Capstone Project: Travel App. HTML - CSS - Javascript - API - Node.js(Express) - Webpack and plugins - Babel - ESLint - Jest
by amadeus4dev javascript
7 MIT
Demo app which implementes Airport & City Search API autocompletion using a MERN stack
by BlondelSeumo javascript
7
Booking Core is a Booking System based on Laravel, designed for a travel website, Marketplace, Travel Agency, Tour Operator, Room Bnb, Villa Rental, Resort Rental, Make Travel website.
by krishkamani java
6
This is a Ticket booking system application in android studio.
by mezidia csharp
6 MIT
Our project with databases
by hngi java
5
Top Authors in Airlines
1
2 Libraries
47
2
2 Libraries
38
3
1 Libraries
6
4
1 Libraries
5
5
1 Libraries
13
6
1 Libraries
5
7
1 Libraries
19
8
1 Libraries
5
9
1 Libraries
6
10
1 Libraries
7
1
2 Libraries
47
2
2 Libraries
38
3
1 Libraries
6
4
1 Libraries
5
5
1 Libraries
13
6
1 Libraries
5
7
1 Libraries
19
8
1 Libraries
5
9
1 Libraries
6
10
1 Libraries
7
Trending Kits in Airlines
No Trending Kits are available at this moment for Airlines
Trending Discussions on Airlines
Clickhouse query with dictionary
I couldn't pass an img using ajax?
Traversing Relationships a Variable Number of Times in Cypher
Laravel using WHERE orWHERE
In Foundry Contour, How do I filter by multiple terms?
Question about my computation (Using R with dplyr and nyflights13 to figure out number of seat miles by carrier)
How do you find max/min of a non-numeric vector?
Problems with changing the size of the two upper boxes ( text/image)
Apache Spark Data Generator Function on Databricks Not working
EnhancedSeatMap Seat Without Price
QUESTION
Clickhouse query with dictionary
Asked 2022-Apr-15 at 03:13I imported the database of ontime airlines from here https://clickhouse.com/docs/en/getting-started/example-datasets/ontime/
Then I created a dictionary mapping the 2 digit airplane codes to company names like this:
1id,code,company
21,UA,United Airlines
32,HA,Hawaiian Airlines
43,OO,SkyWest
54,B6,Jetblue Airway
65,QX,Horizon Air
76,YX,Republic Airway
87,G4,Allegiant Air
9...
10..
11
I used this query to generate it and it seems to be working:
1id,code,company
21,UA,United Airlines
32,HA,Hawaiian Airlines
43,OO,SkyWest
54,B6,Jetblue Airway
65,QX,Horizon Air
76,YX,Republic Airway
87,G4,Allegiant Air
9...
10..
11CREATE DICTIONARY airlinecompany
12(
13 id UInt64,
14 code String,
15 company String
16
17)
18PRIMARY KEY id
19SOURCE(FILE(path '/var/lib/clickhouse/user_files/airlinenames.csv' format 'CSVWithNames'))
20LAYOUT(FLAT())
21LIFETIME(3600)
22
In the main database (ontime) Looks like this:
1id,code,company
21,UA,United Airlines
32,HA,Hawaiian Airlines
43,OO,SkyWest
54,B6,Jetblue Airway
65,QX,Horizon Air
76,YX,Republic Airway
87,G4,Allegiant Air
9...
10..
11CREATE DICTIONARY airlinecompany
12(
13 id UInt64,
14 code String,
15 company String
16
17)
18PRIMARY KEY id
19SOURCE(FILE(path '/var/lib/clickhouse/user_files/airlinenames.csv' format 'CSVWithNames'))
20LAYOUT(FLAT())
21LIFETIME(3600)
22SELECT Reporting_Airline AS R_air
23FROM ontime
24GROUP BY R_air
25LIMIT 4
26
27
28┌─R_air─┐
29│ UA │
30│ HA │
31│ OO │
32│ B6 │
33└───────┘
34
What I want to do is have a table that uses R_air's 2 code value and then checks it against the airlinecompany
dict to create a mapping ie
1id,code,company
21,UA,United Airlines
32,HA,Hawaiian Airlines
43,OO,SkyWest
54,B6,Jetblue Airway
65,QX,Horizon Air
76,YX,Republic Airway
87,G4,Allegiant Air
9...
10..
11CREATE DICTIONARY airlinecompany
12(
13 id UInt64,
14 code String,
15 company String
16
17)
18PRIMARY KEY id
19SOURCE(FILE(path '/var/lib/clickhouse/user_files/airlinenames.csv' format 'CSVWithNames'))
20LAYOUT(FLAT())
21LIFETIME(3600)
22SELECT Reporting_Airline AS R_air
23FROM ontime
24GROUP BY R_air
25LIMIT 4
26
27
28┌─R_air─┐
29│ UA │
30│ HA │
31│ OO │
32│ B6 │
33└───────┘
34R_Air Company
35UA | United Airlines
36HA | Hawaiian Airlines
3700 | SkyWest
38...
39..
40
But I cant seem to form this query correctly:
1id,code,company
21,UA,United Airlines
32,HA,Hawaiian Airlines
43,OO,SkyWest
54,B6,Jetblue Airway
65,QX,Horizon Air
76,YX,Republic Airway
87,G4,Allegiant Air
9...
10..
11CREATE DICTIONARY airlinecompany
12(
13 id UInt64,
14 code String,
15 company String
16
17)
18PRIMARY KEY id
19SOURCE(FILE(path '/var/lib/clickhouse/user_files/airlinenames.csv' format 'CSVWithNames'))
20LAYOUT(FLAT())
21LIFETIME(3600)
22SELECT Reporting_Airline AS R_air
23FROM ontime
24GROUP BY R_air
25LIMIT 4
26
27
28┌─R_air─┐
29│ UA │
30│ HA │
31│ OO │
32│ B6 │
33└───────┘
34R_Air Company
35UA | United Airlines
36HA | Hawaiian Airlines
3700 | SkyWest
38...
39..
40SELECT
41 Reporting_Airline AS R_Air,
42 dictGetString('airlinecompany', 'company', R_Air) AS company
43FROM ontime
44GROUP BY R_Air
45
46
47Received exception from server (version 22.3.3):
48Code: 6. DB::Exception: Received from localhost:9000. DB::Exception: Cannot parse string 'UA' as UInt64: syntax error at begin of string. Note: there are toUInt64OrZero and toUInt64OrNull functions, which returns zero/NULL instead of throwing exception.: while executing 'FUNCTION dictGetString('airlinecompany' :: 1, 'company' :: 2, Reporting_Airline :: 0) -> dictGetString('airlinecompany', 'company', Reporting_Airline) String : 4'. (CANNOT_PARSE_TEXT)
49
What am I missing? I dont know why it thinks UA is a UInt64
ANSWER
Answered 2022-Apr-15 at 03:13LAYOUT = COMPLEX_KEY_HASHED
1id,code,company
21,UA,United Airlines
32,HA,Hawaiian Airlines
43,OO,SkyWest
54,B6,Jetblue Airway
65,QX,Horizon Air
76,YX,Republic Airway
87,G4,Allegiant Air
9...
10..
11CREATE DICTIONARY airlinecompany
12(
13 id UInt64,
14 code String,
15 company String
16
17)
18PRIMARY KEY id
19SOURCE(FILE(path '/var/lib/clickhouse/user_files/airlinenames.csv' format 'CSVWithNames'))
20LAYOUT(FLAT())
21LIFETIME(3600)
22SELECT Reporting_Airline AS R_air
23FROM ontime
24GROUP BY R_air
25LIMIT 4
26
27
28┌─R_air─┐
29│ UA │
30│ HA │
31│ OO │
32│ B6 │
33└───────┘
34R_Air Company
35UA | United Airlines
36HA | Hawaiian Airlines
3700 | SkyWest
38...
39..
40SELECT
41 Reporting_Airline AS R_Air,
42 dictGetString('airlinecompany', 'company', R_Air) AS company
43FROM ontime
44GROUP BY R_Air
45
46
47Received exception from server (version 22.3.3):
48Code: 6. DB::Exception: Received from localhost:9000. DB::Exception: Cannot parse string 'UA' as UInt64: syntax error at begin of string. Note: there are toUInt64OrZero and toUInt64OrNull functions, which returns zero/NULL instead of throwing exception.: while executing 'FUNCTION dictGetString('airlinecompany' :: 1, 'company' :: 2, Reporting_Airline :: 0) -> dictGetString('airlinecompany', 'company', Reporting_Airline) String : 4'. (CANNOT_PARSE_TEXT)
49CREATE DICTIONARY airlinecompany
50(
51 id UInt64,
52 code String,
53 company String
54
55)
56PRIMARY KEY code
57SOURCE(FILE(path '/var/lib/clickhouse/user_files/airlinenames.csv' format 'CSVWithNames'))
58LAYOUT(COMPLEX_KEY_HASHED())
59LIFETIME(3600)
60
61
62SELECT dictGet('airlinecompany', 'company', tuple('UA'))
63┌─dictGet('airlinecompany', 'company', tuple('UA'))─┐
64│ United Airlines │
65└───────────────────────────────────────────────────┘
66
67
68SELECT Reporting_Airline AS R_air,
69 dictGetString('airlinecompany', 'company', tuple(R_Air)) AS company
70FROM ontime
71LIMIT 4;
72
73┌─R_Air─┬─company───────────┐
74│ B6 │ Jetblue Airway │
75│ G4 │ Allegiant Air │
76│ HA │ Hawaiian Airlines │
77│ OO │ SkyWest │
78└───────┴───────────────────┘
79
80
QUESTION
I couldn't pass an img using ajax?
Asked 2022-Mar-26 at 06:29I'm trying to include a logo when adding a new airline, but I don't know how can I pass input with file type to the controller with ajax. I tried to use FormData(). I did not get any error, but the file was not passed to the controller I have looked at some questions similar to my problem, but I can't find a solution.
1<form action="javascript:void(0)" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
2 <input type="hidden" name="id" id="id">
3 <div class="form-group">
4 <label for="name" class="col-sm-2 control-label">Name</label>
5 <div class="col-sm-12">
6 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
7 </div>
8 </div>
9 <div class="form-group">
10 <label for="name" class="col-sm-2 control-label">country</label>
11 <div class="col-sm-12">
12 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
13 </div>
14 </div>
15 <div class="form-group">
16 <label class="col-sm-2 control-label">Logo</label>
17 <div class="col-sm-12">
18 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
19 </div>
20 </div>
21 <div class="col-sm-offset-2 col-sm-10">
22 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
23 </button>
24 </div>
25 </form>
26
ajax:
1<form action="javascript:void(0)" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
2 <input type="hidden" name="id" id="id">
3 <div class="form-group">
4 <label for="name" class="col-sm-2 control-label">Name</label>
5 <div class="col-sm-12">
6 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
7 </div>
8 </div>
9 <div class="form-group">
10 <label for="name" class="col-sm-2 control-label">country</label>
11 <div class="col-sm-12">
12 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
13 </div>
14 </div>
15 <div class="form-group">
16 <label class="col-sm-2 control-label">Logo</label>
17 <div class="col-sm-12">
18 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
19 </div>
20 </div>
21 <div class="col-sm-offset-2 col-sm-10">
22 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
23 </button>
24 </div>
25 </form>
26 $('body').on('click', '#btn-save', function (event) {
27 event.preventDefault()
28 var id = $("#id").val();
29 var name = $("#name").val();
30 var country = $("#country").val();
31 let logo = new FormData(document.getElementById("addEditBookForm"));
32 $("#btn-save").html('Please Wait...');
33 $("#btn-save"). attr("disabled", true);
34
35 // ajax
36
37 $.ajax({
38 type:"POST",
39 url: "{{ url('admin/add-update-Airlines') }}",
40 data: {
41 id:id,
42 name:name,
43 country:country,
44 logo:logo,
45 },
46 contentType: false,
47 processData:false,
48 cache: false,
49 dataType: 'json',
50 success: function(res){
51 window.location.reload();
52 $("#btn-save").html('Submit');
53 $("#btn-save"). attr("disabled", false);
54 Swal.fire(
55 'Good job!',
56 'You clicked the button!',
57 'success'
58 )
59 }
60
61 });
62
63 });
64
Controller:
1<form action="javascript:void(0)" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
2 <input type="hidden" name="id" id="id">
3 <div class="form-group">
4 <label for="name" class="col-sm-2 control-label">Name</label>
5 <div class="col-sm-12">
6 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
7 </div>
8 </div>
9 <div class="form-group">
10 <label for="name" class="col-sm-2 control-label">country</label>
11 <div class="col-sm-12">
12 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
13 </div>
14 </div>
15 <div class="form-group">
16 <label class="col-sm-2 control-label">Logo</label>
17 <div class="col-sm-12">
18 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
19 </div>
20 </div>
21 <div class="col-sm-offset-2 col-sm-10">
22 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
23 </button>
24 </div>
25 </form>
26 $('body').on('click', '#btn-save', function (event) {
27 event.preventDefault()
28 var id = $("#id").val();
29 var name = $("#name").val();
30 var country = $("#country").val();
31 let logo = new FormData(document.getElementById("addEditBookForm"));
32 $("#btn-save").html('Please Wait...');
33 $("#btn-save"). attr("disabled", true);
34
35 // ajax
36
37 $.ajax({
38 type:"POST",
39 url: "{{ url('admin/add-update-Airlines') }}",
40 data: {
41 id:id,
42 name:name,
43 country:country,
44 logo:logo,
45 },
46 contentType: false,
47 processData:false,
48 cache: false,
49 dataType: 'json',
50 success: function(res){
51 window.location.reload();
52 $("#btn-save").html('Submit');
53 $("#btn-save"). attr("disabled", false);
54 Swal.fire(
55 'Good job!',
56 'You clicked the button!',
57 'success'
58 )
59 }
60
61 });
62
63 });
64 public function store(Request $request)
65 {
66
67
68 $newImgName = time() . '-' . $request->name . '.' .$request->logo->extension();
69 $request->logo->move(public_path('img'),$newImgName);
70 $Airline = Airline::updateOrCreate(
71 [
72 'id' => $request->id
73 ],
74 $request->validate([
75 'name' => ['required', 'string', 'max:255'],
76 'country' => ['required', 'string', 'max:255'],
77 'logo' => ['required|mimes:ipg,png,jpeg|max:5048'],
78 ]),
79
80 [
81 'name' => $request->name,
82 'country' => $request->country,
83 'logo' => $newImgName,
84 ]);
85
86 return response()->json(['success' => true]);
87 }
88
ANSWER
Answered 2022-Mar-26 at 05:57First thing is csrf token not passing to ajax so change form as below.Also updated
1<form action="javascript:void(0)" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
2 <input type="hidden" name="id" id="id">
3 <div class="form-group">
4 <label for="name" class="col-sm-2 control-label">Name</label>
5 <div class="col-sm-12">
6 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
7 </div>
8 </div>
9 <div class="form-group">
10 <label for="name" class="col-sm-2 control-label">country</label>
11 <div class="col-sm-12">
12 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
13 </div>
14 </div>
15 <div class="form-group">
16 <label class="col-sm-2 control-label">Logo</label>
17 <div class="col-sm-12">
18 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
19 </div>
20 </div>
21 <div class="col-sm-offset-2 col-sm-10">
22 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
23 </button>
24 </div>
25 </form>
26 $('body').on('click', '#btn-save', function (event) {
27 event.preventDefault()
28 var id = $("#id").val();
29 var name = $("#name").val();
30 var country = $("#country").val();
31 let logo = new FormData(document.getElementById("addEditBookForm"));
32 $("#btn-save").html('Please Wait...');
33 $("#btn-save"). attr("disabled", true);
34
35 // ajax
36
37 $.ajax({
38 type:"POST",
39 url: "{{ url('admin/add-update-Airlines') }}",
40 data: {
41 id:id,
42 name:name,
43 country:country,
44 logo:logo,
45 },
46 contentType: false,
47 processData:false,
48 cache: false,
49 dataType: 'json',
50 success: function(res){
51 window.location.reload();
52 $("#btn-save").html('Submit');
53 $("#btn-save"). attr("disabled", false);
54 Swal.fire(
55 'Good job!',
56 'You clicked the button!',
57 'success'
58 )
59 }
60
61 });
62
63 });
64 public function store(Request $request)
65 {
66
67
68 $newImgName = time() . '-' . $request->name . '.' .$request->logo->extension();
69 $request->logo->move(public_path('img'),$newImgName);
70 $Airline = Airline::updateOrCreate(
71 [
72 'id' => $request->id
73 ],
74 $request->validate([
75 'name' => ['required', 'string', 'max:255'],
76 'country' => ['required', 'string', 'max:255'],
77 'logo' => ['required|mimes:ipg,png,jpeg|max:5048'],
78 ]),
79
80 [
81 'name' => $request->name,
82 'country' => $request->country,
83 'logo' => $newImgName,
84 ]);
85
86 return response()->json(['success' => true]);
87 }
88<form action="{{ url('admin/add-update-Airlines') }}" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
89 @csrf
90 <input type="hidden" name="id" id="id">
91 <div class="form-group">
92 <label for="name" class="col-sm-2 control-label">Name</label>
93 <div class="col-sm-12">
94 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
95 </div>
96 </div>
97 <div class="form-group">
98 <label for="name" class="col-sm-2 control-label">country</label>
99 <div class="col-sm-12">
100 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
101 </div>
102 </div>
103 <div class="form-group">
104 <label class="col-sm-2 control-label">Logo</label>
105 <div class="col-sm-12">
106 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
107 </div>
108 </div>
109 <div class="col-sm-offset-2 col-sm-10">
110 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
111 </button>
112 </div>
113 </form>
114
Then in ajax I have simplified for testing so you can modify according to your need
1<form action="javascript:void(0)" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
2 <input type="hidden" name="id" id="id">
3 <div class="form-group">
4 <label for="name" class="col-sm-2 control-label">Name</label>
5 <div class="col-sm-12">
6 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
7 </div>
8 </div>
9 <div class="form-group">
10 <label for="name" class="col-sm-2 control-label">country</label>
11 <div class="col-sm-12">
12 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
13 </div>
14 </div>
15 <div class="form-group">
16 <label class="col-sm-2 control-label">Logo</label>
17 <div class="col-sm-12">
18 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
19 </div>
20 </div>
21 <div class="col-sm-offset-2 col-sm-10">
22 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
23 </button>
24 </div>
25 </form>
26 $('body').on('click', '#btn-save', function (event) {
27 event.preventDefault()
28 var id = $("#id").val();
29 var name = $("#name").val();
30 var country = $("#country").val();
31 let logo = new FormData(document.getElementById("addEditBookForm"));
32 $("#btn-save").html('Please Wait...');
33 $("#btn-save"). attr("disabled", true);
34
35 // ajax
36
37 $.ajax({
38 type:"POST",
39 url: "{{ url('admin/add-update-Airlines') }}",
40 data: {
41 id:id,
42 name:name,
43 country:country,
44 logo:logo,
45 },
46 contentType: false,
47 processData:false,
48 cache: false,
49 dataType: 'json',
50 success: function(res){
51 window.location.reload();
52 $("#btn-save").html('Submit');
53 $("#btn-save"). attr("disabled", false);
54 Swal.fire(
55 'Good job!',
56 'You clicked the button!',
57 'success'
58 )
59 }
60
61 });
62
63 });
64 public function store(Request $request)
65 {
66
67
68 $newImgName = time() . '-' . $request->name . '.' .$request->logo->extension();
69 $request->logo->move(public_path('img'),$newImgName);
70 $Airline = Airline::updateOrCreate(
71 [
72 'id' => $request->id
73 ],
74 $request->validate([
75 'name' => ['required', 'string', 'max:255'],
76 'country' => ['required', 'string', 'max:255'],
77 'logo' => ['required|mimes:ipg,png,jpeg|max:5048'],
78 ]),
79
80 [
81 'name' => $request->name,
82 'country' => $request->country,
83 'logo' => $newImgName,
84 ]);
85
86 return response()->json(['success' => true]);
87 }
88<form action="{{ url('admin/add-update-Airlines') }}" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
89 @csrf
90 <input type="hidden" name="id" id="id">
91 <div class="form-group">
92 <label for="name" class="col-sm-2 control-label">Name</label>
93 <div class="col-sm-12">
94 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
95 </div>
96 </div>
97 <div class="form-group">
98 <label for="name" class="col-sm-2 control-label">country</label>
99 <div class="col-sm-12">
100 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
101 </div>
102 </div>
103 <div class="form-group">
104 <label class="col-sm-2 control-label">Logo</label>
105 <div class="col-sm-12">
106 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
107 </div>
108 </div>
109 <div class="col-sm-offset-2 col-sm-10">
110 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
111 </button>
112 </div>
113 </form>
114$(document).on('click', '#btn-save', function(e) {
115 e.preventDefault()
116 var url = $("#applicationForm").attr('action');
117 let myForm = document.getElementById('addEditBookForm');
118 let formData = new FormData(myForm);
119 $.ajax({
120 type:"POST",
121 url:url,
122 data: formData,
123 contentType: false,
124 processData:false,
125 cache: false,
126 dataType: 'json',
127 success: function(res){
128
129 }
130
131 });
132
133 });
134
Validation
1<form action="javascript:void(0)" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
2 <input type="hidden" name="id" id="id">
3 <div class="form-group">
4 <label for="name" class="col-sm-2 control-label">Name</label>
5 <div class="col-sm-12">
6 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
7 </div>
8 </div>
9 <div class="form-group">
10 <label for="name" class="col-sm-2 control-label">country</label>
11 <div class="col-sm-12">
12 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
13 </div>
14 </div>
15 <div class="form-group">
16 <label class="col-sm-2 control-label">Logo</label>
17 <div class="col-sm-12">
18 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
19 </div>
20 </div>
21 <div class="col-sm-offset-2 col-sm-10">
22 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
23 </button>
24 </div>
25 </form>
26 $('body').on('click', '#btn-save', function (event) {
27 event.preventDefault()
28 var id = $("#id").val();
29 var name = $("#name").val();
30 var country = $("#country").val();
31 let logo = new FormData(document.getElementById("addEditBookForm"));
32 $("#btn-save").html('Please Wait...');
33 $("#btn-save"). attr("disabled", true);
34
35 // ajax
36
37 $.ajax({
38 type:"POST",
39 url: "{{ url('admin/add-update-Airlines') }}",
40 data: {
41 id:id,
42 name:name,
43 country:country,
44 logo:logo,
45 },
46 contentType: false,
47 processData:false,
48 cache: false,
49 dataType: 'json',
50 success: function(res){
51 window.location.reload();
52 $("#btn-save").html('Submit');
53 $("#btn-save"). attr("disabled", false);
54 Swal.fire(
55 'Good job!',
56 'You clicked the button!',
57 'success'
58 )
59 }
60
61 });
62
63 });
64 public function store(Request $request)
65 {
66
67
68 $newImgName = time() . '-' . $request->name . '.' .$request->logo->extension();
69 $request->logo->move(public_path('img'),$newImgName);
70 $Airline = Airline::updateOrCreate(
71 [
72 'id' => $request->id
73 ],
74 $request->validate([
75 'name' => ['required', 'string', 'max:255'],
76 'country' => ['required', 'string', 'max:255'],
77 'logo' => ['required|mimes:ipg,png,jpeg|max:5048'],
78 ]),
79
80 [
81 'name' => $request->name,
82 'country' => $request->country,
83 'logo' => $newImgName,
84 ]);
85
86 return response()->json(['success' => true]);
87 }
88<form action="{{ url('admin/add-update-Airlines') }}" id="addEditBookForm" name="addEditBookForm" class="form-horizontal" method="POST" enctype="multipart/form-data">
89 @csrf
90 <input type="hidden" name="id" id="id">
91 <div class="form-group">
92 <label for="name" class="col-sm-2 control-label">Name</label>
93 <div class="col-sm-12">
94 <input type="text" class="form-control" id="name" name="name" placeholder="Enter Airline Name" value="" maxlength="50" required="">
95 </div>
96 </div>
97 <div class="form-group">
98 <label for="name" class="col-sm-2 control-label">country</label>
99 <div class="col-sm-12">
100 <input type="text" class="form-control" id="country" name="country" placeholder="Enter Airline country" value="" maxlength="50" required="">
101 </div>
102 </div>
103 <div class="form-group">
104 <label class="col-sm-2 control-label">Logo</label>
105 <div class="col-sm-12">
106 <input type="file" class="form-control" id="logo" name="logo" placeholder="Enter Airline Code" value="" required="">
107 </div>
108 </div>
109 <div class="col-sm-offset-2 col-sm-10">
110 <button type="submit" class="btn btn-primary" id="btn-save" value="addNewBook">Save changes
111 </button>
112 </div>
113 </form>
114$(document).on('click', '#btn-save', function(e) {
115 e.preventDefault()
116 var url = $("#applicationForm").attr('action');
117 let myForm = document.getElementById('addEditBookForm');
118 let formData = new FormData(myForm);
119 $.ajax({
120 type:"POST",
121 url:url,
122 data: formData,
123 contentType: false,
124 processData:false,
125 cache: false,
126 dataType: 'json',
127 success: function(res){
128
129 }
130
131 });
132
133 });
134public function store(Request $request)
135{
136
137 $request->validate([
138 'name' => ['required', 'string', 'max:255'],
139 'country' => ['required', 'string', 'max:255'],
140 'logo' => ['required','mimes:ipg,png,jpeg','max:5048'],
141 ]);
142}
143
QUESTION
Traversing Relationships a Variable Number of Times in Cypher
Asked 2022-Mar-01 at 03:52I have a graph of Airports, Routes between them and Airlines that carry it. I created routes as separate nodes, rather than just a relationship, so that I can connect each with an Airline, and other nodes.
Each Route
node has an IS_FROM
relationship with the origin airport and an IS_TO
relationship with the destination. It also has an IS_BY
relationship with its airline:
I am trying to traverse this tree, n
times, for routes between two airports. For example, if n = 3
, I want to get all the routes, that will lead from LAX
to LHR
, with 3 or fewer connections.
So basically, my result would be a union of the following: No Connecting Airports:
1MATCH (a1:Airport {iata : 'LAX'})<-[:IS_FROM]-(r:Route)-[:IS_TO]->(a2:Airport {iata : 'LHR'}), (r)-[:IS_BY]->(ai:Airline) return a1 , r , a2 , ai;
2
1 Connecting airports:
1MATCH (a1:Airport {iata : 'LAX'})<-[:IS_FROM]-(r:Route)-[:IS_TO]->(a2:Airport {iata : 'LHR'}), (r)-[:IS_BY]->(ai:Airline) return a1 , r , a2 , ai;
2MATCH (a1:Airport {iata : 'LAX'})<-[:IS_FROM]-(r:Route)-[:IS_TO]->(a2:Airport)<-[IS_FROM]-(r2:Route)-[:IS_TO]->(a3:Airport {iata: 'LHR'}), (r2)-[:IS_BY]->(ai:Airline) return a1 , r , a2 , a3 , r2 , ai;
3
and so on.
So the query should dynamically traverse the (:Airport)<-[:IS_FROM]-(:Route)-[:IS_TO]->(:Airport)
pattern n times, and return the nodes (I am more interested in returning the Airline
s that connect to those routes.
ANSWER
Answered 2022-Feb-28 at 10:13I don't know if i got your question right. To me your problem could be solved this way:
1MATCH (a1:Airport {iata : 'LAX'})<-[:IS_FROM]-(r:Route)-[:IS_TO]->(a2:Airport {iata : 'LHR'}), (r)-[:IS_BY]->(ai:Airline) return a1 , r , a2 , ai;
2MATCH (a1:Airport {iata : 'LAX'})<-[:IS_FROM]-(r:Route)-[:IS_TO]->(a2:Airport)<-[IS_FROM]-(r2:Route)-[:IS_TO]->(a3:Airport {iata: 'LHR'}), (r2)-[:IS_BY]->(ai:Airline) return a1 , r , a2 , a3 , r2 , ai;
3MATCH (a1:Airport {iata : 'LAX'})<-[r1:IS_FROM]-(r:Route)-[r2:IS_TO]->(a2:Airport{iata : 'LHR'})
4OPTIONAL MATCH (r)-[r3:IS_BY]->(ai:Airline)
5RETURN a1,r1,r,r2,a2,r3,ai
6
QUESTION
Laravel using WHERE orWHERE
Asked 2022-Feb-18 at 11:50I have a query as below. When i search using the query below, it fetches the products but it shows other products from other airlines even tho i have specified the airline id. When i take out the orWhere("code","LIKE","%{$request->search}%")
, it works perfectly fine and it doesn't show the products of other airlines.
I know where the issue is but then i still need the search parameter to be either name or code. How do i fix this ?
1 Product::with('airline')
2 ->where('airline_id', $request->airline_id)
3 ->select('id','name','code')
4 ->where("name","LIKE","%{$request->search}%")
5 ->orWhere("code","LIKE","%{$request->search}%")
6 ->limit(5)
7 ->get();
8
ANSWER
Answered 2022-Feb-18 at 11:49Your current query will generate:
1 Product::with('airline')
2 ->where('airline_id', $request->airline_id)
3 ->select('id','name','code')
4 ->where("name","LIKE","%{$request->search}%")
5 ->orWhere("code","LIKE","%{$request->search}%")
6 ->limit(5)
7 ->get();
8WHERE airline_id = ? AND name LIKE ? OR code LIKE ?
9
The OR
will discount any other conditions unless you group them properly. You need to use logical grouping to solve that:
1 Product::with('airline')
2 ->where('airline_id', $request->airline_id)
3 ->select('id','name','code')
4 ->where("name","LIKE","%{$request->search}%")
5 ->orWhere("code","LIKE","%{$request->search}%")
6 ->limit(5)
7 ->get();
8WHERE airline_id = ? AND name LIKE ? OR code LIKE ?
9->select('id','name','code')
10->where('airline_id', $request->airline_id)
11->where(function ($query) use ($request) {
12 $query->where("name","LIKE","%{$request->search}%")
13 ->orWhere("code","LIKE","%{$request->search}%");
14})
15
This will generate:
1 Product::with('airline')
2 ->where('airline_id', $request->airline_id)
3 ->select('id','name','code')
4 ->where("name","LIKE","%{$request->search}%")
5 ->orWhere("code","LIKE","%{$request->search}%")
6 ->limit(5)
7 ->get();
8WHERE airline_id = ? AND name LIKE ? OR code LIKE ?
9->select('id','name','code')
10->where('airline_id', $request->airline_id)
11->where(function ($query) use ($request) {
12 $query->where("name","LIKE","%{$request->search}%")
13 ->orWhere("code","LIKE","%{$request->search}%");
14})
15WHERE airline_id = ? AND (name LIKE ? OR code LIKE ?)
16
QUESTION
In Foundry Contour, How do I filter by multiple terms?
Asked 2022-Feb-02 at 14:55I'm working on one of the tutorial exercises "Bootcamp, Day 1"
The Problem
Specifically, the problem says
Filter this Flights path to only: Flights between Delta Airlines hubs (ATL, JFK, LGA, BOS, DTW, MSP, SLC, SEA, LAX)
I know in SQL I would do something like:
1SELECT * FROM flights
2WHERE origin IN ATL, JFK, LGA, BOS, DTW, MSP, SLC, SEA, LAX
3AND dest IN ATL, JFK, LGA, BOS, DTW, MSP, SLC, SEA, LAX
4
But I'm not sure how to accomplish this in Contour. I know I shouldn't have to put a new filter in for each airport and origin/dest, right?
Question
How do I filter by multiple terms in one line?
What I'm Looking for
I'd like to do something like
origin
is in ATL, JFK, LGA, BOS, DTW, MSP, SLC, SEA, LAX
AND
dest
is in ATL, JFK, LGA, BOS, DTW, MSP, SLC, SEA, LAX
But there is only is
What I've Tried
origin
is ATL, JFK, LGA, BOS, DTW, MSP, SLC, SEA, LAX
origin
matches (x) 'ATL','JFK','LGA','BOS','DTW','MSP','SLC','SEA','LAX'
I get no data in the resulting table for either attempt.
ANSWER
Answered 2022-Feb-02 at 14:55QUESTION
Question about my computation (Using R with dplyr and nyflights13 to figure out number of seat miles by carrier)
Asked 2022-Jan-25 at 16:25I understand the problem and showed all my work. I'm working through the modern dive data science book (https://moderndive.com/3-wrangling.html#joins book), and got stuck on (LC3.20) at the end of chapter 3.Using the nycflights13 package on R and dplyr, I'm supposed to generate a tibble that has only two columns, airline name and seat miles. Seat miles is just seats * miles. I understand the problem and I thought my code was going to output the correct result, however my seat miles are different for each airline carrier than in the solution. Can someone please help me to figure out why my code went wrong. Additionally, I do understand the books solution, I just don't know why my solution is wrong. I posted all my work.
1 #seat miles = miles*seats
2
3View(flights) #distance and identifiers year and tail num and carrier
4View(airlines) # names and indentifiers carrier
5View(planes) #seats and identifiers year and tail num
6
7
8#join names to flights
9
10named_flights <- flights %>%
11 inner_join(airlines, by = 'carrier')
12
13named_flights #same number of rows, all good
14flights
15
16#join seats to named_flights
17
18named_seat_flights <- named_flights %>%
19 inner_join(planes, by = c('tailnum'))
20named_seat_flights #noticed 52,596 rows are missing
21#when joining tailnum to named_flights
22
23table(is.na(select(named_flights, 'tailnum')))
24#2512 rows that has NA values for tailnum in named_flights
25
26table(is.na(select(planes, 'tailnum')))
27#no tailnum data is missing from planes dataset
28#and since a given plane (with a given tailnum)
29#can take off multiple times per year
30#we can conclude that the 52,596 missing rows
31#are a result of the missing tailnum data in flights (also named_flights)
32
33
34named_seat_miles_by_airline_name <- named_seat_flights %>%
35 group_by(name) %>%
36 summarise(seat_miles = sum(seats, na.rm = T)*sum(distance,na.rm = T)) %>%
37 rename(airline_name = name) %>%
38 arrange(desc(seat_miles))
39named_seat_miles_by_airline_name #not correct
40
41View(named_seat_miles_by_airline_name)
42
43
44
45flights %>% # book solution
46 inner_join(planes, by = "tailnum") %>%
47 select(carrier, seats, distance) %>%
48 mutate(ASM = seats * distance) %>%
49 group_by(carrier) %>%
50 summarize(ASM = sum(ASM, na.rm = TRUE)) %>%
51 arrange(desc(ASM))**strong text**
52
The output of my code is
1 #seat miles = miles*seats
2
3View(flights) #distance and identifiers year and tail num and carrier
4View(airlines) # names and indentifiers carrier
5View(planes) #seats and identifiers year and tail num
6
7
8#join names to flights
9
10named_flights <- flights %>%
11 inner_join(airlines, by = 'carrier')
12
13named_flights #same number of rows, all good
14flights
15
16#join seats to named_flights
17
18named_seat_flights <- named_flights %>%
19 inner_join(planes, by = c('tailnum'))
20named_seat_flights #noticed 52,596 rows are missing
21#when joining tailnum to named_flights
22
23table(is.na(select(named_flights, 'tailnum')))
24#2512 rows that has NA values for tailnum in named_flights
25
26table(is.na(select(planes, 'tailnum')))
27#no tailnum data is missing from planes dataset
28#and since a given plane (with a given tailnum)
29#can take off multiple times per year
30#we can conclude that the 52,596 missing rows
31#are a result of the missing tailnum data in flights (also named_flights)
32
33
34named_seat_miles_by_airline_name <- named_seat_flights %>%
35 group_by(name) %>%
36 summarise(seat_miles = sum(seats, na.rm = T)*sum(distance,na.rm = T)) %>%
37 rename(airline_name = name) %>%
38 arrange(desc(seat_miles))
39named_seat_miles_by_airline_name #not correct
40
41View(named_seat_miles_by_airline_name)
42
43
44
45flights %>% # book solution
46 inner_join(planes, by = "tailnum") %>%
47 select(carrier, seats, distance) %>%
48 mutate(ASM = seats * distance) %>%
49 group_by(carrier) %>%
50 summarize(ASM = sum(ASM, na.rm = TRUE)) %>%
51 arrange(desc(ASM))**strong text**
52 # A tibble: 16 x 2
53 airline_name seat_miles
54 <chr> <dbl>
55 1 United Air Lines Inc. 8.73e14
56 2 Delta Air Lines Inc. 4.82e14
57 3 JetBlue Airways 4.13e14
58 4 ExpressJet Airlines I~ 9.82e13
59 5 US Airways Inc. 3.83e13
60 6 American Airlines Inc. 3.38e13
61 7 Southwest Airlines Co. 2.10e13
62 8 Endeavor Air Inc. 1.28e13
63 9 Virgin America 1.19e13
6410 AirTran Airways Corpo~ 6.68e11
6511 Alaska Airlines Inc. 2.24e11
6612 Hawaiian Airlines Inc. 2.20e11
6713 Frontier Airlines Inc. 1.17e11
6814 Mesa Airlines Inc. 1.17e10
6915 Envoy Air 7.10e 9
7016 SkyWest Airlines Inc. 4.08e 7
71
The output of books code is
1 #seat miles = miles*seats
2
3View(flights) #distance and identifiers year and tail num and carrier
4View(airlines) # names and indentifiers carrier
5View(planes) #seats and identifiers year and tail num
6
7
8#join names to flights
9
10named_flights <- flights %>%
11 inner_join(airlines, by = 'carrier')
12
13named_flights #same number of rows, all good
14flights
15
16#join seats to named_flights
17
18named_seat_flights <- named_flights %>%
19 inner_join(planes, by = c('tailnum'))
20named_seat_flights #noticed 52,596 rows are missing
21#when joining tailnum to named_flights
22
23table(is.na(select(named_flights, 'tailnum')))
24#2512 rows that has NA values for tailnum in named_flights
25
26table(is.na(select(planes, 'tailnum')))
27#no tailnum data is missing from planes dataset
28#and since a given plane (with a given tailnum)
29#can take off multiple times per year
30#we can conclude that the 52,596 missing rows
31#are a result of the missing tailnum data in flights (also named_flights)
32
33
34named_seat_miles_by_airline_name <- named_seat_flights %>%
35 group_by(name) %>%
36 summarise(seat_miles = sum(seats, na.rm = T)*sum(distance,na.rm = T)) %>%
37 rename(airline_name = name) %>%
38 arrange(desc(seat_miles))
39named_seat_miles_by_airline_name #not correct
40
41View(named_seat_miles_by_airline_name)
42
43
44
45flights %>% # book solution
46 inner_join(planes, by = "tailnum") %>%
47 select(carrier, seats, distance) %>%
48 mutate(ASM = seats * distance) %>%
49 group_by(carrier) %>%
50 summarize(ASM = sum(ASM, na.rm = TRUE)) %>%
51 arrange(desc(ASM))**strong text**
52 # A tibble: 16 x 2
53 airline_name seat_miles
54 <chr> <dbl>
55 1 United Air Lines Inc. 8.73e14
56 2 Delta Air Lines Inc. 4.82e14
57 3 JetBlue Airways 4.13e14
58 4 ExpressJet Airlines I~ 9.82e13
59 5 US Airways Inc. 3.83e13
60 6 American Airlines Inc. 3.38e13
61 7 Southwest Airlines Co. 2.10e13
62 8 Endeavor Air Inc. 1.28e13
63 9 Virgin America 1.19e13
6410 AirTran Airways Corpo~ 6.68e11
6511 Alaska Airlines Inc. 2.24e11
6612 Hawaiian Airlines Inc. 2.20e11
6713 Frontier Airlines Inc. 1.17e11
6814 Mesa Airlines Inc. 1.17e10
6915 Envoy Air 7.10e 9
7016 SkyWest Airlines Inc. 4.08e 7
71# A tibble: 16 x 2
72 carrier ASM
73 <chr> <dbl>
74 1 UA 15516377526
75 2 DL 10532885801
76 3 B6 9618222135
77 4 AA 3677292231
78 5 US 2533505829
79 6 VX 2296680778
80 7 EV 1817236275
81 8 WN 1718116857
82 9 9E 776970310
8310 HA 642478122
8411 AS 314104736
8512 FL 219628520
8613 F9 184832280
8714 YV 20163632
8815 MQ 7162420
8916 OO 1299835
90
91
Also, I know I have airline names instead of carrier, but thats actually what was asked.
ANSWER
Answered 2022-Jan-25 at 16:25The code replaces the sum of the products with the product of the sums.
Compare these:
1 #seat miles = miles*seats
2
3View(flights) #distance and identifiers year and tail num and carrier
4View(airlines) # names and indentifiers carrier
5View(planes) #seats and identifiers year and tail num
6
7
8#join names to flights
9
10named_flights <- flights %>%
11 inner_join(airlines, by = 'carrier')
12
13named_flights #same number of rows, all good
14flights
15
16#join seats to named_flights
17
18named_seat_flights <- named_flights %>%
19 inner_join(planes, by = c('tailnum'))
20named_seat_flights #noticed 52,596 rows are missing
21#when joining tailnum to named_flights
22
23table(is.na(select(named_flights, 'tailnum')))
24#2512 rows that has NA values for tailnum in named_flights
25
26table(is.na(select(planes, 'tailnum')))
27#no tailnum data is missing from planes dataset
28#and since a given plane (with a given tailnum)
29#can take off multiple times per year
30#we can conclude that the 52,596 missing rows
31#are a result of the missing tailnum data in flights (also named_flights)
32
33
34named_seat_miles_by_airline_name <- named_seat_flights %>%
35 group_by(name) %>%
36 summarise(seat_miles = sum(seats, na.rm = T)*sum(distance,na.rm = T)) %>%
37 rename(airline_name = name) %>%
38 arrange(desc(seat_miles))
39named_seat_miles_by_airline_name #not correct
40
41View(named_seat_miles_by_airline_name)
42
43
44
45flights %>% # book solution
46 inner_join(planes, by = "tailnum") %>%
47 select(carrier, seats, distance) %>%
48 mutate(ASM = seats * distance) %>%
49 group_by(carrier) %>%
50 summarize(ASM = sum(ASM, na.rm = TRUE)) %>%
51 arrange(desc(ASM))**strong text**
52 # A tibble: 16 x 2
53 airline_name seat_miles
54 <chr> <dbl>
55 1 United Air Lines Inc. 8.73e14
56 2 Delta Air Lines Inc. 4.82e14
57 3 JetBlue Airways 4.13e14
58 4 ExpressJet Airlines I~ 9.82e13
59 5 US Airways Inc. 3.83e13
60 6 American Airlines Inc. 3.38e13
61 7 Southwest Airlines Co. 2.10e13
62 8 Endeavor Air Inc. 1.28e13
63 9 Virgin America 1.19e13
6410 AirTran Airways Corpo~ 6.68e11
6511 Alaska Airlines Inc. 2.24e11
6612 Hawaiian Airlines Inc. 2.20e11
6713 Frontier Airlines Inc. 1.17e11
6814 Mesa Airlines Inc. 1.17e10
6915 Envoy Air 7.10e 9
7016 SkyWest Airlines Inc. 4.08e 7
71# A tibble: 16 x 2
72 carrier ASM
73 <chr> <dbl>
74 1 UA 15516377526
75 2 DL 10532885801
76 3 B6 9618222135
77 4 AA 3677292231
78 5 US 2533505829
79 6 VX 2296680778
80 7 EV 1817236275
81 8 WN 1718116857
82 9 9E 776970310
8310 HA 642478122
8411 AS 314104736
8512 FL 219628520
8613 F9 184832280
8714 YV 20163632
8815 MQ 7162420
8916 OO 1299835
90
91...
92filter(!is.na(seats)) %>%
93summarise(seat_miles_sums = sum(seats, na.rm = T)*sum(distance,na.rm = T),
94 seat_miles = sum(seats*distance))
95...
96
Graphically, the question is asking for something like the areas below left, but your code calculates the area below right.
1 #seat miles = miles*seats
2
3View(flights) #distance and identifiers year and tail num and carrier
4View(airlines) # names and indentifiers carrier
5View(planes) #seats and identifiers year and tail num
6
7
8#join names to flights
9
10named_flights <- flights %>%
11 inner_join(airlines, by = 'carrier')
12
13named_flights #same number of rows, all good
14flights
15
16#join seats to named_flights
17
18named_seat_flights <- named_flights %>%
19 inner_join(planes, by = c('tailnum'))
20named_seat_flights #noticed 52,596 rows are missing
21#when joining tailnum to named_flights
22
23table(is.na(select(named_flights, 'tailnum')))
24#2512 rows that has NA values for tailnum in named_flights
25
26table(is.na(select(planes, 'tailnum')))
27#no tailnum data is missing from planes dataset
28#and since a given plane (with a given tailnum)
29#can take off multiple times per year
30#we can conclude that the 52,596 missing rows
31#are a result of the missing tailnum data in flights (also named_flights)
32
33
34named_seat_miles_by_airline_name <- named_seat_flights %>%
35 group_by(name) %>%
36 summarise(seat_miles = sum(seats, na.rm = T)*sum(distance,na.rm = T)) %>%
37 rename(airline_name = name) %>%
38 arrange(desc(seat_miles))
39named_seat_miles_by_airline_name #not correct
40
41View(named_seat_miles_by_airline_name)
42
43
44
45flights %>% # book solution
46 inner_join(planes, by = "tailnum") %>%
47 select(carrier, seats, distance) %>%
48 mutate(ASM = seats * distance) %>%
49 group_by(carrier) %>%
50 summarize(ASM = sum(ASM, na.rm = TRUE)) %>%
51 arrange(desc(ASM))**strong text**
52 # A tibble: 16 x 2
53 airline_name seat_miles
54 <chr> <dbl>
55 1 United Air Lines Inc. 8.73e14
56 2 Delta Air Lines Inc. 4.82e14
57 3 JetBlue Airways 4.13e14
58 4 ExpressJet Airlines I~ 9.82e13
59 5 US Airways Inc. 3.83e13
60 6 American Airlines Inc. 3.38e13
61 7 Southwest Airlines Co. 2.10e13
62 8 Endeavor Air Inc. 1.28e13
63 9 Virgin America 1.19e13
6410 AirTran Airways Corpo~ 6.68e11
6511 Alaska Airlines Inc. 2.24e11
6612 Hawaiian Airlines Inc. 2.20e11
6713 Frontier Airlines Inc. 1.17e11
6814 Mesa Airlines Inc. 1.17e10
6915 Envoy Air 7.10e 9
7016 SkyWest Airlines Inc. 4.08e 7
71# A tibble: 16 x 2
72 carrier ASM
73 <chr> <dbl>
74 1 UA 15516377526
75 2 DL 10532885801
76 3 B6 9618222135
77 4 AA 3677292231
78 5 US 2533505829
79 6 VX 2296680778
80 7 EV 1817236275
81 8 WN 1718116857
82 9 9E 776970310
8310 HA 642478122
8411 AS 314104736
8512 FL 219628520
8613 F9 184832280
8714 YV 20163632
8815 MQ 7162420
8916 OO 1299835
90
91...
92filter(!is.na(seats)) %>%
93summarise(seat_miles_sums = sum(seats, na.rm = T)*sum(distance,na.rm = T),
94 seat_miles = sum(seats*distance))
95...
96XXX YY XXXYY
97XXX + YY < XXXYY
98 YY XXXYY
99
QUESTION
How do you find max/min of a non-numeric vector?
Asked 2022-Jan-23 at 07:36I'm trying to answer a homework problem, and I'm not very good at R Studio. The problem involves the nycflights13 dataset. The question is, "Using the flights data, identify which airline carrier had the most flights in 2013? Which had the fewest number of flights? Do this using max() and min()."
So far I've used this:
table(nycflights13::flights$carrier)
It's helped me retrieve a frequency table of the carriers. I know United Airlines has the most and Skywest has the least. But how do I prove this using max() and min()? It has only returned the highest and lowest alphabetical values of the carriers. Thank you!
ANSWER
Answered 2022-Jan-23 at 04:07Just identify which values in your table are minimums and maximums (there may be only one of each):
1tbl <- table(nycflights13::flights$carrier)
2minval <- min(tbl)
3maxval <- max(tbl)
4tbl[which(tbl == minval)]
5tbl[which(tbl == maxval)]
6
QUESTION
Problems with changing the size of the two upper boxes ( text/image)
Asked 2022-Jan-18 at 17:17I'm trying to make my website responsive and for mobile and iPad it seems to work pretty well but for desktop I have a problem. I'm trying to figure out how to expand the two upper boxes (image and text). My website looks like this right now:
But the result should look like the picture to the left:
Here is my HTML for the two upper boxes:
1@import url('https://fonts.googleapis.com/css2?family=Amatic+SC&family=Montserrat:wght@100&family=Open+Sans+Condensed:wght@300;700&display=swap');
2body {
3 margin: 0%;
4 font-family: 'Montserrat', sans-serif;
5 background-color: #f2f2f0;
6}
7
8
9/* Header */
10
11header {
12 height: 100px;
13 display: flex;
14 align-items: center;
15 justify-content: space-between;
16 padding: 16px;
17 color: #d0c8b6;
18}
19
20a {
21 text-decoration: none;
22}
23
24.headertext {
25 font-family: 'Amatic SC', cursive;
26 font-size: 50px;
27 margin-right: 40px;
28}
29
30.title {
31 display: flex;
32 font-family: 'Amatic SC', cursive;
33}
34
35.logo {
36 width: 80px;
37 border-radius: 50%;
38 margin-left: 40px;
39}
40
41
42/* The bigger news */
43
44nav {
45 display: none;
46 font-size: 14px;
47}
48
49nav div {
50 width: 30%;
51 display: flex;
52 justify-content: space-between;
53}
54
55.header-box {
56 display: flex;
57 margin: 0%;
58 justify-content: center;
59}
60
61
62/* The other news */
63
64.flex-parent1 {
65 display: flex;
66 flex-wrap: wrap;
67 justify-content: center;
68}
69
70.flex-parent2 {
71 display: flex;
72 height: 100px;
73 flex-direction: row;
74 flex-wrap: wrap;
75 justify-content: center;
76}
77
78.child1 {
79 margin-bottom: 20px;
80}
81
82.image {
83 height: auto;
84 width: auto;
85 display: inline;
86}
87
88.text {
89 margin-left: 10px;
90 margin-right: 10px;
91 margin-top: 0px;
92 width: 350px;
93 text-align: justify;
94}
95
96.footer-text {
97 color: black;
98 font-size: 14px;
99 margin-top: 5px;
100 margin-bottom: 8px;
101 text-transform: uppercase;
102 text-align: center;
103}
104
105.date {
106 text-align: center;
107 margin-top: 5px;
108 font-size: 10px;
109}
110
111.image {
112 width: 350px;
113 display: flex;
114 align-items: center;
115 flex-direction: column;
116 margin-left: 10px;
117 margin-right: 10px;
118}
119
120.image1 {
121 width: 350px;
122 display: flex;
123 align-items: center;
124 flex-direction: column;
125 margin-left: 10px;
126 margin-right: 10px;
127}
128
129
130/* Mobile */
131
132@media (min-width: 668px) {
133 header {
134 justify-content: center;
135 }
136 nav {
137 width: 80%;
138 display: flex;
139 justify-content: space-between;
140 }
141 .headertext {
142 display: none;
143 }
144 .title {
145 display: none;
146 }
147 .menu {
148 display: none;
149 }
150 .logo {
151 position: absolute;
152 }
153}
154
155
156/* Desktop */
157
158@media (min-width: 1025px) {
159 header {
160 justify-content: space-between;
161 }
162 nav {
163 width: 60%;
164 justify-content: space-evenly;
165 }
166 .logo {
167 position: static;
168 }
169 .headertext {
170 display: block;
171 }
172}
1@import url('https://fonts.googleapis.com/css2?family=Amatic+SC&family=Montserrat:wght@100&family=Open+Sans+Condensed:wght@300;700&display=swap');
2body {
3 margin: 0%;
4 font-family: 'Montserrat', sans-serif;
5 background-color: #f2f2f0;
6}
7
8
9/* Header */
10
11header {
12 height: 100px;
13 display: flex;
14 align-items: center;
15 justify-content: space-between;
16 padding: 16px;
17 color: #d0c8b6;
18}
19
20a {
21 text-decoration: none;
22}
23
24.headertext {
25 font-family: 'Amatic SC', cursive;
26 font-size: 50px;
27 margin-right: 40px;
28}
29
30.title {
31 display: flex;
32 font-family: 'Amatic SC', cursive;
33}
34
35.logo {
36 width: 80px;
37 border-radius: 50%;
38 margin-left: 40px;
39}
40
41
42/* The bigger news */
43
44nav {
45 display: none;
46 font-size: 14px;
47}
48
49nav div {
50 width: 30%;
51 display: flex;
52 justify-content: space-between;
53}
54
55.header-box {
56 display: flex;
57 margin: 0%;
58 justify-content: center;
59}
60
61
62/* The other news */
63
64.flex-parent1 {
65 display: flex;
66 flex-wrap: wrap;
67 justify-content: center;
68}
69
70.flex-parent2 {
71 display: flex;
72 height: 100px;
73 flex-direction: row;
74 flex-wrap: wrap;
75 justify-content: center;
76}
77
78.child1 {
79 margin-bottom: 20px;
80}
81
82.image {
83 height: auto;
84 width: auto;
85 display: inline;
86}
87
88.text {
89 margin-left: 10px;
90 margin-right: 10px;
91 margin-top: 0px;
92 width: 350px;
93 text-align: justify;
94}
95
96.footer-text {
97 color: black;
98 font-size: 14px;
99 margin-top: 5px;
100 margin-bottom: 8px;
101 text-transform: uppercase;
102 text-align: center;
103}
104
105.date {
106 text-align: center;
107 margin-top: 5px;
108 font-size: 10px;
109}
110
111.image {
112 width: 350px;
113 display: flex;
114 align-items: center;
115 flex-direction: column;
116 margin-left: 10px;
117 margin-right: 10px;
118}
119
120.image1 {
121 width: 350px;
122 display: flex;
123 align-items: center;
124 flex-direction: column;
125 margin-left: 10px;
126 margin-right: 10px;
127}
128
129
130/* Mobile */
131
132@media (min-width: 668px) {
133 header {
134 justify-content: center;
135 }
136 nav {
137 width: 80%;
138 display: flex;
139 justify-content: space-between;
140 }
141 .headertext {
142 display: none;
143 }
144 .title {
145 display: none;
146 }
147 .menu {
148 display: none;
149 }
150 .logo {
151 position: absolute;
152 }
153}
154
155
156/* Desktop */
157
158@media (min-width: 1025px) {
159 header {
160 justify-content: space-between;
161 }
162 nav {
163 width: 60%;
164 justify-content: space-evenly;
165 }
166 .logo {
167 position: static;
168 }
169 .headertext {
170 display: block;
171 }
172}<div class="flex-parent1">
173
174 <div class="child1">
175 <img class="image" src="https://images.pexels.com/photos/5581939/pexels-photo-5581939.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="image1" />
176 </div>
177
178 <div class="child2">
179 <p class="text">Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. Tourists
180 go to various destinations, countries with great landmarks, places with lovely beaches or simply areas of wilderness and untouched nature. In the last few decades tourism has grown very much, mostly because people’s lifestyles have changed. They
181 don’t want to stay at home any more. They spend more money on travelling than previous generations did. Travelling has also become cheaper and more affordable. The rise of budget airlines has made it possible to afford trips to faraway countries.
182 Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. he rise
183 of budget airlines has made it possible to afford trips to faraway countries. about other cultures or just relax from stressful working life. he rise of budget airlines has made it possible to.</p>
184 </div>
185
186</div>
ANSWER
Answered 2022-Jan-18 at 17:11If by "expand" you mean put them in a row for larger screens, just set the flex direction to row
by default, and you already have it overridden for mobile.
View this demo in fullscreen mode and resize.
1@import url('https://fonts.googleapis.com/css2?family=Amatic+SC&family=Montserrat:wght@100&family=Open+Sans+Condensed:wght@300;700&display=swap');
2body {
3 margin: 0%;
4 font-family: 'Montserrat', sans-serif;
5 background-color: #f2f2f0;
6}
7
8
9/* Header */
10
11header {
12 height: 100px;
13 display: flex;
14 align-items: center;
15 justify-content: space-between;
16 padding: 16px;
17 color: #d0c8b6;
18}
19
20a {
21 text-decoration: none;
22}
23
24.headertext {
25 font-family: 'Amatic SC', cursive;
26 font-size: 50px;
27 margin-right: 40px;
28}
29
30.title {
31 display: flex;
32 font-family: 'Amatic SC', cursive;
33}
34
35.logo {
36 width: 80px;
37 border-radius: 50%;
38 margin-left: 40px;
39}
40
41
42/* The bigger news */
43
44nav {
45 display: none;
46 font-size: 14px;
47}
48
49nav div {
50 width: 30%;
51 display: flex;
52 justify-content: space-between;
53}
54
55.header-box {
56 display: flex;
57 margin: 0%;
58 justify-content: center;
59}
60
61
62/* The other news */
63
64.flex-parent1 {
65 display: flex;
66 flex-wrap: wrap;
67 justify-content: center;
68}
69
70.flex-parent2 {
71 display: flex;
72 height: 100px;
73 flex-direction: row;
74 flex-wrap: wrap;
75 justify-content: center;
76}
77
78.child1 {
79 margin-bottom: 20px;
80}
81
82.image {
83 height: auto;
84 width: auto;
85 display: inline;
86}
87
88.text {
89 margin-left: 10px;
90 margin-right: 10px;
91 margin-top: 0px;
92 width: 350px;
93 text-align: justify;
94}
95
96.footer-text {
97 color: black;
98 font-size: 14px;
99 margin-top: 5px;
100 margin-bottom: 8px;
101 text-transform: uppercase;
102 text-align: center;
103}
104
105.date {
106 text-align: center;
107 margin-top: 5px;
108 font-size: 10px;
109}
110
111.image {
112 width: 350px;
113 display: flex;
114 align-items: center;
115 flex-direction: column;
116 margin-left: 10px;
117 margin-right: 10px;
118}
119
120.image1 {
121 width: 350px;
122 display: flex;
123 align-items: center;
124 flex-direction: column;
125 margin-left: 10px;
126 margin-right: 10px;
127}
128
129
130/* Mobile */
131
132@media (min-width: 668px) {
133 header {
134 justify-content: center;
135 }
136 nav {
137 width: 80%;
138 display: flex;
139 justify-content: space-between;
140 }
141 .headertext {
142 display: none;
143 }
144 .title {
145 display: none;
146 }
147 .menu {
148 display: none;
149 }
150 .logo {
151 position: absolute;
152 }
153}
154
155
156/* Desktop */
157
158@media (min-width: 1025px) {
159 header {
160 justify-content: space-between;
161 }
162 nav {
163 width: 60%;
164 justify-content: space-evenly;
165 }
166 .logo {
167 position: static;
168 }
169 .headertext {
170 display: block;
171 }
172}<div class="flex-parent1">
173
174 <div class="child1">
175 <img class="image" src="https://images.pexels.com/photos/5581939/pexels-photo-5581939.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="image1" />
176 </div>
177
178 <div class="child2">
179 <p class="text">Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. Tourists
180 go to various destinations, countries with great landmarks, places with lovely beaches or simply areas of wilderness and untouched nature. In the last few decades tourism has grown very much, mostly because people’s lifestyles have changed. They
181 don’t want to stay at home any more. They spend more money on travelling than previous generations did. Travelling has also become cheaper and more affordable. The rise of budget airlines has made it possible to afford trips to faraway countries.
182 Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. he rise
183 of budget airlines has made it possible to afford trips to faraway countries. about other cultures or just relax from stressful working life. he rise of budget airlines has made it possible to.</p>
184 </div>
185
186</div>@import url('https://fonts.googleapis.com/css2?family=Amatic+SC&family=Montserrat:wght@100&family=Open+Sans+Condensed:wght@300;700&display=swap');
187body {
188 margin: 0%;
189 font-family: 'Montserrat', sans-serif;
190 background-color: #f2f2f0;
191}
192
193
194/* Header */
195
196header {
197 height: 100px;
198 display: flex;
199 align-items: center;
200 justify-content: space-between;
201 padding: 16px;
202 color: #d0c8b6;
203}
204
205a {
206 text-decoration: none;
207}
208
209.headertext {
210 font-family: 'Amatic SC', cursive;
211 font-size: 50px;
212 margin-right: 40px;
213}
214
215.title {
216 display: flex;
217 font-family: 'Amatic SC', cursive;
218}
219
220.logo {
221 width: 80px;
222 border-radius: 50%;
223 margin-left: 40px;
224}
225
226
227/* The bigger news */
228
229nav {
230 display: none;
231 font-size: 14px;
232}
233
234nav div {
235 width: 30%;
236 display: flex;
237 justify-content: space-between;
238}
239
240.header-box {
241 display: flex;
242 margin: 0%;
243 justify-content: center;
244}
245
246
247/* The other news */
248
249.flex-parent1 {
250 display: flex;
251 flex-direction: row;
252 flex-wrap: wrap;
253 justify-content: center;
254}
255
256.flex-parent2 {
257 display: flex;
258 height: 100px;
259 flex-direction: row;
260 flex-wrap: wrap;
261 justify-content: center;
262}
263
264.child1 {
265 margin-bottom: 20px;
266}
267
268.image {
269 height: auto;
270 width: auto;
271 display: inline;
272}
273
274.text {
275 margin-left: 10px;
276 margin-right: 10px;
277 margin-top: 0px;
278 width: 350px;
279 text-align: justify;
280}
281
282.footer-text {
283 color: black;
284 font-size: 14px;
285 margin-top: 5px;
286 margin-bottom: 8px;
287 text-transform: uppercase;
288 text-align: center;
289}
290
291.date {
292 text-align: center;
293 margin-top: 5px;
294 font-size: 10px;
295}
296
297.image {
298 width: 350px;
299 display: flex;
300 align-items: center;
301 flex-direction: column;
302 margin-left: 10px;
303 margin-right: 10px;
304}
305
306.image1 {
307 width: 350px;
308 display: flex;
309 align-items: center;
310 flex-direction: column;
311 margin-left: 10px;
312 margin-right: 10px;
313}
314
315
316/* Mobile */
317
318@media (min-width: 668px) {
319 header {
320 justify-content: center;
321 }
322 nav {
323 width: 80%;
324 display: flex;
325 justify-content: space-between;
326 }
327 .headertext {
328 display: none;
329 }
330 .title {
331 display: none;
332 }
333 .menu {
334 display: none;
335 }
336 .logo {
337 position: absolute;
338 }
339}
340
341
342/* Desktop */
343
344@media (min-width: 1025px) {
345 header {
346 justify-content: space-between;
347 }
348 nav {
349 width: 60%;
350 justify-content: space-evenly;
351 }
352 .logo {
353 position: static;
354 }
355 .headertext {
356 display: block;
357 }
358}
1@import url('https://fonts.googleapis.com/css2?family=Amatic+SC&family=Montserrat:wght@100&family=Open+Sans+Condensed:wght@300;700&display=swap');
2body {
3 margin: 0%;
4 font-family: 'Montserrat', sans-serif;
5 background-color: #f2f2f0;
6}
7
8
9/* Header */
10
11header {
12 height: 100px;
13 display: flex;
14 align-items: center;
15 justify-content: space-between;
16 padding: 16px;
17 color: #d0c8b6;
18}
19
20a {
21 text-decoration: none;
22}
23
24.headertext {
25 font-family: 'Amatic SC', cursive;
26 font-size: 50px;
27 margin-right: 40px;
28}
29
30.title {
31 display: flex;
32 font-family: 'Amatic SC', cursive;
33}
34
35.logo {
36 width: 80px;
37 border-radius: 50%;
38 margin-left: 40px;
39}
40
41
42/* The bigger news */
43
44nav {
45 display: none;
46 font-size: 14px;
47}
48
49nav div {
50 width: 30%;
51 display: flex;
52 justify-content: space-between;
53}
54
55.header-box {
56 display: flex;
57 margin: 0%;
58 justify-content: center;
59}
60
61
62/* The other news */
63
64.flex-parent1 {
65 display: flex;
66 flex-wrap: wrap;
67 justify-content: center;
68}
69
70.flex-parent2 {
71 display: flex;
72 height: 100px;
73 flex-direction: row;
74 flex-wrap: wrap;
75 justify-content: center;
76}
77
78.child1 {
79 margin-bottom: 20px;
80}
81
82.image {
83 height: auto;
84 width: auto;
85 display: inline;
86}
87
88.text {
89 margin-left: 10px;
90 margin-right: 10px;
91 margin-top: 0px;
92 width: 350px;
93 text-align: justify;
94}
95
96.footer-text {
97 color: black;
98 font-size: 14px;
99 margin-top: 5px;
100 margin-bottom: 8px;
101 text-transform: uppercase;
102 text-align: center;
103}
104
105.date {
106 text-align: center;
107 margin-top: 5px;
108 font-size: 10px;
109}
110
111.image {
112 width: 350px;
113 display: flex;
114 align-items: center;
115 flex-direction: column;
116 margin-left: 10px;
117 margin-right: 10px;
118}
119
120.image1 {
121 width: 350px;
122 display: flex;
123 align-items: center;
124 flex-direction: column;
125 margin-left: 10px;
126 margin-right: 10px;
127}
128
129
130/* Mobile */
131
132@media (min-width: 668px) {
133 header {
134 justify-content: center;
135 }
136 nav {
137 width: 80%;
138 display: flex;
139 justify-content: space-between;
140 }
141 .headertext {
142 display: none;
143 }
144 .title {
145 display: none;
146 }
147 .menu {
148 display: none;
149 }
150 .logo {
151 position: absolute;
152 }
153}
154
155
156/* Desktop */
157
158@media (min-width: 1025px) {
159 header {
160 justify-content: space-between;
161 }
162 nav {
163 width: 60%;
164 justify-content: space-evenly;
165 }
166 .logo {
167 position: static;
168 }
169 .headertext {
170 display: block;
171 }
172}<div class="flex-parent1">
173
174 <div class="child1">
175 <img class="image" src="https://images.pexels.com/photos/5581939/pexels-photo-5581939.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="image1" />
176 </div>
177
178 <div class="child2">
179 <p class="text">Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. Tourists
180 go to various destinations, countries with great landmarks, places with lovely beaches or simply areas of wilderness and untouched nature. In the last few decades tourism has grown very much, mostly because people’s lifestyles have changed. They
181 don’t want to stay at home any more. They spend more money on travelling than previous generations did. Travelling has also become cheaper and more affordable. The rise of budget airlines has made it possible to afford trips to faraway countries.
182 Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. he rise
183 of budget airlines has made it possible to afford trips to faraway countries. about other cultures or just relax from stressful working life. he rise of budget airlines has made it possible to.</p>
184 </div>
185
186</div>@import url('https://fonts.googleapis.com/css2?family=Amatic+SC&family=Montserrat:wght@100&family=Open+Sans+Condensed:wght@300;700&display=swap');
187body {
188 margin: 0%;
189 font-family: 'Montserrat', sans-serif;
190 background-color: #f2f2f0;
191}
192
193
194/* Header */
195
196header {
197 height: 100px;
198 display: flex;
199 align-items: center;
200 justify-content: space-between;
201 padding: 16px;
202 color: #d0c8b6;
203}
204
205a {
206 text-decoration: none;
207}
208
209.headertext {
210 font-family: 'Amatic SC', cursive;
211 font-size: 50px;
212 margin-right: 40px;
213}
214
215.title {
216 display: flex;
217 font-family: 'Amatic SC', cursive;
218}
219
220.logo {
221 width: 80px;
222 border-radius: 50%;
223 margin-left: 40px;
224}
225
226
227/* The bigger news */
228
229nav {
230 display: none;
231 font-size: 14px;
232}
233
234nav div {
235 width: 30%;
236 display: flex;
237 justify-content: space-between;
238}
239
240.header-box {
241 display: flex;
242 margin: 0%;
243 justify-content: center;
244}
245
246
247/* The other news */
248
249.flex-parent1 {
250 display: flex;
251 flex-direction: row;
252 flex-wrap: wrap;
253 justify-content: center;
254}
255
256.flex-parent2 {
257 display: flex;
258 height: 100px;
259 flex-direction: row;
260 flex-wrap: wrap;
261 justify-content: center;
262}
263
264.child1 {
265 margin-bottom: 20px;
266}
267
268.image {
269 height: auto;
270 width: auto;
271 display: inline;
272}
273
274.text {
275 margin-left: 10px;
276 margin-right: 10px;
277 margin-top: 0px;
278 width: 350px;
279 text-align: justify;
280}
281
282.footer-text {
283 color: black;
284 font-size: 14px;
285 margin-top: 5px;
286 margin-bottom: 8px;
287 text-transform: uppercase;
288 text-align: center;
289}
290
291.date {
292 text-align: center;
293 margin-top: 5px;
294 font-size: 10px;
295}
296
297.image {
298 width: 350px;
299 display: flex;
300 align-items: center;
301 flex-direction: column;
302 margin-left: 10px;
303 margin-right: 10px;
304}
305
306.image1 {
307 width: 350px;
308 display: flex;
309 align-items: center;
310 flex-direction: column;
311 margin-left: 10px;
312 margin-right: 10px;
313}
314
315
316/* Mobile */
317
318@media (min-width: 668px) {
319 header {
320 justify-content: center;
321 }
322 nav {
323 width: 80%;
324 display: flex;
325 justify-content: space-between;
326 }
327 .headertext {
328 display: none;
329 }
330 .title {
331 display: none;
332 }
333 .menu {
334 display: none;
335 }
336 .logo {
337 position: absolute;
338 }
339}
340
341
342/* Desktop */
343
344@media (min-width: 1025px) {
345 header {
346 justify-content: space-between;
347 }
348 nav {
349 width: 60%;
350 justify-content: space-evenly;
351 }
352 .logo {
353 position: static;
354 }
355 .headertext {
356 display: block;
357 }
358}<div class="flex-parent1">
359 <div class="child1">
360 <img class="image" src="https://images.pexels.com/photos/5581939/pexels-photo-5581939.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="image1" />
361 </div>
362
363 <div class="child2">
364 <p class="text">Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. Tourists
365 go to various destinations, countries with great landmarks, places with lovely beaches or simply areas of wilderness and untouched nature. In the last few decades tourism has grown very much, mostly because people’s lifestyles have changed. They
366 don’t want to stay at home any more. They spend more money on travelling than previous generations did. Travelling has also become cheaper and more affordable. The rise of budget airlines has made it possible to afford trips to faraway countries.
367 Tourism is travelling for pleasure or to enjoy yourself away from the place you live. People do this for many different reasons – to have fun, visit other countries and learn about other cultures or just relax from stressful working life. he rise
368 of budget airlines has made it possible to afford trips to faraway countries. about other cultures or just relax from stressful working life. he rise of budget airlines has made it possible to.</p>
369 </div>
370</div>
QUESTION
Apache Spark Data Generator Function on Databricks Not working
Asked 2022-Jan-16 at 23:52I am trying to execute the Data Generator function provided my Microsoft to test streaming data to Event Hubs.
Unfortunately, I keep on getting the error
1Processing failure: No such file or directory
2
When I try and execute the function:
1Processing failure: No such file or directory
2%scala
3DummyDataGenerator.start(15)
4
Can someone take a look at the code and help decipher why I'm getting the error:
1Processing failure: No such file or directory
2%scala
3DummyDataGenerator.start(15)
4class DummyDataGenerator:
5 streamDirectory = "/FileStore/tables/flight"
6None # suppress output
7
I'm not sure how the above cell gets called into the function DummyDataGenerator
1Processing failure: No such file or directory
2%scala
3DummyDataGenerator.start(15)
4class DummyDataGenerator:
5 streamDirectory = "/FileStore/tables/flight"
6None # suppress output
7%scala
8
9import scala.util.Random
10import java.io._
11import java.time._
12
13// Notebook #2 has to set this to 8, we are setting
14// it to 200 to "restore" the default behavior.
15spark.conf.set("spark.sql.shuffle.partitions", 200)
16
17// Make the username available to all other languages.
18// "WARNING: use of the "current" username is unpredictable
19// when multiple users are collaborating and should be replaced
20// with the notebook ID instead.
21val username = com.databricks.logging.AttributionContext.current.tags(com.databricks.logging.BaseTagDefinitions.TAG_USER);
22spark.conf.set("com.databricks.training.username", username)
23
24object DummyDataGenerator extends Runnable {
25 var runner : Thread = null;
26 val className = getClass().getName()
27 val streamDirectory = s"dbfs:/tmp/$username/new-flights"
28 val airlines = Array( ("American", 0.17), ("Delta", 0.12), ("Frontier", 0.14), ("Hawaiian", 0.13), ("JetBlue", 0.15), ("United", 0.11), ("Southwest", 0.18) )
29 val reasons = Array("Air Carrier", "Extreme Weather", "National Aviation System", "Security", "Late Aircraft")
30
31 val rand = new Random(System.currentTimeMillis())
32 var maxDuration = 3 * 60 * 1000 // default to three minutes
33
34 def clean() {
35 System.out.println("Removing old files for dummy data generator.")
36 dbutils.fs.rm(streamDirectory, true)
37 if (dbutils.fs.mkdirs(streamDirectory) == false) {
38 throw new RuntimeException("Unable to create temp directory.")
39 }
40 }
41
42 def run() {
43 val date = LocalDate.now()
44 val start = System.currentTimeMillis()
45
46 while (System.currentTimeMillis() - start < maxDuration) {
47 try {
48 val dir = s"/dbfs/tmp/$username/new-flights"
49 val tempFile = File.createTempFile("flights-", "", new File(dir)).getAbsolutePath()+".csv"
50 val writer = new PrintWriter(tempFile)
51
52 for (airline <- airlines) {
53 val flightNumber = rand.nextInt(1000)+1000
54 val deptTime = rand.nextInt(10)+10
55 val departureTime = LocalDateTime.now().plusHours(-deptTime)
56 val (name, odds) = airline
57 val reason = Random.shuffle(reasons.toList).head
58 val test = rand.nextDouble()
59
60 val delay = if (test < odds)
61 rand.nextInt(60)+(30*odds)
62 else rand.nextInt(10)-5
63
64 println(s"- Flight #$flightNumber by $name at $departureTime delayed $delay minutes due to $reason")
65 writer.println(s""" "$flightNumber","$departureTime","$delay","$reason","$name" """.trim)
66 }
67 writer.close()
68
69 // wait a couple of seconds
70 //Thread.sleep(rand.nextInt(5000))
71
72 } catch {
73 case e: Exception => {
74 printf("* Processing failure: %s%n", e.getMessage())
75 return;
76 }
77 }
78 }
79 println("No more flights!")
80 }
81
82 def start(minutes:Int = 5) {
83 maxDuration = minutes * 60 * 1000
84
85 if (runner != null) {
86 println("Stopping dummy data generator.")
87 runner.interrupt();
88 runner.join();
89 }
90 println(s"Running dummy data generator for $minutes minutes.")
91 runner = new Thread(this);
92 runner.run();
93 }
94
95 def stop() {
96 start(0)
97 }
98}
99
100DummyDataGenerator.clean()
101
102displayHTML("Imported streaming logic...") // suppress output
103
ANSWER
Answered 2022-Jan-08 at 13:16This code will not work on the community edition because of this line:
1Processing failure: No such file or directory
2%scala
3DummyDataGenerator.start(15)
4class DummyDataGenerator:
5 streamDirectory = "/FileStore/tables/flight"
6None # suppress output
7%scala
8
9import scala.util.Random
10import java.io._
11import java.time._
12
13// Notebook #2 has to set this to 8, we are setting
14// it to 200 to "restore" the default behavior.
15spark.conf.set("spark.sql.shuffle.partitions", 200)
16
17// Make the username available to all other languages.
18// "WARNING: use of the "current" username is unpredictable
19// when multiple users are collaborating and should be replaced
20// with the notebook ID instead.
21val username = com.databricks.logging.AttributionContext.current.tags(com.databricks.logging.BaseTagDefinitions.TAG_USER);
22spark.conf.set("com.databricks.training.username", username)
23
24object DummyDataGenerator extends Runnable {
25 var runner : Thread = null;
26 val className = getClass().getName()
27 val streamDirectory = s"dbfs:/tmp/$username/new-flights"
28 val airlines = Array( ("American", 0.17), ("Delta", 0.12), ("Frontier", 0.14), ("Hawaiian", 0.13), ("JetBlue", 0.15), ("United", 0.11), ("Southwest", 0.18) )
29 val reasons = Array("Air Carrier", "Extreme Weather", "National Aviation System", "Security", "Late Aircraft")
30
31 val rand = new Random(System.currentTimeMillis())
32 var maxDuration = 3 * 60 * 1000 // default to three minutes
33
34 def clean() {
35 System.out.println("Removing old files for dummy data generator.")
36 dbutils.fs.rm(streamDirectory, true)
37 if (dbutils.fs.mkdirs(streamDirectory) == false) {
38 throw new RuntimeException("Unable to create temp directory.")
39 }
40 }
41
42 def run() {
43 val date = LocalDate.now()
44 val start = System.currentTimeMillis()
45
46 while (System.currentTimeMillis() - start < maxDuration) {
47 try {
48 val dir = s"/dbfs/tmp/$username/new-flights"
49 val tempFile = File.createTempFile("flights-", "", new File(dir)).getAbsolutePath()+".csv"
50 val writer = new PrintWriter(tempFile)
51
52 for (airline <- airlines) {
53 val flightNumber = rand.nextInt(1000)+1000
54 val deptTime = rand.nextInt(10)+10
55 val departureTime = LocalDateTime.now().plusHours(-deptTime)
56 val (name, odds) = airline
57 val reason = Random.shuffle(reasons.toList).head
58 val test = rand.nextDouble()
59
60 val delay = if (test < odds)
61 rand.nextInt(60)+(30*odds)
62 else rand.nextInt(10)-5
63
64 println(s"- Flight #$flightNumber by $name at $departureTime delayed $delay minutes due to $reason")
65 writer.println(s""" "$flightNumber","$departureTime","$delay","$reason","$name" """.trim)
66 }
67 writer.close()
68
69 // wait a couple of seconds
70 //Thread.sleep(rand.nextInt(5000))
71
72 } catch {
73 case e: Exception => {
74 printf("* Processing failure: %s%n", e.getMessage())
75 return;
76 }
77 }
78 }
79 println("No more flights!")
80 }
81
82 def start(minutes:Int = 5) {
83 maxDuration = minutes * 60 * 1000
84
85 if (runner != null) {
86 println("Stopping dummy data generator.")
87 runner.interrupt();
88 runner.join();
89 }
90 println(s"Running dummy data generator for $minutes minutes.")
91 runner = new Thread(this);
92 runner.run();
93 }
94
95 def stop() {
96 start(0)
97 }
98}
99
100DummyDataGenerator.clean()
101
102displayHTML("Imported streaming logic...") // suppress output
103val dir = s"/dbfs/tmp/$username/new-flights"
104
as there is no DBFS fuse on Databricks community edition (it's supported only on full Databricks). It's potentially possible to make it working by:
- Changing that directory to local directory, like,
/tmp
or something like - adding a code (after
writer.close()
) to listflights-*
files in that local directory, and usingdbutils.fs.mv
to move them intostreamDirectory
QUESTION
EnhancedSeatMap Seat Without Price
Asked 2021-Dec-02 at 19:50I am having some trouble with EnhancedSeatMapRQ
, as the seats for certain airlines (e.g. AC, AA, etc.) do not return any BasePrice
or Price
node. When checked with Sabre software, some of these seats do have a cost charged upon booking.
My understanding is in these situations, the CommercialName
value is supposed to help lookup the price. With that said, there is no reference in the response that indicates any price, for anything.
Here is one with a price node:
1<Offer entitledInd="false">
2 <CommercialName>SEAT ASSIGNMENT</CommercialName>
3 <BasePrice>
4 <TotalAmount currencyCode="CAD">27.12</TotalAmount>
5 <Taxes>
6 <Tax currencyCode="CAD">3.12</Tax>
7 <TaxTypeRef>taxTypeDetail_1</TaxTypeRef>
8 </Taxes>
9 </BasePrice>
10</Offer>
11
And one without it:
1<Offer entitledInd="false">
2 <CommercialName>SEAT ASSIGNMENT</CommercialName>
3 <BasePrice>
4 <TotalAmount currencyCode="CAD">27.12</TotalAmount>
5 <Taxes>
6 <Tax currencyCode="CAD">3.12</Tax>
7 <TaxTypeRef>taxTypeDetail_1</TaxTypeRef>
8 </Taxes>
9 </BasePrice>
10</Offer>
11 <Offer entitledInd="true">
12 <CommercialName>ADVANCE SEAT SELECTION</CommercialName>
13 <OfferItemId>offerItem_1</OfferItemId>
14 <TravellerID>1</TravellerID>
15</Offer>
16
17
Specifies the commercial name associated with matched price.
is all that the docs say about the CommercialName
node.
Please guide me through the process of pricing these seats, as it's crucial to a proper seat selection process.
UPDATE: We have noticed that all the Offer
nodes without a Price
or BasePrice
, are inside seats with chargeableInd
set to false
. With that said, this happens with a significant number of the Airlines, and if unresolved, will render our seat selection counter-productive.
ANSWER
Answered 2021-Dec-02 at 19:50So Sabre team got back to me, and clarified the issue.
When sending a SeatMapQueryEnhanced
, the /CabinDefinition/RBD
is supposed to have the @ProgramSystemCode
, received from BFM.
Example:
1<Offer entitledInd="false">
2 <CommercialName>SEAT ASSIGNMENT</CommercialName>
3 <BasePrice>
4 <TotalAmount currencyCode="CAD">27.12</TotalAmount>
5 <Taxes>
6 <Tax currencyCode="CAD">3.12</Tax>
7 <TaxTypeRef>taxTypeDetail_1</TaxTypeRef>
8 </Taxes>
9 </BasePrice>
10</Offer>
11 <Offer entitledInd="true">
12 <CommercialName>ADVANCE SEAT SELECTION</CommercialName>
13 <OfferItemId>offerItem_1</OfferItemId>
14 <TravellerID>1</TravellerID>
15</Offer>
16
17 <Flight origin="YVR" destination="DFW">
18 <DepartureDate>2022-07-13</DepartureDate>
19 <Operating carrier="AA">392</Operating>
20 <Marketing carrier="AA">392</Marketing>
21 <ArrivalDate>2022-07-13</ArrivalDate>
22 </Flight>
23 <CabinDefinition>
24 <RBD>N</RBD>
25 </CabinDefinition>
26
Where N is extracted form the ProgramSystemCode
attribute of that Segment
node.
Community Discussions contain sources that include Stack Exchange Network
Tutorials and Learning Resources in Airlines
Tutorials and Learning Resources are not available at this moment for Airlines