<commit_before>
'''
Scripts for bench marking the results of the automated assignment. Normally not used.
Just comparing the assignment the algorithm procuced with the original manually made one.
'''
import csv
from time import localtime

def createBenchmark(results) :
  '''
  Output:name of the proh
  Compare the assignment made by malandro to the manual assignment.
  '''
  
  dirName ='/home/joren/malandroBenchmarks/'
  ts = timeStamp()
  #projectName = project.shortName
  
  filePath = '%s%s_%s' %(dirName, 'benchMark', ts)
  
  with open(filePath, 'wb') as csvfile:
    writer = csv.writer(csvfile, dialect='excel')
    
    writer.writerow([ts])
    
    spectraNames = [spectrum.getName() for spectrum in results.getSpectra()]
    
    writer.writerow(spectraNames)
    writer.writerow(['% agree','% disagree', '% agreeing Joker', '% disagreeing Joker'])
    
    residues = results.getChain().getResidues()
    
    for residue in residues :
      
      writer.writerow(calculatePercentages(residue))
      

def calculatePercentages(res):
        
  data = []
  jokers = []
  realSpinSystems = []
    
  resSeqCode = res.getSeqCode()

    
  if res.getCcpnResidue().findFirstResonanceGroup() :
      
    manualAssigned = True
      
  else :
      
    manualAssigned = False
      
  solutions = res.getSolutions()
    
  Nsolutions = len(solutions)
    
  solutionSet = set(solutions)      
    
  for spinSys in solutionSet :
      
    if spinSys.getIsJoker() :
        
      jokers.append(spinSys)
        
    else :
      
      realSpinSystems.append(spinSys)
        
        
    
  for spinsys in realSpinSystems :
      
    assignmentPercentage = int(float(solutions.count(spinsys)) / Nsolutions * 100.0)
          
    data.append((assignmentPercentage,spinsys))
    
      
      
  if jokers :
      
    NumberOfAssignmentsToJoker = 0
      
    for spinSys in jokers :
      
      NumberOfAssignmentsToJoker += solutions.count(spinSys)
      
    assignmentPercentage = int(float(NumberOfAssignmentsToJoker) / Nsolutions * 100.0)
      
    data.append((assignmentPercentage,None))
    
  data = sorted(data, reverse=True)
    
    
  bestWrongPercentage = 0
  agreePercentage = 0
  goodJoker = 0
  badJoker = 0
    
  foundBad = False
    
  for percent, spinSys in data:
      
    if spinSys :
      #print '----'  
      #print spinSys.getCcpnResonanceGroup().residue.seqCode
      #print resSeqCode
      if spinSys.getCcpnResonanceGroup().residue.seqCode == resSeqCode : #spinSys.getCcpnSeqCode() == resSeqCode :
            
        agreePercentage = percent  
        
      elif not foundBad :
            <commit_msg>Got another bug out of the benchmark script. Do not understand how this one slipped in.<commit_after>
'''
Scripts for bench marking the results of the automated assignment. Normally not used.
Just comparing the assignment the algorithm procuced with the original manually made one.
'''
import csv
from time import localtime

def createBenchmark(results) :
  '''
  Output:name of the proh
  Compare the assignment made by malandro to the manual assignment.
  '''
  
  dirName ='/home/joren/malandroBenchmarks/'
  ts = timeStamp()
  #projectName = project.shortName
  
  filePath = '%s%s_%s' %(dirName, 'benchMark', ts)
  
  with open(filePath, 'wb') as csvfile:
    writer = csv.writer(csvfile, dialect='excel')
    
    writer.writerow([ts])
    
    spectraNames = [spectrum.getName() for spectrum in results.getSpectra()]
    
    writer.writerow(spectraNames)
    writer.writerow(['% agree','% disagree', '% agreeing Joker', '% disagreeing Joker'])
    
    residues = results.getChain().getResidues()
    
    for residue in residues :
      
      writer.writerow(calculatePercentages(residue))
      

def calculatePercentages(res):
        
  data = []
  jokers = []
  realSpinSystems = []
    
  resSeqCode = res.getSeqCode()

    
  if res.getCcpnResidue().findFirstResonanceGroup() :
      
    manualAssigned = True
      
  else :
      
    manualAssigned = False
      
  solutions = res.getSolutions()  
  Nsolutions = len(solutions)
  solutionSet = set(solutions)      
    
  for spinSys in solutionSet :
      
    if spinSys.getIsJoker() :
        
      jokers.append(spinSys)
        
    else :
      
      realSpinSystems.append(spinSys)
        

  for spinsys in realSpinSystems :
      
    assignmentPercentage = int(float(solutions.count(spinsys)) / Nsolutions * 100.0)
          
    data.append((assignmentPercentage,spinsys))
    
      
      
  if jokers :
      
    NumberOfAssignmentsToJoker = 0
      
    for spinSys in jokers :
      
      NumberOfAssignmentsToJoker += solutions.count(spinSys)
      
    assignmentPercentage = int(float(NumberOfAssignmentsToJoker) / Nsolutions * 100.0)
      
    data.append((assignmentPercentage,None))
    
  data = sorted(data, reverse=True)
    
    
  bestWrongPercentage = 0
  agreePercentage = 0
  goodJoker = 0
  badJoker = 0
    
  foundBad = False
    
  for percent, spinSys in data:
      
    if spinSys :
      #print '----'  
      #print spinSys.getCcpnResonanceGroup().residue.seqCode
      #print resSeqCode
      if spinSys.getCcpnResonanceGroup().residue and spinSys.getCcpnResonanceGroup().residue.seqCode == resSeqCode :
            
        agreePercentage = percent
        
      elif not foundBad :
            
{'fraction_non_alphanumeric': 0.09094290496559419, 'fraction_numerical': 0.004835410079970244, 'mean_word_length': 2.443021766965429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4085669', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1662, 'n_words': 371}