Advertisement
shalivitalya

Untitled

Apr 7th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. import requests
  2. import numpy as np
  3. import math
  4. URL = 'https://api.arstand-lab.ru'
  5. token = 'Token 581314b5dc6db4dd928dc249bf390affbec4df75'
  6. HEADERS = {'Authorization': token}
  7.  
  8.  
  9. def get_faces_npz():
  10.     res = requests.get(f'{URL}/api/0/task/get_task/pyramid_faces_projections',
  11.                        headers=HEADERS)
  12.     if res.ok:
  13.         with open('file.npz', 'wb') as f:
  14.             f.write(res.content)
  15.         return True
  16.     else:
  17.         print(res)
  18.         return False
  19.  
  20.  
  21. def post_faces_projections_npz(file_path):
  22.     files = {'answer': open(file_path, 'rb')}
  23.     res = requests.post(f'{URL}/api/0/task/check_task/pyramid_faces_projections',
  24.                         headers=HEADERS, files=files)
  25.     if res.ok:
  26.         return True
  27.     else:
  28.         print(res)
  29.         return False
  30.  
  31.  
  32. def getPoint(x,y,z,x1,y1,z1):
  33.     t = math.sqrt((x-x1)**2 + (y-y1)**2 + (z-z1)**2)
  34.     l = (x1 - x)/t
  35.     m = (y1 - y)/t
  36.     n = (z1 - z)/t
  37.     return -1*z*l/n, -1*z*m/n, 0
  38.  
  39. Points = list()
  40. MetaPoints = list()
  41. v1 = 0
  42. if __name__ == '__main__':
  43.     print('GET successful: ', get_faces_npz())
  44.     a = np.load('file.npz')
  45.     x,y,z = a['projector']
  46.     for i in range(len(a['xyz_faces'])):
  47.         Points = list()
  48.         for y in range(4):
  49.             kekes = list()
  50.             np.save('example_1', a['xyz_faces'][i][y])
  51.             b = np.load('example_1.npy')
  52.             for v in range(len(b)):
  53.                 if b[v][2]>0:
  54.                     print(b[v][0], b[v][1], b[v][2])
  55.                     x1,y1,z1 = getPoint(x,y,z,b[v][0],b[v][1],b[v][2])
  56.                     b[v] = x1,y1,z1
  57.                 kekes.append(b[v])
  58.             Points.append(kekes)
  59.         MetaPoints.append(Points)
  60.     np.savez('file.npz', answer=MetaPoints)
  61.     print('POST successful: ', post_faces_projections_npz('file.npz'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement