How to calculate number of downtimes and Total downtime and average downtime in the below xml file using python
Question: How to calculate downtime and average downtime and total down time?


Answer: The overallAvailability is an attribute of the tag ServiceAvailabiltyReport,
so your code needs to look like this.

    
    
    import glob
    import xml.etree.ElementTree as ET
    
    sum = 0; count = 0; avgTime = 0
    for fName in glob.glob("*.xml"):
        tree = ET.parse(fName)
        root = tree.getroot()
        for tag in root.iter('ServiceAvailabilityReport'):
            sum += float(tag.attrib["overallAvailability"])
            count += 1
            avgTime = sum / count
    
    print avgTime
    

Also, just a a side note, the xml file you posted had some issues including
missing closing tags etc. I'm not sure if this is true for all your files, or
if it is an artefact of the copy paste.

