
    ZThh                         d dl Z d dlZd dlmZmZ d dlmZ d dlmZmZm	Z	m
Z
mZ 	 d Zedk(  r e j                   e              yy)    N)datetimetimezone)
SiftClient)CalculatedChannelUpdateChannelReference
RuleActionRuleAnnotationType
RuleUpdatec                    K   t        j                  dd      } t        j                  dd      }t        j                  dd      }t        | ||      }|j                  j	                  d	      }|j
                  }t        d
|j                         |j                  j                  d|      }d}d }|rpt        d|D 	cg c]  }	|	j                   c}	        |D ]D  }	|	j                  dk(  s|	j                  t        d|	j                              }t        d|       F nlt        d       |j                  j                  dddt        dd      t        dd      gd|gd      }t        d|j                   d|j                   d        d!}
t        d"|
        |j                   j                  |
#      }|rt        d$|D cg c]  }|j                   c}        |j                   j#                  |D cg c]  }|j$                   c}%      }t        d&|D cg c]  }|j                   c}        |d'   }t        d(|j                          |j                  t'        d)t)        j*                  t,        j.                  *      j1                          d |g+            }d,}nt        d-|
        |j                   j3                  |g.      }|r&t        d/|D cg c]  }|j                   c}        t        d0       |j                   j                  d1d2d3t        d|j                        gt5        j6                  t8        j:                  d4d5gd 6      7      }t        d8|j                   d|j$                   d        |rt        d9       |j=                          y y c c}	w c c}w c c}w c c}w c c}w w):NSIFT_GRPC_URIzlocalhost:50051SIFT_API_KEY SIFT_REST_URIzlocalhost:8080)grpc_urlapi_keyrest_urlNostromoLV426)namezFound assetzvelocity_per.*)
name_regexasset_idFzFound calculated channels: velocity_per_voltagez$1 / $2 + 0.1)
expressionexpression_channel_referenceszUpdated calculated channelz
Creating calculated channel...z&Ratio of mainmotor velocity to voltagez$1 / $2z$1zmainmotor.velocity)channel_referencechannel_identifierz$2voltagezvelocity/voltagez,Created to monitor velocity-to-voltage ratio)r   descriptionr   channel_referencesunits	asset_ids
user_noteszCreated calculated channel: z (ID: )high_velocity_voltagezLooking for rule containing )name_containszFound rules: )rule_idszBatch get on IDs also works: r   zUpdating rule: z=Alert when velocity-to-voltage ratio exceeds 0.1 (Updated at )tz)r   r    TzNo rules found for )r    zHowever these rules do exist: z?Attempting to create rule for high_velocity_voltage_ratio_alert!high_velocity_voltage_ratio_alertz0Alert when velocity-to-voltage ratio exceeds 0.1z$1 > 0.1
high_ratioalert)annotation_typetagsdefault_assignee_user_id)r   r   r   r   actionzCreated rule: z!Second run through, deleting rule)osgetenvr   assetsfindid_printr   calculated_channelslistupdater   r   creater   calculated_channel_idrules	batch_getrule_idr
   r   nowr   utc	isoformatsearchr   
annotationr	   DATA_REVIEWdelete)r   r   r   clientassetr   r4   updatedcalculated_channelccrule_searchr9   rules                r/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_client/examples/generic_workflow_example.pymainrK      s    yy*;<Hii+Gyy*:;H7XNFMMO4EyyH	-$ 4499# :  G+?R,SRWW,S+TUV% 	HBww00%'YY+#2686K6K&" 24FG	H 	01#77>>'@  4L`a 4IV  %jE ? 
 	*+=+B+B*C6J\JrJrIsstu	

 *K	(
67LL!  E U;Ttyy;<=>&&%0P$0P&Q-U.KTtyy.K-LMNQx		{+,{{[\d\h\hltlxlx\y  ]D  ]D  ]F  \G  GH  I#*
 #K=12##j $ 
 2%3P$DII3P2QRSOP||""4J! &*?Q?V?V 
 (( 2 > >"G,)- # 
 	tyyk~Q?@12 W -TH <0P.K" 4QsK   B<O>N.
O/CON3
"O=N8O"N=
5B1O&O
9CO__main__)asyncior.   r   r   sift_client.clientr   sift_client.sift_typesr   r   r   r	   r
   rK   __name__run     rJ   <module>rT      sF     	 ' ) 
^B zGKK rS   