SHARE
TWEET

Untitled

a guest Jan 21st, 2020 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Research:
  2.     def __init__(self, name, hour, machine, seq):
  3.         self.name = name
  4.         self.hour = hour
  5.         self.machine = machine
  6.         self.seq = seq
  7.  
  8. researchlist = []
  9.  
  10. filelist = []
  11.  
  12. import os
  13. for root, dirs, files in os.walk("data"):
  14.     for file in files:
  15.         if file.endswith(".txt"):
  16.             f = open(root+'\\'+file, 'r')
  17.             lines = f.readlines() #список всех строк
  18.             num_lines = len(lines)
  19.             if num_lines < 51:
  20.                 filelist.append(root+'\\'+file)
  21.  
  22. for l in filelist:
  23.     fi = open(l, 'r')
  24.     for line in fi:
  25.         line = line.replace('\n', '')
  26.         array = line.split('\t')
  27.         if array[0] != "ID": #пропустили первую строку с айди
  28.             if not array[4].count(array[4][0]) == len(array[4]): #повторяющийся символ
  29.                 res = Research(array[1], array[2], array[3], array[4])
  30.                 researchlist.append(res)
  31.  
  32. #создали словарь - имя ресерчера: массив исследований
  33. dict = {}
  34.  
  35. for r in researchlist:
  36.     name = r.name
  37.     seq = r.seq
  38.     if dict.get(name) is None:
  39.         dict[name] = []
  40.     statement = dict.get(name) #достаем значение value для имени ресерчера
  41.     if statement.count(seq) == 0:
  42.         statement.append(seq)
  43.     dict[name] = statement
  44.  
  45. dictionary = {}
  46. dictionary = dictionary.fromkeys(dict, '') #ключи - имена ресерчеров
  47.  
  48. for d in dict:
  49.     arr = dict.get(d) #лист всех исследований
  50.     length = 10000000
  51.     string = ''
  52.     for a in arr:
  53.         if len(a) < length:
  54.             string = a
  55.             length = len(a)
  56.     dictionary[d] = a
  57.  
  58. #задание 1
  59. ffile = open('result.txt', 'w')
  60. for d in dictionary:
  61.     ffile.write(d + '\t' + dictionary.get(d) + '\t' + str(len(dictionary.get(d))) +'\n')
  62. ###################################################
  63.  
  64. newdir = "C:/Users/Olexey/PycharmProjects/untitled3/machines"
  65. os.mkdir(newdir)
  66. os.chdir(newdir)
  67.  
  68. newdict = {}
  69.  
  70. for r in researchlist:
  71.     name = r.name
  72.     hour = r.hour
  73.     machine = r.machine
  74.     seq = r.seq
  75.     helparr = [name, hour, seq]
  76.     if newdict.get(machine) is None:
  77.         newdict[machine] = []
  78.     statement = newdict.get(machine)
  79.     statement.append(helparr)
  80.     newdict[machine] = statement
  81.  
  82. for nd in newdict: #бежим по ключам
  83.     newfile = open(nd +'.txt', 'w')
  84.     helparray = newdict.get(nd) #взяли то что лежит по ключу
  85.     for h in helparray:
  86.         newfile.write(h[0]+'\t'+h[1]+'\t'+h[2]+'\n')
  87.     newfile.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top