Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Nov 12, 2024
1 parent 0d8d4bd commit 43f0ee4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl App<'_> {
None => terminal.hide_cursor()?,
Some((x, y)) => {
terminal.show_cursor()?;
terminal.set_cursor(x, y)?;
terminal.set_cursor_position((x, y))?;
}
}
terminal.flush()?;
Expand Down
22 changes: 11 additions & 11 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#![allow(dead_code)]

use std::{fmt::Display};
use std::fmt::Display;

use chrono::{DateTime, NaiveDateTime, Utc};
use hyper::{client::HttpConnector, Body, Client, Method, Request, Response};
use hyper_rustls::{HttpsConnectorBuilder, HttpsConnector};
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;

use crate::event::{logger::Logger};
use crate::event::logger::Logger;

pub fn new_strava_client(config: StravaConfig, logger: Logger) -> StravaClient {
let connector = HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build();
let connector = HttpsConnectorBuilder::new()
.with_native_roots()
.https_only()
.enable_http1()
.build();
let client = Client::builder().build(connector);

StravaClient {
Expand Down Expand Up @@ -57,7 +61,7 @@ pub struct Activity {
pub location_city: Option<String>,
pub athlete_count: i64,
pub splits_metric: Option<Vec<Split>>,
pub splits_standard: Option<Vec<Split>>
pub splits_standard: Option<Vec<Split>>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -102,11 +106,7 @@ impl StravaClient {
let res: Response<Body> = self.client.request(req).await?;

if res.status() != 200 {
let message = format!(
"Got {} response for URL {}",
res.status(),
&url
);
let message = format!("Got {} response for URL {}", res.status(), &url);
self.logger.error(message.clone()).await;
return Err(anyhow::Error::msg(message));
}
Expand All @@ -131,7 +131,7 @@ impl StravaClient {
per_page,
page,
match after {
Some(epoch) => epoch.timestamp().to_string(),
Some(epoch) => epoch.and_utc().timestamp().to_string(),
None => "".to_string(),
}
),
Expand Down
51 changes: 25 additions & 26 deletions src/component/activity_list/chart.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use chrono::NaiveDateTime;
use chrono::DateTime;
use tui::{
layout::Constraint, prelude::Buffer, style::{Color, Style}, symbols::Marker, text::{Line, Span}, widgets::{Axis, Block, Borders, Chart, Dataset, GraphType, Widget}
layout::Constraint,
prelude::Buffer,
style::{Color, Style},
symbols::Marker,
text::{Line, Span},
widgets::{Axis, Block, Borders, Chart, Dataset, GraphType, Widget},
};

use crate::{
Expand All @@ -10,14 +15,8 @@ use crate::{
};

pub fn handle(_app: &mut App, _key: MappedKey) {}
pub fn draw(
app: &mut App,
f: &mut Buffer,
area: tui::layout::Rect,
) {
let activities = &app
.activities()
.sort(&SortBy::Date, &SortOrder::Asc);
pub fn draw(app: &mut App, f: &mut Buffer, area: tui::layout::Rect) {
let activities = &app.activities().sort(&SortBy::Date, &SortOrder::Asc);
let times: Vec<i64> = activities.timestamps();
let paces: Vec<i64> = activities.meter_per_hours();
let tmax = times.iter().max();
Expand All @@ -38,7 +37,7 @@ pub fn draw(
.to_vec()
.iter()
.map(|a| {
let ts = a.start_date.unwrap().timestamp();
let ts = a.start_date.unwrap().and_utc().timestamp();
(ts as f64, a.meters_per_hour())
})
.collect();
Expand All @@ -47,8 +46,14 @@ pub fn draw(
let activities = app.activities();
if let Some(a) = activities.get(selected) {
if let Some(a) = activities.find(a.id) {
current.push((a.start_date.unwrap().timestamp() as f64, *pmin as f64));
current.push((a.start_date.unwrap().timestamp() as f64, *pmax as f64));
current.push((
a.start_date.unwrap().and_utc().timestamp() as f64,
*pmin as f64,
));
current.push((
a.start_date.unwrap().and_utc().timestamp() as f64,
*pmax as f64,
));
}
}
}
Expand Down Expand Up @@ -84,15 +89,12 @@ pub fn draw(
.title(Span::styled("Date", Style::default().fg(Color::Red)))
.style(Style::default().fg(Color::White))
.bounds([*tmin.unwrap() as f64, *tmax.unwrap() as f64])
.labels(
xaxis
.map(|p| {
Line::from(match NaiveDateTime::from_timestamp_millis(p * 1000) {
Some(t) => t.format("%Y-%m-%d").to_string(),
None => "n/a".to_string(),
})
})
),
.labels(xaxis.map(|p| {
Line::from(match DateTime::from_timestamp_millis(p * 1000) {
Some(t) => t.format("%Y-%m-%d").to_string(),
None => "n/a".to_string(),
})
})),
)
.y_axis(
Axis::default()
Expand All @@ -102,10 +104,7 @@ pub fn draw(
*pmin as f64,
*pmax as f64 + (pdiff as f64 / activities.len() as f64),
])
.labels(
yaxis
.map(|p| Span::from(app.unit_formatter.pace(3600, p as f64)))
),
.labels(yaxis.map(|p| Span::from(app.unit_formatter.pace(3600, p as f64)))),
);
chart.render(area, f);
}
2 changes: 1 addition & 1 deletion src/store/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Activities {
pub fn timestamps(&self) -> Vec<i64> {
self.activities
.iter()
.map(|a| a.start_date.unwrap().timestamp())
.map(|a| a.start_date.unwrap().and_utc().timestamp())
.collect()
}

Expand Down
4 changes: 3 additions & 1 deletion src/sync/ingest_activities.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use chrono::{NaiveDateTime};
use sqlx::{SqlitePool};

Expand Down Expand Up @@ -61,7 +63,7 @@ INSERT INTO raw_activity (id, created_at, listed, synced) VALUES (?, ?, ?, false
).bind(
match NaiveDateTime::parse_from_str(s_activity["start_date"].as_str().unwrap(), "%Y-%m-%dT%H:%M:%SZ") {
Ok(t) => t,
Err(_err) => NaiveDateTime::from_timestamp_millis(0).unwrap(),
Err(_err) => NaiveDateTime::from_str("0")?,
}
).bind(
s_activity.to_string()
Expand Down

0 comments on commit 43f0ee4

Please sign in to comment.