def writeSimpleTest1(filePath, numRecords, testNumber):
  """ Generates requested number of records and saves in a csv file
  """
  with open(filePath+'.csv', 'wb') as f:
    writer = csv.writer(f)

    if testNumber == 1:
      writer.writerow(['field1', 'field2'])
      writer.writerow(['int', 'int'])
      writer.writerow(['', ''])
      for i in ranger(0, numRecords):  
        field1 = int(np.random.random_integers(0, 100, 1))
        field2 = field1 + int(0.025*np.random.normal(0, 100, 1))
        writer.writerow([field1, field2])
        
    elif testNumber == 2:
      writer.writerow(['field1', 'field2', 'field3'])
      writer.writerow(['int', 'int', 'int'])
      writer.writerow(['', '', ''])
      for i in range(0, numRecords):
        field1 = int(np.random.random_integers(0, 100, 1))
        field2 = field1 + int(0.025*np.random.normal(0, 100, 1))
        field3 = int(np.random.random_integers(0, 100, 1))
        writer.writerow([field1, field2, field3])
      pass
    
    elif testNumber == 3:
      writer.writerow(['field1', 'field2', 'field3', 'field4'])
      writer.writerow(['int', 'int', 'int', 'int'])
      writer.writerow(['', '', '', ''])
      for i in range(0, numRecords):
        field2 = int(np.random.random_integers(0, 100, 1))
        field3 = int(np.random.random_integers(0, 100, 1))
        field1 = field2 + field3
        field4 = int(np.random.random_integers(0, 100, 1))
        writer.writerow([field1, field2, field3, field4])

    elif testNumber == 4 or testNumber == 5:
      writer.writerow(['field1', 'field2'])
      writer.writerow(['string', 'string'])
      writer.writerow(['', ''])

      if testNumber == 5:
        categories = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 
                      'k', 'l', 'm', 'n', 'o', 'p']
      else:
        categories = ['a', 'b', 'c', 'd'] 
      numRecsSaved = 0 
      firstFieldInd = 0
      done = False
      while not done:
        while not done:
          field1 = categories[firstFieldInd]
          for category in categories:
            field2 = category
            writer.writerow([field1, field2])
            numRecsSaved += 1
            if numRecsSaved == numRecords:
              done = True
              break
          firstFieldInd += 1
          if firstFieldInd == len(categories):
            firstFieldInd = 0
    
    elif testNumber == 6:
      writer.writerow(['field1', 'field2'])
      writer.writerow(['string', 'string'])
      writer.writerow(['', ''])
      
      choises = [
                 ['a', [0.9, 0.05, 0.05]],
                 ['b', [0.05, 0.9, 0.05]],
                 ['c', [0.05, 0.05, 0.9]]
                ]
      cat2 = ['d', 'e', 'f']
      for i in range(0, numRecords):
        ind1 = int(np.random.random_integers(0, 2, 1))
        field1 = choises[ind1][0]
        ind2 = np.searchsorted(np.cumsum(choises[ind1][1]), np.random.random())
        field2 = cat2[ind2]
        writer.writerow([field1, field2])
      pass
    
    elif testNumber == 7:
      writer.writerow(['field1', 'field2', 'field3'])
      writer.writerow(['string', 'string', 'string'])
      writer.writerow(['', '', ''])      

      choises = [
                 ['a', [0.9, 0.05, 0.05]],
                 ['b', [0.05, 0.9, 0.05]],
                 ['c', [0.05, 0.05, 0.9]]
                ]
      cat2 = ['d', 'e', 'f']
      cat3 = ['g', 'h', 'i']
      for i in range(0, numRecords):
        ind1 = int(np.random.random_integers(0, 2, 1))
        field1 = choises[ind1][0]
        ind2 = np.searchsorted(np.cumsum(choises[ind1][1]), np.random.random())
        field2 = cat2[ind2]
        ind3 = int(np.random.random_integers(0, 2, 1))
        field3 = cat3[ind3]
        writer.writerow([field1, field2, field3])
      pass

    elif testNumber == 8:
      writer.writerow(['field1', 'field2', 'field3'])
      writer.writerow(['string', 'string', 'string'])
      writer.writerow(['', '', ''])      

      choises = [
                 ['a', 'd', [0.9, 0.05, 0.05]],
                 ['a', 'e', [0.05, 0.9, 0.05]],
                 ['a', 'f', [0.05, 0.05, 0.9]],
                 ['b', 'd', [0.9, 0.05, 0.05]],
                 ['b', 'e', [0.05, 0.9, 0.05]],
                 ['b', 'f', [0.05, 0.05, 0.9]],
                 ['c', 'd', [0.9, 0.05, 0.05]],
                 ['c', 'e', [0.05, 0.9, 0.05]],
                 ['c', 'f', [0.05, 0.05, 0.9]]
                ]
      cat3 = ['g', 'h', 'i']
      for i in range(0, numRecords):
        ind1 = int(np.random.random_integers(0, 8, 1))
        field1 = choises[ind1][0]
        field2 = choises[ind1][1]
        ind2 = np.searchsorted(np.cumsum(choises[ind1][2]), np.random.random())
        field3 = cat3[ind2]
        writer.writerow([field1, field2, field3])
      pass
    
  return
