def process_xml(filename): data = xmlr.xmlparse(filename) return data
return size filepath = '/home/hbldh/Downloads/google-renewals-all-20080624.xml' #print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.)) """ """ # xmlparse print ('xmlr.xmlparse using xml.etree.ElementTree') doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.ELEMENTTREE) print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.)) del doc print ('xmlr.xmlparse using xml.etree.cElementTree') doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.C_ELEMENTTREE) print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.)) del doc print ('xmlr.xmlparse using lxml.etree') doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.LXML_ELEMENTTREE) print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.)) del doc # xmliter
##Apnea from xmlr import xmlparse import pandas as pd doc = xmlparse("./apnea/mesa-sleep-0001-profusion.xml" ) #it gives us the file in the form of Dictonaries final = doc["CMPStudyConfig"]["ScoredEvents"]["ScoredEvent"] df = pd.DataFrame.from_dict(final) data = df[df["Name"] == 'Hypopnea'] Apnea = data[["Duration", "Input", "Name", "Start"]] Apnea.to_csv("Apnea.csv") ##Flow import pyedflib import numpy as np f = pyedflib.EdfReader("./flow/mesa-sleep-0001.edf") signal_labels = f.getSignalLabels() #to get the description about labels: for channel in range(len(signal_labels)): print("\nsignal parameters for the %d.channel:\n\n" % channel) print("label: %s" % f.getLabel(channel)) print("samples in file: %i" % f.getNSamples()[channel]) channel = 8 ## this is our required column
def test_parsing_test_doc(parser): f = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_doc.xml') doc = xmlparse(f, parsing_method=parser) assert isinstance(doc, dict) walk_test(doc)
raise ValueError("Unsizable object: {0}".format(type(doc))) return size filepath = '/home/hbldh/Downloads/google-renewals-all-20080624.xml' #print('Size in MB: {0:.2f} MB'.format(document_size(doc)/1024./1024.)) """ """ # xmlparse print('xmlr.xmlparse using xml.etree.ElementTree') doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.ELEMENTTREE) print('Size in MB: {0:.2f} MB'.format(document_size(doc) / 1024. / 1024.)) del doc print('xmlr.xmlparse using xml.etree.cElementTree') doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.C_ELEMENTTREE) print('Size in MB: {0:.2f} MB'.format(document_size(doc) / 1024. / 1024.)) del doc print('xmlr.xmlparse using lxml.etree') doc = xmlparse("/home/hbldh/Downloads/google-renewals-all-20080624.xml", XMLParsingMethods.LXML_ELEMENTTREE) print('Size in MB: {0:.2f} MB'.format(document_size(doc) / 1024. / 1024.)) del doc
def test_parsing_menu(xmldata_menu, parser): doc = xmlparse(xmldata_menu, parsing_method=parser) assert isinstance(doc, dict) walk_test(doc)
def test_parsing_google_renewal_data(parser): f = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'google-renewals-subset-20080624.xml') doc = xmlparse(f, parsing_method=parser) assert isinstance(doc, dict) walk_test(doc)
def test_parsing_note_error(xmldata_note_error, parser): with pytest.raises((ParseError, cParseError, XMLSyntaxError)): xmlparse(xmldata_note_error, parsing_method=parser)
def test_parsing_test_doc(parser): f = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_doc.xml') doc = xmlparse(f, parsing_method=parser) assert isinstance(doc, dict) walk_test(doc)
def test_parsing_google_renewal_data(parser): f = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'google-renewals-subset-20080624.xml') doc = xmlparse(f, parsing_method=parser) assert isinstance(doc, dict) walk_test(doc)
def test_parsing_menu(xmldata_menu, parser): doc = xmlparse(xmldata_menu, parsing_method=parser) assert isinstance(doc, dict) walk_test(doc)
def test_parsing_note_error(xmldata_note_error, parser): with pytest.raises((ParseError, cParseError, XMLSyntaxError)): xmlparse(xmldata_note_error, parsing_method=parser)