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

SPF-OST / pytrnsys_process / 12050814130

27 Nov 2024 12:44PM UTC coverage: 90.52% (-3.5%) from 94.037%
12050814130

push

github

web-flow
Merge pull request #18 from SPF-OST/15-create-example-script-for-per-sim-interaction

15 create example script for per sim interaction

119 of 124 new or added lines in 5 files covered. (95.97%)

20 existing lines in 3 files now uncovered.

487 of 538 relevant lines covered (90.52%)

1.8 hits per line

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

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

4
import pandas as _pd
2✔
5

6
from pytrnsys_process import file_matcher as fm
2✔
7
from pytrnsys_process import readers, utils
2✔
8

9

10
@dataclass
2✔
11
class SimFile:
2✔
12
    name: str
2✔
13
    type: fm.FileType
2✔
14
    data: _pd.DataFrame
2✔
15

16

17
@dataclass
2✔
18
class Simulation:
2✔
19
    name: str
2✔
20
    files: list[SimFile]
2✔
21

22

23
def process_simulation(
2✔
24
    sim_folder: _pl.Path, detect_file_using_content: bool = False
25
) -> Simulation:
26
    sim_files = utils.get_files([sim_folder])
2✔
27
    files = []
2✔
28
    for sim_file in sim_files:
2✔
29
        if detect_file_using_content:
2✔
30
            files.append(process_file_using_file_content(sim_file))
2✔
31
        else:
32
            files.append(process_file_using_file_name(sim_file))
2✔
33

34
    return Simulation(sim_folder.name, files)
2✔
35

36

37
def process_file_using_file_content(file_path: _pl.Path) -> SimFile:
2✔
38
    file_type = fm.get_file_type_using_file_content(file_path)
2✔
39
    reader = readers.PrtReader()
2✔
40
    if file_type == fm.FileType.MONTHLY:
2✔
41
        data = reader.read_monthly(file_path)
2✔
42
    elif file_type == fm.FileType.HOURLY:
2✔
43
        data = reader.read_hourly(file_path)
2✔
UNCOV
44
    elif file_type == fm.FileType.TIMESTEP:
×
UNCOV
45
        data = reader.read_step(file_path)
×
46
    else:
47
        raise ValueError(f"Unknown file type: {file_type}")
×
48

49
    return SimFile(file_path.name, file_type, data)
2✔
50

51

52
def process_file_using_file_name(file_path: _pl.Path) -> SimFile:
2✔
53
    file_type = fm.get_file_type_using_file_name(file_path.name)
2✔
54
    reader = readers.PrtReader()
2✔
55
    if file_type == fm.FileType.MONTHLY:
2✔
56
        data = reader.read_monthly(file_path)
2✔
57
    elif file_type == fm.FileType.HOURLY:
2✔
58
        data = reader.read_hourly(file_path)
2✔
59
    elif file_type == fm.FileType.TIMESTEP:
2✔
60
        data = reader.read_step(file_path)
2✔
61
    else:
62
        raise ValueError(f"Unknown file type: {file_type}")
×
63

64
    return SimFile(file_path.name, file_type, data)
2✔
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

© 2025 Coveralls, Inc