I have an sqlite database as a source {Asset and Test data from a Megger
PAT Tester}, which contains a number of tables, and I end up with an
OpenOffice spreadsheet, with numerous sheets
The data is proceesed in three parts, each using a separate Class.
I extract the useful tables, and store them as '.csv' versions. {Class#1}
I then need to correlate data from various tables, and sort into
locations, again storing them as '.csv' versions. {Class#2}
Finally, I write all of the locations as separate sheets in an
OpenOffice spreadsheet. {Class#3}
At this final stage I am converting table index numbers to the relevant
string.
For example, from the '.csv' file the : TestGroupIndex [1] => Test Group
['SC2']
'.csv' file for a location
AssetIndex AssetId Description TestGroupIndex RetestFrequency
106 43 Router 1 24
164 25 500 Drill 8 24
167 26 110v Ext Lead 11 24
173 37 Router DW625E 1 24
180 47 Vacuum 1 24
181 48 110v Ext 11 24
sheet from '.ods' file
Asset Asset
Test Test Next
Index Id Description Group Freq Test
106 43 Router ['SC2'] 24 24/11/19
164 25 500 Drill ['TO2'] 24 17/12/19
167 26 110v Ext Lead ['EL3'] 24 24/11/19
173 37 Router DW625E ['SC2'] 24 12/10/20
180 47 Vacuum ['SC2'] 24 27/12/19
181 48 110v Ext ['EL3'] 24 17/12/19
Test Group '.csv'
TestGroupIndex Class Description TestGroupId VoltageOutput
1 2 Class 2 Double insulated SC2 230
2 1 Standard class 1 earthed SC1 230
The test group table has 30 entries but the index range is 1:31, i.e.
one test group has been deleted at some point in the past, and the
numbering is out of my control.
To access the test group I read the testgroup.csv file to a numpy array,
inside {Class#3}, with two blanks, one for [0], and the other deleted group.
class OdsProcesses:
def __init__(self, path, filename, noGroups):
.
.
self.group = np.zeros(((self.noGroups + 1), 1), dtype =
np.dtype('U10')) # 10-character string
def extract_TestGroup(self):
# Open Test Group file for reading
groupFilename = self.path
groupFilename += self.filename
groupFilename += self.TG_suffix
testGroup = csv.DictReader(open(groupFilename, 'r'))
# Loop through all Data
for row in testGroup:
index = int(row["TestGroupIndex"])
self.group[index] = row["TestGroupId"]
def get_TestGroup(self, index):
groupStr = self.group[index]
def writeODSData(self, sheet, roomNum):
.
.
groupID = self.get_TestGroup(group)
This works but feels 'clumpy', and I have a feeling that there is a
better way, but I have run out of ideas.
I am running Python 3.7.0, on a Windows 10 PC
Thank you for any assistance
Dave
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor