tradingview/study/
result.rs1use std::time::Duration;
4
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7
8use crate::chart::{DataPoint, SymbolInfo};
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct StudyResult {
13 pub symbol_info: SymbolInfo,
15 pub data: Vec<DataPoint>,
17 pub study_id: String,
19 pub total_points_received: usize,
21 pub elapsed: Duration,
23}
24
25impl StudyResult {
26 #[inline]
28 pub fn len(&self) -> usize {
29 self.data.len()
30 }
31
32 #[inline]
34 pub fn is_empty(&self) -> bool {
35 self.data.is_empty()
36 }
37
38 #[inline]
40 pub fn points(&self) -> &[DataPoint] {
41 &self.data
42 }
43
44 #[inline]
46 pub fn points_mut(&mut self) -> &mut [DataPoint] {
47 &mut self.data
48 }
49
50 #[inline]
52 pub fn into_points(self) -> Vec<DataPoint> {
53 self.data
54 }
55
56 #[inline]
60 pub fn first_timestamp(&self) -> Option<i64> {
61 self.data
62 .first()
63 .and_then(|dp| dp.value.first().copied().map(|v| v as i64))
64 }
65
66 #[inline]
70 pub fn last_timestamp(&self) -> Option<i64> {
71 self.data
72 .last()
73 .and_then(|dp| dp.value.first().copied().map(|v| v as i64))
74 }
75
76 #[inline]
78 pub fn first_datetime(&self) -> Option<DateTime<Utc>> {
79 self.first_timestamp()
80 .and_then(|ts| DateTime::<Utc>::from_timestamp(ts, 0))
81 }
82
83 #[inline]
85 pub fn last_datetime(&self) -> Option<DateTime<Utc>> {
86 self.last_timestamp()
87 .and_then(|ts| DateTime::<Utc>::from_timestamp(ts, 0))
88 }
89}