Guest User

Untitled

a guest
Jul 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import _thread
  2. import matplotlib.pyplot as plt
  3. import matplotlib.animation as animation
  4. from matplotlib import style
  5. import csv
  6. import time
  7.  
  8. def firstfunc():
  9. count=0
  10. with open('airtabletest.txt','r') as dataset:
  11. line=csv.reader(dataset)
  12. arr=[]
  13. for row in line:
  14. if(len(arr)>=9):
  15. arr.clear()
  16. for i in range(1,10):
  17. arr.append(int(row[i]))
  18. t=time.time()+3
  19. while(t>time.time()):
  20. pass
  21. if(count>=8):
  22. with open('live_graph1','r') as file:
  23. lines=file.readlines()
  24. with open('live_graph1','w') as csvfile:
  25. csvfile.writelines(lines[1:])
  26. with open('live_graph1','a+') as file:
  27. arr2=[]
  28. writer=csv.writer(file)
  29. arr2.append(row[0][11:])
  30. arr2.append(sum(arr)/10)
  31. writer.writerow(arr2)
  32. count+=1
  33.  
  34. def secondfunc():
  35. style.use('fivethirtyeight')
  36.  
  37. fig = plt.figure()
  38. ax1 = fig.add_subplot(1,1,1)
  39. def animate(i):
  40. xs = []
  41. ys = []
  42. count=0
  43. label=[]
  44. with open('live_graph1','r') as file:
  45. reader=csv.reader(file)
  46. for row in reader:
  47. if(len(row) == 2):
  48. x = float(row[1])
  49. xs.append(count)
  50. ys.append(x)
  51. label.append(row[0])
  52. count+=1
  53. ax1.clear()
  54. ax1.set_xticks(xs)
  55. ax1.set_xticklabels(label)
  56. ax1.plot(xs,ys)
  57. fig.autofmt_xdate()
  58. ani = animation.FuncAnimation(fig, animate, interval=1000)
  59. plt.show()
  60.  
  61. def main():
  62. try:
  63. _thread.start_new_thread(secondfunc,)
  64. _thread.start_new_thread(firstfunc,)
  65. while 1:
  66. pass
  67.  
  68. if __name__=='__main__':main()
  69.  
  70. File "test.py", line 65
  71. while 1:
  72. ^
  73. SyntaxError: invalid syntax
  74.  
  75. File "test.py", line 66
  76. if __name__=='__main__':main()
  77. ^
  78. IndentationError: unexpected unindent
Add Comment
Please, Sign In to add comment