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

SPF-OST / pytrnsys_process / 12050239394

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

Pull #18

github

sebastian-swob
added batch processing,
added initial example script on how to use the api,
disabled some step tests until requirements are clear
Pull Request #18: 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%)

0.91 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
1✔
2
from dataclasses import dataclass
1✔
3

4
import pandas as _pd
1✔
5

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

9

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

16

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

22

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

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

36

37
def process_file_using_file_content(file_path: _pl.Path) -> SimFile:
1✔
38
    file_type = fm.get_file_type_using_file_content(file_path)
1✔
39
    reader = readers.PrtReader()
1✔
40
    if file_type == fm.FileType.MONTHLY:
1✔
41
        data = reader.read_monthly(file_path)
1✔
42
    elif file_type == fm.FileType.HOURLY:
1✔
43
        data = reader.read_hourly(file_path)
1✔
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)
1✔
50

51

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

64
    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