Skip to content

Commit

Permalink
removes unused functions and optimize docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirio Negri committed May 2, 2024
1 parent f18d84f commit b5d0f88
Showing 2 changed files with 27 additions and 62 deletions.
29 changes: 27 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ use crate::weather::prepare_data;
use crate::weather::ForecastResponse;

/// Renders the user interface widgets.
///
/// * `app`: app state struct
/// * `frame`: frame to work in
pub fn render(app: &mut App, frame: &mut Frame) {
// This is where you add new widgets.
// See the following resources:
@@ -68,6 +71,11 @@ fn centered_rect(r: Rect, percent_x: u16, percent_y: u16) -> Rect {
.split(popup_layout[1])[1]
}

/// Renders main menu
///
/// * `app`: app state struct
/// * `frame`: frame to work in
/// * `layout`: layout
fn render_main_menu(
app: &mut App,
frame: &mut Frame,
@@ -112,6 +120,11 @@ fn render_main_menu(
);
}

/// Renders scheduling menu
///
/// * `app`: app state struct
/// * `frame`: frame to work in
/// * `layout`: layout
fn render_scheduling_menu(
app: &mut App,
frame: &mut Frame,
@@ -156,6 +169,10 @@ fn render_scheduling_menu(
);
}

/// Calculates and formats weather time
///
/// * `time_init`: time start as YYYYMMDDHHMM
/// * `delta_t`: duration to calculate
fn weather_time(time_init: &str, delta_t: i8) -> String {
// Parse the initial time string into a NaiveDateTime
let time_start: NaiveDateTime =
@@ -168,7 +185,10 @@ fn weather_time(time_init: &str, delta_t: i8) -> String {
time.format("%d/%m %H:%M").to_string()
}

fn create_table(data: &ForecastResponse) -> Table {
/// Creates a table widget for weather data
///
/// * `data`: ForecastResponse Data from 7timer
fn create_weather_table(data: &ForecastResponse) -> Table {
// Create the table header
let header = vec![
"Timepoint",
@@ -225,6 +245,11 @@ fn create_table(data: &ForecastResponse) -> Table {
Table::new(rows, widths).header(header)
}

/// Renders weather forecast
///
/// * `app`: app state struct
/// * `frame`: frame to work in
/// * `layout`: layout
fn render_weather_forecast(
app: &mut App,
frame: &mut Frame,
@@ -261,7 +286,7 @@ fn render_weather_forecast(
layout[1],
);
frame.render_widget(
create_table(&app.weather_requested)
create_weather_table(&app.weather_requested)
.header(header)
.style(Style::default().bg(Color::Black).fg(Color::Red)),
layout[2],
60 changes: 0 additions & 60 deletions src/weather.rs
Original file line number Diff line number Diff line change
@@ -172,52 +172,6 @@ impl Display for LiftedIndex {
}
}

/// Returns a string with lifted index
///
/// * `index`: the index from json response
pub fn get_lifted_index_value(index: i8) -> Option<&'static str> {
let lifted_index = HashMap::from([
(-10, "Below -7"),
(-6, "-7 - -5"),
(-4, "-5 - -3"),
(-1, "-3 - 0"),
(2, "0 - 4"),
(6, "4 - 8"),
(10, "8 - 11"),
(15, "Over 11"),
]);
lifted_index.get(&index).cloned()
}

/// Returns a string with rh range
///
/// * `index`: the index from json response
pub fn get_rh2m_value(index: i8) -> Option<&'static str> {
let rh2m = HashMap::from([
(-4, "0%-5%"),
(-3, "5%-10%"),
(-2, "10%-15%"),
(-1, "15%-20%"),
(0, "20%-25%"),
(1, "25%-30%"),
(2, "30%-35%"),
(3, "35%-40%"),
(4, "40%-45%"),
(5, "45%-50%"),
(6, "50%-55%"),
(7, "55%-60%"),
(8, "60%-65%"),
(9, "65%-70%"),
(10, "70%-75%"),
(11, "75%-80%"),
(12, "80%-85%"),
(13, "85%-90%"),
(14, "90%-95%"),
(15, "95%-99%"),
(16, "100%"),
]);
rh2m.get(&index).cloned()
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deserialize_repr)]
#[repr(i8)]
pub enum RH2m {
@@ -339,20 +293,6 @@ pub fn prepare_data() -> Result<ForecastResponse> {
mod test {
use super::*;

#[test]
fn test_get_dict_values() {
if let Some(test) = get_lifted_index_value(2) {
assert_eq!(test, "0 - 4");
} else {
assert!(panic!());
}
if let Some(test) = get_rh2m_value(2) {
assert_eq!(test, "30%-35%");
} else {
assert!(panic!());
}
}

#[test]
fn test_get_forecast() {
assert!(get_forecast().contains("astro"));

0 comments on commit b5d0f88

Please sign in to comment.