
    ZTh                         d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZ d dlmZmZmZ d dlmZ d dlmZ  e	        d Zed	k(  r e j,                   e              yy)
    N)datetime	timedeltatimezone)setup_logger)
SiftClient)ChannelChannelBitFieldElementChannelDataType)Flow)SiftConnectionConfigc                    K   t        j                  dd      } t        j                  dd      }t        j                  dd      }t        t        | ||dd      	      }d
}|j                  j                  dd      }|rIt        d|        |D ]6  }t        d|j                          |j                  j                  |       8 |j                  j                  dt        j                  t        j                        j                          dddg      }t        dt!        dt"        j$                        t!        dt"        j&                  ddd      g      }|j)                  t!        d t"        j*                  t-        d!d"d#$      t-        d%d#d$      t-        d&d'd$      t-        d(d)d$      g*             t        d+t!        d,t"        j$                        g      }|j.                  j0                  j3                  ||j4                  ||g-       d {   }	t        d.|	        	 |j)                  t!        dt"        j$                               t        d0t!        dt"        j$                        g      g}|j.                  j0                  j3                  d1|j4                  |-       d {    d2}d3}d3}d|z  }t        j                  t        j                        }t;        |      D ]J  }|t=        |4      z   }|j?                  |d5tA        jB                  dt@        jD                  z  |z  |z  d6z         z  |dz  dz   tG        jH                  d7d8      tG        jH                  dd7      tG        jJ                  d"dg      tG        jJ                  d"dg      d9d:;       t;        |      D ]q  }d5tA        jB                  dt@        jD                  z  |z  ||d<z  z   z  d"z         z  }|t=        ||z  d=z  >      z   }d,|i}|j0                  j?                  |||?       s tM        jN                  |       M |d"   j?                  |t=        |4      z   dd@i;       	 |j?                  |t=        |4      z   d"ddA;       	 |j?                  |t=        |4      z   d"dCtQ        dDg      d:;       	 |j?                  |t=        |4      z   d"dFtQ        dDg      d:;       |j.                  j0                  jS                  dH       t        j                  t        j                        }tM        jN                  d       t        dI       |j?                  |t=        |dz   4      z   dJdtQ        dKg      d:;       |j.                  j0                  jS                  dLH       |j                  j                  |j4                         |tU        |jV                        z  |z  |tU        |jV                        z  z   }t        dM||z
   dN       t        dO| dP       ||z
  jY                         }t        dQ||z  dRdS       y 7 2# t6        $ r}
t9        |
      d/k(  sJ Y d }
~
d }
~
ww xY w7 # t6        $ r}
dBt9        |
      v sJ Y d }
~
d }
~
ww xY w# t6        $ r}
dEt9        |
      v sJ Y d }
~
d }
~
ww xY w# t6        $ r}
dGt9        |
      v sJ Y d }
~
d }
~
ww xY ww)TNSIFT_GRPC_URIzlocalhost:50051SIFT_API_KEY SIFT_REST_URIzlocalhost:8080T)grpc_urlapi_keyrest_urluse_sslcert_via_openssl)connection_configzian-test-assetztest-run-.*z$1eba461b-fa36-4e98-8fe8-ff32d3e43a6e)
name_regexcreated_by_user_idz%   Deleting previously created runs: z   Deleting run: )runz	test-run-)tzzA test run created via the APIzapi-createdtest)namedescriptiontagsz	test-flowtest-channel)r   	data_typetest-enum-channel      )enum1enum2)r   r!   
enum_types)r   channelstest-bit-field-channel12vr      )r   index	bit_countchargeled   heater   )r   r!   bit_field_elementszhighspeed-flowzhighspeed-channel)
asset_namerun_idflowszconfig_id: z;ValueError('Cannot add a channel to a flow after creation')znew-asset-flowztest-asset-ian2g?2   )secondsg      @gQ?      )r*   r.   r/   r1   )r    r"   r)   )	timestampchannel_valuesgMbP?i  )milliseconds)flowr;   r<   gp=
ף)r    r"   z@Expected all channels in flow to have a data point at same time.U   zGCould not find enum value: -3 in enum options: {'enum1': 1, 'enum2': 2}znonexistent-enumzUCould not find enum value: nonexistent-enum in enum options: {'enum1': 1, 'enum2': 2})timeoutzRestarting ingestiongGz@   g{Gz?zIngestion time: z secondsz	Ingested z datapointszIngestion rate: z.2fz datapoints/second)-osgetenvr   r   runslistprintr   archivecreater   nowr   utcr;   r   r   r
   DOUBLEENUMadd_channel	BIT_FIELDr	   async_	ingestioncreate_ingestion_configid_
ValueErrorreprranger   ingestmathsinpirandomrandintchoicetimesleepbyteswait_for_ingestion_to_completelenr(   total_seconds)r   r   r   clientassetpreviously_created_runsr   regular_flowhighspeed_flow	config_ideother_asset_flows
sleep_timesimulated_durationfake_hs_ratefake_hs_periodstartirJ   jvalr;   r<   endnum_datapoints
total_times                             l/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_client/_tests/integrated/ingestion.pymainrx      s    yy*;<Hii+Gyy*:;H.!
F E %kk.. 5[ /  56M5NOP* 	)C%chhZ01KKC(	) ++

6@@BCD4V$  C ?3I3IJ()..%&3

L )%//&EaH&HAK&EaH&HAK	 		
 ,8N8NO
N mm--EEww^, F  I
 
K	{
#$X  nH^H^!_`
 	! ^7M7MN	
 --
!
!
9
9$ww :   
 JL%NLLHLL)E%& i** #dhhq477{\/IA/MPT/T&U U%&UQY!>>!R0$nnQ2!==!Q0$mmQF3	+	 	 	
 |$ 		ATWW|!;q1u9}!MPQ!QRRCiQ5G$5NOOI#SN ###y $ 		 	

:36 a),>??E
   
]i0BCC !%& 	 	

di0BCC !%'*/*= 	 	

i0BCC !%7*/*= 	 	
 MM::1:E
,,(,,
'CJJqM	
 !),>,BCC !"&+ZL&9
   MM::4:H
KKCGG$!C% /#l6K6K2LLMN 
S5[M
23	In%[
12+,,.J	^j8==O
PQ  XAwWWWWXl  ]QUYZ[U\\\\]  dX\`ab\ccccd  
cAw	

s   H[/Y[/2*Y A[/9Y::F1[/,#Y= .Z# ?.[	 -E$[/	Y7Y2,[/2Y77[/=	Z Z[/Z  [/#	[,[;[/[[/		[,['![/'[,,[/__main__)asynciorX   rC   r[   r^   r   r   r   sift_client._testsr   sift_client.clientr   sift_client.sift_types.channelr   r	   r
    sift_client.sift_types.ingestionr   sift_client.transportr   rx   __name__r        rw   <module>r      s^      	   2 2 + ) 
 2 6 ~RB zGKK r   