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

timcera / pyslice / 12340932278

15 Dec 2024 05:42PM CUT coverage: 45.447%. Remained the same
12340932278

Pull #4

github

web-flow
Merge d90cfa984 into 2ffee6f33
Pull Request #4: build(deps): bump actions/setup-python from 4 to 5

529 of 1164 relevant lines covered (45.45%)

2.27 hits per line

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

19.15
/src/pyslice/pyslice_lib/PySPG/MeanCalculation.py
1
import copy
5✔
2
import sys
5✔
3

4
from .Load import dumpData, loadData
5✔
5
from .ParamParser import ParamParser
5✔
6

7
#
8
#
9
# :::~ Author: Claudio Juan Tessone <tessonec@imedea.uib.es> (c) 2002-2003
10
#
11
# Distributed According to GNU Generic Purpose License (GPL)
12
# Please visit www.gnu.org
13
#
14
#
15

16

17
class MeanCalculation:
5✔
18
    """
19
    When a simulation is run with a given number of repetitions what is needed is a
20
    tool for calculating the mean values. This is that tool
21
    """
22

23
    def __init__(self, lsLines):
5✔
24
        ls2 = [i for i in lsLines if i.strip()[0] != "#"]
×
25

26
        self.pp_varying = ParamParser(ls2)
×
27

28
    def searchinfile(self, fname, st):
5✔
29
        return [i.split() for i in open(fname).readlines() if i.split()[0] == st]
×
30

31
    def mean(self, fin_name="out.dat", fout_name="out.mean"):
5✔
32
        dirname = self.pp_varying.directory_tree()
×
33

34
        fsearch = f"{dirname}{fin_name}"
×
35
        fout = f"{dirname}{fout_name}"
×
36

37
        try:
×
38
            all_data = loadData(fsearch)
×
39
        except Exception:
×
40
            print(f"Error! '{fsearch}' file doesn't exist or not enough permissions...")
×
41
            sys.exit()
×
42

43
        try:
×
44
            columnas = list(range(len(all_data[0])))
×
45
        except Exception:
×
46
            sys.stderr.write(f"mean-> error! in directory '{dirname}'\n")
×
47
            sys.stderr.write(f"all_data = {str(all_data)}\n")
×
48

49
        tmpDict = {i[0]: 0 for i in all_data}
×
50
        valuesX = sorted(tmpDict.keys())
×
51
        xDict = {}
×
52
        nPoints = {}
×
53

54
        zeros = [0 for _ in columnas]
×
55

56
        for i in valuesX:
×
57
            xDict[i] = copy.copy(zeros)
×
58
            nPoints[i] = 0.0
×
59

60
        for row in all_data:
×
61
            if len(row) == len(all_data[0]):
×
62
                nPoints[row[0]] += 1.0
×
63
                vec = xDict[row[0]]
×
64
                for j in columnas:
×
65
                    vec[j] += row[j]
×
66

67
        dataOut = [
×
68
            [(xDict[x][j] // nPoints[x]) for j in columnas]
69
            for x in valuesX
70
            if nPoints[x] != 0
71
        ]
72
        try:
×
73
            dumpData(fout, dataOut)
×
74
        except Exception:
×
75
            print(f"Error! Couldn't create output file '{fsearch}' ...")
×
76
            sys.exit()
×
77

78
    def doit(self, fin_name="out.dat", fout_name="mean.dat"):
5✔
79
        for _ in self.pp_varying:
×
80
            self.mean(fin_name, fout_name)
×
81

82

83
#
84
#
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