Coverage for functions \ flipdare \ analysis \ data \ _time_series_protocol.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12from datetime import datetime 

13from dataclasses import dataclass 

14from typing import Protocol, runtime_checkable 

15 

16from flipdare.app_types import AnalysisDataType, ReportListType 

17 

18__all__ = ["TimeSeriesProtocol", "TimeSeriesPlotInfo"] 

19 

20 

21@dataclass 

22class TimeSeriesPlotInfo: 

23 """ 

24 All data needed to render one chart. 

25 

26 Constraints: 

27 len(data) == len(legend_labels) # one series per legend entry 

28 len(data[i]) == len(x_labels) # one value per x-axis label, for every series 

29 """ 

30 

31 label: str 

32 x_title: str 

33 y_title: str 

34 x_labels: list[str] # x-axis labels, length D 

35 legend_labels: list[str] # one per series, length S 

36 data: AnalysisDataType # shape S x D 

37 

38 @property 

39 def debug_str(self) -> str: 

40 formatted_rows = [] 

41 for row in self.data: 

42 items = [f"{v:.2f}" if v is not None else "None" for v in row] 

43 formatted_rows.append(f"[{', '.join(items)}]") 

44 

45 content = "\n ".join(formatted_rows) 

46 return ( 

47 f"Label: {self.label}\n" 

48 f"X Title: {self.x_title}\n" 

49 f"Y Title: {self.y_title}\n" 

50 f"X Labels: {self.x_labels}\n" 

51 f"Legend Labels: {self.legend_labels}\n" 

52 f"Data:------------------------------------------\n" 

53 f"{content}\n" 

54 f"-----------------------------------------------\n" 

55 ) 

56 

57 

58@runtime_checkable 

59class TimeSeriesProtocol(Protocol): 

60 @property 

61 def has_data(self) -> bool: ... 

62 

63 @property 

64 def count(self) -> int: ... 

65 

66 @property 

67 def dates(self) -> list[datetime]: ... 

68 

69 @property 

70 def headers(self) -> list[str]: ... 

71 

72 @property 

73 def debug_str(self) -> str: ... 

74 

75 def table_data(self) -> ReportListType: ... 

76 

77 def plot_info(self) -> list[TimeSeriesPlotInfo]: ...