• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SPF-OST / pytrnsys_process / 12275439241

11 Dec 2024 11:28AM UTC coverage: 95.252% (+0.9%) from 94.322%
12275439241

push

github

sebastian-swob
fixed converter to behave as expected

3 of 3 new or added lines in 1 file covered. (100.0%)

14 existing lines in 6 files now uncovered.

642 of 674 relevant lines covered (95.25%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.92
/pytrnsys_process/process_sim/process_file.py
1
import pathlib as _pl
1✔
2
from dataclasses import dataclass
1✔
3

4
import pandas as _pd
1✔
5

6
from pytrnsys_process import constants as const
1✔
7
from pytrnsys_process import file_type_detector as fm
1✔
8
from pytrnsys_process import readers, utils
1✔
9
from pytrnsys_process.logger import logger
1✔
10

11

12
@dataclass
1✔
13
class SimFile:
1✔
14
    name: str
1✔
15
    type: const.FileType
1✔
16
    data: _pd.DataFrame
1✔
17

18

19
@dataclass
1✔
20
class Simulation:
1✔
21
    name: str
1✔
22
    files: list[SimFile]
1✔
23

24

25
def process_simulation(
1✔
26
    sim_folder: _pl.Path, detect_file_using_content: bool = False
27
) -> Simulation:
28
    sim_files = utils.get_files([sim_folder])
1✔
29
    files = []
1✔
30
    for sim_file in sim_files:
1✔
31
        try:
1✔
32
            if detect_file_using_content:
1✔
33
                files.append(process_file_using_file_content(sim_file))
1✔
34
            else:
35
                files.append(process_file_using_file_name(sim_file))
1✔
36
        except ValueError as e:
1✔
37
            logger.warning(
1✔
38
                "Error reading file %s it will not be available for processing: %s",
39
                sim_file,
40
                str(e),
41
                exc_info=True,
42
            )
43
    return Simulation(sim_folder.name, files)
1✔
44

45

46
def process_file_using_file_content(file_path: _pl.Path) -> SimFile:
1✔
47
    file_type = fm.get_file_type_using_file_content(file_path)
1✔
48
    reader = readers.PrtReader()
1✔
49
    if file_type == const.FileType.MONTHLY:
1✔
50
        data = reader.read_monthly(file_path)
1✔
51
    elif file_type == const.FileType.HOURLY:
1✔
52
        data = reader.read_hourly(file_path)
1✔
53
    elif file_type == const.FileType.TIMESTEP:
1✔
54
        data = reader.read_step(file_path)
1✔
55
    else:
UNCOV
56
        raise ValueError(f"Unknown file type: {file_type}")
×
57

58
    return SimFile(file_path.name, file_type, data)
1✔
59

60

61
def process_file_using_file_name(file_path: _pl.Path) -> SimFile:
1✔
62
    file_type = fm.get_file_type_using_file_name(file_path)
1✔
63
    reader = readers.PrtReader()
1✔
64
    if file_type == const.FileType.MONTHLY:
1✔
65
        data = reader.read_monthly(file_path)
1✔
66
    elif file_type == const.FileType.HOURLY:
1✔
67
        data = reader.read_hourly(file_path)
1✔
68
    elif file_type == const.FileType.TIMESTEP:
1✔
69
        data = reader.read_step(file_path)
1✔
70
    else:
UNCOV
71
        raise ValueError(f"Unknown file type: {file_type}")
×
72

73
    return SimFile(file_path.name, file_type, data)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc