| 1 |
nino.borges |
622 |
"""
|
| 2 |
|
|
FamilyToRandomDict.py
|
| 3 |
|
|
|
| 4 |
|
|
Created by
|
| 5 |
|
|
Emanuel Borges
|
| 6 |
|
|
02.11.2014
|
| 7 |
|
|
|
| 8 |
|
|
This program will take an export of beg image and beg attach and export a load file randomizing the docuemnts
|
| 9 |
|
|
but keeping the families together.
|
| 10 |
|
|
|
| 11 |
|
|
"""
|
| 12 |
|
|
|
| 13 |
|
|
import random, LitTechHelperTools
|
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
def FamilyDictRandomizer(familyDict, outputFilePath):
|
| 17 |
|
|
"""Takes a family dict and randomizes the keys, but keeps the family in together"""
|
| 18 |
|
|
count = 1
|
| 19 |
|
|
outputFile = open(outputFilePath,'w')
|
| 20 |
|
|
familyKeyList = familyDict.keys()
|
| 21 |
|
|
random.shuffle(familyKeyList)
|
| 22 |
|
|
## gives me a total number of the values, in the lists that are values in dict.
|
| 23 |
|
|
numberOfDocs = sum(len(v) for v in familyDict.itervalues())
|
| 24 |
|
|
for parent in familyKeyList:
|
| 25 |
|
|
for doc in familyDict[parent]:
|
| 26 |
|
|
outputFile.write("%s|%s\n"%(doc,count))
|
| 27 |
|
|
count = count+1
|
| 28 |
|
|
outputFile.close()
|
| 29 |
|
|
|
| 30 |
|
|
|
| 31 |
|
|
if __name__ == '__main__':
|
| 32 |
|
|
outputFilePath = r'/Users/ninoborges/Dropbox/Misc/test_OUTPUT.dat'
|
| 33 |
|
|
export = open(r'/Users/ninoborges/Dropbox/Misc/test.dat').readlines()
|
| 34 |
|
|
d = LitTechHelperTools.FamilyToDict(export)
|
| 35 |
|
|
FamilyDictRandomizer(d,outputFilePath)
|
| 36 |
|
|
|
| 37 |
|
|
|