def writeSimpleTest1 ( filePath , numRecords , testNumber ) : with open ( filePath + '.csv' , 'wb' ) as f : writer = csv . writer ( f ) if testNumber == 1 : writer . writerow ( [ 'field1' , 'field2' ] ) writer . writerow ( [ 'int' , 'int' ] ) writer . writerow ( [ '' , '' ] ) for i in ranger ( 0 , numRecords ) : field1 = int ( np . random . random_integers ( 0 , 100 , 1 ) ) field2 = field1 + int ( 0.025 * np . random . normal ( 0 , 100 , 1 ) ) writer . writerow ( [ field1 , field2 ] ) elif testNumber == 2 : writer . writerow ( [ 'field1' , 'field2' , 'field3' ] ) writer . writerow ( [ 'int' , 'int' , 'int' ] ) writer . writerow ( [ '' , '' , '' ] ) for i in range ( 0 , numRecords ) : field1 = int ( np . random . random_integers ( 0 , 100 , 1 ) ) field2 = field1 + int ( 0.025 * np . random . normal ( 0 , 100 , 1 ) ) field3 = int ( np . random . random_integers ( 0 , 100 , 1 ) ) writer . writerow ( [ field1 , field2 , field3 ] ) pass elif testNumber == 3 : writer . writerow ( [ 'field1' , 'field2' , 'field3' , 'field4' ] ) writer . writerow ( [ 'int' , 'int' , 'int' , 'int' ] ) writer . writerow ( [ '' , '' , '' , '' ] ) for i in range ( 0 , numRecords ) : field2 = int ( np . random . random_integers ( 0 , 100 , 1 ) ) field3 = int ( np . random . random_integers ( 0 , 100 , 1 ) ) field1 = field2 + field3 field4 = int ( np . random . random_integers ( 0 , 100 , 1 ) ) writer . writerow ( [ field1 , field2 , field3 , field4 ] ) elif testNumber == 4 or testNumber == 5 : writer . writerow ( [ 'field1' , 'field2' ] ) writer . writerow ( [ 'string' , 'string' ] ) writer . writerow ( [ '' , '' ] ) if testNumber == 5 : categories = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' ] else : categories = [ 'a' , 'b' , 'c' , 'd' ] numRecsSaved = 0 firstFieldInd = 0 done = False while not done : while not done : field1 = categories [ firstFieldInd ] for category in categories : field2 = category writer . writerow ( [ field1 , field2 ] ) numRecsSaved += 1 if numRecsSaved == numRecords : done = True break firstFieldInd += 1 if firstFieldInd == len ( categories ) : firstFieldInd = 0 elif testNumber == 6 : writer . writerow ( [ 'field1' , 'field2' ] ) writer . writerow ( [ 'string' , 'string' ] ) writer . writerow ( [ '' , '' ] ) choises = [ [ 'a' , [ 0.9 , 0.05 , 0.05 ] ] , [ 'b' , [ 0.05 , 0.9 , 0.05 ] ] , [ 'c' , [ 0.05 , 0.05 , 0.9 ] ] ] cat2 = [ 'd' , 'e' , 'f' ] for i in range ( 0 , numRecords ) : ind1 = int ( np . random . random_integers ( 0 , 2 , 1 ) ) field1 = choises [ ind1 ] [ 0 ] ind2 = np . searchsorted ( np . cumsum ( choises [ ind1 ] [ 1 ] ) , np . random . random ( ) ) field2 = cat2 [ ind2 ] writer . writerow ( [ field1 , field2 ] ) pass elif testNumber == 7 : writer . writerow ( [ 'field1' , 'field2' , 'field3' ] ) writer . writerow ( [ 'string' , 'string' , 'string' ] ) writer . writerow ( [ '' , '' , '' ] ) choises = [ [ 'a' , [ 0.9 , 0.05 , 0.05 ] ] , [ 'b' , [ 0.05 , 0.9 , 0.05 ] ] , [ 'c' , [ 0.05 , 0.05 , 0.9 ] ] ] cat2 = [ 'd' , 'e' , 'f' ] cat3 = [ 'g' , 'h' , 'i' ] for i in range ( 0 , numRecords ) : ind1 = int ( np . random . random_integers ( 0 , 2 , 1 ) ) field1 = choises [ ind1 ] [ 0 ] ind2 = np . searchsorted ( np . cumsum ( choises [ ind1 ] [ 1 ] ) , np . random . random ( ) ) field2 = cat2 [ ind2 ] ind3 = int ( np . random . random_integers ( 0 , 2 , 1 ) ) field3 = cat3 [ ind3 ] writer . writerow ( [ field1 , field2 , field3 ] ) pass elif testNumber == 8 : writer . writerow ( [ 'field1' , 'field2' , 'field3' ] ) writer . writerow ( [ 'string' , 'string' , 'string' ] ) writer . writerow ( [ '' , '' , '' ] ) choises = [ [ 'a' , 'd' , [ 0.9 , 0.05 , 0.05 ] ] , [ 'a' , 'e' , [ 0.05 , 0.9 , 0.05 ] ] , [ 'a' , 'f' , [ 0.05 , 0.05 , 0.9 ] ] , [ 'b' , 'd' , [ 0.9 , 0.05 , 0.05 ] ] , [ 'b' , 'e' , [ 0.05 , 0.9 , 0.05 ] ] , [ 'b' , 'f' , [ 0.05 , 0.05 , 0.9 ] ] , [ 'c' , 'd' , [ 0.9 , 0.05 , 0.05 ] ] , [ 'c' , 'e' , [ 0.05 , 0.9 , 0.05 ] ] , [ 'c' , 'f' , [ 0.05 , 0.05 , 0.9 ] ] ] cat3 = [ 'g' , 'h' , 'i' ] for i in range ( 0 , numRecords ) : ind1 = int ( np . random . random_integers ( 0 , 8 , 1 ) ) field1 = choises [ ind1 ] [ 0 ] field2 = choises [ ind1 ] [ 1 ] ind2 = np . searchsorted ( np . cumsum ( choises [ ind1 ] [ 2 ] ) , np . random . random ( ) ) field3 = cat3 [ ind2 ] writer . writerow ( [ field1 , field2 , field3 ] ) pass return
Generates requested number of records and saves in a csv file