aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2013-05-16 01:36:08 -0400
committerbryan newbold <bnewbold@robocracy.org>2013-05-17 11:27:08 -0400
commitf2dd1ca786e69a19884c2a48eb5f0a1df7d6351d (patch)
tree70e259ca8bcc37daeee45376f19088d901c5dd21
parent243685b78ea1bb83b658bded54d62fdb15be5de0 (diff)
downloadpartmom-f2dd1ca786e69a19884c2a48eb5f0a1df7d6351d.zip
partmom-f2dd1ca786e69a19884c2a48eb5f0a1df7d6351d.tar.gz
WIP: ST micro conversion script
-rwxr-xr-xst_data/convert.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/st_data/convert.py b/st_data/convert.py
new file mode 100755
index 0000000..4b06e4f
--- /dev/null
+++ b/st_data/convert.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+"""
+MPN structure:
+ STM32F101RB
+ STM32F1 01 R B
+ {family} {subfamily} {package} {memory}
+"""
+
+import json
+import csv
+
+ALL_FILE = "stm32_all_20130509.csv"
+
+PREFIXES = [
+ 'STM32F0',
+ 'STM32F1',
+ 'STM32F2',
+ 'STM32F3',
+ 'STM32L',
+ 'STM32W',
+]
+
+def decompose(mpn):
+ "returns (family, subfamily, memory, package"
+ return mpn[:7], mpn[7:9], mpn[9], mpn[10]
+
+def ensure_recurse_dict(tree, addr):
+ if not tree.has_key(addr[0]):
+ tree[addr[0]] = dict()
+ if len(addr) > 1:
+ ensure_recurse_dict(tree[addr[0]], addr[1:])
+
+def identical(l):
+ a = l[0]
+ for b in l[1:]:
+ if a != b:
+ return False
+ return True
+
+stm32_all_list = []
+with open(ALL_FILE, 'r') as f:
+ dr = csv.DictReader(f)
+ stm32_all_list.extend(dr)
+
+for item in stm32_all_list:
+ item['mpn'] = item.pop("Part Number")
+
+lists = dict()
+
+for pref in PREFIXES:
+ lists[pref] = [x for x in stm32_all_list if x['mpn'].startswith(pref)]
+ print "%s:" % pref
+ print '\t' + '\n\t'.join([x['mpn'] for x in lists[pref]])
+
+family = lists[PREFIXES[1]]
+
+# strip common specifications
+family_specs = dict()
+for spec in family[0].keys():
+ if identical([x[spec] for x in family]):
+ family_specs[spec] = family[0][spec]
+ [item.pop(spec) for item in family]
+
+print family_specs
+
+tree = dict()
+for part in family:
+ addr = decompose(part['mpn'])
+ #ensure_recurse_dict(tree, addr)
+ #tree[addr[0]][addr[1]][addr[2]][addr[3]] = part
+ ensure_recurse_dict(tree, addr[1:])
+ tree[addr[1]][addr[2]][addr[3]] = part
+
+print sorted(tree.keys())
+
+
+for subfamily in tree.items():
+ subfamily_keys = part.keys()
+ subfamily_keys.remove('mpn')
+ for spec in subfamily_keys:
+ subfamily_items =
+ if not identical([x[spec] for x in [pkg.items() for pkg in [mem.items() for mem in subfamily.items()]]]):
+ subfamily_keys.remove(spec)
+ print subfamily_keys
+
+def combine(tree, depth):
+ if depth:
+ combinel(