1. David Stone
  2. Technical Machine

Commits

David Stone  committed 9d30243

Made XML easier to parse and match up probabilities.

  • Participants
  • Parent commits 6ae7a11
  • Branches default

Comments (0)

Files changed (1)

File statistics_scripts/smogon.py

View file
 		return name
 
 def save_file(file_name, data):
-	with open(file_name, 'w+') as f:
+	with open(file_name, 'w') as f:
 		for pokemon in data:
 			print>>f, normalize_name(pokemon[0]), '\t', pokemon[1]
 
 def delimit_value_from_text(mixed_content):
 	values = mixed_content.split()
 	text = ''
+	# recombine all values other than the final numeric value
 	for value in values[0:-1]:
 		if text != '':
 			text += ' '
 		text += value
-	text += '\t' + values[-1][0:-1]
-	return text
+	# remove the % sign from the end
+	value = values[-1][0:-1]
+	return [text] + [value]
+
+to_singular = {
+	'abilities':'ability',
+	'items':'item',
+	'natures':'nature',
+	'ev spreads':'ev spread',
+	'moves':'move',
+	'teammates':'teammate'
+}
 
 def create_xml_tree(lines):
 	data = parse_lines_by_pokemon(lines)
 		species = ET.SubElement(pokemon, 'species')
 		species.text = pokemon_data[0][0]
 		for specific in pokemon_data[1:]:
+			super_tag = specific[0].lower()
+			super_element = ET.SubElement(pokemon, super_tag)
 			for value in specific[1:]:
-				element = ET.SubElement(pokemon, specific[0].lower())
-				element.text = delimit_value_from_text(value)
+				element = ET.SubElement(super_element, to_singular[super_tag])
+				info = delimit_value_from_text(value)
+				name = ET.SubElement(element, 'name')
+				name.text = info[0]
+				probability = ET.SubElement(element, 'probability')
+				probability.text = str(float(info[1]) / 100.0)
 	return root
 
 def write_xml(root, depth = 0):
 		result += indent
 	result += '</' + root.tag + '>'
 	return result
-		
+
 root = create_xml_tree(load_detailed('detailed_source.txt'))
 with open('output.xml', 'w') as f:
 	f.write(write_xml(root))