# coding=utf-8
#author:        4N
#createtime:    2021/9/27
#email:         nheweijun@sina.com


# from .ttypes import RasterData

from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

from app.modules.service.image.tutorial import Calculator
from app.modules.service.image.ImageDataService import ImageDataService
import time

def test1():

    host = "172.26.60.100"
    port = 8850

    transport: TSocket = TSocket.TSocket(host, port)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Calculator.Client(protocol)


    transport.open()
    import sys
    test = client.getData("江南_01.tif",[1340.27, -1911.31, 4351.79, 5410.6],[1340.27, -1911.31, 4351.79, 5410.6],[3,2,1],768,768)
    print(sys.getsizeof(test[1]))
    # print(test)

def test2():
    host = "172.26.60.100"
    port = 9090

    transport: TSocket = TSocket.TSocket(host, port)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = ImageDataService.Client(protocol)

    transport.open()

    test = client.getData("/usr/src/data/江南_01.tif", [1340.27, -1911.31, 4351.79, 5410.6], [1340.27, -1911.31, 4351.79, 5410.6],
                          [1,2,3], 768, 768)

    import gzip,numpy
    data = gzip.decompress(test)
    # data = numpy.frombuffer(data, dtype='int64')
    # data = data.reshape((768, 768, 3))

    import sys
    print(sys.getsizeof(data))
    # print(test)

if __name__ == '__main__':
    t1 = time.time()
    # test1()
    print(time.time()-t1)
    t2 = time.time()
    test2()
    print(time.time()-t2)