Skip to content

Commit 5aad0ec

Browse files
linting
1 parent 46243e9 commit 5aad0ec

14 files changed

Lines changed: 1641 additions & 735 deletions

File tree

Cargo.lock

Lines changed: 1549 additions & 608 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "packetraven"
3-
authors = ["Zach Burnett <zachary.r.burnett@gmail.com>"]
3+
authors = ["Zach Burnett <zrb@umd.edu>"]
44
description = "track high-altitude balloon telemetry from a variety of sources"
5-
version = "4.0.2"
5+
version = "4.0.3"
66
edition = "2021"
77
readme = "README.md"
88
license = "GPL-3.0-or-later"
@@ -28,7 +28,7 @@ geo = { version = ">=0.24.1", features = ["serde"] }
2828
geojson = ">=0.24.0"
2929
lazy_static = ">=1.4.0"
3030
log = ">=0.4.17"
31-
postgres = { version="0.19.7", optional=true }
31+
postgres = { version = "0.19.7", optional = true }
3232
ratatui = ">=0.21.0"
3333
crossterm = ">=0.26.1"
3434
regex = ">=1.8.1"
@@ -37,6 +37,6 @@ serde = ">=1.0.160"
3737
serde_json = ">=1.0.96"
3838
serde_with = { version = ">=3.0.0", features = ["chrono"] }
3939
serde_yaml = ">=0.9.21"
40-
serialport = { version= ">=4.2.0", optional=true }
40+
serialport = { version = ">=4.2.0", optional = true }
4141
url = ">=2.3.1"
4242
geo-types = ">=0.7.9"

src/connection/aprs_fi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl AprsFiQuery {
6464
.get("https://api.aprs.fi/api/get")
6565
.query(&parameters)
6666
.send()
67-
.expect(&format!("{:?}", parameters));
67+
.unwrap_or_else(|_| panic!("{parameters:?}"));
6868
let url = response.url().to_string();
6969

7070
self.last_access = Some(now);

src/connection/sondehub.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ impl SondeHubQuery {
7474
for callsign in callsigns {
7575
let response = client
7676
.get(format!(
77-
"https://api.v2.sondehub.org/amateur/telemetry/{:}",
78-
callsign
77+
"https://api.v2.sondehub.org/amateur/telemetry/{callsign:}"
7978
))
8079
.query(&parameters)
8180
.send()
82-
.unwrap_or_else(|error| panic!("{:} - {:?}", error, parameters));
81+
.unwrap_or_else(|error| panic!("{error} - {parameters:?}"));
8382

8483
let url = response.url().to_string().to_owned();
8584

@@ -90,7 +89,7 @@ impl SondeHubQuery {
9089
Ok(object) => object,
9190
Err(error) => {
9291
return Err(crate::connection::ConnectionError::ApiError {
93-
message: format!("{:?}", error),
92+
message: format!("{error:?}"),
9493
url,
9594
});
9695
}
@@ -155,10 +154,7 @@ struct SondeHubLocation {
155154
impl SondeHubLocation {
156155
pub fn to_balloon_location(&self) -> crate::location::BalloonLocation {
157156
let aprs_packet = match self.raw.as_ref() {
158-
Some(frame) => match aprs_parser::AprsPacket::decode_textual(frame.as_bytes()) {
159-
Ok(packet) => Some(packet),
160-
Err(_) => None,
161-
},
157+
Some(frame) => aprs_parser::AprsPacket::decode_textual(frame.as_bytes()).ok(),
162158
None => None,
163159
};
164160
let time = self.datetime.to_owned();

src/connection/text/file.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl GeoJsonFile {
192192
Err(error) => return Err(
193193
crate::connection::ConnectionError::ReadFailure {
194194
connection: self.path.to_owned(),
195-
message: format!("{:} - {:}", time, error),
195+
message: format!("{time} - {error}"),
196196
},
197197
),
198198
}
@@ -283,39 +283,6 @@ impl GeoJsonFile {
283283
}
284284
}
285285

286-
#[cfg(test)]
287-
mod tests {
288-
use super::*;
289-
290-
#[test]
291-
#[ignore]
292-
fn test_aprs_from_url() {
293-
let url = "http://bpp.umd.edu/archives/Launches/NS-111_2022_07_31/APRS/W3EAX-11%20raw.txt"
294-
.to_string();
295-
296-
let connection = AprsTextFile::new(url, None).unwrap();
297-
298-
let packets = connection.read_aprs_from_file().unwrap();
299-
300-
assert!(!packets.is_empty());
301-
}
302-
303-
#[test]
304-
fn test_aprs_from_file() {
305-
let path = format!(
306-
"{:}/{:}",
307-
env!("CARGO_MANIFEST_DIR"),
308-
"data/aprs/W3EAX-8_raw_NS-111.txt"
309-
);
310-
311-
let connection = AprsTextFile::new(path, None).unwrap();
312-
313-
let packets = connection.read_aprs_from_file().unwrap();
314-
315-
assert!(!packets.is_empty());
316-
}
317-
}
318-
319286
pub fn locations_geojson_featurecollection(
320287
locations: Vec<&crate::location::BalloonLocation>,
321288
) -> geojson::FeatureCollection {
@@ -359,3 +326,36 @@ pub fn locations_geojson_featurecollection(
359326

360327
geojson::FeatureCollection::from_iter(features)
361328
}
329+
330+
#[cfg(test)]
331+
mod tests {
332+
use super::*;
333+
334+
#[test]
335+
#[ignore]
336+
fn test_aprs_from_url() {
337+
let url = "http://bpp.umd.edu/archives/Launches/NS-111_2022_07_31/APRS/W3EAX-11%20raw.txt"
338+
.to_string();
339+
340+
let connection = AprsTextFile::new(url, None).unwrap();
341+
342+
let packets = connection.read_aprs_from_file().unwrap();
343+
344+
assert!(!packets.is_empty());
345+
}
346+
347+
#[test]
348+
fn test_aprs_from_file() {
349+
let path = format!(
350+
"{:}/{:}",
351+
env!("CARGO_MANIFEST_DIR"),
352+
"data/aprs/W3EAX-8_raw_NS-111.txt"
353+
);
354+
355+
let connection = AprsTextFile::new(path, None).unwrap();
356+
357+
let packets = connection.read_aprs_from_file().unwrap();
358+
359+
assert!(!packets.is_empty());
360+
}
361+
}

src/connection/text/serial.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,33 +124,25 @@ impl Default for AprsSerial {
124124
fn default() -> Self {
125125
match Self::new(None, None, None) {
126126
Ok(connection) => connection,
127-
Err(error) => panic!("{:}", error),
127+
Err(error) => panic!("{error}"),
128128
}
129129
}
130130
}
131131

132132
fn first_available_port() -> String {
133133
// TODO iterate over baud rates
134-
match serialport::available_ports() {
135-
Ok(available_ports) => {
136-
for available_port in available_ports {
137-
let connection_attempt =
138-
serialport::new(available_port.port_name, *DEFAULT_BAUD_RATE).open();
139-
match connection_attempt {
140-
Ok(successful) => {
141-
return successful.name().unwrap();
142-
}
143-
Err(error) => {
144-
panic!("{:}", error);
145-
}
146-
}
134+
let available_ports = serialport::available_ports().expect("error reading serial ports");
135+
for available_port in available_ports.into_iter() {
136+
match serialport::new(available_port.port_name, *DEFAULT_BAUD_RATE).open() {
137+
Ok(successful) => {
138+
return successful.name().unwrap();
139+
}
140+
Err(_) => {
141+
continue;
147142
}
148-
panic!("{:}", "no open ports");
149-
}
150-
Err(error) => {
151-
panic!("{:}", error);
152143
}
153144
}
145+
panic!("no open ports");
154146
}
155147

156148
fn default_baud_rate() -> u32 {

src/location/track/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use geo::GeodesicDistance;
1+
use geo::{Distance, Geodesic};
22

33
pub type LocationTrack = Vec<crate::location::BalloonLocation>;
44

@@ -201,7 +201,7 @@ pub fn overground_distances(locations: &[super::BalloonLocation]) -> Vec<f64> {
201201
let current_point: geo::Point = current.location.coord.into();
202202
let next_point: geo::Point = next.location.coord.into();
203203

204-
values.push(current_point.geodesic_distance(&next_point));
204+
values.push(Geodesic.distance(current_point, next_point));
205205

206206
current = next;
207207
index += 1;

src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
9494
let profile = prediction::FlightProfile::new(
9595
ascent_rate,
9696
float_altitude,
97-
match float_duration {
98-
Some(seconds) => Some(chrono::Duration::seconds(seconds as i64)),
99-
None => None,
100-
},
97+
float_duration.map(|seconds| chrono::Duration::seconds(seconds as i64)),
10198
None,
10299
burst_altitude,
103100
sea_level_descent_rate,

src/prediction/tawhiri.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl TawhiriQuery {
6666
"ascent_rate",
6767
format!("{:.2}", self.query.profile.ascent_rate),
6868
),
69-
("burst_altitude", format!("{:.2}", burst_altitude)),
69+
("burst_altitude", format!("{burst_altitude:.2}")),
7070
(
7171
"descent_rate",
7272
format!("{:.2}", self.query.profile.sea_level_descent_rate,),
@@ -75,13 +75,13 @@ impl TawhiriQuery {
7575

7676
let launch_altitude = self.query.start.altitude;
7777
if let Some(altitude) = launch_altitude {
78-
parameters.push(("launch_altitude", format!("{:.2}", altitude)));
78+
parameters.push(("launch_altitude", format!("{altitude:.2}")));
7979
}
8080
if let Some(dataset_time) = self.dataset_time {
8181
parameters.push(("dataset", dataset_time.to_rfc3339()));
8282
}
8383
if let Some(version) = self.version {
84-
parameters.push(("version", format!("{:}", version)));
84+
parameters.push(("version", format!("{version}")));
8585
}
8686

8787
if let Some(float_duration) = self.query.profile.float_duration {
@@ -98,7 +98,7 @@ impl TawhiriQuery {
9898
}
9999
}
100100

101-
parameters.push(("float_altitude", format!("{:.2}", float_altitude)));
101+
parameters.push(("float_altitude", format!("{float_altitude:.2}")));
102102

103103
let float_start_time = self.query.float_start.unwrap_or({
104104
self.query.start.time

src/retrieve.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn retrieve_locations(
1919
let num_new_packets = new_packets.len();
2020
messages.push((
2121
chrono::Local::now(),
22-
format!("received {:} packets", num_new_packets),
22+
format!("received {num_new_packets} packets"),
2323
log::Level::Debug,
2424
));
2525

@@ -72,7 +72,7 @@ pub fn retrieve_locations(
7272
_ => {
7373
messages.push((
7474
chrono::Local::now(),
75-
format!("started track {:}", &name),
75+
format!("started track {name}"),
7676
log::Level::Debug,
7777
));
7878
packet_track_lengths.insert(name.to_owned(), 0);
@@ -107,18 +107,15 @@ pub fn retrieve_locations(
107107
if num_duplicates > 0 {
108108
messages.push((
109109
chrono::Local::now(),
110-
format!("skipped {:} duplicate packet(s)", num_duplicates),
110+
format!("skipped {num_duplicates} duplicate packet(s)"),
111111
log::Level::Debug,
112112
));
113113
}
114114

115115
if num_time_lagged_duplicates > 0 {
116116
messages.push((
117117
chrono::Local::now(),
118-
format!(
119-
"skipped {:} time-lagged duplicate packet(s)",
120-
num_time_lagged_duplicates
121-
),
118+
format!("skipped {num_time_lagged_duplicates} time-lagged duplicate packet(s)"),
122119
log::Level::Debug,
123120
));
124121
}
@@ -161,7 +158,7 @@ fn location_update(track: &crate::location::track::BalloonTrack) -> String {
161158
&last_location.location.coord.x, &last_location.location.coord.y,
162159
);
163160
if let Some(altitude) = last_location.location.altitude {
164-
message += &format!(", {:.2} m", altitude,)
161+
message += &format!(", {altitude:.2} m",)
165162
};
166163
message += &String::from(")");
167164

0 commit comments

Comments
 (0)