@@ -1,59 +1,59 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on May 2, 2013 |
|
3 | 3 | |
|
4 | 4 | @author: Jose Antonio Sal y Rosas Celi |
|
5 | 5 | @contact: jose.salyrosas@jro.igp.gob.pe |
|
6 | 6 | ''' |
|
7 | 7 | from datetime import datetime |
|
8 | 8 | import os |
|
9 | 9 | |
|
10 | 10 | class saveABSFile(object): |
|
11 | 11 | |
|
12 | 12 | __scriptName = "saveABSFile.py" |
|
13 | 13 | |
|
14 | 14 | def __init__(self): |
|
15 | 15 | self.path = "" |
|
16 | 16 | self.number_patterns = 0 |
|
17 | 17 | self.patterns = [] |
|
18 | 18 | |
|
19 | 19 | def save(self): |
|
20 | 20 | #filename = "%s.txt" % (self.setFilename()) |
|
21 | 21 | filename = "%s.abs" % (self.exp_name) |
|
22 | 22 | final_path = os.path.join(self.path, filename) |
|
23 | 23 | self.saveFile(final_path) |
|
24 | 24 | filesize = os.path.getsize(final_path) |
|
25 | 25 | |
|
26 | 26 | return final_path, filesize |
|
27 | 27 | |
|
28 | 28 | def setParameters(self, path, exp_name, lsPatterns): |
|
29 | 29 | self.path = path |
|
30 | 30 | self.exp_name = exp_name |
|
31 | 31 | strExperimentName = " title ='%s'" % exp_name |
|
32 | 32 | self.patterns = lsPatterns |
|
33 | 33 | number_patterns = len(lsPatterns) |
|
34 | 34 | self.number_patterns = " #Experiments = %d" % number_patterns |
|
35 | 35 | contentPatterns = "" |
|
36 | 36 | for element in lsPatterns: |
|
37 | 37 | valueUp = self.convertValue(element["up"]) |
|
38 | 38 | valueDown = self.convertValue(element["down"]) |
|
39 | 39 | contentPatterns += "\n%d = \n%s\n%s" % (element["number"], valueUp, valueDown) |
|
40 | 40 | contentPatterns = contentPatterns.replace("]],$", "]]") |
|
41 | 41 | self.content = "%s\r\n\n%s\r\n%s" % (strExperimentName, self.number_patterns, contentPatterns) |
|
42 | 42 | |
|
43 | 43 | def convertValue(self, strAntenna): |
|
44 | 44 | value = "" |
|
45 | 45 | strAntenna = strAntenna.replace("],[","]+[") |
|
46 | 46 | lsAntenna = strAntenna.split("+") |
|
47 | 47 | for element in lsAntenna: |
|
48 | 48 | value += " %s,$\n" % element |
|
49 | 49 | |
|
50 | 50 | return value |
|
51 | 51 | |
|
52 | 52 | def setFilename(self): |
|
53 | 53 | return datetime.today().strftime("%Y%m%d%H%M%S%f") |
|
54 | 54 | |
|
55 | 55 | def saveFile(self, filename): |
|
56 |
f = open(filename, ' |
|
|
56 | f = open(filename, 'w+') | |
|
57 | 57 | f.write(self.content) |
|
58 | 58 | f.close() |
|
59 | No newline at end of file | |
|
59 |
General Comments 0
You need to be logged in to leave comments.
Login now